-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
59 lines (40 loc) · 1.46 KB
/
main.py
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
57
58
59
# Copyright 2023-present Kensho Technologies, LLC.
import sys
import time
import pandas as pd
import pathpiece
CORPUS = "corpus_tiny.csv"
tokenizer = pathpiece.Tokenizer("pathpiece/data/vdump_32768.vocab")
if CORPUS == "corpus_tiny.csv":
corpus_len = 5
elif CORPUS == "corpus_train.csv":
corpus_len = 10 ** 6
def test_load_corpus():
start_time = time.time()
df = pd.read_csv(f'pathpiece/data/{CORPUS}') # excludes header
corpus = df.iloc[:, 0].tolist()
print(f"Corpus loaded [{round(time.time() - start_time)}s]")
try:
assert len(corpus) == corpus_len
except AssertionError:
print(f'{len(corpus)} ≠ {corpus_len}')
raise
return corpus
def test_max_len():
assert tokenizer.get_max_len() == 16
print(f"Max Len Passed")
def test_encode_decode_inverse(corpus):
start_time = time.time()
for i in range(corpus_len):
assert corpus[i] == tokenizer.decode(tokenizer(corpus[i])["input_ids"])
print(f"Encode-Decode Passed [{round(time.time() - start_time)}s]")
def test_encode_decode_batch_inverse(corpus):
start_time = time.time()
assert corpus == tokenizer.decode_batch(tokenizer(corpus)["input_ids"])
print(f"Batch Encode-Decode Passed [{round(time.time() - start_time)}s]")
start_time = time.time()
corpus = test_load_corpus()
test_max_len()
test_encode_decode_inverse(corpus)
test_encode_decode_batch_inverse(corpus)
print(f"All tests passed [{round(time.time() - start_time)}s]")