模型:
cross-encoder/qnli-electra-base
此模型是使用 SentenceTransformers Cross-Encoder 类进行训练的。
给定一个问题和段落,问题能否通过段落回答?这些模型是在 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)