stormtrooper
v1.0.0

선적 서류 비치
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"] 생성 및 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 및 생성 모델로만 작동합니다.
model = Trooper("HuggingFaceH4/zephyr-7b-beta", device_map="auto")