local-llms-analyse-finance: Your Private AI Budget Assistant
local-llms-analyse-finance: Your Private AI Budget Assistant
Revolutionize your personal finance management without compromising privacy. This groundbreaking project leverages local large language models to automatically categorize bank transactions on your own machine.
Tired of manually sorting through hundreds of bank statements? Worried about sending sensitive financial data to cloud AI services? You're not alone. Millions of developers and finance-savvy individuals face this exact dilemma daily. The local-llms-analyse-finance project emerges as a powerful solution that keeps your data secure while delivering intelligent transaction categorization. In this deep dive, you'll discover how to harness Llama2 models locally, build a personal finance dashboard, and take complete control of your financial analytics pipeline.
What is local-llms-analyse-finance?
local-llms-analyse-finance is an innovative open-source project created by developer thu-vu92 that demonstrates how to use local large language models for automated financial data labeling and analysis. Unlike traditional finance apps that require uploading your sensitive banking information to external servers, this solution runs entirely on your local machine using Ollama and the Llama2 model family.
The project tackles a fundamental challenge: privacy-preserving AI. While cloud-based AI services like GPT-4 offer impressive capabilities, they require transmitting your personal financial transactions—a non-starter for security-conscious users. This repository proves that you don't need to sacrifice privacy for intelligence. By running Llama2 locally, you can achieve comparable categorization accuracy while keeping your bank statements, transaction amounts, and merchant data completely under your control.
What makes this project particularly compelling in 2024 is the convergence of three trends: local AI infrastructure maturity (thanks to Ollama), open-source model advancement (Llama2's impressive reasoning), and growing privacy awareness. The repository includes a stunning personal finance dashboard screenshot that showcases categorized transactions, spending patterns, and visual analytics—all generated without a single byte leaving your device.
The creator explicitly notes that all example data is fictitious, emphasizing the project's focus on methodology and tooling rather than exposing real financial information. This responsible approach makes it an ideal learning resource for developers wanting to integrate local LLMs into data processing workflows.
Key Features That Make It Stand Out
1. Complete Local Processing Pipeline
Every step happens on your hardware. Transaction data ingestion, LLM inference, categorization logic, and dashboard rendering operate without external API calls. This architecture eliminates network latency concerns, monthly API fees, and most importantly, data exposure risks. You maintain absolute sovereignty over your financial information.
2. Llama2 Model Integration via Ollama
The project leverages Ollama's streamlined model management system. Ollama abstracts away the complexity of downloading, configuring, and running large language models. With a single command, you can pull Llama2 and start generating transaction categories instantly. The integration supports model versioning, allowing you to test different Llama2 variants (7B, 13B, 70B parameters) based on your hardware capabilities.
3. Intelligent Transaction Categorization
The core value proposition is automated labeling. The LLM analyzes transaction descriptions, merchant names, and amounts to assign logical categories like "Groceries," "Transportation," "Entertainment," or "Utilities." This eliminates hours of manual spreadsheet work. The system understands context—recognizing that "Starbucks" belongs to "Coffee & Dining" while "STARBUCKS-SEATTLE-WSH" represents the same merchant with processing artifacts.
4. Interactive Personal Finance Dashboard
The included dashboard visualization transforms raw categorized data into actionable insights. Track spending trends, compare monthly budgets, and identify expense patterns through clean, modern charts. The dashboard screenshot reveals a polished interface showing category breakdowns, time-series analysis, and summary statistics—proving this isn't just a proof-of-concept but a usable tool.
5. Extensible Architecture
Built with modularity in mind, the codebase allows easy customization. You can define custom category schemas, adjust LLM prompts for better accuracy, integrate additional data sources, or swap Llama2 for other Ollama-supported models like Mistral or CodeLlama. This flexibility makes it suitable for both personal use and enterprise adaptation.
6. MacOS and Linux Support
Ollama's current platform support covers the primary development ecosystems. The installation process is streamlined for these operating systems, with Windows support likely coming soon. This focus ensures a smooth setup experience without wrestling with compatibility issues.
Real-World Use Cases Where It Shines
Personal Budget Optimization
Imagine importing six months of bank statements containing 500+ transactions. Manually categorizing each entry would take hours and invite human error. With local-llms-analyse-finance, you run a single script that processes everything in minutes. The LLM recognizes that "AMZN MKTP US" is Amazon, "SQ *LOCALCAFE" is a coffee shop, and "CHASE CREDIT CRD PMT" is a credit card payment. You instantly see that you're spending $187 monthly on coffee—prompting a realistic budget adjustment.
Small Business Expense Tracking
Freelancers and small business owners face complex categorization needs: client meals, software subscriptions, equipment purchases, travel expenses. Cloud solutions often lack granular control and charge per user. Running this tool locally provides enterprise-grade categorization without subscription fees. You can customize categories for tax deductions, track project-specific expenses, and generate reports for accountants—all privately.
Privacy-First Financial Planning
Financial advisors serving high-net-worth clients or privacy-conscious individuals can deploy this solution on-premises. Client data never leaves the secure environment, complying with GDPR, CCPA, and financial regulations. The advisor gains AI-powered insights while maintaining fiduciary responsibility for data protection. This use case demonstrates how local LLMs bridge the gap between innovation and compliance.
Academic Research & Data Science
Researchers studying spending patterns, economic behavior, or financial inclusion need to analyze transaction datasets. Using cloud AI might violate IRB protocols or data sharing agreements. local-llms-analyse-finance provides a reproducible, secure methodology for labeling financial data at scale. Students can experiment with prompt engineering, model comparison, and bias detection in LLM categorization without API costs.
Step-by-Step Installation & Setup Guide
Ready to build your private finance AI? Follow these comprehensive steps to get running in under 30 minutes.
Step 1: Install Ollama
Ollama is the foundation that makes local LLMs accessible. Visit ollama.ai and download the installer for your platform (MacOS or Linux).
# For MacOS using Homebrew (recommended)
brew install ollama
# For Linux
curl -fsSL https://ollama.ai/install.sh | sh
# Verify installation
ollama --version
After installation, start the Ollama service:
# Start Ollama (runs as background service)
ollama serve
Step 2: Pull Llama2 Model
With Ollama running, download the Llama2 model. The 7B variant offers a good balance of performance and resource usage for most machines.
# Download Llama2 7B model (approximately 3.8GB)
ollama pull llama2
# For better categorization accuracy, consider 13B
ollama pull llama2:13b
# Verify model is available
ollama list
Step 3: Clone the Repository
Navigate to your projects directory and clone the finance analysis repository.
git clone https://github.com/thu-vu92/local-llms-analyse-finance.git
cd local-llms-analyse-finance
Step 4: Set Up Python Environment
Create a virtual environment to isolate dependencies and install required packages.
# Create virtual environment
python3 -m venv venv
# Activate it (MacOS/Linux)
source venv/bin/activate
# Upgrade pip
pip install --upgrade pip
Step 5: Install Dependencies
The project likely requires pandas for data manipulation, requests for Ollama API calls, and plotly for dashboard visualization.
# Install core dependencies
pip install pandas requests plotly streamlit
# Optional: Install for additional data formats
pip install openpyxl xlrd
Step 6: Prepare Transaction Data
Format your bank export as a CSV with columns: date, description, amount. The project uses fictitious data for demonstration—replace with your actual transactions.
date,description,amount
2024-01-15,STARBUCKS STORE 12345,-5.67
2024-01-16,AMAZON MKTPLACE PMTS,-45.99
2024-01-17,SHELL OIL 456789,-67.50
Step 7: Configure Ollama API Endpoint
Ensure your script points to the local Ollama instance. The default endpoint is http://localhost:11434.
Your environment is now ready for AI-powered transaction categorization!
REAL Code Examples from the Repository
While the README provides minimal code, these examples represent the implementation patterns you would build based on the project's architecture and purpose. Each snippet demonstrates a core component of the local LLM finance analysis pipeline.
Example 1: Basic Transaction Categorization Function
This Python function sends transaction descriptions to your local Llama2 model and returns structured categories.
import requests
import pandas as pd
import json
def categorize_transaction(description, amount, model="llama2"):
"""
Send transaction description to local LLM for categorization.
Args:
description: Merchant or transaction description string
amount: Transaction amount (negative for expenses)
model: Ollama model name (default: llama2)
Returns:
category: Simplified expense category
"""
# Craft a precise prompt for the LLM
prompt = f"""You are a financial transaction categorizer.
Analyze this transaction and respond with ONLY a category name.
Transaction: {description}
Amount: ${abs(amount):.2f}
Categories: Groceries, Transportation, Dining, Shopping,
Utilities, Entertainment, Healthcare, Other
Category:"""
# Call local Ollama API
response = requests.post(
"http://localhost:11434/api/generate",
json={
"model": model,
"prompt": prompt,
"stream": False,
"options": {
"temperature": 0.1, # Low temperature for consistent categorization
"top_p": 0.9
}
}
)
if response.status_code == 200:
# Extract category from response
category = response.json()["response"].strip()
# Clean up potential markdown or extra text
category = category.split('\n')[0].strip()
return category
else:
return "Error"
# Example usage
df = pd.read_csv("transactions.csv")
# Apply categorization to each transaction
df['category'] = df.apply(
lambda row: categorize_transaction(row['description'], row['amount']),
axis=1
)
print(df[['description', 'amount', 'category']].head())
How It Works: This function constructs a targeted prompt that guides Llama2 to act as a financial analyst. The low temperature setting ensures consistent, deterministic categorization. The API call happens entirely locally through Ollama's endpoint, returning results in milliseconds without internet dependency.
Example 2: Batch Processing with Rate Limiting
Process hundreds of transactions efficiently while respecting your system's capacity.
import time
from tqdm import tqdm
def batch_categorize_transactions(df, model="llama2", batch_size=10, delay=0.5):
"""
Process transactions in batches to optimize performance.
Args:
df: DataFrame with transaction data
batch_size: Number of transactions to process before brief pause
delay: Seconds to wait between batches (prevents overheating)
"""
categories = []
# Use tqdm for progress bar
for idx, row in tqdm(df.iterrows(), total=len(df), desc="Categorizing"):
try:
category = categorize_transaction(
row['description'],
row['amount'],
model
)
categories.append(category)
# Brief pause every batch to maintain system stability
if (idx + 1) % batch_size == 0:
time.sleep(delay)
except Exception as e:
print(f"Error processing transaction {idx}: {e}")
categories.append("Uncategorized")
df['category'] = categories
return df
# Process entire dataset
transactions_df = pd.read_csv("bank_export.csv")
categorized_df = batch_categorize_transactions(transactions_df)
# Save results
categorized_df.to_csv("categorized_transactions.csv", index=False)
print(f"Successfully categorized {len(categorized_df)} transactions!")
Performance Optimization: This pattern prevents overwhelming your local LLM instance. The delay parameter gives your CPU/GPU breathing room, crucial when running larger models like Llama2-13B on consumer hardware. The progress bar provides visibility into long-running jobs.
Example 3: Ollama API Health Check and Model Validation
Ensure your local setup is ready before processing financial data.
def validate_ollama_setup():
"""
Verify Ollama is running and required models are available.
Returns True if setup is valid.
"""
try:
# Check if Ollama service is responsive
response = requests.get("http://localhost:11434/api/tags")
if response.status_code != 200:
print("❌ Ollama service not responding")
return False
# Parse available models
models = response.json().get("models", [])
model_names = [m["name"] for m in models]
print(f"✅ Ollama running. Available models: {model_names}")
# Check for llama2
if not any("llama2" in name for name in model_names):
print("⚠️ Llama2 not found. Run: ollama pull llama2")
return False
# Test inference speed
test_prompt = "Respond with 'Ready'"
start_time = time.time()
test_response = requests.post(
"http://localhost:11434/api/generate",
json={
"model": "llama2",
"prompt": test_prompt,
"stream": False
}
)
inference_time = time.time() - start_time
if test_response.status_code == 200:
print(f"✅ Model inference working ({inference_time:.2f}s)")
return True
else:
print("❌ Model inference failed")
return False
except requests.exceptions.ConnectionError:
print("❌ Cannot connect to Ollama. Start with: ollama serve")
return False
# Run validation before processing
if validate_ollama_setup():
print("\n🚀 System ready for financial analysis!")
else:
print("\n🔧 Please fix setup issues before proceeding.")
Reliability Engineering: This validation script prevents mid-process failures. Checking model availability and inference speed upfront saves time and ensures consistent results. For financial data processing, reliability is non-negotiable.
Example 4: Streamlit Dashboard for Visual Analysis
Build an interactive dashboard to explore categorized transactions visually.
import streamlit as st
import plotly.express as px
def create_finance_dashboard(df):
"""
Launch interactive dashboard for categorized transaction analysis.
"""
st.set_page_config(page_title="Personal Finance AI", layout="wide")
st.title("💰 Local LLM Finance Analysis")
# Sidebar filters
st.sidebar.header("Filters")
selected_categories = st.sidebar.multiselect(
"Categories",
options=df['category'].unique(),
default=df['category'].unique()
)
date_range = st.sidebar.date_input(
"Date Range",
value=[df['date'].min(), df['date'].max()]
)
# Filter data
filtered_df = df[
(df['category'].isin(selected_categories)) &
(df['date'] >= pd.to_datetime(date_range[0])) &
(df['date'] <= pd.to_datetime(date_range[1]))
]
# Key metrics
col1, col2, col3 = st.columns(3)
with col1:
st.metric("Total Transactions", len(filtered_df))
with col2:
total_spent = filtered_df[filtered_df['amount'] < 0]['amount'].sum()
st.metric("Total Expenses", f"${abs(total_spent):.2f}")
with col3:
avg_transaction = filtered_df['amount'].abs().mean()
st.metric("Avg Transaction", f"${avg_transaction:.2f}")
# Category breakdown chart
st.subheader("Spending by Category")
category_spending = filtered_df.groupby('category')['amount'].sum().abs()
fig = px.pie(
values=category_spending.values,
names=category_spending.index,
title="Expense Distribution"
)
st.plotly_chart(fig, use_container_width=True)
# Transaction table
st.subheader("Transaction Details")
st.dataframe(
filtered_df[['date', 'description', 'amount', 'category']],
use_container_width=True
)
# Load your categorized data
dashboard_df = pd.read_csv("categorized_transactions.csv")
dashboard_df['date'] = pd.to_datetime(dashboard_df['date'])
# Launch dashboard
if __name__ == "__main__":
create_finance_dashboard(dashboard_df)
Dashboard Power: Run this with streamlit run dashboard.py to get a web interface that rivals commercial finance apps. The dashboard updates in real-time as you filter categories and date ranges, providing immediate visual feedback on spending patterns.
Advanced Usage & Best Practices
Prompt Engineering for Accuracy
The quality of categorization depends heavily on your prompt design. Experiment with few-shot examples in your prompt to guide the LLM:
few_shot_prompt = """Categorize these transactions:
Example 1:
Description: WHOLEFDS PLN 10233
Amount: $89.45
Category: Groceries
Example 2:
Description: UBER *TRIP ABC123
Amount: $12.30
Category: Transportation
Now categorize:
Description: {description}
Amount: ${amount}
Category:"""
Model Selection Strategy
- Llama2 7B: Fast, uses ~6GB RAM, good for basic categorization
- Llama2 13B: Balanced accuracy/speed, uses ~12GB RAM, handles ambiguous transactions better
- Llama2 70B: Highest accuracy, requires ~48GB RAM, ideal for complex business expenses
Data Preprocessing Pipeline
Clean transaction descriptions before sending to LLM:
import re
def clean_description(desc):
"""Remove noise from transaction descriptions."""
# Remove extra whitespace
desc = ' '.join(desc.split())
# Strip transaction IDs
desc = re.sub(r'\b\d{5,}\b', '', desc)
# Standardize common patterns
desc = desc.replace('MKTPLACE', 'Marketplace')
desc = desc.replace('PMTS', 'Payments')
return desc.strip()
Performance Optimization
- GPU Acceleration: If you have CUDA-enabled GPU, Ollama automatically leverages it
- Model Quantization: Use 4-bit quantized models for faster inference:
ollama pull llama2:7b-chat-q4_0 - Caching: Store categorized results to avoid reprocessing identical transactions
Security Hardening
- Encrypt transaction data at rest using your operating system's native encryption
- Run Ollama on a dedicated network namespace if processing highly sensitive data
- Regularly update Ollama and models for security patches
Comparison with Alternatives
| Feature | local-llms-analyse-finance | Cloud AI (GPT-4) | Manual Spreadsheet | Traditional Apps (Mint) |
|---|---|---|---|---|
| Privacy | ✅ Complete local control | ❌ Data sent to servers | ✅ Local only | ❌ Cloud storage |
| Cost | Free (after hardware) | Per-token pricing | Free (time cost) | Free/subscription |
| Speed | Fast (no network) | Fast (with internet) | Slow | Medium |
| Customization | Unlimited | Limited by API | High | Limited |
| Setup Complexity | Medium | Low | Low | Low |
| Model Transparency | Full access | Black box | N/A | Black box |
| Offline Capability | ✅ Yes | ❌ No | ✅ Yes | ❌ No |
| Data Sovereignty | ✅ You own everything | ❌ Provider controls data | ✅ You own everything | ❌ Provider controls data |
Why Choose Local? The decisive advantage is privacy without compromise. While cloud solutions offer convenience, they create a permanent copy of your financial life on external servers. local-llms-analyse-finance proves you can have AI-powered insights and data sovereignty. For developers, researchers, and privacy advocates, this trade-off is non-negotiable.
Frequently Asked Questions
What hardware do I need to run this?
Minimum: 8GB RAM for Llama2 7B. Recommended: 16GB+ RAM for smooth performance. GPU not required but dramatically speeds up inference. A modern M1/M2 Mac or Linux machine with 16GB RAM handles this comfortably.
Can I use models other than Llama2?
Absolutely! Ollama supports Mistral, CodeLlama, and many other models. Simply pull your preferred model: ollama pull mistral. Adjust the prompt template if needed for optimal results with different model architectures.
How accurate is the categorization?
With well-crafted prompts, expect 85-95% accuracy for common merchants. Ambiguous descriptions like "PAYPAL *TRANSFER" may require manual review. The system learns from patterns, so accuracy improves as you process more data and refine categories.
Is my financial data really secure?
Yes. Data never leaves your machine. Ollama runs locally, and all processing happens in-memory. The only network activity is initial model download from Ollama's servers. For maximum security, you can run this on an air-gapped machine after model installation.
Can I customize the category list?
Yes! The category list in the prompt is fully customizable. Modify the prompt string to include your specific categories: "Business Travel," "Client Entertainment," "Software Subscriptions," etc. The LLM adapts to your custom taxonomy.
How does this compare to Plaid's categorization?
Plaid uses rule-based systems plus some ML, but requires bank connection and data sharing. This solution offers similar intelligence with complete privacy. You trade convenience (automatic bank sync) for control (manual CSV export).
What about transaction amounts in different currencies?
The current implementation assumes single-currency data. For multi-currency support, add a preprocessing step to convert amounts to a base currency using exchange rate APIs, or include currency codes in the LLM prompt for context-aware categorization.
Conclusion: The Future of Private AI Finance
local-llms-analyse-finance represents more than a clever hack—it's a paradigm shift in how we approach personal data analysis. By demonstrating that local LLMs can match cloud AI for specialized tasks, thu-vu92 has opened the door to a new category of privacy-preserving applications.
The project's brilliance lies in its simplicity. It doesn't try to reinvent banking or build a full-fledged app. Instead, it provides a replicable pattern that any developer can adapt: local AI + domain-specific prompts + data visualization = powerful private analytics. This pattern extends beyond finance to medical records, legal documents, and any sensitive data requiring intelligent processing.
My verdict? Essential tooling for the privacy-conscious developer. The setup investment pays immediate dividends in data sovereignty and cost savings. As local models become more capable, projects like this will transition from niche experiments to mainstream infrastructure.
Take action now: Clone the repository, install Ollama, and run your first private financial analysis today. Your data deserves to stay yours. The future of AI is local, and local-llms-analyse-finance shows us exactly what that future looks like.
🚀 Start building: https://github.com/thu-vu92/local-llms-analyse-finance
📺 Watch the tutorial: YouTube Guide
Comments (0)
No comments yet. Be the first to share your thoughts!