mukaj commited on
Commit
2af624e
1 Parent(s): f91f7bf

Initial Commit #1

Browse files
README.md ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <h1><center>Falcon-7B-Hawkish-Lora</center></h1>
3
+
4
+ <font size="1">rev1-119</font>
5
+
6
+ <br/>
7
+
8
+ <center>A GPT4-Distilled-Instruct-7B Model, trained with 9000+ Curated Financial & Economic Instruction Prompts. Shows improved reasoning and accuracy on some financial questions and benchmarks over ChatGPT and comparable scores to BloombergGPT (https://arxiv.org/pdf/2303.17564.pdf) on Public Finance NLP Benchmark scores while having 85% less parameters (7B vs 50B). 0.2 of an Epoch completed in released adapter weights and further work is to be done.. </center>
9
+
10
+ <h2><center> Hawkish vs BloombergGPT </center></h2>
11
+ <center>Financial Sentiment Analysis benchmark tests have been attempted to be matched as close as possible to BloombergGPT paper, 5 few shots and using F1 Weighted.</center>
12
+
13
+ | FinBenchmark | Hawkish-7B | BloombergGPT |
14
+ | :------------ |:------------- | :----------- |
15
+ | Headline (SA)*| 71.29 | **82.20** |
16
+ | FiQA SA | **77.01** | 75.07 |
17
+ | FPB | **73.41** | 51.07 |
18
+
19
+
20
+ <center><font size="1">*Sentiment analysis task only</font> </center>
21
+ <br/>
22
+
23
+ <h2><center> Hawkish vs CFA Level 1 Mock Exam</center></h2>
24
+
25
+ <br/>
26
+ <center>The new model surpasses Falcon-Instruct & ChatGPT on a publicly found CFA Level 1 mock exam both with one-shot prompting. Due to both models showing discrepences between samples, both were sampled twice for their best answers. First answer scores were 46.52 (ChatGPT) and 49.46 (Hawkish). </center>
27
+ <br/>
28
+
29
+
30
+ | CFA Level 1 Past Paper | # Questions| ChatGPT (%) | Falcon-Instruct (%) | Hawkish-7B (%) | Exam Weighting |
31
+ | :---------------------------- | :--------: | :---------: | :----------------: | :------------: | :------------: |
32
+ | Ethical and Professional | 18 | **66.66** | 33.3 | 50.0 | 0.15 |
33
+ | Quantitative Methods | 14 | 57.15 | 50.0 | **78.57** | 0.1 |
34
+ | Economics | 12 | **58.33** | 25.0 | 50.0 | 0.1 |
35
+ | Financial Reporting | 24 | 37.5 | 25.0 | **58.3** | 0.15 |
36
+ | Corporate Finance | 10 | 40.0 | 20.0 | **60.0** | 0.1 |
37
+ | Equity Investments | 12 | 58.3 | 33.3 | **66.6** | 0.11 |
38
+ | Fixed Income | 14 | 50.0 | 35.7 | **57.15** | 0.11 |
39
+ | Derivatives | 6 | **66.6** | 16.7 | 50.0 | 0.06 |
40
+ | Alternative Investments | 4 | **50.0** | 0.0 | 25.0 | 0.06 |
41
+ | Portfolio Management | 6 | 0.0 | **50.0** | **50.0** | 0.06 |
42
+ | Weighted Average | - | 50.1 | 29.8 | **56.2** | |
43
+ <br/>
44
+
45
+
46
+ <h3><center> Disclaimer & Intended Uses </center></h3>
47
+
48
+ <center>This model is intended for use as a research artifact, exclusively for research purposes, to study the influence of financial data in the use of training. It is not recommended using this model in high-risk applications (e.g. educational or vocational training, product safety components, or other uses that may impact the well-being of individuals.) as it has not been evaluated fully. The opinions in this paper are solely those of the author and do not reflect the views of the evaluated exam boards or any affiliated entities, including the authors' employers. This research is independent and neither endorsed nor sponsored by these bodies. Any inaccuracies or omissions are entirely the authors' responsibility. Any findings are for academic discourse only and should be used at the reader's discretion. All trademarks and logos belong to their respective owners. </center>
49
+
50
+
51
+
52
+ ## Inference Code
53
+
54
+ Use the provided instruction template for prompting, you can modify system prompt to "You are an AI assistant. You are a financial expert." for better performance on Finance and Economics instructions. Minimum 10GB VRAM and 15GB CPU RAM required.
55
+
56
+ ```
57
+ import torch
58
+ from transformers import BitsAndBytesConfig, AutoModelForCausalLM, AutoTokenizer
59
+ from peft import PeftModel
60
+
61
+ bnb_config = BitsAndBytesConfig(
62
+ load_in_4bit=True,
63
+ bnb_4bit_quant_type="nf4",
64
+ bnb_4bit_compute_dtype=getattr(torch, "bfloat16"),
65
+ bnb_4bit_use_double_quant=True,
66
+ )
67
+
68
+ tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-7b")
69
+ tokenizer.pad_token = tokenizer.eos_token
70
+ model = AutoModelForCausalLM.from_pretrained(
71
+ "tiiuae/falcon-7b", quantization_config=bnb_config, device_map="auto", trust_remote_code=True
72
+ )
73
+ model = PeftModel.from_pretrained(model, "mukaj/falcon-7b-hawkish-lora")
74
+
75
+ def PROMPT_TEMPLATE(system, human):
76
+ return f"### System: {system}\n### Human: {human}\n### Assistant:"
77
+
78
+ PROMPT = PROMPT_TEMPLATE("You are a helpful assistant.","Which bird is on the Albanian flag?")
79
+
80
+ inputs = tokenizer(PROMPT, return_tensors="pt").to(device)
81
+
82
+ outputs = model.generate(input_ids=inputs["input_ids"].to("cuda"),
83
+ attention_mask=inputs["attention_mask"],
84
+ max_new_tokens=10,
85
+ pad_token_id=tokenizer.eos_token_id,
86
+ do_sample=True, temperature=0.8, top_p=0.9)
87
+
88
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
89
+
90
+ ### The bird on the Albanian flag is the eagle.
91
+
92
+ ```
93
+
94
+
95
+ # Financial Domain Completion Examples
96
+
97
+ Equities
98
+ ```
99
+ ### System: You are an AI assistant. You are a financial expert and answer questions with respect to finance and economic domains.
100
+ ### Human: Explain the types of standard ratios used in company analysis.
101
+ ### Assistant: The types of standard ratios used in company analysis are:
102
+
103
+ 1. Liquidity ratios: These ratios measure a company's ability to meet its short-term obligations.
104
+ 2. Profitability ratios: These ratios measure a company's ability to generate profits.
105
+ 3. Efficiency ratios: These ratios measure a company's ability to use its assets and liabilities effectively.
106
+ 4. Market ratios: These ratios measure a company's ability to meet the expectations of its investors.
107
+ 5. Financial leverage ratios: These ratios measure a company's ability to use debt to finance its assets.
108
+ 6. Activity ratios: These ratios measure a company's ability to generate sales and profits.
109
+ 7. Asset turnover ratios: These ratios measure a company's ability to generate sales and profits from its assets.
110
+ 8. Investment ratios: These ratios measure a company's ability to generate profits from its investments.
111
+ 9. Coverage ratios: These ratios measure a company's ability to meet its short-term obligations.
112
+ 10. Du Pont ratios: These ratios measure a company's ability to generate profits from its assets and investments.
113
+ ```
114
+
115
+ <hr style="border:1px solid gray">
116
+
117
+ Fixed Income
118
+ ```
119
+ ### System: You are an AI assistant. You are a financial expert and answer questions with respect to finance and economic domains.
120
+ ### Human: What is CMBS-level call protection, and is a Residual Tranche an example of one or is a Prepayment lockout an example? Or is that a individual loan level protection?
121
+ ### Assistant: CMBS-level call protection is a level of protection that covers all individual loans in a CMBS transaction, and ensures that any single prepayment on any class of assets covered by the loan level protection, will not result in a call of the remaining underlying assets. A Residual Tranche is an example of CMBS-level call protection, which is more commonly employed in public deals, as opposed to private transactions.
122
+ ```
123
+ <hr style="border:1px solid gray">
124
+
125
+ Economics
126
+ ```
127
+ ### System: You are an AI assistant. You are a financial expert and answer questions with respect to finance and economic domains.
128
+ ### Human: A new country is formed in Wakanda. They introduce a new currency. How does the international market value what it is worth?.
129
+ ### Assistant: The value of such a novel economy could be difficult to determine. Assume a nominal return of 0.4%, constant to inflation based on the national nominal wage. Assume nominal wages of both countries have a 200% price level (real price would be less). GDP of the novel sector will be about 5% (20% of the total GDP), assuming labor productivity is unchanged. National product will decrease. With trade of a factor of the nominal price level, the novel GDP will be about 5%x20(50%). Nominal wage in the novel economy can be the same as for the main economy, resulting in the price level equal to (3/5)*(200/100) = 60/.
130
+ One of the challenges in valuing this asset will be deciding if the novel sector should be valued more as the capital market or the labor market. Assume a 30-year horizon. Real wage of labor will be about 8% with national real interest rate at 5%. Assume that nominal returns and capital gains yield a 7/12 interest rate. The present value of the factor-adjusted wage-based return would be: $1.4(7/12)×15(5).
131
+ It would be a risky asset yielding a return of about 4.6%. This is also equivalent to investing 0.4 + $1.4×(30) = $50 at risk in 30 years. Of course, if the rate is higher, the value of the real wage is correspondingly higher. The return to holding labor is the wage rate, plus a risk premium equal to 0.5/4.4/3*(30). The present value of expected cash flows and the intrinsic value of capital are assumed equal. In general, the expected discounted cash flows will be the market price, less expected inflation and real interest rates for those sectors. The present value is therefore determined by multiplying the cash flows by an appropriate discount rate which can be estimated based by using historical inflation-adjusted returns, and discounting cash flows at the domestic risk-adjusted risk premium and discounting future flows at the domestic real interest rate.
132
+ ```
133
+ <hr style="border:1px solid gray">
134
+
135
+ Real Estate
136
+ ```
137
+ ### System: You are an AI assistant. You are a financial expert and answer questions with respect to finance and economic domains.
138
+ ### Human: Joshua Petersen is a real estate analyst that wants to make appropriate adjustments to a capitalization rate. He predicts that vacancy rates will increase and that the availability of credit will decrease. Based on these views, it is most likely that Petersen:
139
+
140
+ 1) should increase the capitalization rate.
141
+
142
+ 2) may need to either increase or decrease the capitalization rate because the two predictions have offsetting effects.
143
+
144
+ 3) should decrease the capitalization rate.
145
+ ### Assistant: B) To determine the impact of vacancy rate fluctuations and availability of credit the two views must be considered as opposed to simply adjusting due to increases in vacancies for vacant rates to go down
146
+ With these two views are the vacancy increases and decreases likely to result in a decline in available capital with credit getting more selective? To make a more robust conclusion, we'll use some of this input. We will assume vacancy rates remain unchanged and assume available lines of credit are unchanged. In those two cases, vacancy increases can have a much greater effect leading to even higher and worse risks to asset value. We're also assuming here that there are no issues with interest in rates, so higher vacancy rate and limited credit availability are really enough to put real assets assets out of consideration until conditions look better. A decline in capital appreciation potential due to falling value of real estate, may require the investor to exit and switch to safer investments or wait out the conditions and have the potential of a huge capital gain when conditions improve.
147
+ From looking to real time statistics the conditions mentioned probably wouldn't be significant in most real contexts of what to capitalize on at real rates. Real estate investment in certain large metros may see value drops, other investment categories will show some movement up while still some will look flat.
148
+
149
+ Here's where your analysis is missing, an important point not to skip that impacts whether all investors leave because of real estate volatility being high. With vacancy rates and credit issues combined, it is true that assets would be viewed as poor assets to capitalize rates or real assets in general at that moment, because so much money leaves market causing lack of market liquidity which makes investing an almost irrational thing at points.
150
+ You have a good understanding with this but need the market understanding and data side, then add it to a robust analysis of macro outlook. Your conclusion is based on real market conditions and future conditions is uncertain so no hard conclusions should be drawn, there can be multiple markets over same period, in your same industry, or across the whole industry that are going down for various reasons which you need to determine prior to assuming. It gets more granular and looks deeper than numbers on a piece of paper for individual assets but instead it relates it with a market condition. Hope it helps.
151
+ ```
152
+ ## Limitations & Further Work
153
+
154
+ Model is not fully evaluated, it is still work in progess, and is only trained on 0.2 Epochs.
155
+
156
+ <ol>
157
+ <li>Repeat experiment with larger model.</li>
158
+ <p>This is self explanatory, larger models have been shown to be better all-around, so a larger base model should help drastically.</p>
159
+ <li>Filter data further.</li>
160
+ <p>Less is more, filter to highest quality samples that maintain highest diversity and compare results.</p>
161
+ <li>Data Mix Comparison</li>
162
+ <p>Different mixes of finance weightings in the data need to be tried to get best performance.</p>
163
+ </ol>
164
+
165
+
166
+ ### Compute
167
+
168
+ Hardware:
169
+
170
+ 1 x RTX 4090
171
+
172
+ Training Software:
173
+
174
+ https://huggingface.co/docs/trl/main/en/sft_trainer
175
+
176
+ Max Seq Length: 2048
177
+
178
+ Learning Rate: 2e-4
179
+
180
+
181
+ ## Attributions & References
182
+
183
+ Base Model: https://huggingface.co/tiiuae/falcon-7b
184
+
185
+ Trained with QLoRA: https://arxiv.org/abs/2305.14314
186
+
187
+ OpenOrca Data: https://huggingface.co/datasets/Open-Orca/OpenOrca
188
+
189
+ Guanaco Data: https://huggingface.co/datasets/timdettmers/openassistant-guanaco
190
+
191
+ CodeParrot Self Instruct: https://huggingface.co/datasets/codeparrot/self-instruct-starcoder
192
+
193
+ BloombergGPT Paper: https://arxiv.org/pdf/2303.17564.pdf
194
+
adapter_config.json ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "base_model_name_or_path": "tiiuae/falcon-7b",
3
+ "bias": "none",
4
+ "fan_in_fan_out": false,
5
+ "inference_mode": true,
6
+ "init_lora_weights": true,
7
+ "layers_pattern": null,
8
+ "layers_to_transform": null,
9
+ "lora_alpha": 16,
10
+ "lora_dropout": 0.1,
11
+ "modules_to_save": null,
12
+ "peft_type": "LORA",
13
+ "r": 64,
14
+ "revision": null,
15
+ "target_modules": [
16
+ "query_key_value"
17
+ ],
18
+ "task_type": "CAUSAL_LM"
19
+ }
adapter_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fcc6eed9390d040d40ee87c9a6f1b60fb4bc5f6b4eada64fc012352728055349
3
+ size 75521265
special_tokens_map.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ ">>TITLE<<",
4
+ ">>ABSTRACT<<",
5
+ ">>INTRODUCTION<<",
6
+ ">>SUMMARY<<",
7
+ ">>COMMENT<<",
8
+ ">>ANSWER<<",
9
+ ">>QUESTION<<",
10
+ ">>DOMAIN<<",
11
+ ">>PREFIX<<",
12
+ ">>SUFFIX<<",
13
+ ">>MIDDLE<<"
14
+ ],
15
+ "eos_token": "<|endoftext|>",
16
+ "pad_token": "<|endoftext|>"
17
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "clean_up_tokenization_spaces": true,
4
+ "eos_token": "<|endoftext|>",
5
+ "model_max_length": 2048,
6
+ "tokenizer_class": "PreTrainedTokenizerFast"
7
+ }