🚀 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']