Package: tasknet
tasknet : simple multi-task transformer fine-tuning with Trainer and HuggingFace datasets.tasknetis an interface between Huggingfacedatasetsand HuggingfaceTrainer.Task templatestasknetrelies on task templates to avoid boilerplate codes. The task templates correspond to Transformers AutoClasses:SequenceClassificationTokenClassificationMultipleChoiceSeq2SeqLM(experimental support)The task templates follow the same interface. They implementpreprocess_function, a data collator andcompute_metrics.
Look attasks.pyand use existing templates as a starting point to implement a custom task template.Installation and examplepip install tasknetEach task template has fields that should be matched with specific dataset columns. Classification has two text fieldss1,s2, and a labely. Pass a dataset to a template, and fill in the mapping between the template fields and the dataset columns to instantiate a task.importtasknetastn;fromdatasetsimportload_datasetrte=tn.Classification(dataset=load_dataset("glue","rte"),s1="sentence1",s2="sentence2",y="label")#s2 is optional # See AutoTask for shorter codeclasshparams: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.TrainingArgumentstasks=[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 inferenceTasknet is multitask by design.model.task_models_listcontains one model per task, with a shared encoder.Balancing dataset sizestn.Classification(dataset,nrows=5000,nrows_eval=500,oversampling=2)You can balance multiple datasets withnrowsandoversampling.nrowsis the maximal number of examples. If a dataset has less thannrows, it will be oversampled at mostoversamplingtimes.AutoTaskYou can also leveragetasksourcewith tn.AutoTask and have one-line access to 600+ datasets, seeimplemented 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).Colab examplesMinimal-ish example:https://colab.research.google.com/drive/15Xf4Bgs3itUmok7XlAK6EEquNbvjD9BD?usp=sharingMore complex example, where tasknet was scaled to600 tasks:https://colab.research.google.com/drive/1iB4Oxl9_B5W3ZDzXoWJN-olUbqLBxgQS?usp=sharingtasknet vs jiantjiantis another library comparable to tasknet.  tasknet is a minimal extension ofTrainercentered on task templates, while jiant builds aTrainerequivalent from scratch calledrunner.tasknetis leaner and closer to Huggingface native tools. Jiant is config-based and command line focused while tasknet is designed for interactive use and python scripting.CreditThis code uses some part of the examples of thetransformerslibrary and some code frommultitask-learning-transformers.ContactYou can request features on github or reach me atdamien.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}}