基于BERT实现文本多标签多分类,参考Transformers的AutoModelForSequenceClassification利用Pytorch代码实现, 目的是更灵活的使用PyTorch应用到其他项目中(初心是PyTorch更稳定。。。尤其是在内网环境下)
- Python 3.6+
- PyTorch
pip install -r requirements.txt
python train.py
python inference.py
hamming loss: 0.1361
zero_one_loss: 0.7844
类别(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.