Colab来训练bert模型

Colab使用

1.切换tensorflow版本号

%tensorflow_version 1.x

2.查看tensorflow版本

!pip show tensorflow

3.训练模型

!python /content/drive/My\ Drive/bert/run_english_classify.py --task_name=mypro  --do_train=true --do_eval=true  --data_dir=/content/drive/My\ Drive/english --vocab_file=/content/drive/My\ Drive/wwm_uncased_L-24_H-1024_A-16/vocab.txt --bert_config_file=/content/drive/My\ Drive/wwm_uncased_L-24_H-1024_A-16/bert_config.json --num_train_epochs=100 --train_batch_size=5 --max_seq_length=50 --output_dir=/content/drive/My\ Drive/english_model/fine-tuning-model

4.导出模型

!python /content/drive/My\ Drive/bert/run_english_classify.py --task_name=mypro --do_predict=true --data_dir=/content/drive/My\ Drive/english --vocab_file=/content/drive/My\ Drive/wwm_uncased_L-24_H-1024_A-16/vocab.txt --bert_config_file=/content/drive/My\ Drive/wwm_uncased_L-24_H-1024_A-16/bert_config.json --init_checkpoint=/content/drive/My\ Drive/english_model/fine-tuning-model --max_seq_length=128 --output_dir=content/drive/My\ Drive/english_model/fine-tuning-model --export_model_dir=/content/drive/My\ Drive/english_model/export-model

5.运行在tf-serving上

docker run -p 8501:8501 --mount type=bind,source=/root/bert/export-model,target=/models/chnsenticorp -e MODEL_NAME=chnsenticorp -t tensorflow/serving

你可能感兴趣的:(自然语言处理)