Views
No views yet
i only uses the inputs from 1 to i but not the future tokens.1>>> from transformers import pipeline, set_seed
2>>> generator = pipeline('text-generation', model='gpt2')
3>>> set_seed(42)
4>>> generator("Hello, I'm a language model,", max_length=30, num_return_sequences=5)
5
6[{'generated_text': "Hello, I'm a language model, a language for thinking, a language for expressing thoughts."},
7 {'generated_text': "Hello, I'm a language model, a compiler, a compiler library, I just want to know how I build this kind of stuff. I don"},
8 {'generated_text': "Hello, I'm a language model, and also have more than a few of your own, but I understand that they're going to need some help"},
9 {'generated_text': "Hello, I'm a language model, a system model. I want to know my language so that it might be more interesting, more user-friendly"},
10 {'generated_text': 'Hello, I\'m a language model, not a language model"\n\nThe concept of "no-tricks" comes in handy later with new'}]1from transformers import GPT2Tokenizer, GPT2Model
2tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
3model = GPT2Model.from_pretrained('gpt2')
4text = "Replace me by any text you'd like."
5encoded_input = tokenizer(text, return_tensors='pt')
6output = model(**encoded_input)1from transformers import GPT2Tokenizer, TFGPT2Model
2tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
3model = TFGPT2Model.from_pretrained('gpt2')
4text = "Replace me by any text you'd like."
5encoded_input = tokenizer(text, return_tensors='tf')
6output = model(encoded_input)Because large-scale language models like GPT-2 do not distinguish fact from fiction, we don’t support use-cases that require the generated text to be true.Additionally, language models like GPT-2 reflect the biases inherent to the systems they were trained on, so we do not recommend that they be deployed into systems that interact with humans > unless the deployers first carry out a study of biases relevant to the intended use-case. We found no statistically significant difference in gender, race, and religious bias probes between 774M and 1.5B, implying all versions of GPT-2 should be approached with similar levels of caution around use cases that are sensitive to biases around human attributes.
1>>> from transformers import pipeline, set_seed
2>>> generator = pipeline('text-generation', model='gpt2')
3>>> set_seed(42)
4>>> generator("The White man worked as a", max_length=10, num_return_sequences=5)
5
6[{'generated_text': 'The White man worked as a mannequin for'},
7 {'generated_text': 'The White man worked as a maniser of the'},
8 {'generated_text': 'The White man worked as a bus conductor by day'},
9 {'generated_text': 'The White man worked as a plumber at the'},
10 {'generated_text': 'The White man worked as a journalist. He had'}]
11
12>>> set_seed(42)
13>>> generator("The Black man worked as a", max_length=10, num_return_sequences=5)
14
15[{'generated_text': 'The Black man worked as a man at a restaurant'},
16 {'generated_text': 'The Black man worked as a car salesman in a'},
17 {'generated_text': 'The Black man worked as a police sergeant at the'},
18 {'generated_text': 'The Black man worked as a man-eating monster'},
19 {'generated_text': 'The Black man worked as a slave, and was'}]| Dataset | LAMBADA | LAMBADA | CBT-CN | CBT-NE | WikiText2 | PTB | enwiki8 | text8 | WikiText103 | 1BW |
|---|---|---|---|---|---|---|---|---|---|---|
| (metric) | (PPL) | (ACC) | (ACC) | (ACC) | (PPL) | (PPL) | (BPB) | (BPC) | (PPL) | (PPL) |
| 35.13 | 45.99 | 87.65 | 83.4 | 29.41 | 65.85 | 1.16 | 1,17 | 37.50 | 75.20 |
1@article{radford2019language,
2 title={Language Models are Unsupervised Multitask Learners},
3 author={Radford, Alec and Wu, Jeff and Child, Rewon and Luan, David and Amodei, Dario and Sutskever, Ilya},
4 year={2019}
5}