Skip to main content

grouphug

GroupHug is a library with extensions to 🤗 transformers for multitask language modelling. In addition, it contains utilities that ease data preparation, training, and inference.

Project Moved

Grouphug maintenance and future versions have moved to my personal repository.

Overview

The package is optimized for training a single language model to make quick and robust predictions for a wide variety of related tasks at once, as well as to investigate the regularizing effect of training a language modelling task at the same time.

You can train on multiple datasets, with each dataset containing an arbitrary subset of your tasks. Supported tasks include:

  • A single language modelling task (Masked language modelling, Masked token detection, Causal language modelling).
    • The default collator included handles most preprocessing for these heads automatically.
  • Any number of classification tasks, including single- and multi-label classification and regression
    • A utility function that automatically creates a classification head from your data.
    • Additional options such as hidden layer size, additional input variables, and class weights.
  • You can also define your own model heads.

Quick Start

The project is based on Python 3.8+ and PyTorch 1.10+. To install it, simply use:

pip install grouphug

Documentation

Documentation can be generated from docstrings using make html in the docs directory, but this is not yet on a hosted site.

Example usage

import pandas as pd
from datasets import load_dataset
from transformers import AutoTokenizer

from grouphug import AutoMultiTaskModel, ClassificationHeadConfig, DatasetFormatter, LMHeadConfig, MultiTaskTrainer

# load some data. 'label' gets renamed in huggingface, so is better avoided as a feature name.
task_one = load_dataset("tweet_eval",'emoji').rename_column("label", "tweet_label")
both_tasks = pd.DataFrame({"text": ["yay :)", "booo!"], "sentiment": ["pos", "neg"], "tweet_label": [0,14]})

# create a tokenizer
base_model = "prajjwal1/bert-tiny"
tokenizer = AutoTokenizer.from_pretrained(base_model)

# preprocess your data: tokenization, preparing class variables
formatter = DatasetFormatter().tokenize().encode("sentiment")
# data converted to a DatasetCollection: essentially a dict of DatasetDict
data = formatter.apply({"one": task_one, "both": both_tasks}, tokenizer=tokenizer, test_size=0.05)

# define which model heads you would like
head_configs = [
    LMHeadConfig(weight=0.1),  # default is BERT-style masked language modelling
    ClassificationHeadConfig.from_data(data, "sentiment"),  # detects dimensions and type
    ClassificationHeadConfig.from_data(data, "tweet_label"),  # detects dimensions and type
]
# create the model, optionally saving the tokenizer and formatter along with it
model = AutoMultiTaskModel.from_pretrained(base_model, head_configs, formatter=formatter, tokenizer=tokenizer)
# create the trainer
trainer = MultiTaskTrainer(
    model=model,
    tokenizer=tokenizer,
    train_data=data[:, "train"],
    eval_data=data[["one"], "test"],
    eval_heads={"one": ["tweet_label"]},  # limit evaluation to one classification task
)
trainer.train()

Tutorials

See examples for a few notebooks that demonstrate the key features.

Supported Models

The package has support for the following base models:

  • Bert, DistilBert, Roberta/DistilRoberta, XLM-Roberta
  • Deberta/DebertaV2
  • Electra
  • GPT2, GPT-J, GPT-NeoX, OPT

Extending it to support other models is possible by simply inheriting from _BaseMultiTaskModel, although language modelling head weights may not always load.

Limitations

  • The package only supports PyTorch, and will not work with other frameworks. There are no plans to change this.
  • Grouphug was developed and tested with 🤗 transformers 4.19-4.22. We will aim to test and keep compatibility with the latest version, but it is still recommended to lock the latest working versions.

See the contributing page if you are interested in contributing.

License

grouphug was developed by Chatdesk and is licensed under the Apache 2 license.

Metadata

Release files for chatdesk-grouphug 0.8.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chatdesk-grouphug 0.8.1
File Size Uploaded Provenance Actions
chatdesk_grouphug-0.8.1.tar.gz 36.1 kB Without provenance Details for chatdesk_grouphug-0.8.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for chatdesk-grouphug 0.8.1
File Interpreter ABI Platform Actions
chatdesk_grouphug-0.8.1-py3-none-any.whl Python 3 none any Details for chatdesk_grouphug-0.8.1-py3-none-any.whl

Total release size: 76.6 kB

Release files / chatdesk_grouphug-0.8.1.tar.gz

Download URL chatdesk_grouphug-0.8.1.tar.gz
Size 36.1 kB
Tags Source
SHA-256 checksum
How to use checksums
fed0a49d3c22cd11a35c906b0f1bbf4b323bb4bb2165217c7ee3d6ecba6cb53c
BLAKE2b-256 checksum
How to use checksums
d8ff2e64862626006f57593b94555da9e950463fc75a0765a9a8ea0d2954efa6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / chatdesk_grouphug-0.8.1-py3-none-any.whl

Download URL chatdesk_grouphug-0.8.1-py3-none-any.whl
Size 40.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
70aa59008242818bc5d767038f736c7249fcb868798ebc1d5a8cd21d7eed7095
BLAKE2b-256 checksum
How to use checksums
9f3ef8fbc45b472616c775fdfbd5e8c3e43258160c080b5b7f3c362433b6ed01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Security for chatdesk-grouphug 0.8.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page