# Bert-Chinese-Text-Classification-Pytorch-Learn **Repository Path**: linzhengtian/bert-chinese-text-classification-pytorch-learn ## Basic Information - **Project Name**: Bert-Chinese-Text-Classification-Pytorch-Learn - **Description**: Bert-Chinese-Text-Classification-Pytorch学习代码,支持ERNIE - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2024-01-15 - **Last Updated**: 2024-03-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: bert, classification, Huggingface ## README # Bert-Chinese-Text-Classification-Pytorch-Learn Bert-Chinese-Text-Classification-Pytorch项目学习材料,补充Huggingface案例。 中文文本分类,Bert,ERNIE,Huggingface,基于pytorch,开箱即用。 ## 介绍 推荐2080Ti及以上配置GPU,显存建议20G及以上。 ## 中文数据集 从[THUCNews](http://thuctc.thunlp.org/) 中抽取了20万条新闻标题,文本长度在20到30之间。一共10个类别,每类2万条。数据以字为单位输入模型。 类别:财经、房产、股票、教育、科技、社会、时政、体育、游戏、娱乐。 数据集划分: |数据集|数据量| | --- | --- | |训练集|18万| |验证集|1万| |测试集|1万| ### 其他数据集 jd-京东读书数据集,laws-法律文书,news-新闻摘要(多标签),或者按照以上数据集的格式来格式化你的中文数据集。 ## THUCNews效果 | 模型 | acc | 备注 | | --- | --- | --- | |bert|94.83%|单纯的bert| |ERNIE|94.61%|中文bert| |bert_CNN|94.44%|bert + CNN| |bert_RNN|94.57%|bert + RNN| |bert_RCNN|94.51%|bert + RCNN| |bert_DPCNN|94.47%|bert + DPCNN| CNN、RNN、DPCNN、RCNN、RNN+Attention、FastText等模型效果,见[仓库](https://github.com/649453932/Chinese-Text-Classification-Pytorch) 。 ## 预训练语言模型 bert模型放在 bert_pretain目录下,ERNIE模型放在ERNIE_pretrain目录下,每个目录下都是三个文件: - pytorch_model.bin - bert_config.json - vocab.txt 预训练模型下载地址: bert_Chinese: - 模型 https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-chinese.tar.gz - 词表 https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-chinese-vocab.txt - 或者来自[这里](https://github.com/huggingface/pytorch-transformers) ERNIE_Chinese: - https://huggingface.co/nghuyong - 或者来自[这里](https://github.com/nghuyong/ERNIE-Pytorch) 解压后,按照上面说的放在对应目录下,文件名称确认无误即可。 ## 原始模型使用说明 下载好预训练模型就可以跑了。 ``` # 训练并测试: # bert python run.py --model bert # bert + 其它 python run.py --model bert_CNN # ERNIE python run.py --model ERNIE ``` ### 参数 模型都在models目录下,超参定义和模型定义在同一文件中。 ## Huggingface使用说明 执行huggingface_example目录代码 ## 对应论文 [1] BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding [2] ERNIE: Enhanced Representation through Knowledge Integration