Promptzl
v1.0.0
เปลี่ยน LLM ที่ทันสมัยเป็นศูนย์ + -shot pytorch classifiers ในรหัสเพียงไม่กี่บรรทัด
ข้อเสนอ 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สำหรับการสอนโดยละเอียดเพิ่มเติมลองดูเอกสาร!