Text Classification
Transformers
Chinese
bert
sentiment-analysis
chinese
transformer
roberta
text-embeddings-inference
Instructions to use hax404/cn-transformer-sentiment with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use hax404/cn-transformer-sentiment with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="hax404/cn-transformer-sentiment")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("hax404/cn-transformer-sentiment") model = AutoModelForSequenceClassification.from_pretrained("hax404/cn-transformer-sentiment") - Notebooks
- Google Colab
- Kaggle
cn-transformer-sentiment
这是一个基于中文预训练 Transformer 微调得到的外卖评论情感分析模型。
模型主要用于判断一条中文外卖评论是:
负面 / 正面
标签含义:
LABEL_0 / 负面 = 负面
LABEL_1 / 正面 = 正面
模型来源
本模型基于以下预训练模型继续微调:
uer/chinese_roberta_L-8_H-512
训练方式为全量微调,即 Transformer 主体参数和分类头参数都会更新。
训练数据
训练数据来自公开中文外卖评论数据集 waimai_10k,整理后数据规模为:
训练集:9584 条
验证集:1198 条
测试集:1198 条
数据格式为:
text,label
配送很快,味道也不错,1
等了两个小时,菜都凉了,0
测试集结果
在 waimai_10k_test.csv 上的测试结果:
accuracy: 0.9115
macro_precision: 0.9044
macro_recall: 0.8949
macro_f1: 0.8994
分类细节:
负面 precision 0.9240 | recall 0.9449 | f1 0.9343 | support 798
正面 precision 0.8848 | recall 0.8450 | f1 0.8645 | support 400
混淆矩阵:
pred_负面 pred_正面
true_负面 754 44
true_正面 62 338
使用方法
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch
model_name = "hax404/cn-transformer-sentiment"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
text = "配送很快,味道也不错"
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)
with torch.no_grad():
logits = model(**inputs).logits
probs = torch.softmax(logits, dim=-1)[0]
pred = int(torch.argmax(probs))
print(model.config.id2label[pred], float(probs[pred]))
局限性
这个模型是二分类模型,只输出正面或负面。真实外卖评论里经常会出现混合情绪,例如:
味道不错,但是送餐太慢
送得挺快,就是饮料送错了
有点腻,味道还可以
这类评论很难简单归为正面或负面,因此模型在混合情绪、反讽表达和标签噪声较多的数据上可能会判断不稳定。
适用场景
适合作为中文评论情感分析、Transformer 微调和文本分类实验的 baseline。
不建议直接作为商业生产系统使用。
- Downloads last month
- 57
Model tree for hax404/cn-transformer-sentiment
Base model
uer/chinese_roberta_L-8_H-512