w11wo commited on
Commit
b6a1587
·
1 Parent(s): 7c1b2a9

Initial README update

Browse files
Files changed (1) hide show
  1. README.md +77 -1
README.md CHANGED
@@ -1 +1,77 @@
1
- GPT-2 English trained on Javanese Wikipedia articles.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: jv
3
+ tags:
4
+ - javanese-gpt2-small
5
+ license: mit
6
+ datasets:
7
+ - wikipedia
8
+ ---
9
+
10
+ ## Javanese GPT-2 Small
11
+ Javanese GPT-2 Small is a language model based on the [GPT-2 model](https://cdn.openai.com/better-language-models/language_models_are_unsupervised_multitask_learners.pdf). It was trained on the latest (late December 2020) Javanese Wikipedia articles.
12
+
13
+ The model was originally HuggingFace's pretrained [English GPT-2 model](https://huggingface.co/transformers/model_doc/gpt2.html) and is later fine-tuned on the Javanese dataset. Many of the techniques used
14
+ are based on a [notebook](https://github.com/piegu/fastai-projects/blob/master/finetuning-English-GPT2-any-language-Portuguese-HuggingFace-fastaiv2.ipynb)/[blog](https://medium.com/@pierre_guillou/faster-than-training-from-scratch-fine-tuning-the-english-gpt-2-in-any-language-with-hugging-f2ec05c98787) shared by [Pierre Guillou](https://medium.com/@pierre_guillou), where Pierre Guillou fine-tuned the English GPT-2 model on a Portuguese dataset.
15
+
16
+ Frameworks used include HuggingFace's [Transformers](https://huggingface.co/transformers) and fast.ai's [Deep Learning library](https://docs.fast.ai/). PyTorch was used as the backend framework during training, but the model remains compatible with TensorFlow nonetheless.
17
+
18
+ ## Model
19
+ | Model | #params | Arch. | Training /Validation data (text) |
20
+ |-----------------------|---------|-------------|-------------------------------------|
21
+ | `javanese-gpt2-small` | 124M | GPT-2 Small | Javanese Wikipedia (319 MB of text) |
22
+
23
+ ## Evaluation Results
24
+ Before fine-tuning, the English GPT-2 model went through a validation step just to see how the model fairs prior to training.
25
+
26
+ | valid loss | perplexity |
27
+ |------------|------------|
28
+ | 10.845 | 51313.62 |
29
+
30
+ The model was then trained afterwards for 5 epochs and the following are the results.
31
+
32
+ | epoch | train loss | valid loss | perplexity | total time |
33
+ |-------|------------|------------|------------|------------|
34
+ | 0 | 4.336 | 4.110 | 60.94 | 22:28 |
35
+ | 1 | 3.598 | 3.543 | 34.58 | 23:27 |
36
+ | 2 | 3.161 | 3.331 | 27.98 | 24:17 |
37
+ | 3 | 2.974 | 3.265 | 26.18 | 25:03 |
38
+ | 4 | 2.932 | 3.234 | 25.39 | 25:06 |
39
+
40
+ ## How to Use (PyTorch)
41
+ ### Load Model and Byte-level Tokenizer
42
+ ```python
43
+ from transformers import GPT2TokenizerFast, GPT2LMHeadModel
44
+ pretrained_name = "w11wo/javanese-gpt2-small"
45
+ tokenizer = GPT2TokenizerFast.from_pretrained(pretrained_name)
46
+ tokenizer.model_max_length = 1024
47
+ model = GPT2LMHeadModel.from_pretrained(pretrained_name)
48
+ ```
49
+
50
+ ### Generate a Sequence
51
+ ```python
52
+ # sample prompt
53
+ prompt = "Jenengku Budi, saka Indonesia"
54
+ input_ids = tokenizer.encode(prompt, return_tensors='pt')
55
+ model.eval()
56
+
57
+ # generate output using top-k sampling
58
+ sample_outputs = model.generate(input_ids,
59
+ pad_token_id=50256,
60
+ do_sample=True,
61
+ max_length=40,
62
+ min_length=40,
63
+ top_k=40,
64
+ num_return_sequences=1)
65
+
66
+ for i, sample_output in enumerate(sample_outputs):
67
+ print(tokenizer.decode(sample_output.tolist()))
68
+ ```
69
+
70
+ ## Disclaimer
71
+ Do remember that although the dataset originated from Wikipedia, the model may not always generate factual texts. Additionally, the biases which came from the Wikipedia articles may be carried over into the results of this model.
72
+
73
+ ## Credits
74
+ Major thanks to Pierre Guillou for sharing his work, which did not only enable me to realize this project but also taught me tons of new, exciting stuff.
75
+
76
+ ## Author
77
+ Javanese GPT-2 Small was trained and evaluated by [Wilson Wongso](https://w11wo.github.io/). All computation and development are done on Google Colaboratory using their free GPU access.