summaryrefslogtreecommitdiff
path: root/length.py
diff options
context:
space:
mode:
Diffstat (limited to 'length.py')
-rw-r--r--length.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/length.py b/length.py
new file mode 100644
index 0000000..06f8055
--- /dev/null
+++ b/length.py
@@ -0,0 +1,23 @@
1import json
2from transformers import AutoTokenizer
3
4MODEL_ID = "google/gemma-3-270m-it"
5DATASET_PATH = "train.jsonl"
6
7tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
8token_lengths = []
9
10print(f"Loading dataset from {DATASET_PATH}...")
11with open(DATASET_PATH, 'r', encoding='utf-8') as f:
12 for line in f:
13 entry = json.loads(line)
14 text = entry.get("text", "")
15 # Tokenize the text and get the number of tokens
16 length = len(tokenizer(text).input_ids)
17 token_lengths.append(length)
18
19print(f"Number of examples: {len(token_lengths)}")
20if token_lengths:
21 print(f"Min length: {min(token_lengths)}")
22 print(f"Max length: {max(token_lengths)}")
23 print(f"Average length: {sum(token_lengths) / len(token_lengths):.2f}")