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