🚀 e5-base-v2-mnli-anli
本模型是 intfloat/e5-base-v2 在 glue (mnli) 和 anli 數據集上的微調版本。它可用於零樣本分類任務,為文本分類提供了高效且準確的解決方案。
✨ 主要特性
📦 安裝指南
文檔未提及具體安裝步驟,可參考 transformers
庫的官方安裝說明進行安裝。
💻 使用示例
基礎用法
使用 zero-shot-classification
管道加載模型:
from transformers import pipeline
classifier = pipeline("zero-shot-classification",
model="mjwong/e5-base-v2-mnli-anli")
使用該管道將序列分類到指定的類別名稱中:
sequence_to_classify = "one day I will see the world"
candidate_labels = ['travel', 'cooking', 'dancing']
classifier(sequence_to_classify, candidate_labels)
如果有多個候選標籤可能正確,可傳遞 multi_class=True
獨立計算每個類別:
candidate_labels = ['travel', 'cooking', 'dancing', 'exploration']
classifier(sequence_to_classify, candidate_labels, multi_class=True)
高級用法
將模型應用於 NLI 任務:
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
model_name = "mjwong/e5-base-v2-mnli-anli"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
premise = "But I thought you'd sworn off coffee."
hypothesis = "I thought that you vowed to drink more coffee."
input = tokenizer(premise, hypothesis, truncation=True, return_tensors="pt")
output = model(input["input_ids"].to(device))
prediction = torch.softmax(output["logits"][0], -1).tolist()
label_names = ["entailment", "neutral", "contradiction"]
prediction = {name: round(float(pred) * 100, 2) for pred, name in zip(prediction, label_names)}
print(prediction)
📚 詳細文檔
評估結果
模型使用 MultiNLI 的開發集和 ANLI 的測試集進行評估,使用的指標是準確率。
訓練超參數
訓練過程中使用了以下超參數:
- 學習率:2e-05
- 訓練批次大小:16
- 評估批次大小:16
- 隨機種子:42
- 優化器:Adam,
betas=(0.9, 0.999)
,epsilon=1e-08
- 學習率調度器類型:線性
- 學習率調度器熱身比例:0.1
框架版本
- Transformers 4.28.1
- Pytorch 1.12.1+cu116
- Datasets 2.11.0
- Tokenizers 0.12.1
📄 許可證
本模型採用 MIT 許可證。