深度学习模型bert中文多分类准备工作

1、得到语料之后,初步决定使用bert模型来完成文本分类。有Google和哈工大两种,Google是字粒度,哈工大是词粒度,哈工大的好像没有开源代码

https://github.com/ymcui/Chinese-BERT-wwmhttps://github.com/ymcui/Chinese-BERT-wwmGitHub - renxingkai/BERT_Chinese_Classification: 本实验,是用BERT进行中文情感分类,记录了详细操作及完整程序https://github.com/renxingkai/BERT_Chinese_Classification这是一个在线工具包Online Tools, Utilities for developers, webmasters | WTOOLS

2、用Google的模型

3、用自己电脑的gpu跑数据,查看自己电脑的型号(GeForce mx150)适配的cuda和cudnn型号

安装vs2017、cuda9.0、cudnn7.6.5、新建虚拟python环境3.6、安装tensorflow-gpu1.12.0

安装很慢:vs用站长工具查询IP;cuda用迅雷下载;cudnn百度云资源;

Dns检测|Dns查询 - 站长工具

4、环境配置完成,接下来就是代码部分了(24条消息) 基于BERT做中文文本分类(情感分析)_我开心呀的博客-CSDN博客_bert中文情感分析

用自己的电脑跑gpu显存不够用,放弃(所以以上又是漫长的弯路行走的一天)

5、转向天池,天池要排队,放弃

6、转向colab,去github搜科学上网解决网络问题

7、无法从网站上传文件,故下载云端硬盘客户端

8、colab自己的版本是tensorflow2,代码是1.x,需要替换为1.x,然后刷新(必须刷新!restart runtime)

卸载!pip uninstall tensorflow

pip install tensorflow-gpu==1.13.1

pip install numpy==1.16.0

!pip install tf-nightly

cd /content/drive/MyDrive/BERT_CC

%tensorflow_version 1.x

9、结果1花了12分钟(out)

!python run_classifier.py --task_name=mytask --do_train=true --do_eval=true  --data_dir=/content/drive/MyDrive/data/ --vocab_file=/content/drive/MyDrive/bert-chinese/chinese/vocab.txt --bert_config_file=/content/drive/MyDrive/bert-chinese/chinese/bert_config.json --init_checkpoint=/content/drive/MyDrive/bert-chinese/chinese/bert_model.ckpt --max_seq_length=64 --train_batch_size=4 --learning_rate=2e-5 --num_train_epochs=3.0 --output_dir=/content/drive/MyDrive/bert-chinese/out

 结果2花了13分钟--max_seq_length=128 --train_batch_size=8

结果3也是13分钟--max_seq_legnth=512 --train_batch_size=8 --learning_rate=2e-5 --num_train_epochs=6.0

 

--max_seq_length=256 --train_batch_size=8 --learning_rate=2e-5 --num_train_epochs=6.0

42分钟

 

总结,只是初步,后期还要对数据进行一些改善,虽然这个准确率已经这么高了(也不知道为啥,其实考虑到对于长文本来说这种不大合理,不知道预测结果怎么样。

10、预测-(24条消息) 基于BERT做中文文本分类(情感分析)_我开心呀的博客-CSDN博客_bert中文情感分析

!python run_classifier.py --task_name=mytask --do_predict=true --data_dir=/content/drive/MyDrive/data/ --vocab_file=/content/drive/MyDrive/bert-chinese/chinese/vocab.txt --bert_config_file=/content/drive/MyDrive/bert-chinese/chinese/bert_config.json --init_checkpoint=/content/drive/MyDrive/bert-chinese/out1 --max_seq_length=512 --output_dir=/content/drive/MyDrive/bert-chinese/predict_out/

预测结果91.87

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值