chinese-sentiment-bert

bert-base-chinese 在 ChnSentiCorp(中文酒店评论情感分类)上微调的中文情感二分类模型。 NLP 课程作业产出。

指标

split n accuracy precision recall F1
validation 1200 0.9450 0.9414 0.9477 0.9445
test 1200 0.9475 0.9431 0.9539 0.9485

对比:hfl/chinese-roberta-wwm-ext 同配置训练,test acc 0.9492 / F1 0.9502。

用法(PyTorch)

from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

repo = "monica-2/chinese-sentiment-bert"
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModelForSequenceClassification.from_pretrained(repo).eval()

text = "酒店位置很好,服务也热情,下次还会再来。"
enc = tok(text, truncation=True, max_length=256, return_tensors="pt")
with torch.no_grad():
    logits = model(**enc).logits[0]
print(torch.softmax(logits, -1))   # tensor([0.0064, 0.9936]) -> 正面

用法(浏览器 / transformers.js)

仓库内含 int8 动态量化 ONNX:onnx/model_quantized.onnx(103 MB), 可在纯前端推理(无需服务器):

import { pipeline } from '@huggingface/transformers';
const clf = await pipeline('text-classification', 'monica-2/chinese-sentiment-bert', { dtype: 'q8' });
await clf('房间又小又脏,隔音差,不推荐。');  // [{label: 'negative', score: 0.94}, ...]

量化模型在 600 条验证样本上 acc 0.9467(原 PyTorch 模型 0.9450),几乎无损。

在线 Demo:https://monica-2-chinese-sentiment-demo.static.hf.space

局限

  • 领域是酒店评论,迁移到其他领域(如商品、社交媒体)会有明显掉点;
  • 训练数据正负各半,长文本中的转折句、隐式反讽容易判错;
  • 训练集来自公开数据,未做去偏处理。
Downloads last month
98
Safetensors
Model size
0.1B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for monica-2/chinese-sentiment-bert

Quantized
(4)
this model

Dataset used to train monica-2/chinese-sentiment-bert

Space using monica-2/chinese-sentiment-bert 1