Views
No views yet
1
2import torch
3from transformers import AutoModelForCausalLM, AutoTokenizer
4
5# Load the fine-tuned model and tokenizer
6model_path = "MISHANM/Assamese_text_generation_Llama3_8B_instruct"
7
8model = AutoModelForCausalLM.from_pretrained(model_path,device_map="auto")
9
10tokenizer = AutoTokenizer.from_pretrained(model_path)
11
12# Function to generate text
13def generate_text(prompt, max_length=1000, temperature=0.9):
14 # Format the prompt according to the chat template
15 messages = [
16 {
17 "role": "system",
18 "content": "You are a Assamese language expert and linguist, with same knowledge give response in Assamese language.",
19 },
20 {"role": "user", "content": prompt}
21 ]
22
23 # Apply the chat template
24 formatted_prompt = f"<|system|>{messages[0]['content']}<|user|>{messages[1]['content']}<|assistant|>"
25
26 # Tokenize and generate output
27 inputs = tokenizer(formatted_prompt, return_tensors="pt")
28 output = model.generate( # Use model.module for DataParallel
29 **inputs, max_new_tokens=max_length, temperature=temperature, do_sample=True
30 )
31 return tokenizer.decode(output[0], skip_special_tokens=True)
32
33# Example usage
34prompt = """What is LLM ."""
35translated_text = generate_text(prompt)
36print(translated_text)
37
38
39@misc{MISHANM/Assamese_text_generation_Llama3_8B_instruct,
author = {Mishan Maurya},
title = {Introducing Fine Tuned LLM for Assamese Language},
year = {2025},
publisher = {Hugging Face},
journal = {Hugging Face repository},
}