byeongal commited on
Commit
a9a9543
1 Parent(s): 85c14fa

gpt2-large model for teachable-nlp

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