Google BERT模型提取句子Token特征
生活随笔
收集整理的这篇文章主要介绍了
Google BERT模型提取句子Token特征
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
BERT模型:https://github.com/google-research/bert#fine-tuning-with-bert
环境:linux+python3+tensorflow,也有pytorch版。
1、下载:
- BERT-Base, Chinese: Chinese Simplified and Traditional, 12-layer, 768-hidden, 12-heads, 110M parameters
解压到指定目录。
2、Git Clone下https://github.com/google-research/bert.git
3、输入句子到指定文件:
echo '如图,a、b、c分别是数轴上A、B、C所对应的实数,试化简' > edp/input.txt4、执行:
python3 bert/extract_features.py \--input_file=edp/input.txt \--output_file=edp/output.json \--vocab_file=chinese_L-12_H-768_A-12/vocab.txt \--bert_config_file=chinese_L-12_H-768_A-12/bert_config.json \--init_checkpoint=chinese_L-12_H-768_A-12/bert_model.ckpt \--layers=-1 \--max_seq_length=128 \--batch_size=8具体参数参考github上解释。
5、如果有自己特定预料,可以在谷歌训练的模型上再预训练。
参考:https://daiwk.github.io/posts/nlp-bert-code.html#pretrained-model
由于句子长度不一样,token数不一样,每个token的向量长度一样,但token数不一样,一个句子的总体向量长度也就不一样。
总结
以上是生活随笔为你收集整理的Google BERT模型提取句子Token特征的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 概率分布函数的关系框架
- 下一篇: Bert-as-Service库Embe