Skip to main content

Seamless integration of tasks with huggingface models

Project description

tasknet

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)

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

Each task template is associated with specific fields. Classification has two text fields s1,s2, and a label y. Pass a dataset to a template, and fill-in the mapping between the dataset fields and the template fields 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"
)

class args:
  model_name='roberta-base'
  learning_rate = 3e-5 # see https://huggingface.co/docs/transformers/v4.24.0/en/main_classes/trainer#transformers.TrainingArguments

 
tasks = [rte]
model = tn.Model(tasks, args)
trainer = tn.Trainer(model, tasks, args)
trainer.train()

As you can see, tasknet is multitask by design. It works with list of tasks and the model creates a task_models_list attribute.

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 custom analog of Trainer from scratch called runner. tasknet is leaner and easier to extend. jiant is config-based while tasknet is designed for interative use and 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{sileod21-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.15.0.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

tasknet-1.15.0-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for tasknet-1.15.0.tar.gz
Algorithm Hash digest
SHA256 061ac3b3bbe30da8ce449738dc6d1bf73ab268eb377b7fb06491c6595499a38a
MD5 c11a9343a0d2753d6b685b5df344b049
BLAKE2b-256 3180a8bfeb283467328eb159804a3a49140fde971ab027c43a326f2c4370ee08

See more details on using hashes here.

Provenance

File details

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

File metadata

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

File hashes

Hashes for tasknet-1.15.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e4ccb97237b11db0a28537cf65a4c78d9bb9fd08652c8df418f6803d84369e6d
MD5 921ad827a2ce9df4df18de5da181e587
BLAKE2b-256 1cfd9dfd36dfb999f8c4406c386651d2415691d7d32130e57f62838cdadab85c

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