Views
No views yet
| Metric | Value |
|---|---|
| Accuracy | 83.0% |
| F1 Score | 82.5% |
| Precision | 83.5% |
| Recall | 82.0% |
1from transformers import AutoTokenizer, AutoModelForCausalLM
2from peft import PeftModel
3import torch
4
5# Load base model and tokenizer
6base_model = AutoModelForCausalLM.from_pretrained(
7 "meta-llama/Meta-Llama-3-8B",
8 torch_dtype=torch.float16,
9 device_map="auto"
10)
11tokenizer = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3-8B")
12
13# Load fine-tuned model
14model = PeftModel.from_pretrained(base_model, "jengyang/trained-llama3-sentences_allagree-financial-sentiment")
15
16# Prepare input
17text = "The company reported strong quarterly earnings, exceeding analyst expectations."
18prompt = f"Classify the sentiment of this financial text as positive, negative, or neutral: {text}\n\nSentiment:"
19
20# Tokenize and generate
21inputs = tokenizer(prompt, return_tensors="pt")
22with torch.no_grad():
23 outputs = model.generate(
24 **inputs,
25 max_new_tokens=10,
26 do_sample=False,
27 pad_token_id=tokenizer.eos_token_id
28 )
29
30response = tokenizer.decode(outputs[0], skip_special_tokens=True)
31print(response)1@misc{trained_llama3_sentences_allagree,
2 title={Trained Llama3 Sentences_Allagree: Fine-tuned Meta-Llama-3-8B for Financial Sentiment Analysis},
3 author={Final Year Project},
4 year={2024},
5 howpublished={\url{https://huggingface.co/jengyang/trained-llama3-sentences_allagree-financial-sentiment}}
6}