1 Star 0 Fork 0

yangxin/SubCharTokenization

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
build_vocab_bertzh.py 769 Bytes
一键复制 编辑 原始数据 按行查看 历史
NoviScl 提交于 2021-12-22 21:11 . push
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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yx75/SubCharTokenization.git
git@gitee.com:yx75/SubCharTokenization.git
yx75
SubCharTokenization
SubCharTokenization
main

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385