Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tasknet-1.47.0.tar.gz (52.2 kB view details)

Uploaded Source

Built Distribution

tasknet-1.47.0-py3-none-any.whl (30.5 kB view details)

Uploaded Python 3

File details

Details for the file tasknet-1.47.0.tar.gz.

File metadata

  • Download URL: tasknet-1.47.0.tar.gz
  • Upload date:
  • Size: 52.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for tasknet-1.47.0.tar.gz
Algorithm Hash digest
SHA256 cd72a2a252c77db459e205f79638347cdc4dab9683f66f2563fb4042634eb1d0
MD5 c1aad663d6ebef5de274df08c2359492
BLAKE2b-256 de78b60529f87eb25b3809514107e761329ef5d85740ccf3ceeb56af53a2595b

See more details on using hashes here.

Provenance

File details

Details for the file tasknet-1.47.0-py3-none-any.whl.

File metadata

  • Download URL: tasknet-1.47.0-py3-none-any.whl
  • Upload date:
  • Size: 30.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for tasknet-1.47.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b0ee12ba4d718248e75828b7fc69f048b765c7b30a15b4da3740470238e490ba
MD5 269f95b12b674e29d8f4c48f2c925817
BLAKE2b-256 47903d79a91b5592cea5e65c706bad84bce4649006445d9172fdd390ead1cb44

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page