Downloads · 30 days
0
hassanaliemon/bn_rag_llama3-8b
bn_rag_llama3-8b is a question answering model from hassanaliemon. Use it when the input is a question plus a passage. It is set up for transformers. The card lists the license as apache-2.0.
You can use the model with a pipeline for a high-level helper or load the model directly. Here's how:
Downloads · 30 days
0
Access
Public
Updated Jun 11, 2024
Repo size
75.5 MB
Likes
4
Public
Click a slice to open those files.
.safetensors75.5 MB · 89%
From the Hugging Face model README
You can use the model with a pipeline for a high-level helper or load the model directly. Here's how:
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
# Determine the device to use (GPU if available, else CPU)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# Load pre-trained model and tokenizer
tokenizer = AutoTokenizer.from_pretrained("hassanaliemon/bn_rag_llama3-8b")
# model = AutoModelForCausalLM.from_pretrained("hassanaliemon/bn_rag_llama3-8b")
model = AutoModelForCausalLM.from_pretrained(
"hassanaliemon/bn_rag_llama3-8b",
load_in_8bit=True,
torch_dtype=torch.bfloat16,
device_map="auto",
)
# Define the prompt template
prompt = """এখানে একটি নির্দেশনা দেওয়া হলো, যা একটি কাজ সম্পন্ন করার উপায় বর্ণনা করে, এবং এর সাথে একটি ইনপুট দেওয়া হলো যা আরও প্রেক্ষাপট প্রদান করে। একটি উত্তর লিখুন যা অনুরোধটি সঠিকভাবে পূরণ করে। প্রসঙ্গ থেকে সুনির্দিষ্ট উত্তর দিন.
### Instruction:
{}
### Input:
{}
### Response:
{}
"""
def generate_response(question, context):
# Tokenize the input and move tensors to the selected device
inputs = tokenizer([prompt.format(question, context, "")], return_tensors="pt").to(device)
# Generate the response
outputs = model.generate(**inputs, max_new_tokens=1024, use_cache=True)
# Decode the generated text
responses = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
# Extract the response text
response_start = responses.find("### Response:") + len("### Response:")
response = responses[response_start:].strip()
return response
# Example Usage
question = "ভারতীয় বাঙালি কথাসাহিত্যিক মহাশ্বেতা দেবীর মৃত্যু কবে হয় ?"
context = "২০১৬ সালের ২৩ জুলাই হৃদরোগে আক্রান্ত হয়ে মহাশ্বেতা দেবী কলকাতার বেল ভিউ ক্লিনিকে ভর্তি হন। সেই বছরই ২৮ জুলাই একাধিক অঙ্গ বিকল হয়ে তাঁর মৃত্যু ঘটে। তিনি মধুমেহ, সেপ্টিসেমিয়া ও মূত্র সংক্রমণ রোগেও ভুগছিলেন।"
answer = generate_response(question, context)
print(answer)
# মহাশ্বেতা দেবী ২০১৬ সালের ২৮ জুলাই মারা যান।