oliverwang15
commited on
Commit
·
8612366
1
Parent(s):
9be5d93
Update README.md
Browse files
README.md
CHANGED
@@ -1,6 +1,58 @@
|
|
1 |
---
|
2 |
library_name: peft
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
## Training procedure
|
5 |
|
6 |
|
|
|
1 |
---
|
2 |
library_name: peft
|
3 |
---
|
4 |
+
|
5 |
+
# FinGPT_v3.3
|
6 |
+
|
7 |
+
## Model info
|
8 |
+
- Base model: Llama2-13B
|
9 |
+
- Training method: Instruction Fine-tuning + LoRA + 8bit
|
10 |
+
- Task: Sentiment Analysis
|
11 |
+
|
12 |
+
|
13 |
+
## Try the model
|
14 |
+
``` python
|
15 |
+
from transformers import AutoModel, AutoTokenizer, AutoModelForCausalLM, LlamaForCausalLM, LlamaTokenizerFast
|
16 |
+
from peft import PeftModel # 0.5.0
|
17 |
+
|
18 |
+
# Load Models
|
19 |
+
base_model = "NousResearch/Llama-2-13b-hf"
|
20 |
+
peft_model = "oliverwang15/FinGPT_v33_Llama2_13B_Sentiment_Instruction_LoRA_FT_8bit"
|
21 |
+
tokenizer = LlamaTokenizerFast.from_pretrained(base_model, trust_remote_code=True)
|
22 |
+
tokenizer.pad_token = tokenizer.eos_token
|
23 |
+
model = LlamaForCausalLM.from_pretrained(base_model, trust_remote_code=True, device_map = "cuda:0", load_in_8bit = True,)
|
24 |
+
model = PeftModel.from_pretrained(model, peft_model)
|
25 |
+
model = model.eval()
|
26 |
+
|
27 |
+
# Make prompts
|
28 |
+
prompt = [
|
29 |
+
'''Instruction: What is the sentiment of this news? Please choose an answer from {negative/neutral/positive}
|
30 |
+
Input: FINANCING OF ASPOCOMP 'S GROWTH Aspocomp is aggressively pursuing its growth strategy by increasingly focusing on technologically more demanding HDI printed circuit boards PCBs .
|
31 |
+
Answer: ''',
|
32 |
+
'''Instruction: What is the sentiment of this news? Please choose an answer from {negative/neutral/positive}
|
33 |
+
Input: According to Gran , the company has no plans to move all production to Russia , although that is where the company is growing .
|
34 |
+
Answer: ''',
|
35 |
+
'''Instruction: What is the sentiment of this news? Please choose an answer from {negative/neutral/positive}
|
36 |
+
Input: A tinyurl link takes users to a scamming site promising that users can earn thousands of dollars by becoming a Google ( NASDAQ : GOOG ) Cash advertiser .
|
37 |
+
Answer: ''',
|
38 |
+
]
|
39 |
+
|
40 |
+
# Generate results
|
41 |
+
tokens = tokenizer(prompt, return_tensors='pt', padding=True, max_length=512)
|
42 |
+
res = model.generate(**tokens, max_length=512)
|
43 |
+
res_sentences = [tokenizer.decode(i) for i in res]
|
44 |
+
out_text = [o.split("Answer: ")[1] for o in res_sentences]
|
45 |
+
|
46 |
+
# show results
|
47 |
+
for sentiment in out_text:
|
48 |
+
print(sentiment)
|
49 |
+
|
50 |
+
# Output:
|
51 |
+
# positive
|
52 |
+
# neutral
|
53 |
+
# negative
|
54 |
+
```
|
55 |
+
|
56 |
## Training procedure
|
57 |
|
58 |
|