Views
No views yet
1from transformers import AutoTokenizer, AutoModelForCausalLM
2from peft import PeftModel
3
4# Load model and tokenizer
5base_model = AutoModelForCausalLM.from_pretrained(
6 "NousResearch/Llama-2-7b-chat-hf",
7 load_in_4bit=True,
8 device_map="auto"
9)
10model = PeftModel.from_pretrained(base_model, "AA65327/llama2-emotion-activity-20251005")
11tokenizer = AutoTokenizer.from_pretrained("AA65327/llama2-emotion-activity-20251005")
12
13# Format your prompt
14def format_prompt(instruction, input_text, activity_log):
15 return f"""Below is an instruction that describes a task, paired with an input that provides further context.
16Write a response that appropriately completes the request.
17
18### Instruction:
19{instruction}
20
21### Input:
22Current message: {input_text}
23Activity log (past 3 days, hours per activity): {activity_log}
24
25### Response:
26"""
27
28# Example usage
29instruction = "Evaluate the emotion in this text and suggest why the person might feel this way."
30input_text = "I'm feeling really excited about this new project!"
31activity_log = "working_out: [2, 1, 3]; reading: [1, 2, 0]; socializing: [3, 4, 2]"
32
33prompt = format_prompt(instruction, input_text, activity_log)
34inputs = tokenizer(prompt, return_tensors="pt")
35outputs = model.generate(**inputs, max_new_tokens=150, temperature=0.7)
36response = tokenizer.decode(outputs[0], skip_special_tokens=True)
37print(response)1@misc{llama2-emotion-activity-2025,
2 author = {AA65327},
3 title = {LLaMA-2-7B Emotion Analysis with Activity Context},
4 year = {2025},
5 publisher = {Hugging Face},
6 url = {https://huggingface.co/AA65327/llama2-emotion-activity-20251005}
7}