🚀 多語言e5大模型指令微調XNLI-ANLI
本項目基於XNLI和ANLI數據集對intfloat/multilingual-e5-large-instruct模型進行微調,旨在提升模型在多語言自然語言推理任務上的性能。
🚀 快速開始
零樣本分類管道
可以使用zero-shot-classification
管道加載模型,示例代碼如下:
from transformers import pipeline
classifier = pipeline("zero-shot-classification",
model="mjwong/multilingual-e5-large-instruct-xnli-anli")
使用該管道將序列分類到指定的類別名稱中,示例如下:
sequence_to_classify = "Angela Merkel ist eine Politikerin in Deutschland und Vorsitzende der CDU"
candidate_labels = ["politics", "economy", "entertainment", "environment"]
classifier(sequence_to_classify, candidate_labels)
如果多個候選標籤都可能正確,可以通過傳遞multi_class=True
獨立計算每個類別的概率:
candidate_labels = ["politics", "economy", "entertainment", "environment"]
classifier(sequence_to_classify, candidate_labels, multi_label=True)
手動使用PyTorch
該模型也可以應用於自然語言推理(NLI)任務,示例代碼如下:
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
model_name = "mjwong/multilingual-e5-large-instruct-xnli-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)
✨ 主要特性
- 多語言支持:支持多種語言,包括英語、阿拉伯語、保加利亞語等。
- 零樣本分類:可以對未在訓練集中出現的類別進行分類。
- 自然語言推理:適用於自然語言推理任務。
📦 安裝指南
文檔未提及安裝步驟,可根據使用的深度學習框架(如Transformers、PyTorch等)的官方文檔進行安裝。
💻 使用示例
基礎用法
from transformers import pipeline
classifier = pipeline("zero-shot-classification",
model="mjwong/multilingual-e5-large-instruct-xnli-anli")
sequence_to_classify = "Angela Merkel ist eine Politikerin in Deutschland und Vorsitzende der CDU"
candidate_labels = ["politics", "economy", "entertainment", "environment"]
classifier(sequence_to_classify, candidate_labels)
高級用法
candidate_labels = ["politics", "economy", "entertainment", "environment"]
classifier(sequence_to_classify, candidate_labels, multi_label=True)
📚 詳細文檔
評估結果
模型在15種語言的XNLI測試集上進行了評估,使用的指標為準確率。結果如下:
模型還在MultiNLI的開發集和ANLI的測試集上進行了評估,使用的指標為準確率。結果如下:
訓練超參數
訓練過程中使用的超參數如下:
- 學習率:2e - 05
- 訓練批次大小:16
- 評估批次大小:16
- 隨機種子:42
- 優化器:Adam,β1 = 0.9,β2 = 0.999,ε = 1e - 08
- 學習率調度器類型:線性
- 學習率調度器熱身比例:0.1
框架版本
- Transformers 4.28.1
- Pytorch 1.12.1+cu116
- Datasets 2.19.2
- Tokenizers 0.12.1
🔧 技術細節
模型基於論文Text Embeddings by Weakly-Supervised Contrastive Pre-training進行開發,作者為Liang Wang、Nan Yang、Xiaolong Huang等,發表於arXiv 2022。
📄 許可證
本模型使用MIT許可證。
屬性 |
詳情 |
模型類型 |
多語言微調模型 |
訓練數據 |
XNLI和ANLI數據集 |