Update README.md
Browse files
README.md
CHANGED
@@ -9,4 +9,125 @@ tags:
|
|
9 |
- unsloth
|
10 |
- llama
|
11 |
- trl
|
12 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
- unsloth
|
10 |
- llama
|
11 |
- trl
|
12 |
+
---
|
13 |
+
|
14 |
+
# Bangla LLaMA 1B-LoRA
|
15 |
+
|
16 |
+
**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.
|
17 |
+
|
18 |
+
## Features
|
19 |
+
|
20 |
+
- **Model Size:** 1B parameters
|
21 |
+
- **Format:** LoRA Fine-Tuned
|
22 |
+
- **Language:** Bengali
|
23 |
+
- **Use Cases:**
|
24 |
+
- Context-based Question Answering
|
25 |
+
- Bengali Retrieval-Augmented Generation
|
26 |
+
- **Integration:** Compatible with Hugging Face `transformers` and optimized for efficient inference using LoRA
|
27 |
+
|
28 |
+
## Usage
|
29 |
+
|
30 |
+
### 1. Installation
|
31 |
+
|
32 |
+
Ensure you have the necessary libraries installed:
|
33 |
+
|
34 |
+
```bash
|
35 |
+
pip install transformers peft accelerate
|
36 |
+
```
|
37 |
+
|
38 |
+
### 2. Loading the Model with Transformers and PEFT
|
39 |
+
|
40 |
+
```python
|
41 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
42 |
+
from peft import PeftModel
|
43 |
+
import torch
|
44 |
+
|
45 |
+
# Load the tokenizer
|
46 |
+
tokenizer = AutoTokenizer.from_pretrained("asif00/bangla-llama-1B")
|
47 |
+
|
48 |
+
# Load the base model
|
49 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
50 |
+
"asif00/bangla-llama-1B",
|
51 |
+
device_map="auto",
|
52 |
+
torch_dtype=torch.float16
|
53 |
+
)
|
54 |
+
|
55 |
+
# Load the LoRA weights
|
56 |
+
model = PeftModel.from_pretrained(
|
57 |
+
base_model,
|
58 |
+
"asif00/bangla-llama-1B-lora"
|
59 |
+
)
|
60 |
+
|
61 |
+
# Set the model to evaluation mode
|
62 |
+
model.eval()
|
63 |
+
|
64 |
+
# Define the prompt structure
|
65 |
+
prompt_template = """
|
66 |
+
নিচের নির্দেশনা বাংলা ভাষায় যা একটি কাজ বর্ণনা করে, এবং ইনপুটও বাংলা ভাষায় যা অতিরিক্ত প্রসঙ্গ প্রদান করে। উপযুক্তভাবে অনুরোধ পূরণ করে বাংলা ভাষায় একটি প্রতিক্রিয়া লিখুন।
|
67 |
+
|
68 |
+
### নির্দেশনা:
|
69 |
+
{}
|
70 |
+
|
71 |
+
### ইনপুট:
|
72 |
+
{}
|
73 |
+
|
74 |
+
### প্রতিক্রিয়া:
|
75 |
+
"""
|
76 |
+
|
77 |
+
def generate_response(instruction, context):
|
78 |
+
prompt = prompt_template.format(instruction, context)
|
79 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
80 |
+
with torch.no_grad():
|
81 |
+
outputs = model.generate(
|
82 |
+
**inputs,
|
83 |
+
max_length=512,
|
84 |
+
do_sample=True,
|
85 |
+
temperature=0.7,
|
86 |
+
top_p=0.9,
|
87 |
+
eos_token_id=tokenizer.eos_token_id
|
88 |
+
)
|
89 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
90 |
+
response = response.split("### প্রতিক্রিয়া:")[-1].strip()
|
91 |
+
return response
|
92 |
+
|
93 |
+
# Example Usage
|
94 |
+
if __name__ == "__main__":
|
95 |
+
instruction = "ভারতীয় বাঙালি কথাসাহিত্যিক মহাশ্বেতা দেবীর সম্পর্কে একটি সংক্ষিপ্ত বিবরণ দিন।"
|
96 |
+
context = "মহাশ্বেতা দেবী ২০১৬ সালে হৃদরোগে আক্রান্ত হয়ে কলকাতায় মৃত্যুবরণ করেন।"
|
97 |
+
answer = generate_response(instruction, context)
|
98 |
+
print("উত্তর:", answer)
|
99 |
+
```
|
100 |
+
|
101 |
+
### 3. Example
|
102 |
+
|
103 |
+
```python
|
104 |
+
instruction = "ভারতীয় বাঙালি কথাসাহিত্যিক মহাশ্বেতা দেবীর মৃত্যু কবে হয়?"
|
105 |
+
context = (
|
106 |
+
"২০১৬ সালের ২৩ জুলাই হৃদরোগে আক্রান্ত হয়ে মহাশ্বেতা দেবী কলকাতার বেল ভিউ ক্লিনিকে ভর্তি হন। "
|
107 |
+
"সেই বছরই ২৮ জুলাই একাধিক অঙ্গ বিকল হয়ে তাঁর মৃত্যু ঘটে। তিনি মধুমেহ, সেপ্টিসেমিয়া ও মূত্র সংক্রমণ রোগেও ভুগছিলেন।"
|
108 |
+
)
|
109 |
+
answer = generate_response(instruction, context)
|
110 |
+
print("উত্তর:", answer)
|
111 |
+
```
|
112 |
+
|
113 |
+
**Output:**
|
114 |
+
```
|
115 |
+
উত্তর: মহাশ্বেতা দেবী ২৮ জুলাই ২০১৬ সালে মৃত্যুবরণ করেন।
|
116 |
+
```
|
117 |
+
|
118 |
+
## Limitations
|
119 |
+
|
120 |
+
- **Dataset Size:** Trained on a limited dataset, which may affect response accuracy.
|
121 |
+
- **Factuality:** May generate incorrect or nonsensical answers.
|
122 |
+
- **Language Support:** Primarily optimized for Bengali; performance may vary for other languages.
|
123 |
+
|
124 |
+
## Disclaimer
|
125 |
+
|
126 |
+
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.
|
127 |
+
|
128 |
+
## Additional Resources
|
129 |
+
|
130 |
+
- **Hugging Face Model Page:** [asif00/bangla-llama-1B-lora](https://huggingface.co/asif00/bangla-llama-1B-lora)
|
131 |
+
- **Hugging Face Dataset:** [OdiaGenAI/all_combined_bengali_252k](https://huggingface.co/datasets/OdiaGenAI/all_combined_bengali_252k)
|
132 |
+
- **Transformers Documentation:** [https://huggingface.co/docs/transformers](https://huggingface.co/docs/transformers)
|
133 |
+
- **PEFT (Parameter-Efficient Fine-Tuning) Library:** [https://github.com/huggingface/peft](https://github.com/huggingface/peft)
|