CJHauser commited on
Commit
e29424f
·
verified ·
1 Parent(s): 08d59ce

Upload folder using huggingface_hub

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