Foirst version
Browse files
README.md
CHANGED
|
@@ -1,199 +1,186 @@
|
|
| 1 |
---
|
| 2 |
library_name: transformers
|
| 3 |
-
tags:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
---
|
| 5 |
|
| 6 |
-
#
|
| 7 |
|
| 8 |
-
|
| 9 |
|
|
|
|
| 10 |
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
|
| 14 |
-
### Model Description
|
| 15 |
|
| 16 |
-
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
- **Funded by [optional]:** [More Information Needed]
|
| 22 |
-
- **Shared by [optional]:** [More Information Needed]
|
| 23 |
-
- **Model type:** [More Information Needed]
|
| 24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
| 25 |
-
- **License:** [More Information Needed]
|
| 26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
| 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 |
-
[More Information Needed]
|
| 114 |
-
|
| 115 |
-
#### Factors
|
| 116 |
-
|
| 117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
| 118 |
-
|
| 119 |
-
[More Information Needed]
|
| 120 |
-
|
| 121 |
-
#### Metrics
|
| 122 |
-
|
| 123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 124 |
-
|
| 125 |
-
[More Information Needed]
|
| 126 |
-
|
| 127 |
-
### Results
|
| 128 |
-
|
| 129 |
-
[More Information Needed]
|
| 130 |
-
|
| 131 |
-
#### Summary
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
## Model Examination [optional]
|
| 136 |
-
|
| 137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
| 138 |
-
|
| 139 |
-
[More Information Needed]
|
| 140 |
-
|
| 141 |
-
## Environmental Impact
|
| 142 |
-
|
| 143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
| 144 |
-
|
| 145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
| 146 |
-
|
| 147 |
-
- **Hardware Type:** [More Information Needed]
|
| 148 |
-
- **Hours used:** [More Information Needed]
|
| 149 |
-
- **Cloud Provider:** [More Information Needed]
|
| 150 |
-
- **Compute Region:** [More Information Needed]
|
| 151 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 152 |
-
|
| 153 |
-
## Technical Specifications [optional]
|
| 154 |
-
|
| 155 |
-
### Model Architecture and Objective
|
| 156 |
-
|
| 157 |
-
[More Information Needed]
|
| 158 |
-
|
| 159 |
-
### Compute Infrastructure
|
| 160 |
-
|
| 161 |
-
[More Information Needed]
|
| 162 |
-
|
| 163 |
-
#### Hardware
|
| 164 |
-
|
| 165 |
-
[More Information Needed]
|
| 166 |
-
|
| 167 |
-
#### Software
|
| 168 |
-
|
| 169 |
-
[More Information Needed]
|
| 170 |
-
|
| 171 |
-
## Citation [optional]
|
| 172 |
-
|
| 173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
| 174 |
-
|
| 175 |
-
**BibTeX:**
|
| 176 |
-
|
| 177 |
-
[More Information Needed]
|
| 178 |
-
|
| 179 |
-
**APA:**
|
| 180 |
-
|
| 181 |
-
[More Information Needed]
|
| 182 |
-
|
| 183 |
-
## Glossary [optional]
|
| 184 |
-
|
| 185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
| 186 |
-
|
| 187 |
-
[More Information Needed]
|
| 188 |
-
|
| 189 |
-
## More Information [optional]
|
| 190 |
-
|
| 191 |
-
[More Information Needed]
|
| 192 |
-
|
| 193 |
-
## Model Card Authors [optional]
|
| 194 |
-
|
| 195 |
-
[More Information Needed]
|
| 196 |
-
|
| 197 |
-
## Model Card Contact
|
| 198 |
-
|
| 199 |
-
[More Information Needed]
|
|
|
|
| 1 |
---
|
| 2 |
library_name: transformers
|
| 3 |
+
tags:
|
| 4 |
+
- finance
|
| 5 |
+
- chat
|
| 6 |
+
license: apache-2.0
|
| 7 |
+
datasets:
|
| 8 |
+
- sujet-ai/Sujet-Finance-Instruct-177k
|
| 9 |
+
language:
|
| 10 |
+
- en
|
| 11 |
+
base_model:
|
| 12 |
+
- HuggingFaceTB/SmolLM2-360M-Instruct
|
| 13 |
---
|
| 14 |
|
| 15 |
+
# FinChat-XS
|
| 16 |
|
| 17 |
+
FinChat-XS is a lightweight financial domain language model designed to answer questions about finance, markets, investments, and economics in a conversational style.
|
| 18 |
|
| 19 |
+
## Model Overview
|
| 20 |
|
| 21 |
+
FinChat-XS is a fine-tuned version of [HuggingFaceTB/SmolLM2-360M-Instruct](https://huggingface.co/HuggingFaceTB/SmolLM2-360M-Instruct), optimized for financial domain conversations using LoRA (Low-Rank Adaptation). With only 360M parameters, it offers a balance between performance and efficiency, making it accessible for deployment on consumer hardware.
|
| 22 |
|
| 23 |
+
The model combines professional financial knowledge with a conversational communication style, making it suitable for applications where users need expert financial information delivered in an approachable manner.
|
| 24 |
|
|
|
|
| 25 |
|
| 26 |
+
## Repository & Resources
|
| 27 |
|
| 28 |
+
- **Model weights**: Available in this repository
|
| 29 |
+
- **Training code**: [GitHub Notebook](https://github.com/peremartra/FinLLMOpt/tree/main/FinChat-XS)
|
| 30 |
+
- **Base model**: [HuggingFaceTB/SmolLM2-360M-Instruct](https://huggingface.co/HuggingFaceTB/SmolLM2-360M-Instruct)
|
| 31 |
+
- **Training dataset**: [sujet-ai/Sujet-Finance-Instruct-177k](https://huggingface.co/datasets/sujet-ai/Sujet-Finance-Instruct-177k)
|
| 32 |
|
| 33 |
+
## How the Model was Created
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
FinChat-XS was developed through a focused fine-tuning process designed to enhance financial domain expertise while maintaining conversational abilities:
|
| 36 |
|
| 37 |
+
1. **Base model selection**: Started with SmolLM2-360M-Instruct, a lightweight instruction-tuned language model
|
| 38 |
+
2. **Dataset preparation**:
|
| 39 |
+
- Filtered the sujet-ai/Sujet-Finance-Instruct-177k dataset to focus on QA and conversational QA examples
|
| 40 |
+
- Applied length filtering to keep responses below 500 characters
|
| 41 |
+
- Augmented short conversational QA examples to improve conciseness
|
| 42 |
|
| 43 |
+
3. **Fine-tuning approach**:
|
| 44 |
+
- Applied LoRA (Low-Rank Adaptation) to efficiently fine-tune the model
|
| 45 |
+
- Targeted key attention modules (q_proj, v_proj)
|
| 46 |
+
- Used rank r=4 and alpha=16
|
| 47 |
+
- Training configuration:
|
| 48 |
+
- Batch size: 2 (effective batch size 16 with gradient accumulation)
|
| 49 |
+
- Learning rate: 1.5e-4
|
| 50 |
+
- BF16 precision
|
| 51 |
|
| 52 |
+
## Challenges
|
| 53 |
+
The primary challenge encountered during the development of FinChat-XS was the lack of high-quality conversational datasets specifically focused on personal finance. While the Sujet-Finance-Instruct-177k dataset provided valuable financial QA examples, there remains a notable gap in naturalistic, multi-turn conversations about personal financial scenarios.
|
| 54 |
|
| 55 |
+
## Why Use This Model?
|
| 56 |
|
| 57 |
+
FinChat-XS offers several advantages for specific use cases:
|
| 58 |
|
| 59 |
+
- **Efficient deployment**: At only 362MB, it can run on devices with limited resources.
|
| 60 |
+
- **Financial domain knowledge**: Fine-tuned specifically on financial QA data
|
| 61 |
+
- **Balanced communication style**: Combines professional financial knowledge with conversational delivery
|
| 62 |
+
- **Low deployment cost**: Requires significantly less computational resources than larger models
|
| 63 |
+
- **Customizable**: The LoRA adapter can be mixed with other adapters or further fine-tuned
|
| 64 |
|
| 65 |
+
Ideal for:
|
| 66 |
+
- Embedded financial assistants in mobile apps
|
| 67 |
+
- Personal financial planning tools
|
| 68 |
+
- Educational applications about finance and investing
|
| 69 |
+
- Customer service automation for financial institutions
|
| 70 |
+
- Quick deployment scenarios where larger models aren't practical
|
| 71 |
|
| 72 |
+
## How to Use the Model
|
| 73 |
|
| 74 |
+
### Basic Usage with Transformers
|
| 75 |
|
| 76 |
+
```python
|
| 77 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 78 |
+
import torch
|
| 79 |
|
| 80 |
+
# Load model and tokenizer
|
| 81 |
+
model_name = "oopere/FinChat-XS"
|
| 82 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 83 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16)
|
| 84 |
|
| 85 |
+
# Create a conversation
|
| 86 |
+
messages = [
|
| 87 |
+
{"role": "user", "content": "What's the difference between stocks and bonds?"}
|
| 88 |
+
]
|
| 89 |
|
| 90 |
+
# Format the prompt using the chat template
|
| 91 |
+
prompt = tokenizer.apply_chat_template(messages, tokenize=False)
|
| 92 |
|
| 93 |
+
# Tokenize the prompt
|
| 94 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 95 |
|
| 96 |
+
# Generate a response
|
| 97 |
+
outputs = model.generate(
|
| 98 |
+
**inputs,
|
| 99 |
+
max_new_tokens=256,
|
| 100 |
+
temperature=0.7,
|
| 101 |
+
top_p=0.9,
|
| 102 |
+
do_sample=True,
|
| 103 |
+
repetition_penalty=1.2
|
| 104 |
+
)
|
| 105 |
|
| 106 |
+
# Decode and print the response
|
| 107 |
+
response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
|
| 108 |
+
print(response)
|
| 109 |
+
```
|
| 110 |
|
| 111 |
+
### Optimized Inference with 8-bit Quantization
|
| 112 |
|
| 113 |
+
```python
|
| 114 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
| 115 |
+
import torch
|
| 116 |
|
| 117 |
+
# Configure 8-bit quantization
|
| 118 |
+
bnb_config = BitsAndBytesConfig(
|
| 119 |
+
load_in_8bit=True,
|
| 120 |
+
bnb_4bit_compute_dtype=torch.float16
|
| 121 |
+
)
|
| 122 |
|
| 123 |
+
# Load model with quantization
|
| 124 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 125 |
+
"oopere/FinChat-XS",
|
| 126 |
+
quantization_config=bnb_config,
|
| 127 |
+
device_map="auto"
|
| 128 |
+
)
|
| 129 |
+
tokenizer = AutoTokenizer.from_pretrained("oopere/FinChat-XS")
|
| 130 |
|
| 131 |
+
# Continue with the same usage pattern as above
|
| 132 |
+
```
|
| 133 |
|
| 134 |
+
### Using with LoRA Adapter Only
|
| 135 |
|
| 136 |
+
```python
|
| 137 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 138 |
+
from peft import PeftModel, PeftConfig
|
| 139 |
|
| 140 |
+
# Load base model
|
| 141 |
+
base_model = AutoModelForCausalLM.from_pretrained("HuggingFaceTB/SmolLM2-360M-Instruct")
|
| 142 |
+
tokenizer = AutoTokenizer.from_pretrained("HuggingFaceTB/SmolLM2-360M-Instruct")
|
| 143 |
|
| 144 |
+
# Load LoRA adapter
|
| 145 |
+
peft_model = PeftModel.from_pretrained(base_model, "oopere/qa-adapterFinChat-XS")
|
| 146 |
|
| 147 |
+
# Continue with the same usage pattern as above
|
| 148 |
+
```
|
| 149 |
|
| 150 |
+
## Limitations & Considerations
|
| 151 |
|
| 152 |
+
While FinChat-XS performs well in many financial conversation scenarios, users should be aware of these limitations:
|
| 153 |
|
| 154 |
+
1. **Knowledge limitations**: The model's knowledge is limited to its training data and has a knowledge cutoff date from the base model (SmolLM2).
|
| 155 |
|
| 156 |
+
2. **Size trade-offs**: As a 360M parameter model, it has less capacity than larger models (7B+) and may provide less nuanced or detailed responses on complex topics.
|
| 157 |
|
| 158 |
+
3. **Financial advice disclaimer**: The model is not a certified financial advisor and should not be used for making investment decisions. Its responses should be considered educational, not professional financial advice.
|
| 159 |
|
| 160 |
+
4. **Domain boundaries**: While focused on finance, the model may struggle with highly specialized financial topics or recent developments not covered in its training data.
|
| 161 |
|
| 162 |
+
5. **Hallucination potential**: Like all language models, FinChat-XS may occasionally generate plausible-sounding but incorrect information, especially when asked about specific numerical data or complex financial details.
|
| 163 |
|
| 164 |
+
6. **Style variations**: The model balances formal financial knowledge with a conversational style, which may not be appropriate for all professional contexts.
|
| 165 |
|
| 166 |
+
7. **Regulatory compliance**: This model has not been specifically audited for compliance with financial regulations in various jurisdictions.
|
| 167 |
|
| 168 |
+
## Citation
|
| 169 |
|
| 170 |
+
If you use FinChat-XS in your research or applications, please consider citing it as:
|
| 171 |
|
| 172 |
+
```
|
| 173 |
+
@misc{oopere2025finchatxs,
|
| 174 |
+
author = {Martra, P.},
|
| 175 |
+
title = {FinChat-XS: A Lightweight Financial Domain Chat Language Model},
|
| 176 |
+
year = {2025},
|
| 177 |
+
publisher = {Hugging Face},
|
| 178 |
+
howpublished = {\url{https://huggingface.co/oopere/FinChat-XS}}
|
| 179 |
+
}
|
| 180 |
+
```
|
| 181 |
|
| 182 |
+
## Acknowledgements
|
| 183 |
|
| 184 |
+
- [HuggingFaceTB](https://huggingface.co/HuggingFaceTB) for creating the SmolLM2 model series
|
| 185 |
+
- [Sujet AI](https://huggingface.co/sujet-ai) for their financial instruction dataset
|
| 186 |
+
- [Hugging Face](https://huggingface.co/) for providing the infrastructure and tools for model development
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|