🚀 自然言語推論用クロスエンコーダ
このモデルは、自然言語推論を行うためのクロスエンコーダです。SentenceTransformersを用いて訓練され、SNLIやMultiNLIデータセットを利用しています。
🚀 クイックスタート
このモデルは、SentenceTransformers の Cross-Encoder クラスを使用して訓練されました。
✨ 主な機能
- 与えられた文のペアに対して、矛盾、含意、中立の3つのラベルに対応するスコアを出力します。
- 事前学習済みモデルを簡単に使用できます。
- Transformersライブラリを直接使用することも可能です。
- ゼロショット分類にも利用できます。
📦 インストール
このモデルを使用するには、sentence-transformers
または transformers
ライブラリが必要です。以下のコマンドでインストールできます。
pip install sentence-transformers
pip install transformers
💻 使用例
基本的な使用法
事前学習済みモデルの使用例です。
from sentence_transformers import CrossEncoder
model = CrossEncoder('cross-encoder/nli-deberta-base')
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ライブラリを直接使用する例です。
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model = AutoModelForSequenceClassification.from_pretrained('cross-encoder/nli-deberta-base')
tokenizer = AutoTokenizer.from_pretrained('cross-encoder/nli-deberta-base')
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-base')
sent = "Apple just announced the newest iPhone X"
candidate_labels = ["technology", "sports", "politics"]
res = classifier(sent, candidate_labels)
print(res)
📚 ドキュメント
訓練データ
このモデルは、SNLI と MultiNLI データセットで訓練されました。
性能
評価結果については、SBERT.net - Pretrained Cross-Encoder を参照してください。
📄 ライセンス
このモデルは、Apache-2.0ライセンスの下で公開されています。
プロパティ |
詳細 |
モデルタイプ |
自然言語推論用クロスエンコーダ |
訓練データ |
SNLIとMultiNLIデータセット |
メトリクス |
精度 |
ベースモデル |
microsoft/deberta-base |
ライブラリ名 |
sentence-transformers |