Conformers
1.0.0
這是紙條形式建模的非正式實施。我發現該論文很有趣,並想和它一起玩。仍處於非常早的狀態 - 目前唯一嚴格的統計保證是存在錯誤和誤解。請原諒當前代碼的狀態 - 我保證我會清理它!
尚無PYPI軟件包。要安裝,請克隆存儲庫並運行
pip install poetry
poetry installPython API尚未設置在石頭上,但目的是使使用不同的入院,團體信心和拒絕功能變得容易。最近的CFG語言模型論文可能會有一些非常有趣的組合。以下是GPT2的示例。
from conformer import Calibrator , Sampler , Components
import torch
from random import randint
x = [
"What is the capital of France?" ,
"Which prime-minster of the UK was the biggest nob?" ,
]
from transformers import GPT2LMHeadModel , GPT2Tokenizer
model_name = "gpt2"
model = GPT2LMHeadModel . from_pretrained ( model_name ). cuda ()
tokenizer = GPT2Tokenizer . from_pretrained ( model_name )
tokenizer . pad_token_id = tokenizer . eos_token_id
calibrator = Calibrator (
model = model ,
tokenizer = tokenizer ,
calibration_prompts = x ,
)
calibrator . set_admission_function ( Components . admission . debug )
calibrator . set_group_confidence_function ( Components . group_confidence . debug , torch . tensor ([ 0.1 , 0.5 , 1 ]))
calibrator . add_rejection_function ( Components . rejection . debug , torch . tensor ([ 0.1 , 0.5 , 1 ]))
calibrator . set_FWER ( Components . FWER . debug )
lambdaz = calibrator . search ()
sampler = Sampler . from_calibrator ( calibrator )
sampler . sample_with_rejection ( "What is the capital of France?" )這使用了一些內置入學/gf/fwer/拒絕功能。也可以使用您自己的功能,例如:
calibrator . set_group_confidence_function ( lambda x : x > 0.5 , torch . tensor ([ 0.1 , 0.5 , 1 ]))