MCPcopy Index your code
hub / github.com/zai-org/CodeGeeX / tokenize_wiki

Function tokenize_wiki

codegeex/mindspore/src/preprocess.py:107–121  ·  view source on GitHub ↗

tokenize wikitext-2/wikitext-103 dataset

(tokenizer, file_path, seq_length, eot)

Source from the content-addressed store, hash-verified

105
106
107def tokenize_wiki(tokenizer, file_path, seq_length, eot):
108 """tokenize wikitext-2/wikitext-103 dataset"""
109 content = []
110 with open(file_path, "r", encoding="utf-8") as f:
111 for para in clean_wikitext(f.read()).split("\n\n"):
112 if para and para.strip().startswith("=") is False:
113 tokenized_text = tokenizer.tokenize(para)
114 content += tokenizer.convert_tokens_to_ids(tokenized_text) + [
115 eot
116 ]
117 for chunk in chunks(content, seq_length):
118 sample = {}
119 if len(chunk) == seq_length:
120 sample["input_ids"] = np.array(chunk, dtype=np.int32)
121 yield sample
122
123
124def tokenize_lambada(tokenizer, file_path, seq_length, eot):

Callers 1

preprocess.pyFile · 0.85

Calls 5

clean_wikitextFunction · 0.85
chunksFunction · 0.85
readMethod · 0.80
tokenizeMethod · 0.45
convert_tokens_to_idsMethod · 0.45

Tested by

no test coverage detected