ByFinTech commited on
Commit
acef56e
1 Parent(s): 56c403a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +56 -0
README.md CHANGED
@@ -1,3 +1,59 @@
1
  ---
2
  license: mit
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
  ---
4
+ ---
5
+ library_name: peft
6
+ ---
7
+
8
+ # FinGPT_v3.3
9
+
10
+ ## Model info
11
+ - Base model: Llama2-13B
12
+ - Training method: Instruction Fine-tuning + LoRA + 8bit
13
+ - Task: Sentiment Analysis
14
+
15
+
16
+ ## Try the model
17
+ ``` python
18
+ from transformers import AutoModel, AutoTokenizer, AutoModelForCausalLM, LlamaForCausalLM, LlamaTokenizerFast
19
+ from peft import PeftModel # 0.5.0
20
+
21
+ # Load Models
22
+ base_model = "NousResearch/Llama-2-13b-hf"
23
+ peft_model = "FinGPT/fingpt-sentiment_llama2-13b_lora"
24
+ tokenizer = LlamaTokenizerFast.from_pretrained(base_model, trust_remote_code=True)
25
+ tokenizer.pad_token = tokenizer.eos_token
26
+ model = LlamaForCausalLM.from_pretrained(base_model, trust_remote_code=True, device_map = "cuda:0", load_in_8bit = True,)
27
+ model = PeftModel.from_pretrained(model, peft_model)
28
+ model = model.eval()
29
+
30
+ # Make prompts
31
+ prompt = [
32
+ '''Instruction: What is the sentiment of this news? Please choose an answer from {negative/neutral/positive}
33
+ 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 .
34
+ Answer: ''',
35
+ '''Instruction: What is the sentiment of this news? Please choose an answer from {negative/neutral/positive}
36
+ Input: According to Gran , the company has no plans to move all production to Russia , although that is where the company is growing .
37
+ Answer: ''',
38
+ '''Instruction: What is the sentiment of this news? Please choose an answer from {negative/neutral/positive}
39
+ 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 .
40
+ Answer: ''',
41
+ ]
42
+
43
+ # Generate results
44
+ tokens = tokenizer(prompt, return_tensors='pt', padding=True, max_length=512)
45
+ res = model.generate(**tokens, max_length=512)
46
+ res_sentences = [tokenizer.decode(i) for i in res]
47
+ out_text = [o.split("Answer: ")[1] for o in res_sentences]
48
+
49
+ # show results
50
+ for sentiment in out_text:
51
+ print(sentiment)
52
+
53
+ # Output:
54
+ # positive
55
+ # neutral
56
+ # negative
57
+ ```
58
+
59
+ - PEFT 0.5.0