Downloads · 30 days
25
7% of all-time downloads
claritylab/zero-shot-implicit-gpt2
zero-shot-implicit-gpt2 is a text generation model from claritylab. Use it when you need the model to write or continue text. It is set up for zeroshot_classifier. The card lists the license as mit.
This is a modified GPT2 model. It was introduced in the Findings of ACL'23 Paper Label Agnostic Pre-training for Zero-shot Text Classification by Christopher Clarke, Yuzhao Heng, Yiping Kang, Krisztian Flautner, Lingj…
Downloads · 30 days
25
7% of all-time downloads
All-time downloads
374
Public
Repo size
2.9 GB
Likes
0
Public
Click a slice to open those files.
.bin1.4 GB · 100%
From the Hugging Face model README
This is a modified GPT2 model. It was introduced in the Findings of ACL'23 Paper Label Agnostic Pre-training for Zero-shot Text Classification by Christopher Clarke, Yuzhao Heng, Yiping Kang, Krisztian Flautner, Lingjia Tang and Jason Mars. The code for training and evaluating this model can be found here.
This model is intended for zero-shot text classification. It was trained under the generative classification framework via implicit training with the aspect-normalized UTCD dataset.
gpt2-mediumInstall our python package:
pip install zeroshot-classifier
Then, you can use the model like this:
>>> import torch
>>> from zeroshot_classifier.models import ZsGPT2Tokenizer, ZsGPT2LMHeadModel
>>> training_strategy = 'implicit'
>>> model_name = f'claritylab/zero-shot-{training_strategy}-gpt2'
>>> model = ZsGPT2LMHeadModel.from_pretrained(model_name)
>>> tokenizer = ZsGPT2Tokenizer.from_pretrained(model_name, form=training_strategy)
>>> text = "I'd like to have this track onto my Classical Relaxations playlist."
>>> labels = [
>>> 'Add To Playlist', 'Book Restaurant', 'Get Weather', 'Play Music', 'Rate Book', 'Search Creative Work',
>>> 'Search Screening Event'
>>> ]
>>> aspect = 'intent'
>>> inputs = tokenizer(dict(text=text, label_options=labels, aspect=aspect), mode='inference-sample')
>>> inputs = {k: torch.tensor(v).unsqueeze(0) for k, v in inputs.items()}
>>> outputs = model.generate(**inputs, max_length=128)
>>> decoded = tokenizer.batch_decode(outputs, skip_special_tokens=False)[0]
>>> print(decoded)
<|question|>Which of these categories best describes the following document? : " Play Music ", " Add To Playlist ", " Rate Book ", " Book Restaurant ", " Search Creative Work ", " Search Screening Event ", " Get Weather "<|endoftext|><|text|>intent[ASPECT_SEP]I'd like to have this track onto my Classical Relaxations playlist.<|endoftext|><|answer|>Play Media<|endoftext|>