|
--- |
|
base_model: unsloth/llama-3.2-1b-bnb-4bit |
|
language: |
|
- en |
|
license: apache-2.0 |
|
tags: |
|
- text-generation-inference |
|
- transformers |
|
- unsloth |
|
- llama |
|
- trl |
|
--- |
|
|
|
# Bangla LLaMA 1B-LoRA |
|
|
|
**Bangla LLaMA 1B-LoRA** is a 1-billion-parameter language model fine-tuned using Low-Rank Adaptation (LoRA) for Bengali-language tasks such as context-based question answering and retrieval-augmented generation. It is derived from **LLaMA 3.2 1B** and trained on the [OdiaGenAI/all_combined_bengali_252k](https://huggingface.co/datasets/OdiaGenAI/all_combined_bengali_252k) dataset. |
|
|
|
## Features |
|
|
|
- **Model Size:** 1B parameters |
|
- **Format:** LoRA Fine-Tuned |
|
- **Language:** Bengali |
|
- **Use Cases:** |
|
- Context-based Question Answering |
|
- Bengali Retrieval-Augmented Generation |
|
- **Integration:** Compatible with Hugging Face `transformers` and optimized for efficient inference using LoRA |
|
|
|
## Usage |
|
|
|
### 1. Installation |
|
|
|
Ensure you have the necessary libraries installed: |
|
|
|
```bash |
|
pip install transformers peft accelerate |
|
``` |
|
|
|
### 2. Loading the Model with Transformers and PEFT |
|
|
|
```python |
|
from transformers import AutoTokenizer, AutoModelForCausalLM |
|
from peft import PeftModel |
|
import torch |
|
|
|
# Load the tokenizer |
|
tokenizer = AutoTokenizer.from_pretrained("asif00/bangla-llama-1B") |
|
|
|
# Load the base model |
|
base_model = AutoModelForCausalLM.from_pretrained( |
|
"asif00/bangla-llama-1B", |
|
device_map="auto", |
|
torch_dtype=torch.float16 |
|
) |
|
|
|
# Load the LoRA weights |
|
model = PeftModel.from_pretrained( |
|
base_model, |
|
"asif00/bangla-llama-1B-lora" |
|
) |
|
|
|
# Set the model to evaluation mode |
|
model.eval() |
|
|
|
# Define the prompt structure |
|
prompt_template = """ |
|
নিচের নির্দেশনা বাংলা ভাষায় যা একটি কাজ বর্ণনা করে, এবং ইনপুটও বাংলা ভাষায় যা অতিরিক্ত প্রসঙ্গ প্রদান করে। উপযুক্তভাবে অনুরোধ পূরণ করে বাংলা ভাষায় একটি প্রতিক্রিয়া লিখুন। |
|
|
|
### নির্দেশনা: |
|
{} |
|
|
|
### ইনপুট: |
|
{} |
|
|
|
### প্রতিক্রিয়া: |
|
""" |
|
|
|
def generate_response(instruction, context): |
|
prompt = prompt_template.format(instruction, context) |
|
inputs = tokenizer(prompt, return_tensors="pt").to(model.device) |
|
with torch.no_grad(): |
|
outputs = model.generate( |
|
**inputs, |
|
max_length=512, |
|
do_sample=True, |
|
temperature=0.7, |
|
top_p=0.9, |
|
eos_token_id=tokenizer.eos_token_id |
|
) |
|
response = tokenizer.decode(outputs[0], skip_special_tokens=True) |
|
response = response.split("### প্রতিক্রিয়া:")[-1].strip() |
|
return response |
|
|
|
# Example Usage |
|
if __name__ == "__main__": |
|
instruction = "ভারতীয় বাঙালি কথাসাহিত্যিক মহাশ্বেতা দেবীর সম্পর্কে একটি সংক্ষিপ্ত বিবরণ দিন।" |
|
context = "মহাশ্বেতা দেবী ২০১৬ সালে হৃদরোগে আক্রান্ত হয়ে কলকাতায় মৃত্যুবরণ করেন।" |
|
answer = generate_response(instruction, context) |
|
print("উত্তর:", answer) |
|
``` |
|
|
|
### 3. Example |
|
|
|
```python |
|
instruction = "ভারতীয় বাঙালি কথাসাহিত্যিক মহাশ্বেতা দেবীর মৃত্যু কবে হয়?" |
|
context = ( |
|
"২০১৬ সালের ২৩ জুলাই হৃদরোগে আক্রান্ত হয়ে মহাশ্বেতা দেবী কলকাতার বেল ভিউ ক্লিনিকে ভর্তি হন। " |
|
"সেই বছরই ২৮ জুলাই একাধিক অঙ্গ বিকল হয়ে তাঁর মৃত্যু ঘটে। তিনি মধুমেহ, সেপ্টিসেমিয়া ও মূত্র সংক্রমণ রোগেও ভুগছিলেন।" |
|
) |
|
answer = generate_response(instruction, context) |
|
print("উত্তর:", answer) |
|
``` |
|
|
|
**Output:** |
|
``` |
|
উত্তর: মহাশ্বেতা দেবী ২৮ জুলাই ২০১৬ সালে মৃত্যুবরণ করেন। |
|
``` |
|
|
|
## Limitations |
|
|
|
- **Dataset Size:** Trained on a limited dataset, which may affect response accuracy. |
|
- **Factuality:** May generate incorrect or nonsensical answers. |
|
- **Language Support:** Primarily optimized for Bengali; performance may vary for other languages. |
|
|
|
## Disclaimer |
|
|
|
The **Bangla LLaMA 1B-LoRA** model's performance depends on the quality and diversity of the training data. Users should verify the information generated, especially for critical applications. |
|
|
|
## Additional Resources |
|
|
|
- **Hugging Face Model Page:** [asif00/bangla-llama-1B-lora](https://huggingface.co/asif00/bangla-llama-1B-lora) |
|
- **Hugging Face Dataset:** [OdiaGenAI/all_combined_bengali_252k](https://huggingface.co/datasets/OdiaGenAI/all_combined_bengali_252k) |
|
- **Transformers Documentation:** [https://huggingface.co/docs/transformers](https://huggingface.co/docs/transformers) |
|
- **PEFT (Parameter-Efficient Fine-Tuning) Library:** [https://github.com/huggingface/peft](https://github.com/huggingface/peft) |