-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsamples_eda.py
More file actions
56 lines (42 loc) · 1.66 KB
/
Copy pathsamples_eda.py
File metadata and controls
56 lines (42 loc) · 1.66 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from huggingface_hub import snapshot_download
from pathlib import Path
import json
from transformers import AutoTokenizer
def samples_eda():
samples = Path(snapshot_download(
repo_id="Carson-Shively/ai-math-tutor",
repo_type="dataset",
allow_patterns=["train.json", "test.json"]
))
model_name = "Qwen/Qwen3-4B-Instruct-2507"
tokenizer = AutoTokenizer.from_pretrained(model_name)
with open(samples / "train.json", "r") as con:
train = json.load(con)
with open(samples / "test.json", "r") as con:
test = json.load(con)
train_structured = []
for sample in train:
train_structured.append({"messages": sample})
test_structured = []
for sample in test:
test_structured.append({"messages": sample})
train_count = 0
train_max_len = 0
for sample in train_structured:
text = tokenizer.apply_chat_template(sample["messages"], tokenize=True, add_generation_prompt=False)
if len(text["input_ids"]) > 2048:
train_count += 1
train_max_len = max(train_max_len, len(text["input_ids"]))
print(f"{train_count} exceed")
print(f"train max: {train_max_len}")
test_count = 0
test_max_len = 0
for sample in test_structured:
text = tokenizer.apply_chat_template(sample["messages"], tokenize=True, add_generation_prompt=False)
if len(text["input_ids"]) > 2048:
test_count += 1
test_max_len = max(test_max_len, len(text["input_ids"]))
print(f"{test_count} exceed")
print(f"test max: {test_max_len}")
if __name__ == "__main__":
samples_eda()