{"id":7918,"date":"2024-10-08T01:01:00","date_gmt":"2024-10-08T05:01:00","guid":{"rendered":"https:\/\/www.both.org\/?p=7918"},"modified":"2024-10-08T06:20:34","modified_gmt":"2024-10-08T10:20:34","slug":"harnessing-ollama-for-financial-analysis","status":"publish","type":"post","link":"https:\/\/www.both.org\/?p=7918","title":{"rendered":"Harnessing Ollama for financial analysis"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"7918\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\r\n<\/div><\/div>\n<p>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 <a href=\"https:\/\/www.gnucash.org\/\">GnuCash<\/a>,&nbsp;which could make that project much more effortless. Instead, we downloaded a&nbsp;CSV&nbsp;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.<\/p>\n\n\n\n<p>Recently<span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\">, while working on other projects with&nbsp;<a href=\"https:\/\/ollama.com\/\" target=\"_blank\" rel=\"noopener\">Ollama,<\/a>&nbsp;I wondered if it might be possible to use a local large language model to accomplish the same task. It is easy to&nbsp;<a href=\"https:\/\/ollama.com\/download\" target=\"_blank\" rel=\"noopener\">download<\/a>&nbsp;Ollama. If you are a Linux user like I am,<\/span> you can enter the following command in a terminal.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -fsSL https:\/\/ollama.com\/install.sh | sh<\/code><\/pre>\n\n\n\n<p>I decided to use the <a href=\"https:\/\/ollama.com\/library\/phi3.5\">Phi3.5<\/a> model as a base.  It is easy to pull the model down to your computer with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ ollama pull phi3.5<\/code><\/pre>\n\n\n\n<p>Once the model was downloaded to my computer, I wanted to make a custom model to analyze my financial data set, a CSV&nbsp;file from the bank. I created a model file, which I called&nbsp;<strong>finance<\/strong>,&nbsp;using&nbsp;nano. Here is the text of the modelfile I made for this activity:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>FROM phi3.5:latest\n\n# set the temperature to 1 (higher is more creative, lower is more coherent)\nPARAMETER temperature 1\n\n# Set the system prompt\nSYSTEM \"\"\"\n\nYou are a financial analyst which evaluates my personal finances.\n\"\"\"<\/code><\/pre>\n\n\n\n<p>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:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ ollama create finance -f finance<\/code><\/pre>\n\n\n\n<p>This created a unique LLM based on Phi3.5 that performed the financial analysis. I ensured that my financial institution&#8217;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.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ollama run finance:latest \"$(cat data.csv)\", Summarize my transactions. \n<\/code><\/pre>\n\n\n\n<p>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\u00a0for\u00a0tasks\u00a0requiring\u00a0high\u00a0accuracy\u00a0and\u00a0nuanced\u00a0analysis,\u00a0such\u00a0as\u00a0financial\u00a0transactions.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Several weeks ago, a person asked me to assist her with organizing her financial records and taking them<\/p>\n","protected":false},"author":32,"featured_media":3282,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[307,593,5],"tags":[560],"class_list":["post-7918","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai","category-financial-analysis","category-linux","tag-ollama"],"modified_by":"David Both","_links":{"self":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/7918","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/users\/32"}],"replies":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7918"}],"version-history":[{"count":10,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/7918\/revisions"}],"predecessor-version":[{"id":7930,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/7918\/revisions\/7930"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/3282"}],"wp:attachment":[{"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7918"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7918"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7918"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}