Datasets:
added data, processing
Browse files- process.py +34 -0
- typescript-chunks.jsonl +0 -0
process.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datasets import Dataset, load_dataset
|
| 2 |
+
from transformers import AutoTokenizer
|
| 3 |
+
|
| 4 |
+
tokenizer = AutoTokenizer.from_pretrained('models/RedPajama-INCITE-Instruct-7B')
|
| 5 |
+
max_seq = 2048
|
| 6 |
+
|
| 7 |
+
def make_prompt(code):
|
| 8 |
+
return f'Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\n{code}\n\n### Response:\n'
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def is_not_too_long(data):
|
| 12 |
+
encoded = tokenizer.encode(make_prompt(data['content']))
|
| 13 |
+
return len(encoded) < max_seq
|
| 14 |
+
|
| 15 |
+
def deduplicate_dicts(dicts):
|
| 16 |
+
seen = {}
|
| 17 |
+
result = []
|
| 18 |
+
for d in dicts:
|
| 19 |
+
content = d.get('content')
|
| 20 |
+
if content not in seen:
|
| 21 |
+
seen[content] = True
|
| 22 |
+
result.append(d)
|
| 23 |
+
return result
|
| 24 |
+
|
| 25 |
+
dataset = load_dataset('json', data_files='ts_parser/ts-chunks.jsonl')
|
| 26 |
+
|
| 27 |
+
data_short = dataset.filter(is_not_too_long)
|
| 28 |
+
|
| 29 |
+
dedup = deduplicate_dicts(data_short['train'])
|
| 30 |
+
|
| 31 |
+
data_short_dedup = Dataset.from_list(dedup)
|
| 32 |
+
print(data_short_dedup)
|
| 33 |
+
|
| 34 |
+
data_short_dedup.to_json('typescript-chunks.json')
|
typescript-chunks.jsonl
ADDED
|
Binary file (55 MB). View file
|
|
|