BERT 是2018年Google提出的“11项全能模型”,在很多NLP场景里取得了非常好的结果。随着“Pretrain-Finetune”的模式逐渐发展,衍生出了很多类似的 BERT 类模型,我们统一把它们称之为预训练语言模型。除了对BERT预训练好的模型进行Finetune以外,BERT生成的向量本身也很有价值,我们也可以将BERT看做一个特征提取器,输入一个文本序列,输出一个向量的序列,同时我们可以将CLS输出的向量经过Dense后的向量作为整个句子的句向量。
image.png

读取数据

  1. if [ ! -f ./dev2.tsv ]; then
  2. wget http://atp-modelzoo-sh.oss-cn-shanghai.aliyuncs.com/release/tutorials/classification/dev2.tsv
  3. fi

跑代码提取特征

  1. easynlp \
  2. --mode=predict \
  3. --worker_gpu=1 \
  4. --tables=dev2.tsv \
  5. --outputs=dev.pred.tsv \
  6. --input_schema=label:str:1,sid1:str:1,sid2:str:1,sent1:str:1,sent2:str:1 \
  7. --output_schema=pooler_output,first_token_output,all_hidden_outputs \
  8. --first_sequence=sent1 \
  9. --append_cols=label \
  10. --checkpoint_dir=bert-small-uncased \
  11. --micro_batch_size=32 \
  12. --sequence_length=128 \
  13. --app_name=vectorization