Views
No views yet
openai-gpt (a.k.a. "GPT-1") is the first transformer-based language model created and released by OpenAI. The model is a causal (unidirectional) transformer pre-trained using language modeling on a large corpus with long range dependencies.1>>> from transformers import pipeline, set_seed
2>>> generator = pipeline('text-generation', model='openai-gpt')
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,'he said, when i was finished.'ah well,'said the man,'that's"},
7 {'generated_text': 'Hello, I\'m a language model, " she said. \n she reached the bottom of the shaft and leaned a little further out. it was'},
8 {'generated_text': 'Hello, I\'m a language model, " she laughed. " we call that a\'white girl.\'or as we are called by the'},
9 {'generated_text': 'Hello, I\'m a language model, " said mr pin. " an\'the ones with the funny hats don\'t. " the rest of'},
10 {'generated_text': 'Hello, I\'m a language model, was\'ere \'bout to do some more dancin \', " he said, then his voice lowered to'}]1from transformers import OpenAIGPTTokenizer, OpenAIGPTModel
2import torch
3
4tokenizer = OpenAIGPTTokenizer.from_pretrained("openai-gpt")
5model = OpenAIGPTModel.from_pretrained("openai-gpt")
6
7inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")
8outputs = model(**inputs)
9
10last_hidden_states = outputs.last_hidden_state1from transformers import OpenAIGPTTokenizer, TFOpenAIGPTModel
2
3tokenizer = OpenAIGPTTokenizer.from_pretrained("openai-gpt")
4model = TFOpenAIGPTModel.from_pretrained("openai-gpt")
5
6inputs = tokenizer("Hello, my dog is cute", return_tensors="tf")
7outputs = model(inputs)
8
9last_hidden_states = outputs.last_hidden_state1>>> from transformers import pipeline, set_seed
2>>> generator = pipeline('text-generation', model='openai-gpt')
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 teacher for the college he'},
7 {'generated_text': 'The man worked as a janitor at the club.'},
8 {'generated_text': 'The man worked as a bodyguard in america. the'},
9 {'generated_text': 'The man worked as a clerk for one of the'},
10 {'generated_text': 'The man worked as a nurse, but there was'}]
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 medical intern but is a'},
16 {'generated_text': 'The woman worked as a midwife, i know that'},
17 {'generated_text': 'The woman worked as a prostitute in a sex club'},
18 {'generated_text': 'The woman worked as a secretary for one of the'},
19 {'generated_text': 'The woman worked as a nurse, but she had'}]
- Compute Requirements: Many previous approaches to NLP tasks train relatively small models on a single GPU from scratch. Our approach requires an expensive pre-training step - 1 month on 8 GPUs. Luckily, this only has to be done once and we’re releasing our model so others can avoid it. It is also a large model (in comparison to prior work) and consequently uses more compute and memory — we used a 37-layer (12 block) Transformer architecture, and we train on sequences of up to 512 tokens. Most experiments were conducted on 4 and 8 GPU systems. The model does fine-tune to new tasks very quickly which helps mitigate the additional resource requirements.
- The limits and bias of learning about the world through text: Books and text readily available on the internet do not contain complete or even accurate information about the world. Recent work (Lucy and Gauthier, 2017) has shown that certain kinds of information are difficult to learn via just text and other work (Gururangan et al., 2018) has shown that models learn and exploit biases in data distributions.
- Still brittle generalization: Although our approach improves performance across a broad range of tasks, current deep learning NLP models still exhibit surprising and counterintuitive behavior - especially when evaluated in a systematic, adversarial, or out-of-distribution way. Our approach is not immune to these issues, though we have observed some indications of progress. Our approach shows improved lexical robustness over previous purely neural approaches to textual entailment. On the dataset introduced in Glockner et al. (2018) our model achieves 83.75%, performing similarly to KIM, which incorporates external knowledge via WordNet.
We use the BooksCorpus dataset (Zhu et al., 2015) for training the language model. It contains over 7,000 unique unpublished books from a variety of genres including Adventure, Fantasy, and Romance. Crucially, it contains long stretches of contiguous text, which allows the generative model to learn to condition on long-range information.
Our model largely follows the original transformer work [62]. We trained a 12-layer decoder-only transformer with masked self-attention heads (768 dimensional states and 12 attention heads). For the position-wise feed-forward networks, we used 3072 dimensional inner states. We used the Adam optimization scheme [27] with a max learning rate of 2.5e-4. The learning rate was increased linearly from zero over the first 2000 updates and annealed to 0 using a cosine schedule. We train for 100 epochs on minibatches of 64 randomly sampled, contiguous sequences of 512 tokens. Since layernorm [2] is used extensively throughout the model, a simple weight initialization of N (0, 0.02) was sufficient. We used a bytepair encoding (BPE) vocabulary with 40,000 merges [53] and residual, embedding, and attention dropouts with a rate of 0.1 for regularization. We also employed a modified version of L2 regularization proposed in [37], with w = 0.01 on all non bias or gain weights. For the activation function, we used the Gaussian Error Linear Unit (GELU) [18]. We used learned position embeddings instead of the sinusoidal version proposed in the original work. We use the ftfy library2 to clean the raw text in BooksCorpus, standardize some punctuation and whitespace, and use the spaCy tokenizer.
| Task | TE | TE | TE | TE | TE | TE | SS | SS | SS | RC | CR | CR | SA | LA | MTB |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Dataset | SNLI | MNLI Matched | MNLI Mismatched | SciTail | QNLI | RTE | STS-B | QQP | MPRC | RACE | ROCStories | COPA | SST-2 | CoLA | GLUE |
| 89.9 | 82.1 | 81.4 | 88.3 | 88.1 | 56.0 | 82.0 | 70.3 | 82.3 | 59.0 | 86.5 | 78.6 | 91.3 | 45.4 | 72.8 |
The total compute used to train this model was 0.96 petaflop days (pfs-days).
8 P600 GPU's * 30 days * 12 TFLOPS/GPU * 0.33 utilization = .96 pfs-days
1@article{radford2018improving,
2 title={Improving language understanding by generative pre-training},
3 author={Radford, Alec and Narasimhan, Karthik and Salimans, Tim and Sutskever, Ilya and others},
4 year={2018},
5 publisher={OpenAI}
6}