Promptzl
v1.0.0
최첨단 LLM을 몇 줄의 코드로 단지 0 + -shot Pytorch 분류기로 전환하십시오.
Promptzl 제공 :
자세한 내용은 공식 문서를 확인하십시오.
pip install -U promptzl
몇 줄의 코드로, 선택한 LLM을 바람직한 속성을 갖춘 구식 분류기로 변환 할 수 있습니다.
데이터 세트 설정 :
from datasets import Dataset
dataset = Dataset . from_dict (
{
'text' : [
"The food was absolutely wonderful, from preparation to presentation, very pleasing." ,
"The service was a bit slow, but the food made up for it. Highly recommend the pasta!" ,
"The restaurant was too noisy and the food was mediocre at best. Not worth the price." ,
],
'label' : [ 1 , 1 , 0 ]
}
)언어 모델을 올바른 예측으로 안내하라는 프롬프트를 정의하십시오.
from promptzl import FnVbzPair , Vbz
prompt = FnVbzPair (
lambda e : f"""Restaurant review classification into categories 'positive' or 'negative'.
'Best pretzls in town!'='positive'
'Rude staff, horrible food.'='negative'
' { e [ 'text' ] } '=""" ,
Vbz ({ 0 : [ "negative" ], 1 : [ "positive" ]}))모델 초기화 :
from promptzl import CausalLM4Classification
model = CausalLM4Classification (
'HuggingFaceTB/SmolLM2-1.7B' ,
prompt = prompt )데이터 분류 :
from sklearn . metrics import accuracy_score
output = model . classify ( dataset , show_progress_bar = True , batch_size = 1 )
accuracy_score ( dataset [ 'label' ], output . predictions )
1.0자세한 자습서는 문서를 확인하십시오!