View on GitHub

LLM Finetuning & Yfinance

by Atharva K

Download this project as a .zip file Download this project as a tar.gz file

Finance Chatbot: Sentiment Analysis & Investment Advisor

Author: Atharva Kulkarni

Key Features

Technical Stack

| Component | Technology | |————————-|————————————-| | Base Model | Meta-Llama-3-8B-Instruct | | Fine-tuning Framework | Unsloth | | Quantization | 4-bit QLoRA | | Data Processing | Pandas, Hugging Face Datasets | | Real-time Data | yfinance, NewsAPI | | Deployment | Transformers, PEFT |

Installation

# Clone repository
git clone https://github.com/Atharvack/LLM-Finetuning-Yfinance.git
cd finance-chatbot

# Additional setup
pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
pip install --no-deps xformers trl peft accelerate bitsandbytes

Usage

Fine-tuning Process

from unsloth import FastLanguageModel

# Initialize model with LoRA
model, tokenizer = FastLanguageModel.from_pretrained(
  model_name="meta-llama/Meta-Llama-3-8B-Instruct",
  max_seq_length=1024,
  load_in_4bit=True,
  token="your_hf_token"
)

# Start training
trainer = SFTTrainer(
  model=model,
  train_dataset=dataset,
  dataset_text_field="text",
  max_seq_length=1024,
  # ... additional config
)
trainer.train()

Real-time Inference

# Initialize chatbot interface
def main():
  context = build_context()  # Collects real-time data
  while True:
    question = input("Ask financial question: ")
    response = inference(question, context)
    print(f"Assistant: {extract_response(response)}")

📊 System Architecture

graph TD A[User Input] --> B[Data Collection Module] B --> C[yFinance API] B --> D[NewsAPI] C --> E[Real-time Metrics] D --> F[News Context] E --> G[LLaMA-3 Processor] F --> G G --> H[Sentiment Analysis] G --> I[Investment Advice] H --> J[Response Generation] I --> J J --> K[Output]

Dataset

Configuration

  1. Obtain Hugging Face Token
  2. Get NewsAPI Key
  3. Update hf_token and api_key in code

License

MIT License - See LICENSE for details


Disclaimer: This project is for educational purposes only. Never make actual financial decisions based on AI outputs without consulting qualified professionals.

Jupyter Notebooks

Check repo here

Try out the LLM on Huggingface [here][https://huggingface.co/spaces/Rashtardeep/Finance-llm]