Views
No views yet
transformers library.
To use the fine-tuned model for text generation based on a persona, follow these steps:1from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
2
3# Load the fine-tuned model and tokenizer
4model_name = "rudrajadon18/Llama-2-7b-chat-finetune"
5model = AutoModelForCausalLM.from_pretrained(model_name)
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7
8# Define the persona and prompt
9prompt = "<persona_b>I love traveling, reading romance novels, and trying new cuisines. I have a deep passion for animals and enjoy volunteering at shelters. I enjoy hiking in the mountains and spending time at the beach. I am a carnivore who loves sharing my experiences with friends over a good meal.</persona_b><s>[INST] \n What do you think about animals? \n</INST>"
10
11# Generate response for the prompt
12pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_length=200)
13result = pipe(f"<s>[INST] {prompt} [/INST]")
14
15# Print the generated text
16print("Response: \n")
17print(result[0]['generated_text'])