Views
No views yet
gpt2-mediumpip install zeroshot-classifier1>>> import torch
2>>> from zeroshot_classifier.models import ZsGPT2Tokenizer, ZsGPT2LMHeadModel
3
4>>> training_strategy = 'explicit'
5>>> model_name = f'claritylab/zero-shot-{training_strategy}-gpt2'
6>>> model = ZsGPT2LMHeadModel.from_pretrained(model_name)
7>>> tokenizer = ZsGPT2Tokenizer.from_pretrained(model_name, form=training_strategy)
8
9>>> text = "I'd like to have this track onto my Classical Relaxations playlist."
10>>> labels = [
11>>> 'Add To Playlist', 'Book Restaurant', 'Get Weather', 'Play Music', 'Rate Book', 'Search Creative Work',
12>>> 'Search Screening Event'
13>>> ]
14
15>>> inputs = tokenizer(dict(text=text, label_options=labels), mode='inference-sample')
16>>> inputs = {k: torch.tensor(v).unsqueeze(0) for k, v in inputs.items()}
17>>> outputs = model.generate(**inputs, max_length=128)
18>>> decoded = tokenizer.batch_decode(outputs, skip_special_tokens=False)[0]
19>>> print(decoded)
20
21<|question|>Which of these choices best describes the following document? : " Play Music ", " Add To Playlist ", " Rate Book ", " Get Weather ", " Book Restaurant ", " Search Screening Event ", " Search Creative Work "<|endoftext|><|text|>I'd like to have this track onto my Classical Relaxations playlist.<|endoftext|><|answer|>Play Media<|endoftext|>