?モデル|データセット|ドキュメント|ブログ| ?紙
SetFitは、文の変圧器の少数の微調整のための効率的で迅速なフレームワークです。ラベル付けされたデータがほとんどない場合、それは高精度を達成します - たとえば、顧客レビューセンチメントデータセットのクラスごとに8つのラベルのある例のみがあり、SetFitは3Kの例の完全なトレーニングセットでRobertaの大規模な微調整と競争力がありますか?!
他の少ないショット学習方法と比較して、SetFitにはいくつかのユニークな機能があります。
詳細については、SetFitドキュメントをご覧ください!
実行してsetfitをダウンロードしてインストールします:
pip install setfit代わりに出血エッジバージョンが必要な場合は、実行してソースからインストールしてください。
pip install git+https://github.com/huggingface/setfit.gitクイックスタートは、SetFitモデルを使用したトレーニング、保存、ロード、および推論の実行について学ぶのに適した場所です。
その他の例については、 notebooksディレクトリ、チュートリアル、またはハウツーガイドをご覧ください。
setfit 、ハグするフェイスハブと統合されており、2つの主要なクラスを提供します。
SetFitModel : sentence_transformersの前提条件とscikit-learnまたはSetFitHead ( sentence_transformersの上に類似したAPIを持つPyTorchの上に構築された微分ヘッド)からの分類ヘッドを組み合わせたラッパー。Trainer :SetFitの微調整プロセスをラップするヘルパークラス。 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を使用してPython仮想環境を作成します。
conda create -n setfit python=3.9 && conda activate setfit次に、次のような基本要件をインストールします。
pip install -e ' .[dev] 'これにより、 datasetsなどのSetFitの必須パッケージと、一貫したコードフォーマットを確保するために使用するblackやisortなどの開発パッケージがインストールされます。
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 }
}