Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: zeroshot_classifier
|
| 3 |
+
tags:
|
| 4 |
+
- transformers
|
| 5 |
+
- sentence-transformers
|
| 6 |
+
- zeroshot_classifier
|
| 7 |
+
license: mit
|
| 8 |
+
datasets:
|
| 9 |
+
- claritylab/UTCD
|
| 10 |
+
language:
|
| 11 |
+
- en
|
| 12 |
+
pipeline_tag: text-generation
|
| 13 |
+
metrics:
|
| 14 |
+
- accuracy
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# Zero-shot Implicit GPT2
|
| 18 |
+
|
| 19 |
+
This is a modified GPT2 model.
|
| 20 |
+
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***.
|
| 21 |
+
The code for training and evaluating this model can be found [here](https://github.com/ChrisIsKing/zero-shot-text-classification/tree/master).
|
| 22 |
+
|
| 23 |
+
## Model description
|
| 24 |
+
|
| 25 |
+
This model is intended for zero-shot text classification.
|
| 26 |
+
It was trained under the generative classification framework via implicit training with the aspect-normalized [UTCD](https://huggingface.co/datasets/claritylab/UTCD) dataset.
|
| 27 |
+
|
| 28 |
+
- **Finetuned from model:** [`gpt2-medium`](https://huggingface.co/gpt2-medium)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
## Usage
|
| 32 |
+
|
| 33 |
+
You can use the model like this:
|
| 34 |
+
|
| 35 |
+
```python
|
| 36 |
+
>>> import torch
|
| 37 |
+
>>> from zeroshot_classifier.models import ZsGPT2Tokenizer, ZsGPT2LMHeadModel
|
| 38 |
+
|
| 39 |
+
>>> training_strategy = 'implicit'
|
| 40 |
+
>>> model_name = f'claritylab/zero-shot-{training_strategy}-gpt2'
|
| 41 |
+
>>> model = ZsGPT2LMHeadModel.from_pretrained(model_name)
|
| 42 |
+
>>> tokenizer = ZsGPT2Tokenizer.from_pretrained(model_name, form=training_strategy)
|
| 43 |
+
|
| 44 |
+
>>> text = "I'd like to have this track onto my Classical Relaxations playlist."
|
| 45 |
+
>>> labels = [
|
| 46 |
+
>>> 'Add To Playlist', 'Book Restaurant', 'Get Weather', 'Play Music', 'Rate Book', 'Search Creative Work',
|
| 47 |
+
>>> 'Search Screening Event'
|
| 48 |
+
>>> ]
|
| 49 |
+
>>> aspect = 'intent'
|
| 50 |
+
|
| 51 |
+
>>> inputs = tokenizer(dict(text=text, label_options=labels, aspect=aspect), mode='inference-sample')
|
| 52 |
+
>>> inputs = {k: torch.tensor(v).unsqueeze(0) for k, v in inputs.items()}
|
| 53 |
+
>>> outputs = model.generate(**inputs, max_length=128)
|
| 54 |
+
>>> decoded = tokenizer.batch_decode(outputs, skip_special_tokens=False)[0]
|
| 55 |
+
>>> print(decoded)
|
| 56 |
+
|
| 57 |
+
<|question|>How is the text best described? : " Rate Book ", " Search Screening Event ", " Add To Playlist ", " Search Creative Work ", " Get Weather ", " Play Music ", " Book Restaurant "<|endoftext|><|text|>I'd like to have this track onto my Classical Relaxations playlist.<|endoftext|><|answer|>Play Media<|endoftext|>
|
| 58 |
+
```
|