🚀 Albert-base-v2-emotion
該項目基於Albert-base-v2模型,在情感數據集上進行微調,用於文本情感分類任務。它能有效識別文本中的情感類別,如悲傷、喜悅、愛等,為自然語言處理中的情感分析提供了有力支持。
🚀 快速開始
你可以使用以下代碼快速調用該模型進行文本情感分類:
from transformers import pipeline
classifier = pipeline("text-classification",model='bhadresh-savani/albert-base-v2-emotion', return_all_scores=True)
prediction = classifier("I love using transformers. The best part is wide range of support and its easy to use", )
print(prediction)
"""
Output:
[[
{'label': 'sadness', 'score': 0.010403595864772797},
{'label': 'joy', 'score': 0.8902180790901184},
{'label': 'love', 'score': 0.042532723397016525},
{'label': 'anger', 'score': 0.041297927498817444},
{'label': 'fear', 'score': 0.011772023513913155},
{'label': 'surprise', 'score': 0.0037756056990474463}
]]
"""
✨ 主要特性
- 輕量級架構:基於Albert(A Lite BERT)架構,相較於傳統的BERT架構,參數顯著減少。
- 多情感分類:能夠識別多種情感類別,如悲傷、喜悅、愛、憤怒、恐懼和驚訝等。
📦 安裝指南
文檔未提及具體安裝步驟,可參考Hugging Face的通用安裝指南來安裝所需依賴。
💻 使用示例
基礎用法
from transformers import pipeline
classifier = pipeline("text-classification",model='bhadresh-savani/albert-base-v2-emotion', return_all_scores=True)
prediction = classifier("I love using transformers. The best part is wide range of support and its easy to use", )
print(prediction)
"""
Output:
[[
{'label': 'sadness', 'score': 0.010403595864772797},
{'label': 'joy', 'score': 0.8902180790901184},
{'label': 'love', 'score': 0.042532723397016525},
{'label': 'anger', 'score': 0.041297927498817444},
{'label': 'fear', 'score': 0.011772023513913155},
{'label': 'surprise', 'score': 0.0037756056990474463}
]]
"""
📚 詳細文檔
模型描述
Albert 是一種輕量級的BERT架構,相較於傳統的BERT架構,其參數顯著減少。
Albert-base-v2 在情感數據集上使用HuggingFace Trainer進行了微調,使用的超參數如下:
學習率 2e-5,
批量大小 64,
訓練輪數 num_train_epochs = 8
模型性能比較
在來自Twitter的情感數據集上,該模型與其他模型的性能對比如下:
數據集
使用的數據集為 Twitter-Sentiment-Analysis。
訓練過程
訓練過程可參考 Colab Notebook。
評估結果
{
"test_accuracy": 0.936,
"test_f1": 0.9365658988006296,
"test_loss": 0.15278364717960358,
"test_runtime": 10.9413,
"test_samples_per_second": 182.794,
"test_steps_per_second": 2.925
}
參考資料
📄 許可證
本項目採用 Apache-2.0 許可證。