Tasknet
Easy modernBERT fine-tuning and multi-task learning
Install / Use
/learn @sileod/TasknetREADME
tasknet : simple modernBERT fine-tuning, with multi-task support
tasknet is an interface between Huggingface datasets and Huggingface transformers Trainer.
Tasknet should work with all recent versions of Transformers.
Installation and example
pip install tasknet
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 template fields and the dataset columns to instantiate 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 for classification, used to represent text pairs
# See AutoTask for shorter code
class hparams:
model_name = 'tasksource/ModernBERT-base-nli' # better performance for most tasks
learning_rate = 3e-5 # see hf.co/docs/transformers/en/main_classes/trainer#transformers.TrainingArguments
model, trainer = tn.Model_Trainer(tasks=[rte],hparams)
trainer.train(), trainer.evaluate()
p = trainer.pipeline()
p([{'text':'premise here','text_pair': 'hypothesis here'}]) # HuggingFace pipeline for inference
Tasknet is multitask by design. model.task_models_list contains one model per task, with a shared encoder.
Task templates
tasknet relies on task templates to avoid boilerplate codes. The task templates correspond to Transformers AutoClasses:
SequenceClassification(s1, s2, y)TokenClassification(tokens, labels)(tokens and labels are lists of words and assigned labels)MultipleChoice(s1, choices)(s1 is a prompt/qusetion, choices is a list of texts, y is the index of the correct choice)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.
AutoTask
You can also leverage tasksource with tn.AutoTask and have one-line access to 600+ datasets, see implemented tasks.
rte = tn.AutoTask("glue/rte", nrows=5000)
AutoTask guesses a template based on the dataset structure. It also accepts a dataset as input, if it fits the template (e.g. after tasksource custom preprocessing).
Balancing dataset sizes
tn.Classification(dataset, nrows=5000, nrows_eval=500, oversampling=2)
You can balance multiple datasets with nrows and oversampling. nrows is the maximal number of examples. If a dataset has less than nrows, it will be oversampled at most oversampling times.
Colab examples
Minimal-ish example:
https://colab.research.google.com/drive/15Xf4Bgs3itUmok7XlAK6EEquNbvjD9BD?usp=sharing
More complex example, where tasknet was scaled to 600 tasks:
https://colab.research.google.com/drive/1iB4Oxl9_B5W3ZDzXoWJN-olUbqLBxgQS?usp=sharing
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}}
Related Skills
proje
Interactive vocabulary learning platform with smart flashcards and spaced repetition for effective language acquisition.
YC-Killer
2.7kA library of enterprise-grade AI agents designed to democratize artificial intelligence and provide free, open-source alternatives to overvalued Y Combinator startups. If you are excited about democratizing AI access & AI agents, please star ⭐️ this repository and use the link in the readme to join our open source AI research team.
best-practices-researcher
The most comprehensive Claude Code skills registry | Web Search: https://skills-registry-web.vercel.app
groundhog
398Groundhog's primary purpose is to teach people how Cursor and all these other coding agents work under the hood. If you understand how these coding assistants work from first principles, then you can drive these tools harder (or perhaps make your own!).
