Seamless integration of tasks with huggingface models
Project description
tasknet : simple multi-task transformer fine-tuning with Trainer and HuggingFace datasets.
tasknet
is an interface between Huggingface datasets and Huggingface Trainer.
Task templates
tasknet
relies on task templates to avoid boilerplate codes. The task templates correspond to Transformers AutoClasses:
SequenceClassification
TokenClassification
MultipleChoice
Seq2SeqLM
(experimental support)
The task templates follow the same interface. They implement preprocess_function
, a data collator and compute_metrics
.
Look at tasks.py and use existing templates as a starting point to implement a custom task template.
Task instances and example
Each task template has fields that should be matched with specific dataset columns. Classification has two text fields s1
,s2
, and a label y
. Pass a dataset to a template, and fill-in the mapping between the tempalte fields and the dataset columns to instanciate a task.
import tasknet as tn; from datasets import load_dataset
rte = tn.Classification(
dataset=load_dataset("glue", "rte"),
s1="sentence1", s2="sentence2", y="label") #s2 is optional
class hparams:
model_name='microsoft/deberta-v3-base' # deberta models have the best results (and tasknet support)
learning_rate = 3e-5 # see hf.co/docs/transformers/en/main_classes/trainer#transformers.TrainingArguments
tasks = [rte]
model = tn.Model(tasks, hparams)
trainer = tn.Trainer(model, tasks, hparams)
trainer.train()
trainer.evaluate()
p = trainer.pipeline()
p([{'text':x.premise,'text_pair': x.hypothesis}]) # HuggingFace pipeline for inference
Tasknet is multitask by design. model.task_models_list
contains one model per task, with shared encoder.
Installation
pip install tasknet
Additional examples:
Colab:
https://colab.research.google.com/drive/15Xf4Bgs3itUmok7XlAK6EEquNbvjD9BD?usp=sharing
tasknet vs jiant
jiant is another library comparable to tasknet. tasknet is a minimal extension of Trainer
centered on task templates, while jiant builds a Trainer
equivalent from scratch called runner
.
tasknet
is leaner and closer to Huggingface native tools. Jiant is config-based and command line focused while tasknet is designed for interative use and python scripting.
Credit
This code uses some part of the examples of the transformers library and some code from multitask-learning-transformers.
Contact
You can request features on github or reach me at damien.sileo@inria.fr
@misc{sileod22-tasknet,
author = {Sileo, Damien},
doi = {10.5281/zenodo.561225781},
month = {11},
title = {{tasknet, multitask interface between Trainer and datasets}},
url = {https://github.com/sileod/tasknet},
version = {1.5.0},
year = {2022}}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tasknet-1.45.0.tar.gz
.
File metadata
- Download URL: tasknet-1.45.0.tar.gz
- Upload date:
- Size: 52.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c96a8f98ed92159b1733cbd366c54d24d8b8c5b80a6c1c515e0e20df31c604a1 |
|
MD5 | 5011590f60e47d90095bc4206a1f6e15 |
|
BLAKE2b-256 | c6fc6b5a8a6660293b297844960bc01546b7e9b9c639435b19dffba53858b5e6 |
Provenance
File details
Details for the file tasknet-1.45.0-py3-none-any.whl
.
File metadata
- Download URL: tasknet-1.45.0-py3-none-any.whl
- Upload date:
- Size: 30.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e71a2a3dae39772806925115b11ea8dab5be319c05c6eae77f01c32762de2309 |
|
MD5 | 11a11568e2ffc53f59d34e60941e8941 |
|
BLAKE2b-256 | 5efbe1870aab4c252c0ec05f218d6411284b9843170f124e7afe25cd53cd0752 |