Skip to content

基于Pytroch实现文本多标签分类(Implement multi-label classification of text based on Pytroch)

Notifications You must be signed in to change notification settings

LXXiaogege/BERT-based-Multi-Label-CLS

Repository files navigation


基于BERT的文本多标签分类

基于sem_eval_2018_task_1部分数据集,利用BERT预训练模型实现文本多分类模型微调

目录
  1. 介绍
  2. 快速开始
  3. 用例

介绍

基于BERT实现文本多标签多分类,参考Transformers的AutoModelForSequenceClassification利用Pytorch代码实现, 目的是更灵活的使用PyTorch应用到其他项目中(初心是PyTorch更稳定。。。尤其是在内网环境下)

(back to top)

建立

  • Python

(back to top)

快速开始

环境要求

  • Python 3.6+
  • PyTorch

环境安装

pip install -r requirements.txt

模型训练

python train.py

模型推理

python inference.py

(back to top)

模型评估结果

Hamming Loss

hamming loss: 0.1361

Zero-One Loss

zero_one_loss: 0.7844

Classification Report

类别(class) 精度(precision) 召回率(recall) F1 分数(f1-score) 样本数量(support)
anger 0.74 0.81 0.77 507
anticipation 0.41 0.33 0.36 200
disgust 0.70 0.76 0.73 516
fear 0.83 0.66 0.73 283
joy 0.82 0.83 0.83 507
love 0.61 0.43 0.51 136
optimism 0.71 0.62 0.66 400
pessimism 0.45 0.30 0.36 166
sadness 0.67 0.64 0.66 424
surprise 0.54 0.17 0.26 76
trust 0.36 0.06 0.10 71
micro avg 0.71 0.65 0.67
macro avg 0.62 0.51 0.54
weighted avg 0.69 0.65 0.66
samples avg 0.71 0.67 0.65

混淆矩阵

[[ 718 143] [ 97 410]] [[1074 94] [ 135 65]] [[ 687 165] [ 122 394]] [[1047 38] [ 97 186]] [[ 768 93] [ 85 422]] [[1194 38] [ 77 59]] [[ 864 104] [ 150 250]] [[1141 61] [ 117 49]] [[ 813 131] [ 153 271]] [[1281 11] [ 63 13]] [[1290 7] [ 67 4]]

用例

Use this space to show useful examples of how a project can be used. Additional screenshots, code examples and demos work well in this space. You may also link to more resources.

(back to top)

About

基于Pytroch实现文本多标签分类(Implement multi-label classification of text based on Pytroch)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published