All Projects → yaleimeng → Textclassify_with_bert

yaleimeng / Textclassify_with_bert

使用BERT模型做文本分类;面向工业用途

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Textclassify with bert

Neuronblocks
NLP DNN Toolkit - Building Your NLP DNN Models Like Playing Lego
Stars: ✭ 1,356 (+959.38%)
Mutual labels:  text-classification
Text rnn attention
嵌入Word2vec词向量的RNN+ATTENTION中文文本分类
Stars: ✭ 117 (-8.59%)
Mutual labels:  text-classification
Dan Jurafsky Chris Manning Nlp
My solution to the Natural Language Processing course made by Dan Jurafsky, Chris Manning in Winter 2012.
Stars: ✭ 124 (-3.12%)
Mutual labels:  text-classification
Texting
[ACL 2020] Tensorflow implementation for "Every Document Owns Its Structure: Inductive Text Classification via Graph Neural Networks"
Stars: ✭ 103 (-19.53%)
Mutual labels:  text-classification
Pytorch Rnn Text Classification
Word Embedding + LSTM + FC
Stars: ✭ 112 (-12.5%)
Mutual labels:  text-classification
Classifier multi label textcnn
multi-label,classifier,text classification,多标签文本分类,文本分类,BERT,ALBERT,multi-label-classification
Stars: ✭ 116 (-9.37%)
Mutual labels:  text-classification
Doc2vec
📓 Long(er) text representation and classification using Doc2Vec embeddings
Stars: ✭ 92 (-28.12%)
Mutual labels:  text-classification
Ml Projects
ML based projects such as Spam Classification, Time Series Analysis, Text Classification using Random Forest, Deep Learning, Bayesian, Xgboost in Python
Stars: ✭ 127 (-0.78%)
Mutual labels:  text-classification
Rnn Text Classification Tf
Tensorflow Implementation of Recurrent Neural Network (Vanilla, LSTM, GRU) for Text Classification
Stars: ✭ 114 (-10.94%)
Mutual labels:  text-classification
Python Stop Words
Get list of common stop words in various languages in Python
Stars: ✭ 122 (-4.69%)
Mutual labels:  text-classification
Fastrtext
R wrapper for fastText
Stars: ✭ 103 (-19.53%)
Mutual labels:  text-classification
Kadot
Kadot, the unsupervised natural language processing library.
Stars: ✭ 108 (-15.62%)
Mutual labels:  text-classification
Context
ConText v4: Neural networks for text categorization
Stars: ✭ 120 (-6.25%)
Mutual labels:  text-classification
Text Classification
An example on how to train supervised classifiers for multi-label text classification using sklearn pipelines
Stars: ✭ 100 (-21.87%)
Mutual labels:  text-classification
Cluedatasetsearch
搜索所有中文NLP数据集,附常用英文NLP数据集
Stars: ✭ 2,112 (+1550%)
Mutual labels:  text-classification
Tia
Your Advanced Twitter stalking tool
Stars: ✭ 98 (-23.44%)
Mutual labels:  text-classification
Bdci2017 Minglue
BDCI2017-让AI当法官,决赛第四(4/415)https://www.datafountain.cn/competitions/277/details
Stars: ✭ 118 (-7.81%)
Mutual labels:  text-classification
Fasttext.js
FastText for Node.js
Stars: ✭ 127 (-0.78%)
Mutual labels:  text-classification
Rcnn Text Classification
Tensorflow Implementation of "Recurrent Convolutional Neural Network for Text Classification" (AAAI 2015)
Stars: ✭ 127 (-0.78%)
Mutual labels:  text-classification
Nlp Pretrained Model
A collection of Natural language processing pre-trained models.
Stars: ✭ 122 (-4.69%)
Mutual labels:  text-classification

TextClassify_with_BERT

使用BERT模型做文本分类;面向工业用途

  • 自己研究了当前开源的使用BERT做文本分类的许多存储库,各有各的缺点。通病就是面向学术,不考虑实际应用。
  • 使用txt、tsv、csv等不同数据集也就算了,有些项目甚至似乎存在bug。所以还是要自己动手解决。
  • 已经较为完整可用,欢迎收藏加关注。有问题可提issue交流。

与同类代码库相比的亮点:

  • 在自定义Processor类中添加了针对单条文本的处理方法。在常规的针对test数据集的predict方法之外添加了针对单条数据的类别预测方法。
  • 编写了简单的web服务,直接搭建对外服务的API接口。
  • estimator 从 tf.contrib.tpu.TPUEstimator换成 tf.estimator.Estimator,以便在 gpu 上更高效运行。于此同时 model_fn 里tf.contrib.tpu.TPUEstimatorSpec 也修改成 tf.estimator.EstimatorSpec形式,相关调用参数也做了调整。
  • 在转换成较普通的 estimator 后便可以使用常用方式处理,如生成用于部署的 *.pb 文件等。

使用方法:

  1. 准备工作
  1. 单机运行
  • 在arguments.py中修改运行参数。主要是数据目录、BERT目录、模型目录、序列长度、batch大小、学习率等。

如果仅对test.txt执行预测,只需要把 do_predict 设为True,do_train 与do_eval 设置为false。

  • 训练+评估:运行train_eval.py

如果上面步骤进展顺利,恭喜,在输出目录内已经生成了训练和评估结果。屏幕上也打印出了评估准确率等。

  • 测试:先修改自己要测试的问题,运行predict_GPU.py
  1. 使用自己的真实数据集。修改训练参数,重新进行训练和评估。
  2. 搭建分类预测服务
  • 使用自己的pb模型+开源框架。 【强烈推荐】
  • 运行server.py 【仅供玩耍】
  • 有pb模型自己使用TensorFlow Serving部署
  1. 关于用bert-base搭建服务的简介:
  • 在服务器端、客户端安装:pip install bert-base
  • 在PB模型所在目录下新建一个 run.sh文件,写入以下内容:

bert-base-serving-start \ -model_dir ./ \ # 训练输出目录【主要是其他Mode用到】。 -bert_model_dir F:\chinese_L-12_H-768_A-12 # BERT自身的目录。 -model_pb_dir ./ \ # pb模型路径,就填./ 当前目录就行了。。 -mode CLASS \ # 运行模式,分类就是CLASS -max_seq_len 200 \ # 最大序列长度。要跟训练时参数一致。

  • 运行编写好的run.sh,如果没报错,提示已经开始监听的话就表示服务成功开启。可以使用客户端运行示例了。 非本机运行的话,构造BertClient时需要设置ip参数,例如BertClient(ip=192.168.20.20 )。
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].