Downloads · 30 days
133
1% of all-time downloads
jackietung/bert-base-chinese-finetuned-sentiment
bert-base-chinese-finetuned-sentiment is a text classification model from jackietung. Use it when you need a label for a piece of text. It is set up for transformers. The card lists the license as mit.
這是一個基於 BERT 的中文情感分析模型,可用於判斷文本的情感傾向(正面、負面或中性)。
Downloads · 30 days
133
1% of all-time downloads
All-time downloads
13.1K
Public
Parameters
102M
409 MB on disk
Likes
7
Public
Click a slice to open those files.
.safetensors409 MB · 100%
From the Hugging Face model README
這是一個基於 BERT 的中文情感分析模型,可用於判斷文本的情感傾向(正面、負面或中性)。
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch
# 載入模型和分詞器
model = AutoModelForSequenceClassification.from_pretrained("jackietung/bert-base-chinese-sentiment-finetuned")
tokenizer = AutoTokenizer.from_pretrained("jackietung/bert-base-chinese-sentiment-finetuned")
# 準備輸入
text = "這個App使用體驗很差!"
inputs = tokenizer(text, return_tensors="pt")
# 進行預測
with torch.no_grad():
outputs = model(**inputs)
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
# 獲取預測結果
label_names = ["負面", "正面", "中性"]
predicted_class = torch.argmax(predictions, dim=1).item()
print(f"預測類別: {label_names[predicted_class]}")
print(f"預測分數: {predictions[0][predicted_class].item():.4f}")
# 顯示所有類別的分數
for i, label in enumerate(label_names):
print(f"{label} 分數: {predictions[0][i].item():.4f}")