byeongal commited on
Commit
2e765e0
·
1 Parent(s): f3a4516

forked from https://huggingface.co/gpt2

Browse files
README.md CHANGED
@@ -1,3 +1,166 @@
1
  ---
 
 
 
 
2
  license: mit
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language: en
3
+ tags:
4
+ - exbert
5
+
6
  license: mit
7
  ---
8
+
9
+
10
+ This repository has been forked from https://huggingface.co/gpt2
11
+ ---
12
+
13
+ # GPT-2
14
+
15
+ Test the whole generation capabilities here: https://transformer.huggingface.co/doc/gpt2-large
16
+
17
+ Pretrained model on English language using a causal language modeling (CLM) objective. It was introduced in
18
+ [this paper](https://d4mucfpksywv.cloudfront.net/better-language-models/language_models_are_unsupervised_multitask_learners.pdf)
19
+ and first released at [this page](https://openai.com/blog/better-language-models/).
20
+
21
+ Disclaimer: The team releasing GPT-2 also wrote a
22
+ [model card](https://github.com/openai/gpt-2/blob/master/model_card.md) for their model. Content from this model card
23
+ has been written by the Hugging Face team to complete the information they provided and give specific examples of bias.
24
+
25
+ ## Model description
26
+
27
+ GPT-2 is a transformers model pretrained on a very large corpus of English data in a self-supervised fashion. This
28
+ means it was pretrained on the raw texts only, with no humans labelling them in any way (which is why it can use lots
29
+ of publicly available data) with an automatic process to generate inputs and labels from those texts. More precisely,
30
+ it was trained to guess the next word in sentences.
31
+
32
+ More precisely, inputs are sequences of continuous text of a certain length and the targets are the same sequence,
33
+ shifted one token (word or piece of word) to the right. The model uses internally a mask-mechanism to make sure the
34
+ predictions for the token `i` only uses the inputs from `1` to `i` but not the future tokens.
35
+
36
+ This way, the model learns an inner representation of the English language that can then be used to extract features
37
+ useful for downstream tasks. The model is best at what it was pretrained for however, which is generating texts from a
38
+ prompt.
39
+
40
+ ## Intended uses & limitations
41
+
42
+ You can use the raw model for text generation or fine-tune it to a downstream task. See the
43
+ [model hub](https://huggingface.co/models?filter=gpt2) to look for fine-tuned versions on a task that interests you.
44
+
45
+ ### How to use
46
+
47
+ You can use this model directly with a pipeline for text generation. Since the generation relies on some randomness, we
48
+ set a seed for reproducibility:
49
+
50
+ ```python
51
+ >>> from transformers import pipeline, set_seed
52
+ >>> generator = pipeline('text-generation', model='gpt2')
53
+ >>> set_seed(42)
54
+ >>> generator("Hello, I'm a language model,", max_length=30, num_return_sequences=5)
55
+
56
+ [{'generated_text': "Hello, I'm a language model, a language for thinking, a language for expressing thoughts."},
57
+ {'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"},
58
+ {'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"},
59
+ {'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"},
60
+ {'generated_text': 'Hello, I\'m a language model, not a language model"\n\nThe concept of "no-tricks" comes in handy later with new'}]
61
+ ```
62
+
63
+ Here is how to use this model to get the features of a given text in PyTorch:
64
+
65
+ ```python
66
+ from transformers import GPT2Tokenizer, GPT2Model
67
+ tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
68
+ model = GPT2Model.from_pretrained('gpt2')
69
+ text = "Replace me by any text you'd like."
70
+ encoded_input = tokenizer(text, return_tensors='pt')
71
+ output = model(**encoded_input)
72
+ ```
73
+
74
+ and in TensorFlow:
75
+
76
+ ```python
77
+ from transformers import GPT2Tokenizer, TFGPT2Model
78
+ tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
79
+ model = TFGPT2Model.from_pretrained('gpt2')
80
+ text = "Replace me by any text you'd like."
81
+ encoded_input = tokenizer(text, return_tensors='tf')
82
+ output = model(encoded_input)
83
+ ```
84
+
85
+ ### Limitations and bias
86
+
87
+ The training data used for this model has not been released as a dataset one can browse. We know it contains a lot of
88
+ unfiltered content from the internet, which is far from neutral. As the openAI team themselves point out in their
89
+ [model card](https://github.com/openai/gpt-2/blob/master/model_card.md#out-of-scope-use-cases):
90
+
91
+ > Because large-scale language models like GPT-2 do not distinguish fact from fiction, we don’t support use-cases
92
+ > that require the generated text to be true.
93
+ >
94
+ > Additionally, language models like GPT-2 reflect the biases inherent to the systems they were trained on, so we do
95
+ > not recommend that they be deployed into systems that interact with humans > unless the deployers first carry out a
96
+ > study of biases relevant to the intended use-case. We found no statistically significant difference in gender, race,
97
+ > and religious bias probes between 774M and 1.5B, implying all versions of GPT-2 should be approached with similar
98
+ > levels of caution around use cases that are sensitive to biases around human attributes.
99
+
100
+ Here's an example of how the model can have biased predictions:
101
+
102
+ ```python
103
+ >>> from transformers import pipeline, set_seed
104
+ >>> generator = pipeline('text-generation', model='gpt2')
105
+ >>> set_seed(42)
106
+ >>> generator("The White man worked as a", max_length=10, num_return_sequences=5)
107
+
108
+ [{'generated_text': 'The White man worked as a mannequin for'},
109
+ {'generated_text': 'The White man worked as a maniser of the'},
110
+ {'generated_text': 'The White man worked as a bus conductor by day'},
111
+ {'generated_text': 'The White man worked as a plumber at the'},
112
+ {'generated_text': 'The White man worked as a journalist. He had'}]
113
+
114
+ >>> set_seed(42)
115
+ >>> generator("The Black man worked as a", max_length=10, num_return_sequences=5)
116
+
117
+ [{'generated_text': 'The Black man worked as a man at a restaurant'},
118
+ {'generated_text': 'The Black man worked as a car salesman in a'},
119
+ {'generated_text': 'The Black man worked as a police sergeant at the'},
120
+ {'generated_text': 'The Black man worked as a man-eating monster'},
121
+ {'generated_text': 'The Black man worked as a slave, and was'}]
122
+ ```
123
+
124
+ This bias will also affect all fine-tuned versions of this model.
125
+
126
+ ## Training data
127
+
128
+ The OpenAI team wanted to train this model on a corpus as large as possible. To build it, they scraped all the web
129
+ pages from outbound links on Reddit which received at least 3 karma. Note that all Wikipedia pages were removed from
130
+ this dataset, so the model was not trained on any part of Wikipedia. The resulting dataset (called WebText) weights
131
+ 40GB of texts but has not been publicly released. You can find a list of the top 1,000 domains present in WebText
132
+ [here](https://github.com/openai/gpt-2/blob/master/domains.txt).
133
+
134
+ ## Training procedure
135
+
136
+ ### Preprocessing
137
+
138
+ The texts are tokenized using a byte-level version of Byte Pair Encoding (BPE) (for unicode characters) and a
139
+ vocabulary size of 50,257. The inputs are sequences of 1024 consecutive tokens.
140
+
141
+ The larger model was trained on 256 cloud TPU v3 cores. The training duration was not disclosed, nor were the exact
142
+ details of training.
143
+
144
+ ## Evaluation results
145
+
146
+ The model achieves the following results without any fine-tuning (zero-shot):
147
+
148
+ | Dataset | LAMBADA | LAMBADA | CBT-CN | CBT-NE | WikiText2 | PTB | enwiki8 | text8 | WikiText103 | 1BW |
149
+ |:--------:|:-------:|:-------:|:------:|:------:|:---------:|:------:|:-------:|:------:|:-----------:|:-----:|
150
+ | (metric) | (PPL) | (ACC) | (ACC) | (ACC) | (PPL) | (PPL) | (BPB) | (BPC) | (PPL) | (PPL) |
151
+ | | 35.13 | 45.99 | 87.65 | 83.4 | 29.41 | 65.85 | 1.16 | 1,17 | 37.50 | 75.20 |
152
+
153
+
154
+ ### BibTeX entry and citation info
155
+
156
+ ```bibtex
157
+ @article{radford2019language,
158
+ title={Language Models are Unsupervised Multitask Learners},
159
+ author={Radford, Alec and Wu, Jeff and Child, Rewon and Luan, David and Amodei, Dario and Sutskever, Ilya},
160
+ year={2019}
161
+ }
162
+ ```
163
+
164
+ <a href="https://huggingface.co/exbert/?model=gpt2">
165
+ <img width="300px" src="https://cdn-media.huggingface.co/exbert/button.png">
166
+ </a>
config.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name_or_path": "gpt2-small",
3
+ "activation_function": "gelu_new",
4
+ "architectures": [
5
+ "GPT2LMHeadModel"
6
+ ],
7
+ "attn_pdrop": 0.1,
8
+ "bos_token_id": 50256,
9
+ "embd_pdrop": 0.1,
10
+ "eos_token_id": 50256,
11
+ "initializer_range": 0.02,
12
+ "layer_norm_epsilon": 1e-05,
13
+ "model_type": "gpt2",
14
+ "n_ctx": 1024,
15
+ "n_embd": 768,
16
+ "n_head": 12,
17
+ "n_inner": null,
18
+ "n_layer": 12,
19
+ "n_positions": 1024,
20
+ "reorder_and_upcast_attn": false,
21
+ "resid_pdrop": 0.1,
22
+ "scale_attn_by_inverse_layer_idx": false,
23
+ "scale_attn_weights": true,
24
+ "summary_activation": null,
25
+ "summary_first_dropout": 0.1,
26
+ "summary_proj_to_labels": true,
27
+ "summary_type": "cls_index",
28
+ "summary_use_proj": true,
29
+ "task_specific_params": {
30
+ "text-generation": {
31
+ "do_sample": true,
32
+ "max_length": 50
33
+ }
34
+ },
35
+ "torch_dtype": "float32",
36
+ "transformers_version": "4.23.1",
37
+ "use_cache": true,
38
+ "vocab_size": 50257
39
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7c5d3f4b8b76583b422fcb9189ad6c89d5d97a094541ce8932dce3ecabde1421
3
+ size 548118077
special_tokens_map.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<|endoftext|>",
3
+ "eos_token": "<|endoftext|>",
4
+ "pad_token": "<|endoftext|>",
5
+ "unk_token": "<|endoftext|>"
6
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "bos_token": "<|endoftext|>",
4
+ "eos_token": "<|endoftext|>",
5
+ "model_max_length": 1024,
6
+ "name_or_path": "gpt2",
7
+ "special_tokens_map_file": null,
8
+ "tokenizer_class": "GPT2Tokenizer",
9
+ "unk_token": "<|endoftext|>"
10
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff