Home
Softono
y

yongzhuo

Professional software vendor delivering innovative solutions on the Softono platform. Specialized in both open-source and proprietary software development.

Total Products
2

Software by yongzhuo

Keras-TextClassification
Open Source

Keras-TextClassification

# [Keras-TextClassification](https://github.com/yongzhuo/Keras-TextClassification) [![PyPI](https://img.shields.io/pypi/v/Keras-TextClassification)](https://pypi.org/project/Keras-TextClassification/) [![Build Status](https://travis-ci.com/yongzhuo/Keras-TextClassification.svg?branch=master)](https://travis-ci.com/yongzhuo/Keras-TextClassification) [![PyPI_downloads](https://img.shields.io/pypi/dm/Keras-TextClassification)](https://pypi.org/project/Keras-TextClassification/) [![Stars](https://img.shields.io/github/stars/yongzhuo/Keras-TextClassification?style=social)](https://github.com/yongzhuo/Keras-TextClassification/stargazers) [![Forks](https://img.shields.io/github/forks/yongzhuo/Keras-TextClassification.svg?style=social)](https://github.com/yongzhuo/Keras-TextClassification/network/members) [![Join the chat at https://gitter.im/yongzhuo/Keras-TextClassification](https://badges.gitter.im/yongzhuo/Keras-TextClassification.svg)](https://gitter.im/yongzhuo/Keras-TextClassification?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) # Install(安装) ```bash pip install Keras-TextClassification ``` ```python step2: download and unzip the dir of 'data.rar', 地址: 链接:https://pan.baidu.com/s/1pIDzGaGXCZ7cjng1XU_kPA 提取码:w6ps 压缩包密码: 2022 cover the dir of data to anaconda, like '/anaconda/3.5.1/envs/tensorflow13/Lib/site-packages/keras_textclassification/data' step3: goto # Train&Usage(调用) and Predict&Usage(调用) ``` # keras_textclassification(代码主体,未完待续...) - Electra-fineture(todo) - Albert-fineture - Xlnet-fineture - Bert-fineture - FastText - TextCNN - charCNN - TextRNN - TextRCNN - TextDCNN - TextDPCNN - TextVDCNN - TextCRNN - DeepMoji - SelfAttention - HAN - CapsuleNet - Transformer-encode - SWEM - LEAM - TextGCN(todo) # run(运行, 以FastText为例) - 1. 进入keras_textclassification/m01_FastText目录, - 2. 训练: 运行 train.py, 例如: python train.py - 3. 预测: 运行 predict.py, 例如: python predict.py - 说明: 默认不带pre train的random embedding,训练和验证语料只有100条,完整语料移步下面data查看下载 # run(多标签分类/Embedding/test/sample实例) - bert,word2vec,random样例在test/目录下, 注意word2vec(char or word), random-word, bert(chinese_L-12_H-768_A-12)未全部加载,需要下载 - multi_multi_class/目录下以text-cnn为例进行多标签分类实例,转化为multi-onehot标签类别,分类则取一定阀值的类 - sentence_similarity/目录下以bert为例进行两个句子文本相似度计算,数据格式如data/sim_webank/目录下所示 - predict_bert_text_cnn.py - tet_char_bert_embedding.py - tet_char_bert_embedding.py - tet_char_xlnet_embedding.py - tet_char_random_embedding.py - tet_char_word2vec_embedding.py - tet_word_random_embedding.py - tet_word_word2vec_embedding.py # keras_textclassification/data - 数据下载 ** github项目中只是上传部分数据,需要的前往链接: https://pan.baidu.com/s/1I3vydhmFEQ9nuPG2fDou8Q 提取码: rket - baidu_qa_2019(百度qa问答语料,只取title作为分类样本,17个类,有一个是空'',已经压缩上传) - baike_qa_train.csv - baike_qa_valid.csv - byte_multi_news(今日头条2018新闻标题多标签语料,1070个标签,fate233爬取, 地址为: [byte_multi_news](https://github.com/fate233/toutiao-multilevel-text-classfication-dataset)) -labels.csv -train.csv -valid.csv - embeddings - chinese_L-12_H-768_A-12/(取谷歌预训练好点的模型,已经压缩上传, keras-bert还可以加载百度版ernie(需转换,[https://github.com/ArthurRizar/tensorflow_ernie](https://github.com/ArthurRizar/tensorflow_ernie)), 哈工大版bert-wwm(tf框架,[https://github.com/ymcui/Chinese-BERT-wwm](https://github.com/ymcui/Chinese-BERT-wwm)) - albert_base_zh/(brightmart训练的albert, 地址为https://github.com/brightmart/albert_zh) - chinese_xlnet_base_L-12_H-768_A-12/(哈工大预训练的中文xlnet模型[https://github.com/ymcui/Chinese-PreTrained-XLNet],12层) - term_char.txt(已经上传, 项目中已全, wiki字典, 还可以用新华字典什么的) - term_word.txt(未上传, 项目中只有部分, 可参考词向量的) - w2v_model_merge_short.vec(未上传, 项目中只有部分, 词向量, 可以用自己的) - w2v_model_wiki_char.vec(已上传百度网盘, 项目中只有部分, 自己训练的维基百科字向量, 可以用自己的) - model - fast_text/预训练模型存放地址 # 项目说明 - 1. 构建了base基类(网络(graph)、向量嵌入(词、字、句子embedding)),后边的具体模型继承它们,代码简单 - 2. keras_layers存放一些常用的layer, conf存放项目数据、模型的地址, data存放数据和语料, data_preprocess为数据预处理模块, # 模型与论文paper题与地址 * FastText: [Bag of Tricks for Efficient Text Classification](https://arxiv.org/abs/1607.01759) * TextCNN: [Convolutional Neural Networks for Sentence Classification](https://arxiv.org/abs/1408.5882) * charCNN-kim: [Character-Aware Neural Language Models](https://arxiv.org/abs/1508.06615) * charCNN-zhang: [Character-level Convolutional Networks for Text Classification](https://arxiv.org/pdf/1509.01626.pdf) * TextRNN: [Recurrent Neural Network for Text Classification with Multi-Task Learning](https://www.ijcai.org/Proceedings/16/Papers/408.pdf) * RCNN: [Recurrent Convolutional Neural Networks for Text Classification](http://www.nlpr.ia.ac.cn/cip/~liukang/liukangPageFile/Recurrent%20Convolutional%20Neural%20Networks%20for%20Text%20Classification.pdf) * DCNN: [A Convolutional Neural Network for Modelling Sentences](https://arxiv.org/abs/1404.2188) * DPCNN: [Deep Pyramid Convolutional Neural Networks for Text Categorization](https://www.aclweb.org/anthology/P17-1052) * VDCNN: [Very Deep Convolutional Networks](https://www.aclweb.org/anthology/E17-1104) * CRNN: [A C-LSTM Neural Network for Text Classification](https://arxiv.org/abs/1511.08630) * DeepMoji: [Using millions of emojio ccurrences to learn any-domain represent ations for detecting sentiment, emotion and sarcasm](https://arxiv.org/abs/1708.00524) * SelfAttention: [Attention Is All You Need](https://arxiv.org/abs/1706.03762) * HAN: [Hierarchical Attention Networks for Document Classification](https://www.cs.cmu.edu/~diyiy/docs/naacl16.pdf) * CapsuleNet: [Dynamic Routing Between Capsules](https://arxiv.org/pdf/1710.09829.pdf) * Transformer(encode or decode): [Attention Is All You Need](https://arxiv.org/abs/1706.03762) * Bert: [BERT: Pre-trainingofDeepBidirectionalTransformersfor LanguageUnderstanding]() * Xlnet: [XLNet: Generalized Autoregressive Pretraining for Language Understanding](https://arxiv.org/abs/1906.08237) * Albert: [ALBERT: A LITE BERT FOR SELF-SUPERVISED LEARNING OF LANGUAGE REPRESENTATIONS](https://arxiv.org/pdf/1909.11942.pdf) * RoBERTa: [RoBERTa: A Robustly Optimized BERT Pretraining Approach](https://arxiv.org/abs/1907.11692) * ELECTRA: [ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators](https://openreview.net/pdf?id=r1xMH1BtvB) * TextGCN: [Graph Convolutional Networks for Text Classification](https://arxiv.org/abs/1809.05679) # 参考/感谢 * 文本分类项目: [https://github.com/mosu027/TextClassification](https://github.com/mosu027/TextClassification) * 文本分类看山杯: [https://github.com/brightmart/text_classification](https://github.com/brightmart/text_classification) * Kashgari项目: [https://github.com/BrikerMan/Kashgari](https://github.com/BrikerMan/Kashgari) * 文本分类Ipty : [https://github.com/lpty/classifier](https://github.com/lpty/classifier) * keras文本分类: [https://github.com/ShawnyXiao/TextClassification-Keras](https://github.com/ShawnyXiao/TextClassification-Keras) * keras文本分类: [https://github.com/AlexYangLi/TextClassification](https://github.com/AlexYangLi/TextClassification) * CapsuleNet模型: [https://github.com/bojone/Capsule](https://github.com/bojone/Capsule) * transformer模型: [https://github.com/CyberZHG/keras-transformer](https://github.com/CyberZHG/keras-transformer) * keras_albert_model: [https://github.com/TinkerMob/keras_albert_model](https://github.com/TinkerMob/keras_albert_model) # 训练简单调用: ```python from keras_textclassification import train train(graph='TextCNN', # 必填, 算法名, 可选"ALBERT","BERT","XLNET","FASTTEXT","TEXTCNN","CHARCNN", # "TEXTRNN","RCNN","DCNN","DPCNN","VDCNN","CRNN","DEEPMOJI", # "SELFATTENTION", "HAN","CAPSULE","TRANSFORMER" label=17, # 必填, 类别数, 训练集和测试集合必须一样 path_train_data=None, # 必填, 训练数据文件, csv格式, 必须含'label,ques'头文件, 详见keras_textclassification/data path_dev_data=None, # 必填, 测试数据文件, csv格式, 必须含'label,ques'头文件, 详见keras_textclassification/data rate=1, # 可填, 训练数据选取比例 hyper_parameters=None) # 可填, json格式, 超参数, 默认embedding为'char','random' ``` # Reference For citing this work, you can refer to the present GitHub project. For example, with BibTeX: ``` @misc{Keras-TextClassification, howpublished = {\url{https://github.com/yongzhuo/Keras-TextClassification}}, title = {Keras-TextClassification}, author = {Yongzhuo Mo}, publisher = {GitHub}, year = {2019} } ``` *希望对你有所帮助!

AI & Machine Learning Developer Tools ML Frameworks
1.8K Github Stars
nlp_xiaojiang
Open Source

nlp_xiaojiang

# nlp_xiaojiang # AugmentText - 回译(效果比较好) - EDA(同义词替换、插入、交换和删除)(效果还行) - HMM-marko(质量较差) - syntax(依存句法、句法、语法书)(简单句还可) - seq2seq(深度学习同义句生成,效果不理想,seq2seq代码大都是 [https://github.com/qhduan/just_another_seq2seq] 的,效果不理想) - 预训练(UNILM生成、开源模型回译) # ChatBot - 检索式ChatBot - 像ES那样直接检索(如使用fuzzywuzzy),只能字面匹配 - 构造句向量,检索问答库,能够检索有同义词的句子 - 生成式ChatBot(todo) - seq2seq - GAN # ClassificationText - bert+bi-lstm(keras) approach 0.78~0.79% acc of weBank Intelligent Customer Service Question Matching Competition - bert + text-cnn(keras) approach 0.78~0.79% acc of weBank Intelligent Customer Service Question Matching Competition - bert + r-cnn(keras) approach 0.78~0.79% acc of weBank Intelligent Customer Service Question Matching Competition - bert + avt-cnn(keras) approach 0.78~0.79% acc of weBank Intelligent Customer Service Question Matching Competition # Ner - bert命名实体提取(bert12层embedding + bilstm + crf) - args.py(配置一些参数) - keras_bert_embedding.py(bert embedding) - keras_bert_layer.py(layer层, 主要有CRF和NonMaskingLayer) - keras_bert_ner_bi_lstm.py(主函数, 定义模型、数据预处理和训练预测等) - layer_crf_bojone.py(CRF层, 未使用) # FeatureProject - bert句向量、文本相似度 - bert/extract_keras_bert_feature.py:提取bert句向量特征 - bert/tet_bert_keras_sim.py:测试xlnet句向量cosin相似度 - xlnet句向量、文本相似度 - xlnet/extract_keras_xlnet_feature.py:提取bert句向量特征 - xlnet/tet_xlnet_keras_sim.py:测试bert句向量cosin相似度 - normalization_util指的是数据归一化 - 0-1归一化处理 - 均值归一化 - sig归一化处理 - sim feature(ML) - distance_text_or_vec:各种计算文本、向量距离等 - distance_vec_TS_SS:TS_SS计算词向量距离 - cut_td_idf:将小黄鸡语料和gossip结合 - sentence_sim_feature:计算两个文本的相似度或者距离,例如qq(问题和问题),或者qa(问题和答案) # run(可以在win10下,pycharm下运行) - 1.创建tf-idf文件等(运行2需要先跑1): ``` python cut_td_idf.py ``` - 2.计算两个句子间的各种相似度,先计算一个预定义的,然后可输入自定义的(先跑1): ``` python sentence_sim_feature.py ``` - 3.chatbot_1跑起来(fuzzy检索-没)(独立): ``` python chatbot_fuzzy.py ``` - 4.chatbot_2跑起来(句向量检索-词)(独立): ``` python chatbot_sentence_vec_by_word.py ``` - 5.chatbot_3跑起来(句向量检索-字)(独立): ``` python chatbot_sentence_vec_by_char.py ``` - 6.数据增强(eda): python enhance_eda.py - 7.数据增强(marko): python enhance_marko.py - 8.数据增强(translate_account): python translate_tencent_secret.py - 9.数据增强(translate_tools): python translate_translate.py - 10.数据增强(translate_web): python translate_google.py - 11.数据增强(augment_seq2seq): 先跑 python extract_char_webank.py生成数据, 再跑 python train_char_anti.py 然后跑 python predict_char_anti.py - 12.特征计算(bert)(提取特征、计算相似度): ``` run extract_keras_bert_feature.py run tet_bert_keras_sim.py ``` # Data - chinese_L-12_H-768_A-12(谷歌预训练好的模型) github项目中只是上传部分数据,需要的前往链接: https://pan.baidu.com/s/1I3vydhmFEQ9nuPG2fDou8Q 提取码: rket 解压后就可以啦 - chinese_xlnet_mid_L-24_H-768_A-12(哈工大训练的中文xlnet, mid, 24层, wiki语料+通用语料) - 下载地址[https://github.com/ymcui/Chinese-PreTrained-XLNet](https://github.com/ymcui/Chinese-PreTrained-XLNet) - chinese_vector github项目中只是上传部分数据,需要的前往链接: https://pan.baidu.com/s/1I3vydhmFEQ9nuPG2fDou8Q 提取码: rket - 截取的部分word2vec训练词向量(自己需要下载全效果才会好) - w2v_model_wiki_char.vec、w2v_model_wiki_word.vec都只有部分,词向量w2v_model_wiki_word.vec可以用这个下载地址的替换[https://pan.baidu.com/s/14JP1gD7hcmsWdSpTvA3vKA](https://pan.baidu.com/s/14JP1gD7hcmsWdSpTvA3vKA) - corpus github项目中只是上传部分数据,需要的前往链接: https://pan.baidu.com/s/1I3vydhmFEQ9nuPG2fDou8Q 提取码: rket - ner(train、dev、test----人民日报语料) - webank(train、dev、test) - 小黄鸡和gossip问答预料(数据没清洗),chicken_and_gossip.txt - 微众银行和支付宝文本相似度竞赛数据, sim_webank.csv - sentence_vec_encode_char - 1.txt(字向量生成的前100000句向量) - sentence_vec_encode_word - 1.txt(词向量生成的前100000句向量) - tf_idf(chicken_and_gossip.txt生成的tf-idf) # requestments.txt - python_Levenshtei - 调用Levenshtein,我的python是3.6, - 打开其源文件: https://www.lfd.uci.edu/~gohlke/pythonlibs/ - 查找python_Levenshtein-0.12.0-cp36-cp36m-win_amd64.whl下载即可 - pyemd - pyhanlp - 下好依赖JPype1-0.6.3-cp36-cp36m-win_amd64.whl # 参考/感谢 * eda_chinese:[https://github.com/zhanlaoban/eda_nlp_for_Chinese](https://github.com/zhanlaoban/eda_nlp_for_Chinese) * 主谓宾提取器:[https://github.com/hankcs/MainPartExtractor](https://github.com/hankcs/MainPartExtractor) * HMM生成句子:[https://github.com/takeToDreamLand/SentenceGenerate_byMarkov](https://github.com/takeToDreamLand/SentenceGenerate_byMarkov) * 同义词等:[https://github.com/fighting41love/funNLP/tree/master/data/](https://github.com/fighting41love/funNLP/tree/master/data/) * 小牛翻译:[http://www.niutrans.com/index.html](http://www.niutrans.com/index.html) # 其他资料 * bert(keras):[https://github.com/CyberZHG/keras-bert](https://github.com/CyberZHG/keras-bert) * NLP数据增强汇总:[https://github.com/quincyliang/nlp-data-augmentation](https://github.com/quincyliang/nlp-data-augmentation) * 知乎NLP数据增强话题:[https://www.zhihu.com/question/305256736/answer/550873100](https://www.zhihu.com/question/305256736/answer/550873100) * chatbot_seq2seq_seqGan(比较好用):[https://github.com/qhduan/just_another_seq2seq](https://github.com/qhduan/just_another_seq2seq) * 自己动手做聊天机器人教程: [https://github.com/warmheartli/ChatBotCourse](https://github.com/warmheartli/ChatBotCourse)

ML Frameworks Live Chat & Chatbots
1.5K Github Stars