初始化项目,由ModelHub XC社区提供模型

Model: augustoafleal/gpt2-ptbr-218m
Source: Original Platform
This commit is contained in:
ModelHub XC
2026-07-07 19:31:30 +08:00
commit 0acd0fff0c
9 changed files with 116589 additions and 0 deletions

2
.gitattributes vendored Normal file
View File

@@ -0,0 +1,2 @@
*.safetensors filter=lfs diff=lfs merge=lfs -text
tokenizer.model filter=lfs diff=lfs merge=lfs -text

116
README.md Normal file
View File

@@ -0,0 +1,116 @@
---
language: pt
license: mit
tags:
- gpt2
- portuguese
- causal-lm
- pytorch
- safetensors
pipeline_tag: text-generation
---
# gpt2-ptbr-218m
Portuguese GPT-2-like autoregressive language model trained from scratch.
## Training pipeline
The released model, `gpt2-ptbr-218m`, is the final checkpoint of a three-stage pipeline:
1. **Pretraining** on Portuguese Wikipedia.
2. **Supervised Fine-Tuning** on Alpaca PT-BR.
3. **Supervised Fine-Tuning** on Canarim-Instruct-PTBR.
The released checkpoint corresponds to the final instruction-tuned model.
## Model description
- **Architecture:** GPT-2 (decoder-only transformer)
- **Parameters:** 218,040,320 trainable unique parameters (weight-tying between token embedding and output projection; zero biases added for Hugging Face compatibility)
- **Layers:** 16
- **Attention heads:** 16
- **Embedding dimension:** 1024
- **Vocabulary:** 16,000 tokens (SentencePiece BPE)
- **Sequence length:** 256 tokens
- **Activation:** GELU
- **Dropout:** 0.1
> **Note on parameter count:** During export, the weight-tying between the token embedding and the language model head is preserved, and zero-initialized bias tensors are added for compatibility with Hugging Face's `GPT2LMHeadModel`. These biases are not part of the original trained model and do not affect behavior.
## Datasets
- **Portuguese Wikipedia corpus** — used for autoregressive pretraining.
- **Alpaca PT-BR** — Portuguese instruction-following dataset derived from Stanford Alpaca (Taori et al., 2023). Used for the first SFT stage.
- **Canarim-Instruct-PTBR** — Portuguese instruction-following dataset by Maicon Domingues (Domingues, 2023). Used for the second SFT stage.
## Tokenizer
- **Type:** SentencePiece BPE
- **Vocabulary:** 16,000 tokens
- **Special tokens:** `<unk>` = 0, `<bos>` = 1, `<eos>` = 2, `<pad>` = 3
- **Pre-tokenizer:** Metaspace (SentencePiece native)
- **Model max length:** 256 tokens
The tokenizer was trained from scratch on the Portuguese Wikipedia corpus.
## Training details
- **Type:** sft_response_only
- **Best validation loss:** 2.1538288593292236
- **Training steps:** 1050
## Usage
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "augustoafleal/gpt2-ptbr-218m"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id)
prompt = "A inteligência artificial é"
inputs = tokenizer(prompt, return_tensors="pt")
output = model.generate(
**inputs,
max_new_tokens=100,
do_sample=True,
temperature=0.7,
top_k=40,
pad_token_id=tokenizer.pad_token_id,
eos_token_id=tokenizer.eos_token_id,
)
print(tokenizer.decode(output[0], skip_special_tokens=True))
```
## Limitations
- The model may generate factual errors.
- The model may repeat phrases.
- The model may fail to follow instructions exactly.
- The context length is limited to 256 tokens.
- The model was trained on limited data compared to modern LLMs.
- This model is not suitable for high-stakes use without human validation.
## Dataset citations
```
Stanford Alpaca: Taori et al., 2023. https://github.com/tatsu-lab/stanford_alpaca
Canarim-Instruct-PTBR: Domingues, 2023. https://huggingface.co/datasets/dominguesm/Canarim-Instruct-PTBR
```
## Citation
If you use this model, please cite:
```bibtex
@misc{gpt2ptbr218m,
title = {gpt2-ptbr-218m: A Portuguese GPT-2-like Autoregressive Language Model},
author = {Augusto Antônio Fontanive Leal},
year = {2026},
howpublished = {\url{https://huggingface.co/augustoafleal/gpt2-ptbr-218m}}
}
```

24
config.json Normal file
View File

@@ -0,0 +1,24 @@
{
"architectures": [
"GPT2LMHeadModel"
],
"model_type": "gpt2",
"vocab_size": 16000,
"n_positions": 256,
"n_ctx": 256,
"n_embd": 1024,
"n_layer": 16,
"n_head": 16,
"n_inner": 4096,
"activation_function": "gelu",
"resid_pdrop": 0.1,
"embd_pdrop": 0.1,
"attn_pdrop": 0.1,
"layer_norm_epsilon": 1e-05,
"initializer_range": 0.02,
"bos_token_id": 1,
"eos_token_id": 2,
"pad_token_id": 3,
"use_cache": true,
"tie_word_embeddings": true
}

10
generation_config.json Normal file
View File

@@ -0,0 +1,10 @@
{
"eos_token_id": 2,
"pad_token_id": 3,
"bos_token_id": 1,
"max_length": 256,
"do_sample": true,
"temperature": 1.0,
"top_k": 50,
"top_p": 1.0
}

3
model.safetensors Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4f6bddaadc7e4f7283b4bc6bfa494e1a047b159a6b26992c16d13ce6916bdb68
size 938307344

6
special_tokens_map.json Normal file
View File

@@ -0,0 +1,6 @@
{
"unk_token": "<unk>",
"bos_token": "<bos>",
"eos_token": "<eos>",
"pad_token": "<pad>"
}

116408
tokenizer.json Normal file

File diff suppressed because it is too large Load Diff

3
tokenizer.model Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8b03e3c520cac6b5283520bb339f5314768b931a9a2f72b2e8ed5f560302a38f
size 492472

17
tokenizer_config.json Normal file
View File

@@ -0,0 +1,17 @@
{
"add_prefix_space": null,
"bos_token": "<bos>",
"clean_up_tokenization_spaces": false,
"eos_token": "<eos>",
"extra_special_tokens": [
"<bos>",
"<eos>",
"<pad>"
],
"model_max_length": 256,
"pad_token": "<pad>",
"tokenizer_class": "LlamaTokenizer",
"unk_token": "<unk>",
"use_default_system_prompt": false,
"model_type": "gpt2"
}