🚀 自然語言推理跨編碼器
本模型是用於自然語言推理的跨編碼器,基於SentenceTransformers庫進行訓練。它能夠對給定的句子對進行推理,輸出矛盾、蘊含、中立三種標籤對應的得分。可用於自然語言推理任務,如文本分類、語義匹配等場景。
🚀 快速開始
本模型使用 SentenceTransformers 的 Cross-Encoder 類進行訓練,基於 microsoft/deberta-v3-large 構建。
✨ 主要特性
- 基於強大的
microsoft/deberta-v3-large
模型,具有良好的語義理解能力。
- 可對給定的句子對輸出矛盾、蘊含、中立三種標籤對應的得分。
- 支持零樣本分類任務。
📦 安裝指南
文檔未提及具體安裝步驟,可參考 SentenceTransformers 和 Transformers 庫的官方安裝說明。
💻 使用示例
基礎用法
使用預訓練模型的示例代碼:
from sentence_transformers import CrossEncoder
model = CrossEncoder('cross-encoder/nli-deberta-v3-large')
scores = model.predict([('A man is eating pizza', 'A man eats something'), ('A black race car starts up in front of a crowd of people.', 'A man is driving down a lonely road.')])
label_mapping = ['contradiction', 'entailment', 'neutral']
labels = [label_mapping[score_max] for score_max in scores.argmax(axis=1)]
高級用法
直接使用 Transformers 庫(不使用 SentenceTransformers 庫)的示例代碼:
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model = AutoModelForSequenceClassification.from_pretrained('cross-encoder/nli-deberta-v3-large')
tokenizer = AutoTokenizer.from_pretrained('cross-encoder/nli-deberta-v3-large')
features = tokenizer(['A man is eating pizza', 'A black race car starts up in front of a crowd of people.'], ['A man eats something', 'A man is driving down a lonely road.'], padding=True, truncation=True, return_tensors="pt")
model.eval()
with torch.no_grad():
scores = model(**features).logits
label_mapping = ['contradiction', 'entailment', 'neutral']
labels = [label_mapping[score_max] for score_max in scores.argmax(dim=1)]
print(labels)
零樣本分類用法
該模型用於零樣本分類的示例代碼:
from transformers import pipeline
classifier = pipeline("zero-shot-classification", model='cross-encoder/nli-deberta-v3-large')
sent = "Apple just announced the newest iPhone X"
candidate_labels = ["technology", "sports", "politics"]
res = classifier(sent, candidate_labels)
print(res)
📚 詳細文檔
訓練數據
模型在 SNLI 和 MultiNLI 數據集上進行訓練。對於給定的句子對,模型將輸出對應於矛盾、蘊含、中立三種標籤的得分。
性能表現
- SNLI 測試數據集上的準確率:92.20
- MNLI 不匹配集上的準確率:90.49
更多評估結果,請參考 SBERT.net - Pretrained Cross-Encoder。
📄 許可證
本項目採用 Apache-2.0 許可證。
📋 信息表格
屬性 |
詳情 |
數據集 |
multi_nli、snli |
語言 |
英語 |
許可證 |
apache-2.0 |
評估指標 |
準確率 |
任務類型 |
零樣本分類 |
標籤 |
microsoft/deberta-v3-large |