Jouer avec une approche SetFit pour un transfert à quelques coups pour la classification du texte.
Edit: J'ai également fait quelques expériences avec un apprentissage actif, alors maintenant j'ai aussi active.py. Je vais l'organiser mieux une journée ensoleillée.
$ ~/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.
Remarque : Si vous souhaitez interroger LLMS hébergé chez HuggingFace (cas 3), vous devez créer votre compte sur HuggingFace Hub et générer des jetons d'accès, après quoi vous devez les coller dans un fichier
./hf_token.key.PS: Ne vous inquiétez pas, j'ai ajouté ce fichier à .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.
Ou vous pouvez simplement exécuter ./run.sh après l'installation des bibliothèques requises (voir requirements.txt )
Ensuite, vous pouvez exécuter le cahier summarise.ipynb pour résumer et visualiser (si j'arrête pour ajouter ce code) les résultats.
PS: Faites attention à
--full-test. Par défaut, nous tronçons chaque test de test sur ses 100 premières instances.
Ce sont tous des ensembles de données de classification qui ont été nettoyés par les gens gentils et gentils qui ont fait la lib setfit. Mais vous pouvez utiliser n'importe quel ensemble de données HF à condition qu'il ait ces trois champs: (i) texte (str), (ii) étiquette (int) et (iii) label_text (str).
Voici mes résultats:
Ce tableau présente les résultats de ce + la configuration d'apprentissage actif. Sauf indication contraire, nous répétons chaque expérience 5 fois. Ces chiffres rapportent la précision des tâches lorsque nous n'avions que 100 instances dans le train.
| BBC-News | sst2 | Senseval-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 |
| Pas de setfit contrastif ft | 0,932 ± 0,015 | 0,854 ± 0,019 | 0,886 ± 0,005 | 0,902 ± 0,019 | 0,942 ± 0,020 |
| FT régulier | 0,466 ± 0,133 | 0,628 ± 0,098 | 0,582 ± 0,054 | 0,836 ± 0,166 | 0,776 ± 0,089 |
| LLM | 0,950 ± 0,000 | 0,930 ± 0,000 | 0,900 ± 0,000 | 0,930 ± 0,000 | 0,820 ± 0,000 |
| AL contrastif | 0,980 ± 0,000 | 0,910 ± 0,000 | 0,910 ± 0,000 | 0,870 ± 0,000 | 0,980 ± 0,000 |
[1]: La demande de LLM est effectuée uniquement avec 10 instances (l'invite réelle peut contenir moins en fonction de la longueur). Ce n'est pas non plus répété pour différentes graines.
[2]: L'Al contrasté n'est pas non plus répété pour différentes graines.