Views
No views yet
pip install transformers torch accelerate1from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
2import torch
3
4model_name = "Kowshik24/Bangla-llama-3.2-3B-Instruct-QA-v2"
5
6# Load model and tokenizer
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8model = AutoModelForCausalLM.from_pretrained(
9 model_name,
10 torch_dtype=torch.bfloat16,
11 device_map="auto"
12)
13
14# Setting up system and user prompts
15messages = [
16 {
17 "role": "system",
18 "content": "১৯৫২ সালের ২১ ফেব্রুয়ারি বাংলা ভাষাকে পাকিস্তানের রাষ্ট্রভাষা হিসেবে স্বীকৃতি দেওয়ার দাবিতে ঢাকা বিশ্ববিদ্যালয়ের ছাত্ররা বিক্ষোভ করে। পুলিশের গুলিতে শহিদ হন রফিক, সালাম, বরকতসহ অনেকে। এই আন্দোলনের ফলস্বরূপ ১৯৫৬ সালে বাংলা রাষ্ট্রভাষার মর্যাদা পায় এবং পরবর্তীতে UNESCO ১৯৯৯ সালে ২১ ফেব্রুয়ারিকে আন্তর্জাতিক মাতৃভাষা দিবস ঘোষণা করে।"
19 },
20 {
21 "role": "user",
22 "content": "ভাষা আন্দোলনের দিনটি কোন তারিখে পালিত হয়?"
23 },
24]
25
26# Processing chat template
27input_ids = tokenizer.apply_chat_template(
28 messages,
29 add_generation_prompt=True,
30 return_tensors="pt"
31).to(model.device)
32
33# Generating the answer
34outputs = model.generate(
35 input_ids,
36 max_new_tokens=256,
37 temperature=0.01,
38 do_sample=True,
39 pad_token_id=tokenizer.eos_token_id,
40)
41
42# Decoding the output
43full_response = tokenizer.decode(outputs[0], skip_special_tokens=True)
44answer = full_response.split("assistant\n\n")[-1].strip()
45print("Answer:", answer)Answer: ২১ ফেব্রুয়ারি| Parameter | Value | Explanation |
|---|---|---|
temperature | 0.01 | Low creativity (deterministic) |
max_new_tokens | 256 | Maximum output length |
torch_dtype | bfloat16 | Memory optimization |
1@INPROCEEDINGS{11013841,
2 author={Debanath, Koshik and Aich, Sagor and Srizon, Azmain Yakin},
3 booktitle={2025 International Conference on Electrical, Computer and Communication Engineering (ECCE)},
4 title={Advancing Low-Resource NLP: Contextual Question Answering for Bengali Language Using Llama},
5 year={2025},
6 volume={},
7 number={},
8 pages={1-6},
9 keywords={Adaptation models;Large language models;Computational modeling;Transfer learning;LoRa;Reinforcement learning;Benchmark testing;Question answering (information retrieval);Multilingual;Synthetic data;Natural Language Processing;Question Answering;Large Language Models;Llama Model;Fine-Tuning;Bengali Dataset},
10 doi={10.1109/ECCE64574.2025.11013841}}
11