? 모델 | 데이터 세트 | 문서 | 블로그 | ? 종이
SetFit은 문장 변압기의 소수의 미세 조정을위한 효율적이고 즉시 프레임 워크입니다. 예를 들어, 고객 리뷰 감정 데이터 세트에서 클래스 당 8 개의 레이블이 붙은 예제만으로도 세트 피트는 3K 예제의 전체 교육 세트에서 미세 조정 Roberta Barge와 경쟁력이 있습니까?!
다른 소수의 학습 방법과 비교하여 Setfit에는 몇 가지 고유 한 기능이 있습니다.
자세한 내용은 SetFit 문서를 확인하십시오!
실행을 통해 setfit 다운로드하고 설치합니다.
pip install setfit대신 출혈 버전을 원하는 경우 소스에서 실행하여 설치하십시오.
pip install git+https://github.com/huggingface/setfit.gitQuickStart는 SetFit 모델에 대한 훈련, 저축,로드 및 추론 수행에 대해 배울 수있는 좋은 장소입니다.
더 많은 예를 보려면 notebooks 디렉토리, 튜토리얼 또는 방법 안내서를 확인하십시오.
setfit Hugging Face Hub와 통합되어 있으며 두 가지 주요 클래스를 제공합니다.
SetFitModel : sentence_transformers 의 사전 취소와 scikit-learn 또는 SetFitHead 의 분류 헤드를 결합한 래퍼 ( sentence_transformers 와 유사한 API가있는 PyTorch 에 구축 된 차별화 가능한 헤드).Trainer : 세트 피트의 미세 조정 과정을 감싸는 도우미 수업. 다음은 scikit-learn 의 기본 분류 헤드를 사용하는 간단한 엔드 투 엔드 교육 예입니다.
from datasets import load_dataset
from setfit import SetFitModel , Trainer , TrainingArguments , sample_dataset
# Load a dataset from the Hugging Face Hub
dataset = load_dataset ( "sst2" )
# Simulate the few-shot regime by sampling 8 examples per class
train_dataset = sample_dataset ( dataset [ "train" ], label_column = "label" , num_samples = 8 )
eval_dataset = dataset [ "validation" ]. select ( range ( 100 ))
test_dataset = dataset [ "validation" ]. select ( range ( 100 , len ( dataset [ "validation" ])))
# Load a SetFit model from Hub
model = SetFitModel . from_pretrained (
"sentence-transformers/paraphrase-mpnet-base-v2" ,
labels = [ "negative" , "positive" ],
)
args = TrainingArguments (
batch_size = 16 ,
num_epochs = 4 ,
eval_strategy = "epoch" ,
save_strategy = "epoch" ,
load_best_model_at_end = True ,
)
trainer = Trainer (
model = model ,
args = args ,
train_dataset = train_dataset ,
eval_dataset = eval_dataset ,
metric = "accuracy" ,
column_mapping = { "sentence" : "text" , "label" : "label" } # Map dataset columns to text/label expected by trainer
)
# Train and evaluate
trainer . train ()
metrics = trainer . evaluate ( test_dataset )
print ( metrics )
# {'accuracy': 0.8691709844559585}
# Push model to the Hub
trainer . push_to_hub ( "tomaarsen/setfit-paraphrase-mpnet-base-v2-sst2" )
# Download from Hub
model = SetFitModel . from_pretrained ( "tomaarsen/setfit-paraphrase-mpnet-base-v2-sst2" )
# Run inference
preds = model . predict ([ "i loved the spiderman movie!" , "pineapple on pizza is the worst ?" ])
print ( preds )
# ["positive", "negative"] 우리는 SetFit의 결과와 논문의 표 2에 제시된 다양한 기준선에 대한 결과를 재현하기위한 스크립트를 제공합니다. scripts/ 디렉토리에서 설정 및 교육 지침을 확인하십시오.
이 프로젝트에서 코드를 실행하려면 먼저 EG Conda를 사용하여 파이썬 가상 환경을 만듭니다.
conda create -n setfit python=3.9 && conda activate setfit그런 다음 기본 요구 사항을 다음과 같이 설치하십시오.
pip install -e ' .[dev] ' 이 경우 일관된 코드 형식을 보장하기 위해 사용하는 black 및 isort 와 같은 개발 datasets 와 같은 SetFit의 필수 패키지를 설치합니다.
우리는 black 과 isort 사용하여 일관된 코드 형식을 보장합니다. 설치 단계를 따르면 다음을 실행하여 로컬로 코드를 확인할 수 있습니다.
make style && make quality
├── LICENSE
├── Makefile <- Makefile with commands like `make style` or `make tests`
├── README.md <- The top-level README for developers using this project.
├── docs <- Documentation source
├── notebooks <- Jupyter notebooks.
├── final_results <- Model predictions from the paper
├── scripts <- Scripts for training and inference
├── setup.cfg <- Configuration file to define package metadata
├── setup.py <- Make this project pip installable with `pip install -e`
├── src <- Source code for SetFit
└── tests <- Unit tests
@misc { https://doi.org/10.48550/arxiv.2209.11055 ,
doi = { 10.48550/ARXIV.2209.11055 } ,
url = { https://arxiv.org/abs/2209.11055 } ,
author = { Tunstall, Lewis and Reimers, Nils and Jo, Unso Eun Seo and Bates, Luke and Korat, Daniel and Wasserblat, Moshe and Pereg, Oren } ,
keywords = { Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences } ,
title = { Efficient Few-Shot Learning Without Prompts } ,
publisher = { arXiv } ,
year = { 2022 } ,
copyright = { Creative Commons Attribution 4.0 International }
}