🚀 nli-entailment-verifier-xxl
nli-entailment-verifier-xxl 是一个用于验证给定前提是否支持假设的模型。它基于 flan-t5-xxl 模型 进行微调,以排序为目标(从给定前提的一对假设中对最受支持的假设进行排序)。该模型适用于自然语言推理(NLI)风格的数据集和思维链(CoT)推理,尤其经过专门训练以处理多句子前提,这与现代大语言模型(LLM)应用场景中的需求相符。
🚀 快速开始
模型描述
nli-entailment-verifier-xxl 基于 flan-t5-xxl 模型,并通过排序目标进行微调(针对给定前提,从给定的一对假设中对最受支持的假设进行排序)。更多详细信息请参考我们的论文 Are Machines Better at Complex Reasoning? Unveiling Human-Machine Inference Gaps in Entailment Verification。
该模型旨在验证给定前提是否支持某个假设,适用于自然语言推理(NLI)风格的数据集和思维链(CoT)推理。此模型经过专门训练,能够处理多句子前提(类似于我们在思维链推理和其他现代大语言模型用例中所期望的情况)。
⚠️ 重要提示
你可以使用 4 位/8 位 量化 来减少 GPU 内存使用。
💻 使用示例
基础用法
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import torch
def get_score(model, tokenizer, input_ids):
pos_ids = tokenizer('Yes').input_ids
neg_ids = tokenizer('No').input_ids
pos_id = pos_ids[0]
neg_id = neg_ids[0]
logits = model(input_ids, decoder_input_ids=torch.zeros((input_ids.size(0), 1), dtype=torch.long)).logits
pos_logits = logits[:, 0, pos_id]
neg_logits = logits[:, 0, neg_id]
posneg_logits = torch.cat([pos_logits.unsqueeze(-1), neg_logits.unsqueeze(-1)], dim=1)
scores = torch.nn.functional.softmax(posneg_logits, dim=1)[:, 0]
return scores
tokenizer = AutoTokenizer.from_pretrained('google/flan-t5-xxl')
model = AutoModelForSeq2SeqLM.from_pretrained('soumyasanyal/nli-entailment-verifier-xxl')
premise = "A fossil fuel is a kind of natural resource. Coal is a kind of fossil fuel."
hypothesis = "Coal is a kind of natural resource."
prompt = f"Premise: {premise}\nHypothesis: {hypothesis}\nGiven the premise, is the hypothesis correct?\nAnswer:"
input_ids = tokenizer(prompt, return_tensors='pt').input_ids
scores = get_score(model, tokenizer, input_ids)
print(f'Hypothesis entails the premise: {bool(scores >= 0.5)}')
运行上述代码后,输出结果如下:
['Hypothesis entails the premise: False']