基于
hfl/chinese-bert-wwm-ext
在微博情感数据集上微调的
三分类情感分析模型 (negative / positive / neutral).
本模型为本科毕业设计《基于 Spark 的微博舆情分析系统》的配套模型.
完整项目代码:
MOST951/Graduation-Design
1from transformers import pipeline
2
3classifier = pipeline(
4 "text-classification",
5 model="MOST951/weibo-sentiment-chinese-bert",
6)
7result = classifier("今天天气真好,心情也很棒!")
8print(result)
9# [{'label': 'positive', 'score': 0.98...}]
1import torch
2from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
4tokenizer = AutoTokenizer.from_pretrained("MOST951/weibo-sentiment-chinese-bert")
5model = AutoModelForSequenceClassification.from_pretrained("MOST951/weibo-sentiment-chinese-bert")
6model.eval()
7
8texts = [
9 "今天天气真好,心情也很棒!",
10 "这个产品质量太差了,非常失望。",
11 "今天上午开会讨论了新项目的进度安排。",
12]
13
14with torch.no_grad():
15 enc = tokenizer(texts, padding=True, truncation=True, max_length=128, return_tensors="pt")
16 logits = model(**enc).logits
17 probs = torch.softmax(logits, dim=-1)
18 preds = probs.argmax(dim=-1).tolist()
19
20id2label = model.config.id2label
21for text, pred, prob in zip(texts, preds, probs):
22 print(f"{id2label[pred]:<10} ({prob[pred]:.4f}) {text}")
1@misc{weibo-sentiment-chinese-bert-2026,
2 title={基于 Spark 的微博舆情分析系统},
3 author={senlou},
4 year={2026},
5 howpublished={\url{https://github.com/MOST951/Graduation-Design}}
6}