
เอกสาร
Trooper อินเทอร์เฟซ Trooper ใหม่เอี่ยมช่วยให้คุณไม่ต้องระบุประเภทของรุ่นที่คุณต้องการใช้ Stormtrooper จะตรวจจับประเภทรุ่นจากชื่อที่ระบุโดยอัตโนมัติ
from stormtrooper import Trooper
# This loads a setfit model
model = Trooper ( "all-MiniLM-L6-v2" )
# This loads an OpenAI model
model = Trooper ( "gpt-4" )
# This loads a Text2Text model
model = Trooper ( "google/flan-t5-base" )คุณไม่จำเป็นต้องระบุอีกต่อไปว่าโมเดลควรเป็นตัวจําแนกไม่กี่ตัวหรือเป็นตัวจําแนกเป็นศูนย์เมื่อเริ่มต้น หากคุณไม่ผ่านตัวอย่างการฝึกอบรมใด ๆ จะมีการสันนิษฐานโดยอัตโนมัติว่าโมเดลควรเป็นศูนย์
# This is a zero-shot model
model . fit ( None , [ "dog" , "cat" ])
# This is a few-shot model
model . fit ([ "he was a good boy" , "just lay down on my laptop" ], [ "dog" , "cat" ])คุณสามารถใช้แบบจำลองหม้อแปลงทุกประเภทสำหรับการจำแนกประเภทไม่กี่และไม่มีการยิงใน Stormtrooper
Trooper("HuggingFaceH4/zephyr-7b-beta")Trooper("all-MiniLM-L6-v2")Trooper("google/flan-t5-base")Trooper("gpt-4")Trooper("facebook/bart-large-mnli") ค้นหาเพิ่มเติมในเอกสารของเรา
pip install stormtrooper from stormtrooper import Trooper
class_labels = [ "atheism/christianity" , "astronomy/space" ]
example_texts = [
"God came down to earth to save us." ,
"A new nebula was recently discovered in the proximity of the Oort cloud."
]
new_texts = [ "God bless the reailway workers" , "The frigate is ready to launch from the spaceport" ]
# Zero-shot classification
model = Trooper ( "google/flan-t5-base" )
model . fit ( None , class_labels )
model . predict ( new_texts )
# ["atheism/christianity", "astronomy/space"]
# Few-shot classification
model = Trooper ( "google/flan-t5-base" )
model . fit ( example_texts , class_labels )
model . predict ( new_texts )
# ["atheism/christianity", "astronomy/space"] รุ่น Generative และ Text2Text โดยค่าเริ่มต้นจะทำให้เกิดการจับคู่ที่คลุมเครือกับฉลากคลาสที่ใกล้ที่สุดคุณสามารถปิดใช้งานพฤติกรรมนี้ได้โดยการระบุ fuzzy_match=False
หากคุณต้องการเร่งความเร็วการจับคู่ฟัซซี่คุณควรติดตั้ง python-Levenshtein
จากเวอร์ชัน 0.2.2 คุณสามารถเรียกใช้รุ่นบน GPU คุณสามารถระบุอุปกรณ์เมื่อเริ่มต้นโมเดล:
classifier = Trooper ( "all-MiniLM-L6-v2" , device = "cuda:0" ) คุณสามารถเรียกใช้โมเดลบนอุปกรณ์หลายตัวตามลำดับความสำคัญของอุปกรณ์ GPU -> CPU + Ram -> Disk และบนอุปกรณ์หลายเครื่องโดยใช้อาร์กิวเมนต์ device_map โปรดทราบว่าสิ่งนี้ใช้ได้เฉพาะกับ Text2Text และรุ่น Generative เท่านั้น
model = Trooper("HuggingFaceH4/zephyr-7b-beta", device_map="auto")