Views
No views yet
| Weighted F1 | FPB | FiQA-SA | TFNS | NWGI | Devices | Time | Cost |
|---|---|---|---|---|---|---|---|
| [FinDeep R1] | 0.790 | 0.577 | 0.798 | 0.667 | 1 × A100 | 2.57 hours | $12.50 |
| [FinGPT v3.3] | 0.882 | 0.874 | 0.903 | 0.643 | 1 × RTX 3090 | 17.25 hours | $17.25 |
| FinGPT v3.2 | 0.850 | 0.860 | 0.894 | 0.636 | 1 × A100 | 5.5 hours | $ 22.55 |
| FinGPT v3.1 | 0.855 | 0.850 | 0.875 | 0.642 | 1 × A100 | 5.5 hours | $ 22.55 |
| FinGPT (8bit) | 0.855 | 0.847 | 0.879 | 0.632 | 1 × RTX 3090 | 6.47 hours | $ 6.47 |
| FinGPT (QLoRA) | 0.777 | 0.752 | 0.828 | 0.583 | 1 × RTX 3090 | 4.15 hours | $ 4.15 |
| OpenAI Fine-tune | 0.878 | 0.887 | 0.883 | - | - | - | - |
| GPT-4 | 0.833 | 0.630 | 0.808 | - | - | - | - |
| FinBERT | 0.880 | 0.596 | 0.733 | 0.538 | 4 × NVIDIA K80 GPU | - | - |
| Llama2-7B | 0.390 | 0.800 | 0.296 | 0.503 | 2048 × A100 | 21 days | $ 4.23 million |
| BloombergGPT | 0.511 | 0.751 | - | - | 512 × A100 | 53 days | $ 2.67 million |
1pip install transformers peft datasets pandas torch
2
3```python
4from peft import PeftModel, PeftConfig
5from transformers import AutoTokenizer, AutoModelForSequenceClassification
6import torch
7
8# PEFT model directory
9peft_model_path = "huggnface/FinDeepSeek-R1-Distill-Qwen-1.5B-LoRA-Sentiment"
10
11# Load model and adapter configurations
12peft_config = PeftConfig.from_pretrained(peft_model_path)
13base_model = AutoModelForSequenceClassification.from_pretrained(peft_config.base_model_name_or_path,
14 id2label={"positive": 0, "negative": 1, "neutral": 2},
15 label2id={0:"positive", 1: "negative", 2:"neutral"},
16 num_labels=3)
17inference_model = PeftModel.from_pretrained(base_model, peft_model_path)
18tokenizer = AutoTokenizer.from_pretrained(peft_config.base_model_name_or_path)
19
20# Device allocation
21device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
22inference_model.to(device)
23
24print("Base + PEFT adapter model loaded successfully!")
25
26
27def perform_inference(input_text):
28
29 # Tokenize the input text
30 inputs = tokenizer(
31 input_text,
32 return_tensors="pt",
33 truncation=True,
34 padding="max_length",
35 max_length=256, # Adjust max length if necessary
36 )
37
38 # Move inputs to the device
39 inputs = {key: value.to(device) for key, value in inputs.items()}
40
41 # Perform inference
42 with torch.no_grad():
43 outputs = inference_model(**inputs)
44
45 # Extract logits and predictions
46 logits = outputs.logits
47 predicted_class = torch.argmax(logits, dim=-1).item()
48
49 # Map predictions to sentiment labels
50 label_mapping = inference_model.config.label2id
51 predicted_label = label_mapping[predicted_class]
52
53 return predicted_label
54
55test = df['title'].iloc[0]
56print(test)
57#Flex (FLEX) Q3 Earnings Preview: What You Should Know Beyond the Headline Estimates
58
59predictions = []
60
61# Perform inference for each title in the DataFrame
62for title in df['title'][:3]:
63 predictions.append(perform_inference(title))
64
65print(predictions)
66#['neutral', 'positive', 'neutral']