初始化项目,由ModelHub XC社区提供模型
Model: w11wo/indo-gpt2-small Source: Original Platform
This commit is contained in:
10
.gitattributes
vendored
Normal file
10
.gitattributes
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||
*.h5 filter=lfs diff=lfs merge=lfs -text
|
||||
*.tflite filter=lfs diff=lfs merge=lfs -text
|
||||
*.tar.gz filter=lfs diff=lfs merge=lfs -text
|
||||
*.ot filter=lfs diff=lfs merge=lfs -text
|
||||
*.onnx filter=lfs diff=lfs merge=lfs -text
|
||||
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
||||
model.safetensors filter=lfs diff=lfs merge=lfs -text
|
||||
69
README.md
Normal file
69
README.md
Normal file
@@ -0,0 +1,69 @@
|
||||
---
|
||||
language: id
|
||||
tags:
|
||||
- indo-gpt2-small
|
||||
license: mit
|
||||
datasets:
|
||||
- wikipedia
|
||||
widget:
|
||||
- text: "Nama saya Budi, dari Indonesia"
|
||||
---
|
||||
|
||||
## Indo GPT-2 Small
|
||||
Indo 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) Indonesian Wikipedia articles.
|
||||
|
||||
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 Indonesian dataset. Many of the techniques used
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
## Model
|
||||
| Model | #params | Arch. | Training /Validation data (text) |
|
||||
|-------------------|---------|-------------|---------------------------------------|
|
||||
| `indo-gpt2-small` | 124M | GPT-2 Small | Indonesian Wikipedia (3.1 GB of text) |
|
||||
|
||||
## Evaluation Results
|
||||
The model was trained for only 1 epoch and the following is the final result once the training ended.
|
||||
|
||||
| epoch | train loss | valid loss | perplexity | total time |
|
||||
|-------|------------|------------|------------|------------|
|
||||
| 0 | 2.981 | 2.936 | 18.85 | 2:45:25 |
|
||||
|
||||
## How to Use (PyTorch)
|
||||
### Load Model and Byte-level Tokenizer
|
||||
```python
|
||||
from transformers import GPT2TokenizerFast, GPT2LMHeadModel
|
||||
pretrained_name = "w11wo/indo-gpt2-small"
|
||||
tokenizer = GPT2TokenizerFast.from_pretrained(pretrained_name)
|
||||
tokenizer.model_max_length = 1024
|
||||
model = GPT2LMHeadModel.from_pretrained(pretrained_name)
|
||||
```
|
||||
|
||||
### Generate a Sequence
|
||||
```python
|
||||
# sample prompt
|
||||
prompt = "Nama saya Budi, dari Indonesia"
|
||||
input_ids = tokenizer.encode(prompt, return_tensors='pt')
|
||||
model.eval()
|
||||
|
||||
# generate output using top-k sampling
|
||||
sample_outputs = model.generate(input_ids,
|
||||
pad_token_id=50256,
|
||||
do_sample=True,
|
||||
max_length=40,
|
||||
min_length=40,
|
||||
top_k=40,
|
||||
num_return_sequences=1)
|
||||
|
||||
for i, sample_output in enumerate(sample_outputs):
|
||||
print(tokenizer.decode(sample_output.tolist()))
|
||||
```
|
||||
|
||||
## Disclaimer
|
||||
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.
|
||||
|
||||
## Credits
|
||||
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.
|
||||
|
||||
## Author
|
||||
Indo 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.
|
||||
35
config.json
Normal file
35
config.json
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"_name_or_path": "indo-gpt2-small",
|
||||
"activation_function": "gelu_new",
|
||||
"architectures": [
|
||||
"GPT2LMHeadModel"
|
||||
],
|
||||
"attn_pdrop": 0.1,
|
||||
"bos_token_id": 50256,
|
||||
"embd_pdrop": 0.1,
|
||||
"eos_token_id": 50256,
|
||||
"gradient_checkpointing": false,
|
||||
"initializer_range": 0.02,
|
||||
"layer_norm_epsilon": 1e-05,
|
||||
"model_type": "gpt2",
|
||||
"n_ctx": 1024,
|
||||
"n_embd": 768,
|
||||
"n_head": 12,
|
||||
"n_inner": null,
|
||||
"n_layer": 12,
|
||||
"n_positions": 1024,
|
||||
"resid_pdrop": 0.1,
|
||||
"summary_activation": null,
|
||||
"summary_first_dropout": 0.1,
|
||||
"summary_proj_to_labels": true,
|
||||
"summary_type": "cls_index",
|
||||
"summary_use_proj": true,
|
||||
"task_specific_params": {
|
||||
"text-generation": {
|
||||
"do_sample": true,
|
||||
"max_length": 50
|
||||
}
|
||||
},
|
||||
"use_cache": true,
|
||||
"vocab_size": 50257
|
||||
}
|
||||
3
flax_model.msgpack
Normal file
3
flax_model.msgpack
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:bdb93b69bf75d7af440d76d8a8a3ee5dc6f28eb878e774533db628b81846228f
|
||||
size 497764120
|
||||
50001
merges.txt
Normal file
50001
merges.txt
Normal file
File diff suppressed because it is too large
Load Diff
3
model.safetensors
Normal file
3
model.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:c13edc95d190c46ba24b9a04318e5992768f9c356da328f363b614276093e6de
|
||||
size 510359598
|
||||
3
pytorch_model.bin
Normal file
3
pytorch_model.bin
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:bfada227af10dd178f061b62883854d2d8a36433d122e9ee734caf5da2e4d31f
|
||||
size 510406789
|
||||
1
special_tokens_map.json
Normal file
1
special_tokens_map.json
Normal file
@@ -0,0 +1 @@
|
||||
{"bos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "eos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "unk_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "pad_token": "<|endoftext|>"}
|
||||
3
tf_model.h5
Normal file
3
tf_model.h5
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:64a3370d962d60053b74ea01263c9f2fdc8ace2b060c070999603db22a12522d
|
||||
size 497933944
|
||||
1
tokenizer_config.json
Normal file
1
tokenizer_config.json
Normal file
@@ -0,0 +1 @@
|
||||
{"unk_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "bos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "eos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "add_prefix_space": false, "pad_token": "<|endoftext|>", "special_tokens_map_file": null, "name_or_path": "./id_tokens", "errors": "replace"}
|
||||
1
vocab.json
Normal file
1
vocab.json
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user