🚀 用於SQuAD(QNLI)的交叉編碼器
該模型使用 SentenceTransformers 的 Cross-Encoder 類進行訓練,可有效解決文本排序相關問題。
🚀 快速開始
本模型基於 distilbert/distilroberta-base
基礎模型,使用 sentence-transformers
庫進行開發,適用於文本排序任務。
✨ 主要特性
- 基於
SentenceTransformers
庫的 Cross-Encoder
類訓練,在文本排序任務上表現出色。
- 模型在 GLUE QNLI 數據集上進行訓練,該數據集將 SQuAD 數據集 轉換為自然語言推理(NLI)任務。
📦 安裝指南
文檔未提及具體安裝步驟,若需使用 sentence-transformers
庫,可使用以下命令安裝:
pip install sentence-transformers
💻 使用示例
基礎用法
from sentence_transformers import CrossEncoder
model = CrossEncoder('cross-encoder/qnli-distilroberta-base')
scores = model.predict([('Query1', 'Paragraph1'), ('Query2', 'Paragraph2')])
scores = model.predict([('How many people live in Berlin?', 'Berlin had a population of 3,520,031 registered inhabitants in an area of 891.82 square kilometers.'), ('What is the size of New York?', 'New York City is famous for the Metropolitan Museum of Art.')])
高級用法
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model = AutoModelForSequenceClassification.from_pretrained('cross-encoder/qnli-distilroberta-base')
tokenizer = AutoTokenizer.from_pretrained('cross-encoder/qnli-distilroberta-base')
features = tokenizer(['How many people live in Berlin?', 'What is the size of New York?'], ['Berlin had a population of 3,520,031 registered inhabitants in an area of 891.82 square kilometers.', 'New York City is famous for the Metropolitan Museum of Art.'], padding=True, truncation=True, return_tensors="pt")
model.eval()
with torch.no_grad():
scores = torch.nn.functional.sigmoid(model(**features).logits)
print(scores)
📚 詳細文檔
📄 許可證
本項目採用 Apache-2.0 許可證。
屬性 |
詳情 |
基礎模型 |
distilbert/distilroberta-base |
模型類型 |
用於SQuAD(QNLI)的交叉編碼器 |
訓練數據 |
GLUE QNLI 數據集,將 SQuAD 數據集轉換為 NLI 任務 |
庫名稱 |
sentence-transformers |
標籤 |
transformers |