🚀 自然言語推論用クロスエンコーダ
このモデルは、自然言語推論(NLI)のタスクに特化したクロスエンコーダモデルです。SentenceTransformersライブラリを用いて訓練され、高い精度で文の関係性を判断することができます。
🚀 クイックスタート
このモデルは、SentenceTransformers の Cross-Encoder クラスを使用して訓練されています。ベースモデルは microsoft/deberta-v3-xsmall です。
✨ 主な機能
- 与えられた文のペアに対して、矛盾(contradiction)、含意(entailment)、中立(neutral)の3つのラベルに対応するスコアを出力します。
- ゼロショット分類(zero-shot classification)にも利用可能です。
📦 インストール
このモデルを使用するには、sentence-transformers
または transformers
ライブラリが必要です。以下のコマンドでインストールできます。
pip install sentence-transformers
pip install transformers
💻 使用例
基本的な使用法
from sentence_transformers import CrossEncoder
model = CrossEncoder('cross-encoder/nli-deberta-v3-xsmall')
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)]
高度な使用法
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model = AutoModelForSequenceClassification.from_pretrained('cross-encoder/nli-deberta-v3-xsmall')
tokenizer = AutoTokenizer.from_pretrained('cross-encoder/nli-deberta-v3-xsmall')
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-xsmall')
sent = "Apple just announced the newest iPhone X"
candidate_labels = ["technology", "sports", "politics"]
res = classifier(sent, candidate_labels)
print(res)
📚 ドキュメント
訓練データ
このモデルは、SNLI と MultiNLI データセットで訓練されています。
性能
- SNLIテストデータセットでの精度: 91.64
- MNLIミスマッチセットでの精度: 87.77
詳細な評価結果については、SBERT.net - Pretrained Cross-Encoder を参照してください。
📄 ライセンス
このモデルは、Apache 2.0ライセンスの下で提供されています。
📋 情報テーブル
属性 |
詳情 |
パイプラインタグ |
ゼロショット分類 (zero-shot-classification) |
タグ |
transformers |
データセット |
nyu-mll/multi_nli, stanfordnlp/snli |
評価指標 |
精度 (accuracy) |
ライセンス |
apache-2.0 |
ベースモデル |
microsoft/deberta-v3-xsmall |
ライブラリ名 |
sentence-transformers |