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