Conformers
1.0.0
هذا تطبيق غير رسمي لنمذجة اللغة المطابقة. لقد وجدت الورقة مثيرة للاهتمام وأردت أن ألعب معها. لا يزال في حالة مبكرة جدًا - الضمان الإحصائي الوحيد الصارم حاليًا هو وجود أخطاء وسوء فهم. يرجى عذر حالة الكود الحالي - سأقوم بتنظيفه أعدك!
لا تتوفر حزمة PYPI حتى الآن. للتثبيت ، استنساخ المستودع وتشغيله
pip install poetry
poetry installلم يتم تعيين Python 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 ]))