File size: 3,390 Bytes
859a063
 
 
 
 
 
 
 
 
 
 
432e374
859a063
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95707e2
859a063
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
432e374
859a063
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
db48387
859a063
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ad0514
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
---
language:
- en
license: apache-2.0
library_name: peft
tags:
- facebook
- meta
- pytorch
- llama
- llama-2
base_model: DavidLanz/Llama3-tw-8B-Instruct
model_name: Llama 3 8B Instruct
inference: false
model_creator: Meta Llama 3
model_type: llama
pipeline_tag: text-generation
quantized_by: QLoRA
---

# Model Card for Model ID

This PEFT model is designed for predicting the prices of these five Taiwan stocks:

| 證券代號 | 證券名稱 |
|---------|--------|
| 3661    | 世芯-KY |
| 2330    | 台積電   |
| 3017    | 奇鋐     |
| 2618    | 長榮航   |
| 2317    | 鴻海     |

Disclaimer: This model is for a time series problem on LLM performance, and it's not for investment advice; any prediction results are not a basis for investment reference.

## Model Details

The training data source is from the [臺灣證券交易所 / Taiwan Stock Exchange (TWSE)](https://www.twse.com.tw/), covering the period from January 1, 2019, to July 1, 2024 (5 years).

### Model Description

This repo contains QLoRA format model files for [Meta's Llama 3 8B Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct).

## Uses

```python
import torch
from peft import LoraConfig, PeftModel

from transformers import (
    AutoModelForCausalLM,
    AutoTokenizer,
    BitsAndBytesConfig,
    HfArgumentParser,
    TrainingArguments,
    TextStreamer,
    pipeline,
    logging,
)

device_map = {"": 0}
use_4bit = True
bnb_4bit_compute_dtype = "float16"
bnb_4bit_quant_type = "nf4"
use_nested_quant = False
compute_dtype = getattr(torch, bnb_4bit_compute_dtype)

bnb_config = BitsAndBytesConfig(
    load_in_4bit=use_4bit,
    bnb_4bit_quant_type=bnb_4bit_quant_type,
    bnb_4bit_compute_dtype=compute_dtype,
    bnb_4bit_use_double_quant=use_nested_quant,
)

based_model_path = "DavidLanz/Llama3-tw-8B-Instruct"
adapter_path = "DavidLanz/llama3_8b_taiwan_stock_qlora"

base_model = AutoModelForCausalLM.from_pretrained(
    based_model_path,
    low_cpu_mem_usage=True,
    return_dict=True,
    quantization_config=bnb_config,
    torch_dtype=torch.float16,
    device_map=device_map,
)
model = PeftModel.from_pretrained(base_model, adapter_path)

tokenizer = AutoTokenizer.from_pretrained(based_model_path, trust_remote_code=True)

import torch
from transformers import pipeline, TextStreamer

text_gen_pipeline = pipeline(
    "text-generation",
    model=model,
    model_kwargs={"torch_dtype": torch.bfloat16},
    tokenizer=tokenizer,
)

messages = [
    {
        "role": "system",
        "content": "你是一位專業的台灣股市交易分析師",
    },
    {"role": "user", "content": "鴻海上週五的表現,開盤價是211.00,當日最高價是217.50,當日最低價是211.00,收盤價是212.00,與前一天相比下跌了5.50,成交股數為174,076,905,交易金額為37,127,696,834。請預測今天的收盤價?"},
]

prompt = text_gen_pipeline.tokenizer.apply_chat_template(
        messages, 
        tokenize=False, 
        add_generation_prompt=True
)

terminators = [
    text_gen_pipeline.tokenizer.eos_token_id,
    text_gen_pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>")
]

outputs = text_gen_pipeline(
    prompt,
    max_new_tokens=256,
    eos_token_id=terminators,
    do_sample=True,
    temperature=0.6,
    top_p=0.9,
)
print(outputs[0]["generated_text"][len(prompt):])
```

### Framework versions

- PEFT 0.11.1