🚀 自然言語推論用クロスエンコーダ
このモデルは、自然言語推論を行うためのクロスエンコーダモデルです。SentenceTransformersのCross-Encoderクラスを用いて学習されています。
🚀 クイックスタート
このモデルは自然言語推論タスクに使用できます。以下に使用方法の概要を示します。
✨ 主な機能
- 与えられた文のペアに対して、矛盾、含意、中立の3つのラベルに対応するスコアを出力します。
- ゼロショット分類タスクにも使用できます。
📦 インストール
このモデルを使用するには、sentence-transformers
または transformers
ライブラリが必要です。以下のコマンドでインストールできます。
pip install sentence-transformers
または
pip install transformers
💻 使用例
基本的な使用法
from sentence_transformers import CrossEncoder
model = CrossEncoder('cross-encoder/nli-MiniLM2-L6-H768')
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を使用した場合
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model = AutoModelForSequenceClassification.from_pretrained('cross-encoder/nli-MiniLM2-L6-H768')
tokenizer = AutoTokenizer.from_pretrained('cross-encoder/nli-MiniLM2-L6-H768')
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-MiniLM2-L6-H768')
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ライセンスの下で公開されています。
📋 詳細情報
属性 |
详情 |
パイプラインタグ |
ゼロショット分類 |
タグ |
transformers |
学習データセット |
nyu-mll/multi_nli、stanfordnlp/snli |
評価指標 |
正解率 |
ベースモデル |
nreimers/MiniLMv2-L6-H768-distilled-from-RoBERTa-Large |
ライブラリ名 |
sentence-transformers |