代码拉取完成,页面将自动刷新
from tqdm import tqdm
with open('data/baike/formatted/baidubaike_corpus.txt', 'r') as f:
data = f.readlines()
vocab = {}
for line in tqdm(data):
line = line.lower().replace(' ', '')
line = list(line.strip())
for ch in line:
if ch not in vocab:
vocab[ch] = 1
else:
vocab[ch] += 1
vocab = {k: v for k, v in sorted(vocab.items(), key=lambda item: item[1], reverse=True)}
counter = 5
with open('tokenizers/bert_chinese_uncased_30k.vocab', 'w+') as f:
f.write('[UNK] 0\n')
f.write('[PAD] 0\n')
f.write('[CLS] 0\n')
f.write('[SEP] 0\n')
f.write('[MASK] 0\n')
for k,v in vocab.items():
if counter >= 30000:
break
f.write(k+' '+str(v)+'\n')
counter += 1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。