-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsplit_data.py
More file actions
30 lines (23 loc) · 816 Bytes
/
Copy pathsplit_data.py
File metadata and controls
30 lines (23 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import fire
import jsonlines
from transformers import LlamaTokenizer
def main(
dataset_path: str="./pretrain_cht_test.jsonl",
output_path: str="./pretrain_cht_test_1B.jsonl",
model_name: str="meta-llama/Llama-2-7b-chat-hf",
split_length: int=1000000000,
):
total_length = 0
tokenizer = LlamaTokenizer.from_pretrained(model_name)
sub_data = []
with jsonlines.open(dataset_path, "r") as reader:
for d in reader:
total_length += len(tokenizer(d["text"], add_special_tokens=False).input_ids)
sub_data.append(d)
if total_length > split_length:
print(total_length)
break
with jsonlines.open(output_path, "w") as writer:
writer.write_all(sub_data)
if __name__ == "__main__":
fire.Fire(main)