GPT-2 Balochi Text Generation

Model Overview

This model is a fine-tuned GPT-2 decoder-only Transformer model for Balochi text generation.

It demonstrate how a pretrained casual language model can be adapted to support a low-resource language.

The model receives a Balochi text prompt and generates continuation text based on the learned patterns from the Balochi training dataset.


Base Model

The pretrained model used for fine-tuning is:

gpt2

GPT-2 is a decoder-only Transformer language model designed for autoregressive text generation.


Model Architecture

The model uses a decoder-only Transformer architecture.

Architecture Details

  • Architecture: Decoder-only Transformer
  • Model: GPT-2
  • Base model: gpt2
  • Task: Causal Language Modeling / Text Generation
  • Framework: Hugging Face Transformers
  • Language: Balochi

Unlike an encoder-only model such as BERT, GPT-2 generates text sequentially.

The model predicts the next token based on the tokens that came before it.


Task

The model performs Balochi text generation.

A user provides a Balochi prompt, and the model generates additional Balochi text.

Example

Input:

سلام وش کنگ ءَ بلوچی راج

The model generates a continuation based on the prompt and the patterns learned during fine-tuning.


Dataset

The model was fine-tuned using the following Hugging Face dataset:

umairjamali/balochi-instructions-1k

The dataset contains 1,339 Balochi instruction-response examples.

The dataset contains two main columns:

  • instruction
  • response

An example from the dataset contains a Balochi instruction and a corresponding Balochi response.


Dataset Preprocessing

For causal language modeling, the instruction and response were combined into a single text sequence.

The format used during preprocessing was:

Instruction: [instruction]
Response: [response]

The combined text was then passed through the GPT-2 tokenizer.

The maximum sequence length was set to:

256 tokens

Sequences longer than the maximum length were truncated.


Tokenizer Configuration

The original GPT-2 tokenizer does not have a separate padding token.

Therefore, the GPT-2 end-of-sequence token was used as the padding token:

tokenizer.pad_token = tokenizer.eos_token

The model configuration was also updated to use the same padding token.


Train / Validation Split

The original dataset contained 1,339 examples.

The dataset was divided into:

  • 90% training data
  • 10% validation data

The split used:

test_size=0.1
seed=42

This produced approximately:

  • Training examples: 1,205
  • Validation examples: 134

Fine-Tuning Process

The pretrained GPT-2 model was loaded using:

AutoModelForCausalLM

The model was then fine-tuned for causal language modeling.

Fine-Tuning Steps

  1. Load the Balochi instruction dataset.
  2. Inspect the dataset structure.
  3. Load the pretrained GPT-2 tokenizer.
  4. Set the GPT-2 EOS token as the padding token.
  5. Combine each instruction with its response.
  6. Tokenize the combined text.
  7. Truncate sequences to a maximum length of 256 tokens.
  8. Split the dataset into training and validation sets.
  9. Load the pretrained GPT-2 causal language model.
  10. Configure causal language modeling.
  11. Fine-tune GPT-2 for 3 epochs.
  12. Evaluate the model on the validation set.
  13. Calculate perplexity from the evaluation loss.
  14. Save the fine-tuned model and tokenizer.
  15. Upload the model to Hugging Face.

Training Configuration

The model was fine-tuned using Google Colab.

The training configuration used in the notebook was:

Parameter Value
Base model gpt2
Dataset umairjamali/balochi-instructions-1k
Dataset examples 1,339
Training split 90%
Validation split 10%
Maximum sequence length 256
Learning rate 5e-5
Training batch size 4
Evaluation batch size 4
Number of epochs 3
Weight decay 0.01
Evaluation strategy Every epoch
Save strategy Every epoch
Data collator DataCollatorForLanguageModeling
MLM False

Evaluation Results

The fine-tuned GPT-2 model was evaluated using the validation dataset.

The final evaluation loss was:

1.2179713249206543

The corresponding perplexity was:

3.3803231955899524

Results

Metric Result
Evaluation Loss 1.2179713249206543
Perplexity 3.3803231955899524

The final training loss after 3 epochs was:

1.4189509208628674

Interpretation

For causal language modeling, a lower loss and lower perplexity generally indicate that the model is better at predicting the next tokens in the evaluation data.

The model achieved a validation perplexity of approximately 3.38 on the validation split used in this project.


Text Generation

The model can be used with the Hugging Face text-generation pipeline.

from transformers import pipeline

model_name = "Soho77/gpt2-balochi-generation"

generator = pipeline(
    "text-generation",
    model=model_name,
    tokenizer=model_name
)

prompt = "YOUR BALOCHI PROMPT HERE"

result = generator(
    prompt,
    max_new_tokens=50,
    do_sample=True,
    temperature=0.7,
    top_p=0.9
)

print(result[0]["generated_text"])

Generation Settings

The example generation configuration used in the notebook was:

Parameter Value
Maximum new tokens 50
Sampling Enabled
Temperature 0.7
Top-p 0.9
Number of sequences 1

These settings can be changed depending on the desired generation behavior.


Intended Use

This model is intended for:

  • Balochi text generation experiments
  • Balochi NLP research
  • Academic projects
  • Demonstrations of decoder-only Transformer models
  • Low-resource language generation experiments
  • Educational purposes
  • Experimentation with Balochi language modeling

Limitations

This model was developed as part of an academic project and was fine-tuned using a relatively small dataset of 1,339 instruction-response examples.

Because Balochi is a low-resource language, the amount and diversity of available training data can affect generation quality.

Generated text may sometimes contain:

  • Repetition
  • Grammatically incorrect text
  • Inaccurate information
  • Incomplete sentences
  • Unnatural word combinations
  • Content that does not match the user's intended meaning

The model should therefore not be treated as a fully reliable Balochi language expert.

Generated text should be reviewed before being used for important applications.



Training Environment

The model was fine-tuned using:

  • Google Colab
  • Python
  • PyTorch
  • Hugging Face Transformers
  • Hugging Face Datasets
  • Hugging Face Accelerate
  • Hugging Face Hub

Author

Developed for a Natural Language Processing (NLP) project.

License

Apache-2.0

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support