jackietung's picture
Upload folder using huggingface_hub
b2bd158 verified
Raw
History Blame Contribute Delete
1.5 kB
from transformers import pipeline
# 載入文本分類管道
classifier = pipeline(
"text-classification",
model="jackietung/bert-base-chinese-multi-classification",
return_all_scores=True
)
# 測試文本
texts = [
"這個 App 的登入系統太複雜了,每次都要重新輸入密碼,能不能增加指紋登入功能?",
"App 的搜尋功能太爛了,輸入關鍵字後常常顯示不相關的結果,希望能改進搜尋演算法。",
"最新上架的商品圖片解析度太低,而且商品描述不夠詳細,很難做出購買決定。",
"結帳流程太繁瑣,為什麼要填寫這麼多資料?而且付款完成後沒有明確的訂單確認頁面。",
"客服回應速度太慢,我的問題提交三天了還沒有人回覆,這樣的服務品質令人失望。",
"App 最近更新後經常閃退,而且耗電量增加了很多,希望開發團隊能盡快修復這些問題。"
]
# 進行預測
for text in texts:
result = classifier(text)[0]
print(f"文本: {text}")
# 按分數排序
sorted_scores = sorted(result, key=lambda x: x['score'], reverse=True)
# 獲取最高分數的類別
top_category = sorted_scores[0]
print(f"預測類別: {top_category['label']} (分數: {top_category['score']:.4f})")
# 顯示所有類別分數
print("所有類別分數:")
for score_item in sorted_scores:
print(f" {score_item['label']}: {score_item['score']:.4f}")
print("-" * 50)