<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Deepak Sharma on Medium]]></title>
        <description><![CDATA[Stories by Deepak Sharma on Medium]]></description>
        <link>https://medium.com/@probabilisticthoughts?source=rss-256ef68d5349------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*XzNefH4qqCQVodStYZyTcw.png</url>
            <title>Stories by Deepak Sharma on Medium</title>
            <link>https://medium.com/@probabilisticthoughts?source=rss-256ef68d5349------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 14 Nov 2026 15:14:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@probabilisticthoughts/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[2. Chain of Thoughts and Critique and Revise using LangChain]]></title>
            <link>https://medium.com/@probabilisticthoughts/2-chain-of-thoughts-and-critique-and-revise-using-langchain-de401dbd007c?source=rss-256ef68d5349------2</link>
            <guid isPermaLink="false">https://medium.com/p/de401dbd007c</guid>
            <category><![CDATA[llm-agent]]></category>
            <category><![CDATA[langchain]]></category>
            <category><![CDATA[langchain-agents]]></category>
            <category><![CDATA[chain-of-thought]]></category>
            <category><![CDATA[critique-and-revise]]></category>
            <dc:creator><![CDATA[Deepak Sharma]]></dc:creator>
            <pubDate>Sat, 08 Jun 2024 07:08:01 GMT</pubDate>
            <atom:updated>2024-06-08T07:08:01.767Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I explore some examples on using Chain of Thought and Critique and Revise techniques to improve LLMs reasoning capabilities. These techniques are foundation blocks of any <a href="https://github.com/kaushikb11/awesome-llm-agents">Agent framework</a>.</p><p>Do note that all the codes used in this blog are available at the repo — <a href="https://github.com/aryabhattaslair/RAG_Evaluations.git">https://github.com/aryabhattaslair/RAG_Evaluations.git</a>.</p><p><a href="https://arxiv.org/pdf/2201.11903">Chain of Thought </a>explores asking the LLM to generate a series of intermediate reasoning steps when answering a question. This significantly improves LLMs performance in logic, math and reasoning tasks. If you are using one of the available LLM APIs (OpenAI, Claude, Gemini etc) the recent models should come with this ability. Most likely they have been fine-tuned to think step by step for reasoning tasks. One of the example with <strong>gpt-3.5-turbo</strong></p><p><strong>Query: </strong><em>Roger has 5 tennis balls. He buys 2 more cans of tennis balls.<br>Each can has 3 tennis balls. How many tennis balls does he have now?</em></p><p><strong>LLM Response: </strong><em>To find out how many tennis balls Roger has now, we first calculate the number of tennis balls in the cans he bought:<br>Number of tennis balls per can = 3<br>Number of cans bought = 2<br>Total number of tennis balls from the new cans = 3 * 2 = 6</em></p><p><em>Now, we add the original number of tennis balls Roger had to the new ones he bought:<br>Original number of tennis balls = 5<br>Total number of tennis balls now = 5 + 6 = 11</em></p><p><em>Therefore, Roger now has 11 tennis balls.</em></p><p>By default, it appears that the model is trained (and instructed) to think Step by Step. This implies that most likely, the model is fine-tuned with CoT responses and CoT instructions are part of the system instructions.</p><p>However, step by step thinking does not solve all our reasoning problems. Lets take a look at this example</p><p><strong>Query: </strong><em>The bakers at the Beverly Hills Bakery baked 200 loaves of bread on Monday morning. They sold 93 loaves in the morning and 39 loaves in the afternoon. A grocery store returned 6 unsold loaves. How many loaves of bread did they have left?</em></p><p><strong>LLM Response:</strong> <em>To find the number of loaves left, we need to subtract the total number of loaves sold and the number of loaves returned from the total number of loaves baked.</em></p><p><em>Total loaves baked = 200<br>Loaves sold in the morning = 93<br>Loaves sold in the afternoon = 39<br>Loaves returned = 6</em></p><p><em>Total loaves left = 200 — (93 + 39) + 6<br>Total loaves left = 200–132 + 6<br>Total loaves left = 68</em></p><p><em>Therefore, the bakers at the Beverly Hills Bakery had 68 loaves of bread left.</em></p><p>We can see even though the model is thinking step by step it made an error in addition. Lets look at a more advanced method to further improve models reasoning capability. The ideas are discussed in more detail <a href="https://arxiv.org/pdf/2305.11738">here</a> and <a href="https://evjang.com/2023/03/26/self-reflection.html">here</a>. At its core, its the idea that LLMs can critique their own responses. Lets take the example of previous query and try to generate response using Critique and Revise approach.</p><p>Here I will use <a href="https://api.python.langchain.com/en/latest/smart_llm/langchain_experimental.smart_llm.base.SmartLLMChain.html">SmartLLMChain</a> module available within the LangChain framework. SmartLLMChain generates response in 3 steps — Ideation, Critique and Resolve. Lets look at the API</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pqnDTwVcVRaaHrPFxIvr4A.png" /></figure><p>We can see we have defined separate LLM calls for each of the step. Here we are using same models but different models can also be used. Ideation and Critique should use more powerful LLMs with higher temperatures while Resolver can be a less powerful LLM with lower temperatures.</p><p>Lets run the chain. The <strong>Ideation step</strong>, since we have set n_ideas=3, it generates 3 potential solutions<br><strong><em>Idea 1:</em></strong><em><br>Sure, let’s break it down step-by-step:</em></p><ol><li><em>**Total loaves baked:** The bakers baked 200 loaves of bread on Monday morning.</em></li><li><em>2. **Loaves sold in the morning:** They sold 93 loaves.</em></li></ol><p><em>3. **Loaves sold in the afternoon:** They sold 39 loaves.</em></p><p><em>4. **Total loaves sold:** Add the loaves sold in the morning and afternoon.<br> \[<br> 93 + 39 = 132 \text{ loaves}<br> \]</em></p><p><em>5. **Loaves returned:** A grocery store returned 6 loaves. These are loaves that were previously counted as sold but need to be added back to the inventory because they were returned.</em></p><p><em>6. **Total loaves remaining:** Subtract the total loaves sold from the total baked and add back the returned loaves.<br> \[<br> 200–132 + 6 = 74 \text{ loaves}<br> \]</em></p><p><em>So, after all the transactions, the Beverly Hills Bakery had 74 loaves of bread left.<br></em><strong><em>Idea 2:</em></strong><em><br>1. **Total loaves baked**: The bakers made 200 loaves of bread.</em></p><p><em>2. **Loaves sold in the morning**: They sold 93 loaves.</em></p><p><em>3. **Loaves sold in the afternoon**: They sold an additional 39 loaves.</em></p><p><em>Adding the loaves sold in the morning and afternoon gives us:<br> \[<br> 93 (\text{morning}) + 39 (\text{afternoon}) = 132 \text{ loaves sold total}<br> \]</em></p><p><em>4. **Loaves returned by the grocery store**: A grocery store returned 6 unsold loaves.</em></p><p><em>5. **Total loaves sold or returned**: To find out the total number of loaves either sold or returned, add the number sold to the number returned:<br> \[<br> 132 (\text{total sold}) + 6 (\text{returned}) = 138 \text{ loaves}<br> \]</em></p><p><em>6. **Loaves left at the end of the day**: To find out how many loaves are left, subtract the total number of loaves sold or returned from the total baked:<br> \[<br> 200 (\text{total baked}) — 138 (\text{sold or returned}) = 62 \text{ loaves left}<br> \]</em></p><p><em>Therefore, the number of loaves left at the end of the day is **62 loaves**.<br></em><strong><em>Idea 3:</em></strong><em><br>Certainly! Let’s calculate how many loaves of bread the Beverly Hills Bakery had left at the end of the day step by step:</em></p><p><em>1. **Total loaves baked:** 200 loaves.</em></p><p><em>2. **Loaves sold in the morning:** 93 loaves.</em></p><p><em>3. **Loaves sold in the afternoon:** 39 loaves.</em></p><p><em>4. **Total loaves sold:** 93 (morning) + 39 (afternoon) = 132 loaves.</em></p><p><em>5. **Loaves returned by the grocery store:** 6 loaves.</em></p><p><em>6. **Net loaves sold (after accounting for returns):** 132 sold — 6 returned = 126 loaves.</em></p><p><em>7. **Loaves left:** We started with 200 loaves and sold (net) 126, so to find the loaves left, we subtract the net loaves sold from the total loaves baked:<br> \[<br> \text{Loaves left} = \text{Total loaves baked} — \text{Net loaves sold} = 200–126 = 74.<br> \]</em></p><p><em>Thus, the Beverly Hills Bakery had **74 loaves of bread left** at the end of the day.</em></p><p>We can see that in the 3 ideas, ideas 1 and ideas 3 have the correct solution. Now we run critique on these ideas to identify the right ideas.</p><p><strong>Critique:</strong><br><em>Certainly! Let’s analyze each response to identify potential flaws or instances of faulty logic.</em></p><p><em>### **Analysis of Idea 1:**</em></p><p><em>**Flaws:**<br>1. **Misinterpretation of Returned Loaves:** The calculation seems to assume that returned loaves should be subtracted from the total sold. In most scenarios, returned items should be added back to the inventory rather than be subtracted from sales, as they were not finalized sales.<br>2. **Miscount in Final Inventory:** Based on typical inventory logic, the store would have loaves left over by subtracting total sold (including returns) from what was baked, without subtracting returns from sales.</em></p><p><em>### **Analysis of Idea 2:**</em></p><p><em>**Flaws:**<br>1. **Incorrect Final Calculation:** The response states that 138 loaves are “accounted for” and subtracts this from the total baked to get 62 loaves left, ignoring the fact that returned loaves are added back to the available inventory, not just subtracted from total sales.<br>2. **Logic Misstep in Return Addition:** The response treats returned loaves as if still part of the “sold” classification, which could be misleading since these are effectively back in inventory for potential resale.</em></p><p><em>### **Correct Approach:**<br>To find the correct number of loaves left:<br>- Total loaves baked: 200<br>- Total loaves sold: \(93 \, \text{(morning)} + 39 \, \text{(afternoon)} = 132\)<br>- Total effective loaves after considering returns: \(132 \, \text{(sold)} + 6 \, \text{(returned)}\)<br>- Loaves left: \(200–132 = 68 \, \text{loaves left}\)</em></p><p><em>### **Analysis of Idea 3:**</em></p><p><em>**Flaws:**<br>1. **Faulty Return Subtraction:** The logic applied in subtracting the loaves that were returned from the total loaves sold is faulty, as these loaves should be added back to inventory.<br>2. **Misinterpretation of Returns Impact:** Returns have been incorrectly dealt with as a reduction in sales rather than an addition back into available stock.</em></p><p><em>### **Summary:**<br>Each response contains an error in how returns are treated. Returned goods should be added back to the stock rather than subtracted from sales totals. The correct number of loaves left should account for loaves baked minus loaves actually sold, not taking returns from sales but adding returned loaves back to the stock for a correct inventory count. The correct calculation should have been:<br>- Loaves left = Total baked — Total sold<br>- Loaves left = 200–132 = 68 loaves left</em></p><p><em>This error in handling returns and final tally calculation resulted in the incorrect number of loaves being reported as leftover in each scenario.</em></p><p>And eventually resolution which uses this criticism to arrive at the final response<br><strong>Resolution:</strong><br><em>To determine how many loaves of bread were left at the Beverly Hills Bakery after Monday’s activities, we need to consider the total number of loaves baked, the number sold, and the number returned. Here’s the correct calculation:</em></p><p><em>1. **Total Loaves Baked**: The bakery baked 200 loaves of bread on Monday morning.</em></p><p><em>2. **Loaves Sold**: Throughout the day, the bakery sold a total of 132 loaves (93 loaves in the morning plus 39 loaves in the afternoon).</em></p><p><em>3. **Loaves Returned**: A grocery store returned 6 unsold loaves. These returned loaves are added back to the bakery’s inventory since they were not sold.</em></p><p><em>4. **Loaves Remaining**: To find the remaining loaves, subtract the total loaves sold from the total loaves baked, and then add the returned loaves since they are still part of the inventory.<br> <br> \[<br> \text{Loaves Remaining} = (\text{Total Baked} — \text{Total Sold}) + \text{Returned Loaves}<br> \]<br> \[<br> \text{Loaves Remaining} = (200–132) + 6 = 74<br> \]</em></p><p><strong><em>Therefore, after accounting for the sales and returns, the Beverly Hills Bakery had 74 loaves of bread left at the end of Monday.</em></strong></p><p>An excercise for readers, try Critique and Revise to solve Prof. Lecun’s gear question (<a href="https://x.com/ylecun/status/1639690596364308482?lang=en">https://x.com/ylecun/status/1639690596364308482?lang=en</a>). Is it able to solve this problem?</p><p>This framework can also be applied to real world problems such as to reduce hallucinations in RAG applications. Added a notebook in the Github repository (<strong>notebooks/Critique_Revise_RAG.ipynb</strong>) for deep dive.</p><p>Critique and revise is a powerful technique to help LLMs reduce hallucinations and solve complex problems. This comes at a significant cost in terms of compute and latency. In the above example, we make 7 LLM calls to get the final answer. But if the comparison is between the additional LLM calls and 1 hour of human time, the choice is clear.</p><p>We will look at how Critique and Revise can be used for more advanced tasks as we look into Agents.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de401dbd007c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Question Answer Applications using LLMs: Intro to LangChain]]></title>
            <link>https://medium.com/@probabilisticthoughts/question-answer-applications-using-llms-intro-to-langchain-c0b246476292?source=rss-256ef68d5349------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0b246476292</guid>
            <category><![CDATA[qa]]></category>
            <category><![CDATA[langchain]]></category>
            <category><![CDATA[chat]]></category>
            <category><![CDATA[vector-store]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Deepak Sharma]]></dc:creator>
            <pubDate>Tue, 14 May 2024 19:51:14 GMT</pubDate>
            <atom:updated>2024-05-14T19:51:14.058Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently conducted a workshop on building QA applications using <a href="https://www.langchain.com/">LangChain</a>. The workshop was focused on working with external data sources and looking in depth at the capabilities of LangChain as a RAG developer framework.</p><p>Though evaluating LangChain was a valuable experience, I felt that a lot more needs to be explored in the library as well as in the RAG ecosystem which has developed (libraries like LLamaIndex) around this field. I decided to make the repository public and will continue to add more interesting examples, use-cases and modules. Link to the repository — <a href="https://github.com/aryabhattaslair/RAG_Evaluations">https://github.com/aryabhattaslair/RAG_Evaluations</a></p><p>I demonstrated 2 applications in the workshop</p><ul><li>Building a <a href="https://github.com/aryabhattaslair/RAG_Evaluations/blob/main/codes/Chat_QA_News_Articles.py">News QA module</a> where I used a <a href="https://www.pinecone.io/">Pinecone</a> Vector database to support the QA application. The database here was a set of news articles scraped from a news website.</li><li>Building a <a href="https://github.com/aryabhattaslair/RAG_Evaluations/blob/main/codes/PDF_QA_Local_Vector_Store.py">PDF QA module</a> where I used a <a href="https://www.trychroma.com/">Chroma</a> local vector db. The database here was a set of PDFs. A local vector DB is useful for cost-effective development as it allows testing applications with small local datasets.’</li></ul><p>There are 2 major flows in the QA module. We first generate the Search Query using the <strong>create_history_aware_retriever</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1p39-XGL9ziiwxDWgEt1aw.png" /><figcaption>LangChain Flow for Search Query Generation from User Question</figcaption></figure><p>The Search Query Generator created here is used in the second flow to generate the actual conversation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t4J9BW3bc2Da6beZ0tku3A.png" /><figcaption>Flow to generate response to user query and run Memory Aware QA</figcaption></figure><p>Overall I was impressed by the width of connectors and modules available within LangChain. It allows me to prototype applications fairly quickly. I found connectors for almost all Vector DBs I have worked with, LLM module for all major models and ingestion module for various input sources. This also helps avoid a lot of boilerplate code.</p><p>However, I also felt that LangChain library is difficult to work with especially when the use case is more complex and requires custom modifications.</p><ul><li>Class hierarchy seems inconsistent. For example, what is the difference between <em>chains </em>and <em>runnables. Runnables seem to run from chains then why are they in different hierarchy?</em></li><li>LangChain in its efforts to provide high level API for a lot of use cases have made the API very brittle. This makes integration very difficult. If I want to make any changes to the input to a chain, I may need to change the internal code of the <em>Chain.</em></li><li>Library structure keeps changing. Every time I revisit an app I wrote, I have to make significant changes to LangChain code. This may not be LangChain’s fault but they could maintain the interface same and keep changing the implementation as the vendor side changes.</li><li>Documentation appears incomplete and insufficient</li></ul><p><strong>Right now, I am recommending using LangChain to prototype and experiment but develop own library for production use case</strong>. Please note that I may not have completely understood why those design choices are made. Also the library is in aggressive development, and a lot of these issues should be resolved.</p><p>I will continue to explore this area. I am exploring new techniques such as DeepRAG, Chain of Thought prompting, using Knowledge Graphs to improve query and responses, Critique and Revise etc. I will also explore how to optimize RAG pipelines for performance and accuracy and different design choices made for different objectives.</p><p>Please stay tuned.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0b246476292" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your RAG Pipelines May be More Demo than Product]]></title>
            <link>https://medium.com/@probabilisticthoughts/your-rag-pipelines-may-be-more-demo-than-product-56e71a7ab22e?source=rss-256ef68d5349------2</link>
            <guid isPermaLink="false">https://medium.com/p/56e71a7ab22e</guid>
            <category><![CDATA[retrieval-augmented]]></category>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[search]]></category>
            <dc:creator><![CDATA[Deepak Sharma]]></dc:creator>
            <pubDate>Sat, 27 Jan 2024 11:17:35 GMT</pubDate>
            <atom:updated>2024-01-27T11:31:31.187Z</atom:updated>
            <content:encoded><![CDATA[<p>The title might sound a bit bold, and it’s essential to note that not every <strong>Retrieval Augmented Generation (RAG) pipeline</strong> is for a demo. In this post, I want to talk about the challenges of making LLM based Retrieval Augmented Generation pipelines work for <strong>enterprise use cases</strong>. I think there’s some hype around RAGs and the products like ChatBots and Document Q&amp;A that come from them. <strong>I believe the core technology might not be as mature as it’s being made out to be in current marketing.</strong></p><p>This is for those who might be skeptical about AI. Some might find what I’m saying pretty straightforward. When it comes to products, we often talk about the engineering needed for scalability, while demos usually emphasize the core ideas. In this blog, I won’t dwell too much on the platform and scaling aspects, though scaling does pose challenges for Retrieval Augmented Generators (RAGs). Dealing with issues like processing data, choosing Vector DBs, managing latency and throughput, inference on Large Language Models (LLMs), authentication, and logging is crucial for RAGs at scale. However, my main focus is on the <strong>fundamental tech</strong> necessary for the product to function effectively.</p><p>Let me elaborate on my reasons. Do note that these are only my own thoughts and experiences and it may be different from your experience. I will focus on the generation aspect and then talk about challenges with retrieval.</p><ol><li>Lets start with discussing the Generation aspect of the LLMs.</li></ol><p>LLMs can be highly unpredictable when generating answering from context. Formal discussion on my claims below can be read from this excellent survey paper on factuality (<a href="https://arxiv.org/pdf/2310.07521.pdf">link</a>). LLMs have difficulty answering from context specially if the request is more complex or the data itself is complex (fast changing, incomplete etc) . Some of the challenging scenarios which I have seen</p><ul><li>If LLMs have to combine information from its knowledge and context to answer a question. For example, if you are asking questions about changes to a recent product but you are assuming that lot of the product information LLMs should have intrinsically. LLMs can have difficulty robustly decoding responses in such scenarios.</li><li>Large Language Models (LLMs) face challenges when trying to understand quickly changing and messy information. They can easily get confused or misinterpret information that is similar but not quite the same. For instance, when dealing with rapidly changing business data (like sales information), LLMs might struggle to pick out the important details or sort through the relevant information.</li><li>Large Language Models (LLMs) might struggle with understanding complicated questions. These systems are most useful when it comes to finding and piecing together intricate and hard-to-find information. However, their performance in this regard can be shaky because they might lack proper instruction following and reasoning capabilities. For example, if users only wants to see information with specific filters LLMs may not follow it reliably.</li><li>LLMs are very susceptible to hallucinating numbers. You have to be very careful when using it to get accurate numbers.</li><li>LLMs have difficulty saying they do not know. If the context is not relevant to the query LLMs can generate very bizarre output.</li></ul><p>Some of these can be improved by fine-tuning models (look at this excellent <a href="https://arxiv.org/abs/2311.08401">paper</a>)(or pre-training) with close to real application examples and queries. But that is not an off-the-shelf solution and may be prohibitively costly. Some of the factuality issues can also be reduced by using Critique and Revise (<a href="https://arxiv.org/abs/2305.11738">https://arxiv.org/abs/2305.11738</a>) approaches like Chain of Thoughts (<a href="https://arxiv.org/abs/2201.11903">https://arxiv.org/abs/2201.11903</a>). However, these are high latency, high cost inference options and may require ML expertise to integrate with the RAG pipeline.</p><p>2. Lets look at the retrieval aspect of the RAG pipelines</p><ul><li>Creating a strong context is trickier than it seems, especially considering the diverse queries your application will encounter. Ranking enterprise data can be challenging due to a significant overlap in documents, a wide range of domain data, and various types of queries. To build an effective ranking system for your retrieval pipeline, you might need a lot of customized engineering. Additionally, for a unique and new application, establishing a good ranking system could be tough initially, especially if you face a “cold start” problem, meaning you lack sufficient data. Simple search methods like ANN or keyword search based methods like BM25 may not be enough to establish a robust context. (other interesting thoughts on this <a href="https://softwaredoug.com/blog/2024/01/24/are-we-at-peak-vector-db">here</a>).</li><li>Users can write queries with lot of fluff and irrelevant information. You may have to rewrite user query into one or more search queries for better retrieval. This may require you to generate such queries during inference using ML or search based system. You may also hit a cold start problem here.</li><li>You may require a summarization or a filtering system if you don’t have enough control on the document DB side. Search may return lot more information/data you want to consume and you may need to further trim it down. Having a good metadata on your data might help here but lot of enterprise data specifically unstructured data may not have any metadata.</li><li>A lot of information users are interested in is in tables, images, excel sheets (and variety of other proprietary format) which may be harder to combine with text based context. You may also need to write custom pipelines to ingest this data so it becomes available for vector search and for building your context. This may become tedious, expensive and error prone (specifically if this has to be done frequently).</li></ul><p>While these challenges aren’t impossible, addressing them may demand a significant amount of engineering on both the search backend and machine learning fronts to ensure the system works reliably. Additionally, there’s the challenge of establishing effective metrics and benchmarks for Retrieval Augmented Generation (RAG) pipelines, given the inherent difficulty in rating factuality and the further challenge of generalizing benchmarks across a variety of use cases.</p><p>Creating top-notch products for businesses would involve doing substantial work on both the retrieval and generation aspects of these systems. In my opinion, a more effective approach would be to build a specialized platform for specific industries or domains and customize it for each customer. Considering the valuable impact these products can have on making business processes more efficient, I see great opportunities for startups in this space.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56e71a7ab22e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Supervised Fine Tuning of LLMs for QA Applications: A few things to remember]]></title>
            <link>https://medium.com/@probabilisticthoughts/supervised-fine-tuning-of-llms-for-qa-application-a-few-things-to-remember-87fb1496bfd5?source=rss-256ef68d5349------2</link>
            <guid isPermaLink="false">https://medium.com/p/87fb1496bfd5</guid>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[supervised-fine-tuning]]></category>
            <category><![CDATA[question-answering]]></category>
            <category><![CDATA[natural-language-processi]]></category>
            <category><![CDATA[chatbots]]></category>
            <dc:creator><![CDATA[Deepak Sharma]]></dc:creator>
            <pubDate>Tue, 09 Jan 2024 09:30:42 GMT</pubDate>
            <atom:updated>2024-01-09T09:31:50.431Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are building a Chat (or QA) Application using LLMs and want to go the Supervised Fine Tuning (SFT) route to fine tune model to your application needs, here are some tips for you. These are based on my experiences and strictly my personal views so please use with caution.</p><ol><li>Can you solve it using Dynamic Prompting? (and not do SFT)</li></ol><p>Is it possible to get to the relevant performance and behavior by using zero shot or few shot prompting? You could also try to use Dynamic Prompting (DP) by using other signals available from your user. For example, for an enterprise application perhaps you have different prompts for different organizations or different verticals. I have seen amazing level of adaptability in Instruction Tuned LLMs by just using DP. A good reference paper for this — <a href="https://arxiv.org/pdf/2303.02909.pdf">https://arxiv.org/pdf/2303.02909.pdf</a>.</p><p>2. Less data is more.</p><p>Try to be conservative with data being used for SFT. Bad (or even ok) data hurts performance more than it helps. This goes back to the adaptability point that having small amount of good data is way better than having lot of data you are not clear on the quality. Invest in the quality of data being added to SFT both in employee-hours and in tooling. Make sure to run relevant quality checks on data before it gets added to your SFT mix. Usually you need examples in 100s not in 1000s for a given feature unless there is additional variability. A good reference on this — <a href="https://arxiv.org/pdf/2305.11206.pdf">https://arxiv.org/pdf/2305.11206.pdf</a>.<br>This is more difficult than it looks. A lot of times you will see interference in SFT data between features. Data you add to improve feature A starts hurting feature B. So be careful about it. I think there is art there. If you can do it well, it can become a definite competitive advantage.</p><p>3. Tune the model to use context well</p><p>Your SFT context should be as close to the inference as possible and you should provide clear examples where model should use context to answer questions or adjust behavior. A good example of it is using external knowledge base for answering questions (similar to a RAG applications). Add examples in your fine-tuning data on how the results from knowledge base added to the context are used to answer questions. Having a good mix of data representing different behavior is key here and could be the difference between an average and excellent model behavior. Definitely an art and can be a competitive advantage if done well.<br>Another interesting example of using context well is to help LLM understand the current time (or the time at which a query is made) and how to use it.</p><p>4. Distill from larger models</p><p>LLM scaling laws have shown that larger models have much better generalization, better instruction following and better reasoning but these models are costly and have high latency. A good idea is to distill from these models through fine-tuning. One potential approach is to generate the necessary fine tuning data by using a larger instruction tuned model. For example using an instruction tuned LLAMA 2 70B model to finetune LLAMA 2 7B model. Some reference on this (<a href="https://blog.research.google/2023/09/distilling-step-by-step-outperforming.html">https://blog.research.google/2023/09/distilling-step-by-step-outperforming.html</a>)</p><p>5. Use LoRA to experiment</p><p>Fine-tuning sometime requires experimentation as you are not sure how the data will result in model behavior. It can be more optimum to use LoRA for experimentation (and evaluate the model) and full fine-tuning for the final model. LoRA can save you significant money (reduced GPU memory requirement in the LoRA paper <a href="https://arxiv.org/pdf/2106.09685.pdf">https://arxiv.org/pdf/2106.09685.pdf</a> by a factor of 3<a href="https://arxiv.org/pdf/2106.09685.pdf">)</a> and fasten your experimentation velocity. Also look at other PET methods like QLoRA.<br>However, its a good idea to tune the final production ready model using the standard approach to avoid losses.</p><p>6. Invest in Evaluation and Regression Sets</p><p>If you are regularly updating your model through SFT, invest in building good evaluation and regression sets for testing your models. Getting domain experts or users to create this sets can be a bit expensive but will pay off well in the future.<br>This is before any Teamfood or Dogfood step for testing your application. SFT is a probabilistic exercise and can have unpredictable behavior. To avoid pushing a problematic model change, run auto and rated evaluations for any new model. This will also help improve experimentation velocity and help you clearly gauge progress.<br>Also, do regularly update these sets based on logs from your application.</p><p>7. Use Critique and Revise to improve data quality</p><p>I am still exploring this but methods like Chain of Thoughts prompting (<a href="https://arxiv.org/abs/2201.11903">https://arxiv.org/abs/2201.11903</a>) and self critiquing (<a href="https://arxiv.org/pdf/2206.05802.pdf">https://arxiv.org/pdf/2206.05802.pdf</a>) are showing lot of promise in identifying and correcting poor SFT data. One can get very high quality training data by combining Large Model Distillation with Critique and Revise.<br>These methods can also be used during inference to answer more difficult reasoning questions or queries where users request rewrite or further clarification.</p><p>Above is a very high level summary of some of the key areas I believe are relevant for Supervise Fine Tuning. In future, I will try to go into more details of some of these ideas and expand them. Thank you for reading through and do reach out to me on <a href="http://www.linkedin.com/in/deepaksharma09">LinkedIn</a> if you have questions, comments or need advice on SFT.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87fb1496bfd5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>