UER-py icon indicating copy to clipboard operation
UER-py copied to clipboard

添加额外专业词汇

Open srhouyu opened this issue 5 years ago • 1 comments

我有一些专业词汇想添加进词典。 google_zh_vocab.txt 里面有100个空位,但是这个数量远远达不到需求。不知道我如果想添加成千上万的专业词汇该怎么办?

在这个回答中看到,在词典中加新词是可以的 https://github.com/google-research/bert/issues/9

(b) Append it to the end of the vocab, and write a script which generates a new checkpoint that is identical to the pre-trained checkpoint, but but with a bigger vocab where the new embeddings are randomly initialized (for initialized we used tf.truncated_normal_initializer(stddev=0.02)). This will likely require mucking around with some tf.concat() and tf.assign() calls.

但是具体怎么做我也不太懂。

所以,不知道UER-py能否考虑加入附加词典的功能呢?

srhouyu avatar Jun 29 '20 03:06 srhouyu

您好 使用scritps文件夹下面的dynamic_vocab_adapter.py就可以 这个脚本会根据旧的词典和新的词典的区别修改embedding层和softmax前一层,从而得到新的预训练模型 新的词对应的向量会随机初始化 然后我们可以在新的预训练模型基础上增量预训练或者微调

zhezhaoa avatar Sep 20 '20 15:09 zhezhaoa