Harnessing Ollama for financial analysis

0

Several weeks ago, a person asked me to assist her with organizing her financial records and taking them to a tax professional. This person does not use a financial program like GnuCash, which could make that project much more effortless. Instead, we downloaded a CSV file from her bank, and then she used Microsoft Excel to add a category to each expense. This was a tedious process. I used a pivot table to organize further and display her data, which she took to the tax preparer.

Recently, while working on other projects with Ollama, I wondered if it might be possible to use a local large language model to accomplish the same task. It is easy to download Ollama. If you are a Linux user like I am, you can enter the following command in a terminal.

curl -fsSL https://ollama.com/install.sh | sh

I decided to use the Phi3.5 model as a base. It is easy to pull the model down to your computer with the following command:

$ ollama pull phi3.5

Once the model was downloaded to my computer, I wanted to make a custom model to analyze my financial data set, a CSV file from the bank. I created a model file, which I called finance, using nano. Here is the text of the modelfile I made for this activity:

FROM phi3.5:latest

# set the temperature to 1 (higher is more creative, lower is more coherent)
PARAMETER temperature 1

# Set the system prompt
SYSTEM """

You are a financial analyst which evaluates my personal finances.
"""

I used the model file to create the custom model for this financial analysis. I set the temperature PARAMETER to 1. A higher number is more creative, and a lower is more coherent. I entered the following command in the terminal:

$ ollama create finance -f finance

This created a unique LLM based on Phi3.5 that performed the financial analysis. I ensured that my financial institution’s CSV file was in the same directory as where I was currently operating. This is important. Then, I entered the following command to pull the CSV file into the custom LLM.

ollama run finance:latest "$(cat data.csv)", Summarize my transactions. 

This gave me a comprehensive summary of the debits and credits in the small CSV file. Although I encountered some errors, I intend to continue working with the model and studying. The results have encouraged me. Both Ollama and the Phi3.5 model are open-source with an MIT license. I chose the Phi3.5 model as the tool for analysis because, according to Microsoft, it was trained on a combination of textbooks and synthetic data. It is lightweight and efficient and designed to outperform similar models. It is ideal for tasks requiring high accuracy and nuanced analysis, such as financial transactions.

Leave a Reply