🚀 自然言語推論用クロスエンコーダ
このモデルは、自然言語推論(NLI)タスクに特化したクロスエンコーダモデルです。SentenceTransformers の Cross-Encoder クラスを使用して学習され、microsoft/deberta-v3-base をベースに構築されています。
📦 インストール
このモデルを使用するには、sentence-transformers
または transformers
ライブラリが必要です。以下のコマンドでインストールできます。
pip install sentence-transformers transformers
✨ 主な機能
- 高精度な自然言語推論:SNLI と MultiNLI データセットで学習され、高い精度で矛盾、含意、中立の関係を判断します。
- ゼロショット分類:事前学習済みのモデルを使用して、新しいクラスに対する分類タスクを実行できます。
📚 ドキュメント
モデル情報
パフォーマンス
- SNLI テストデータセットでの精度: 92.38
- MNLI 不一致セットでの精度: 90.04
詳細な評価結果については、SBERT.net - Pretrained Cross-Encoder を参照してください。
💻 使用例
基本的な使用法
事前学習済みのモデルは次のように使用できます。
from sentence_transformers import CrossEncoder
model = CrossEncoder('cross-encoder/nli-deberta-v3-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 AutoModel を使用した場合
transformers
ライブラリを直接使用してモデルを利用することもできます(SentenceTransformers
ライブラリを使用せずに)。
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model = AutoModelForSequenceClassification.from_pretrained('cross-encoder/nli-deberta-v3-base')
tokenizer = AutoTokenizer.from_pretrained('cross-encoder/nli-deberta-v3-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-v3-base')
sent = "Apple just announced the newest iPhone X"
candidate_labels = ["technology", "sports", "politics"]
res = classifier(sent, candidate_labels)
print(res)
📄 ライセンス
このモデルは Apache License 2.0 の下で提供されています。