Views
No views yet
1>>> from transformers import pipeline, set_seed
2>>> generator = pipeline('text-generation', model='gpt2-medium')
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, I'm a language. I'm a compiler, I'm a parser, I'm a server process. I"},
7 {'generated_text': "Hello, I'm a language model, and I'd like to join an existing team. What can I do to get started?\n\nI'd"},
8 {'generated_text': "Hello, I'm a language model, why does my code get created? Can't I just copy it? But why did my code get created when"},
9 {'generated_text': "Hello, I'm a language model, a functional language...\n\nI'm a functional language. Is it hard? A little, yes. But"},
10 {'generated_text': "Hello, I'm a language model, not an object model.\n\nIn a nutshell, I need to give me objects from which I can get"}]1from transformers import GPT2Tokenizer, GPT2Model
2tokenizer = GPT2Tokenizer.from_pretrained('gpt2-medium')
3model = GPT2Model.from_pretrained('gpt2-medium')
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-medium')
3model = TFGPT2Model.from_pretrained('gpt2-medium')
4text = "Replace me by any text you'd like."
5encoded_input = tokenizer(text, return_tensors='tf')
6output = model(encoded_input)The primary intended users of these models are AI researchers and practitioners.We primarily imagine these language models will be used by researchers to better understand the behaviors, capabilities, biases, and constraints of large-scale generative language models.
Here are some secondary use cases we believe are likely:
- Writing assistance: Grammar assistance, autocompletion (for normal prose or code)
- Creative writing and art: exploring the generation of creative, fictional texts; aiding creation of poetry and other literary art.
- Entertainment: Creation of games, chat bots, and amusing generations.
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-medium')
3>>> set_seed(42)
4>>> generator("The man worked as a", max_length=10, num_return_sequences=5)
5
6[{'generated_text': 'The man worked as a security guard in a military'},
7 {'generated_text': 'The man worked as a salesman in Mexico and eventually'},
8 {'generated_text': 'The man worked as a supervisor at the department for'},
9 {'generated_text': 'The man worked as a cleaner for the same corporation'},
10 {'generated_text': 'The man worked as a barman and was involved'}]
11
12>>> set_seed(42)
13>>> generator("The woman worked as a", max_length=10, num_return_sequences=5)
14
15[{'generated_text': 'The woman worked as a social worker in a children'},
16 {'generated_text': 'The woman worked as a marketing manager, and her'},
17 {'generated_text': 'The woman worked as a customer service agent in a'},
18 {'generated_text': 'The woman worked as a cleaner for the same corporation'},
19 {'generated_text': 'The woman worked as a barista and was involved'}]i only uses the inputs from 1 to i but not the future tokens.Since our model operates on a byte level and does not require lossy pre-processing or tokenization, we can evaluate it on any language model benchmark. Results on language modeling datasets are commonly reported in a quantity which is a scaled or ex- ponentiated version of the average negative log probability per canonical prediction unit - usually a character, a byte, or a word. We evaluate the same quantity by computing the log-probability of a dataset according to a WebText LM and dividing by the number of canonical units. For many of these datasets, WebText LMs would be tested significantly out- of-distribution, having to predict aggressively standardized text, tokenization artifacts such as disconnected punctuation and contractions, shuffled sentences, and even the stringwhich is extremely rare in WebText - occurring only 26 times in 40 billion bytes. We report our main results...using invertible de-tokenizers which remove as many of these tokenization / pre-processing artifacts as possible. Since these de-tokenizers are invertible, we can still calculate the log probability of a dataset and they can be thought of as a simple form of domain adaptation.
| Dataset | LAMBADA | LAMBADA | CBT-CN | CBT-NE | WikiText2 | PTB | enwiki8 | text8 | WikiText103 | 1BW |
|---|---|---|---|---|---|---|---|---|---|---|
| (metric) | (PPL) | (ACC) | (ACC) | (ACC) | (PPL) | (PPL) | (BPB) | (BPC) | (PPL) | (PPL) |
| 15.60 | 55.48 | 92.35 | 87.1 | 22.76 | 47.33 | 1.01 | 1.06 | 26.37 | 55.72 |
1@article{radford2019language,
2 title={Language models are unsupervised multitask learners},
3 author={Radford, Alec and Wu, Jeffrey and Child, Rewon and Luan, David and Amodei, Dario and Sutskever, Ilya and others},
4 journal={OpenAI blog},
5 volume={1},
6 number={8},
7 pages={9},
8 year={2019}
9}