版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/fjssharpsword/article/details/89407194
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.txt
4、执行:
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数不一样,一个句子的总体向量长度也就不一样。