模型:
cross-encoder/qnli-distilroberta-base
此模型使用 SentenceTransformers 类进行了训练。
给定一个问题和段落,问题是否可以通过段落回答?这些模型是在 GLUE QNLI 数据集上进行训练的,该数据集将 SQuAD dataset 转化为了NLI任务。
关于此模型的性能结果,请参见[SBERT.net预训练交叉编码器]( https://www.sbert.net/docs/pretrained_cross-encoders.html] )。
可以按照以下方式使用预训练模型:
from sentence_transformers import CrossEncoder model = CrossEncoder('model_name') scores = model.predict([('Query1', 'Paragraph1'), ('Query2', 'Paragraph2')]) #e.g. 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.')])
您还可以直接使用Transformers库(而无需使用SentenceTransformers库)。
from transformers import AutoTokenizer, AutoModelForSequenceClassification import torch model = AutoModelForSequenceClassification.from_pretrained('model_name') tokenizer = AutoTokenizer.from_pretrained('model_name') 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)