Instructions to use Soho77/gpt2-balochi-generation with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Soho77/gpt2-balochi-generation with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Soho77/gpt2-balochi-generation")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Soho77/gpt2-balochi-generation", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Soho77/gpt2-balochi-generation with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Soho77/gpt2-balochi-generation" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Soho77/gpt2-balochi-generation", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Soho77/gpt2-balochi-generation
- SGLang
How to use Soho77/gpt2-balochi-generation with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Soho77/gpt2-balochi-generation" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Soho77/gpt2-balochi-generation", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Soho77/gpt2-balochi-generation" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Soho77/gpt2-balochi-generation", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Soho77/gpt2-balochi-generation with Docker Model Runner:
docker model run hf.co/Soho77/gpt2-balochi-generation
- GPT-2 Balochi Text Generation
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:
instructionresponse
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
- Load the Balochi instruction dataset.
- Inspect the dataset structure.
- Load the pretrained GPT-2 tokenizer.
- Set the GPT-2 EOS token as the padding token.
- Combine each instruction with its response.
- Tokenize the combined text.
- Truncate sequences to a maximum length of 256 tokens.
- Split the dataset into training and validation sets.
- Load the pretrained GPT-2 causal language model.
- Configure causal language modeling.
- Fine-tune GPT-2 for 3 epochs.
- Evaluate the model on the validation set.
- Calculate perplexity from the evaluation loss.
- Save the fine-tuned model and tokenizer.
- 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