BERT 是2018年Google提出的“11项全能模型”,在很多NLP场景里取得了非常好的结果。随着“Pretrain-Finetune”的模式逐渐发展,衍生出了很多类似的 BERT 类模型,我们统一把它们称之为预训练语言模型。除了对BERT预训练好的模型进行Finetune以外,BERT生成的向量本身也很有价值,我们也可以将BERT看做一个特征提取器,输入一个文本序列,输出一个向量的序列,同时我们可以将CLS输出的向量经过Dense后的向量作为整个句子的句向量。
读取数据
if [ ! -f ./dev2.tsv ]; thenwget http://atp-modelzoo-sh.oss-cn-shanghai.aliyuncs.com/release/tutorials/classification/dev2.tsvfi
跑代码提取特征
easynlp \--mode=predict \--worker_gpu=1 \--tables=dev2.tsv \--outputs=dev.pred.tsv \--input_schema=label:str:1,sid1:str:1,sid2:str:1,sent1:str:1,sent2:str:1 \--output_schema=pooler_output,first_token_output,all_hidden_outputs \--first_sequence=sent1 \--append_cols=label \--checkpoint_dir=bert-small-uncased \--micro_batch_size=32 \--sequence_length=128 \--app_name=vectorization
