moshik1 commited on
Commit
7abdafe
·
1 Parent(s): cdcf35c

add README.md

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