Jugar con el enfoque SetFit para la transferencia de pocos disparos para la clasificación de texto.
Editar: también hice algunos experimentos con aprendizaje activo, así que ahora también tengo activo.py. Lo organizaré mejor un día soleado.
$ ~/Dev/projects/setfit$ python main.py --help
Usage: main.py [OPTIONS]
Options:
-d, --dataset-name TEXT The name of the dataset as it appears on the
HuggingFace hub e.g. SetFit/SentEval-CR |
SetFit/bbc-news | SetFit/enron_spam ...
-c, --case INTEGER 0, 1, 2, or 3: which experiment are we
running. See readme or docstrings to know
more but briefly: **0**: SentTF ->
Constrastive Pretrain -> +LogReg on task.
**1**: SentTF -> +Dense on task. **2**:
SentTF -> +LogReg on task. **3**:
FewShotPrompting based Clf over Flan-t5-xl
[required]
-r, --repeat INTEGER The number of times we should run the entire
experiment (changing the seed).
-bs, --batch-size INTEGER ... you know what it is.
-ns, --num-sents INTEGER Size of our train set. Set short values
(under 100)
-e, --num-epochs INTEGER Epochs for fitting Clf+SentTF on the main
(classification) task.
-eft, --num-epochs-finetune INTEGER
Epochs for both contrastive pretraining of
SentTF.
-ni, --num-iters INTEGER Number of text pairs to generate for
contrastive learning. Values above 20 can
get expensive to train.
-tot, --test-on-test If true, we report metrics on testset. If
not, on a 20% split of train set. Off by
default.
-ft, --full-test We truncate the testset of every dataset to
have 100 instances. If you know what you're
doing, you can test on the full dataset.NOTE
that if you're running this in case 3 you
should probably be a premium member and not
be paying per use.
--help Show this message and exit.
Nota : Si desea consultar LLMS alojados en Huggingface (caso 3), debe crear su cuenta en Huggingface Hub y generar tokens de acceso, después de lo cual debe pegarlos en un archivo
./hf_token.key.PD: No se preocupe, he agregado este archivo a .gitignore
$ python active.py --help
Usage: active.py [OPTIONS]
Options:
-d, --dataset-name TEXT The name of the dataset as it appears on the
HuggingFace hub e.g. SetFit/SentEval-CR |
SetFit/bbc-news | SetFit/enron_spam | imdb ...
-ns, --num-sents INTEGER Size of our train set. I.e., the dataset at the
END of AL. Not the start of it.
-nq, --num-queries INTEGER Number of times we query the unlabeled set and
pick some labeled examples. Set short values
(under 10)
-ft, --full-test We truncate the testset of every dataset to have
100 instances. If you know what you're doing,
you can test on the full dataset.NOTE that if
you're running this in case 3 you should
probably be a premium member and not be paying
per use.
--help Show this message and exit.
O simplemente puede ejecutar ./run.sh después de instalar las bibliotecas requeridas (ver requirements.txt )
Posteriormente, puede ejecutar el cuaderno summarise.ipynb para resumir y visualizar (si puedo agregar este código) los resultados.
PD: Presta atención a
--full-test. Por defecto, truncamos cada prueba establecida en sus primeras 100 instancias.
Todos son conjuntos de datos de clasificación que han sido limpiados por las personas amables y amables que hicieron el setfit lib. Pero puede usar cualquier conjunto de datos HF siempre que tenga estos tres campos: (i) Texto (STR), (ii) etiqueta (int) y (iii) Label_Text (STR).
Aquí están mis resultados:
Esta tabla presenta los resultados de este + la configuración de aprendizaje activo. A menos que se especifique lo contrario, repetimos cada experimento 5 veces. Estos números informan la precisión de la tarea cuando solo teníamos 100 instancias en el conjunto de trenes.
| BBC-News | SST2 | Senteval-CR | IMDB | enron_spam | |
|---|---|---|---|---|---|
| Setfit ft | 0.978 ± 0.004 | 0.860 ± 0.018 | 0.882 ± 0.029 | 0.924 ± 0.026 | 0.960 ± 0.017 |
| Sin setfit de contraste | 0.932 ± 0.015 | 0.854 ± 0.019 | 0.886 ± 0.005 | 0.902 ± 0.019 | 0.942 ± 0.020 |
| FT regular | 0.466 ± 0.133 | 0.628 ± 0.098 | 0.582 ± 0.054 | 0.836 ± 0.166 | 0.776 ± 0.089 |
| LLM Signicing | 0.950 ± 0.000 | 0.930 ± 0.000 | 0.900 ± 0.000 | 0.930 ± 0.000 | 0.820 ± 0.000 |
| Constrastive al | 0.980 ± 0.000 | 0.910 ± 0.000 | 0.910 ± 0.000 | 0.870 ± 0.000 | 0.980 ± 0.000 |
[1]: la solicitud de LLM solo se realiza con 10 instancias (el aviso real puede contener menos dependiendo de la longitud). Tampoco se repite para diferentes semillas.
[2]: La Al contrastante tampoco se repite para diferentes semillas.