StefanH commited on
Commit
501f5ba
·
1 Parent(s): 9d65d6a

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +58 -0
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 Vanilla 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 via the generative classification framework,
27
+ as a baseline with the aspect-normalized [UTCD](https://huggingface.co/datasets/claritylab/UTCD) dataset.
28
+
29
+ - **Finetuned from model:** [`gpt2-medium`](https://huggingface.co/gpt2-medium)
30
+
31
+
32
+ ## Usage
33
+
34
+ You can use the model like this:
35
+
36
+ ```python
37
+ >>> import torch
38
+ >>> from zeroshot_classifier.models import ZsGPT2Tokenizer, ZsGPT2LMHeadModel
39
+
40
+ >>> training_strategy = 'vanilla'
41
+ >>> model_name = f'claritylab/zero-shot-{training_strategy}-gpt2'
42
+ >>> model = ZsGPT2LMHeadModel.from_pretrained(model_name)
43
+ >>> tokenizer = ZsGPT2Tokenizer.from_pretrained(model_name, form=training_strategy)
44
+
45
+ >>> text = "I'd like to have this track onto my Classical Relaxations playlist."
46
+ >>> labels = [
47
+ >>> 'Add To Playlist', 'Book Restaurant', 'Get Weather', 'Play Music', 'Rate Book', 'Search Creative Work',
48
+ >>> 'Search Screening Event'
49
+ >>> ]
50
+
51
+ >>> inputs = tokenizer(dict(text=text, label_options=labels), 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
+ ```