<?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:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[Helvia.ai Labs]]></title><description><![CDATA[Thoughts, stories and ideas.]]></description><link>https://helvia.ai/labs/</link><image><url>https://helvia.ai/labs/favicon.png</url><title>Helvia.ai Labs</title><link>https://helvia.ai/labs/</link></image><generator>Ghost 5.73</generator><lastBuildDate>Tue, 14 Apr 2026 20:51:06 GMT</lastBuildDate><atom:link href="https://helvia.ai/labs/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[How to evaluate RAG with GRACE using classification metrics]]></title><description><![CDATA[<p>In this blog post, we introduce <strong>GRACE</strong>, which stands for <strong><em>Grounded Retrieval-Augmented Citation Evaluation</em></strong>, a technique that helps us <strong>evaluate LLMs</strong> effectively and affordably using simple classification metrics (like accuracy), just <strong>by comparing the LLM-selected citations vs. the annotated citations</strong> of an LLM-generated answer. In order to enable GRACE and</p>]]></description><link>https://helvia.ai/labs/rag-with-citations-and-grace/</link><guid isPermaLink="false">6732196f32e5a70008466166</guid><category><![CDATA[Posts]]></category><dc:creator><![CDATA[Lefteris Loukas]]></dc:creator><pubDate>Thu, 16 Jan 2025 15:19:00 GMT</pubDate><media:content url="https://helvia.ai/labs/content/images/2024/12/RAG_Blog_post_image-1.png" medium="image"/><content:encoded><![CDATA[<img src="https://helvia.ai/labs/content/images/2024/12/RAG_Blog_post_image-1.png" alt="How to evaluate RAG with GRACE using classification metrics"><p>In this blog post, we introduce <strong>GRACE</strong>, which stands for <strong><em>Grounded Retrieval-Augmented Citation Evaluation</em></strong>, a technique that helps us <strong>evaluate LLMs</strong> effectively and affordably using simple classification metrics (like accuracy), just <strong>by comparing the LLM-selected citations vs. the annotated citations</strong> of an LLM-generated answer. In order to enable GRACE and use citations for evaluation, we need to follow a specific RAG architecture with specific Knowledge Base preprocessing, which we call Grounded RAG with Citations (Grounded RAG+C), explained later. <strong>Using GRACE, we can benchmark, evaluate, and identify the best LLM for each use case.</strong> GRACE avoids the high cost of methodologies like LLM-as-a-Judge or the limitations of older metrics like ROUGE or BLEURT, which work well only for short and simple chatbot responses.</p><h2 id="the-main-issue-how-to-evaluate-rag">The main issue: How to evaluate RAG?</h2><p><strong>Retrieval-Augmented Generation (RAG)</strong> is the go-to approach for enabling LLMs to perform Question Answering on proprietary documents, such as business knowledge bases.</p><p>While there are different<strong> business/research questions </strong>behind RAG, one is the most important:<em> <strong>Did we provide the correct answer to the user?</strong></em></p><p><strong>The key problem in typical RAG systems is the lack of standardized, robust metrics to evaluate LLM chatbot responses. </strong>One approachis to<strong> </strong>use an <strong>LLM-as-a-Judge</strong> (i.e., asking a different LLM to score responses on relevance or groundedness), and while this is promising, it is <strong>expensive to scale</strong>, especially for high-volume tasks. </p><p>Another approach is to use traditional Natural Language Generation (<strong>NLG</strong>) <strong>metrics</strong> like <strong>ROUGE</strong> or <strong>BLEURT</strong>, but these are <strong>limited</strong> <strong>too</strong>. For instance, let&apos;s say you have a user query like<em> &quot;How often can I take vacation days?&quot; </em>and the following responses:</p><ul><li>an LLM <em>generated</em> response, e.g., <em>&quot;You can take vacations as long as you have enough PTO days, but requests must be approved by your department.&quot;</em></li><li><em>and a &quot;gold&quot; response</em>, which might be a bit more lengthy, such as <em>&quot;There is no limit to how often you can take vacation days, as long as you have enough PTO (Paid Time Off) days remaining and your vacation requests are approved.&quot;</em></li></ul><p></p><p>Even when the semantic meaning of these two responses is the same, traditional metrics like BLEURT here will score poorly due to the different sentence length. Such metrics may suffice for simple yes/no queries but fail in evaluating more complex question-answering scenarios, where responses often depend on nuanced interactions and longer contexts. </p><p><strong>Wouldn&apos;t it be great to have simple and reliable evaluation metrics to measure the answers generated by an LLM,  without incurring significant costs?</strong> In this post, <u>we show exactly that, by introducing a simple trick that allows you to leverage classification metrics for evaluating RAG systems effectively, using GRACE.</u></p><h2 id="typical-rag-example">Typical RAG example</h2><p>In the <strong>standard</strong> <strong>RAG</strong> approach, raw <strong>documents</strong> from the Knowledge Base (KB) are <strong>divided</strong> into chunks, <strong>often splitting content mid-paragraph or excluding meaningful context. </strong></p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://helvia.ai/labs/content/images/2024/07/Screenshot-2024-07-12-at-10.59.51-AM.png" class="kg-image" alt="How to evaluate RAG with GRACE using classification metrics" loading="lazy" width="1152" height="274" srcset="https://helvia.ai/labs/content/images/size/w600/2024/07/Screenshot-2024-07-12-at-10.59.51-AM.png 600w, https://helvia.ai/labs/content/images/size/w1000/2024/07/Screenshot-2024-07-12-at-10.59.51-AM.png 1000w, https://helvia.ai/labs/content/images/2024/07/Screenshot-2024-07-12-at-10.59.51-AM.png 1152w" sizes="(min-width: 720px) 720px"><figcaption><i><em class="italic" style="white-space: pre-wrap;">Here&#x2019;s how classic RAG works. 1) The user query is converted into a text embedding. 2) A semantic search retrieves the top-K most relevant chunks from the embedded knowledge base using cosine similarity. 3) These chunks (the &apos;context&apos;) are concatenated with the user query and passed to the LLM as input. 4) The LLM generates an answer using the context-augmented input.</em></i></figcaption></figure><p>Consider the example user query:<em> &quot;How often can I take a vacation?&quot;.</em> Following standard RAG the retriever retrieves the top 5 chunks:</p><ul><li><strong>Chunk 1:</strong> <em>&quot;Employees can request time off as long as they have sufficient PTO balance..&quot;</em></li><li><strong>Chunk 2:</strong> <em>&quot;..Vacation requests must be approved by the employee&apos;s department..&quot;</em></li><li><strong>Chunk 3:</strong> <em>&quot;There are different types of leaves, like maternity leave..&quot;</em></li><li><strong>Chunk 4:</strong> <em>&quot;..Other types of leaves include the Sick Leave, where, according to the labor policy, you are able to ..&quot;</em></li><li><strong>Chunk 5</strong>: <em>&quot;Employees must submit vacation requests via the company portal, and HR policies must be followed..&quot;</em></li></ul><p></p><p>These chunks are concatenated and passed as <em>&quot;context&quot;</em> to the LLM along with the user query, where the <strong>LLM</strong> is asked to provide an <strong>answer</strong> based on it, finally responding with:<br><em>&quot;You can take vacations as long as you have enough PTO days, but requests must be approved by your department.&quot;</em></p><p>When we look at this single user query and the LLM&apos;s answer, it seems fine and it is indeed correct.<strong> However, there is no easy way to automate this manual response evaluation</strong>, other than perhaps utilizing the expensive LLM-as-a-Judge approach which comes with its own limitations.</p><p><strong>Also,</strong> currently, <strong>the answer lacks clear grounding in a single authoritative source. </strong>Of course, we could just instruct the LLM to also provide citations. In that case, the LLM would need to cite <u>both</u> Chunk #1 and Chunk #2, which, in practice, come from the same original document, and this could be  confusing for end-users, having to look at multiple sources.</p><h2 id="our-approach-grounded-rag-with-citations-grounded-ragc-architecture">Our approach: Grounded RAG with Citations (Grounded RAG+C) architecture </h2><p>In order to evaluate LLMs in RAG easily, we follow a custom architecture which we call <strong><em>Grounded RAG with Citations</em></strong>. Grounded RAG+C builds upon standard RAG by introducing one key improvement: the explicit use of <strong>citations</strong>, where the <strong>LLM is prompted to ground its response on a single retrieved article</strong> and <strong>include an inline citation</strong>.</p><p>This Grounded RAG+C approach enables us to evaluate the system performance based on citations (a technique we call GRACE), using classification metrics like accuracy. More specifically, with GRACE, <u>we check whether the cited article matches a predefined correct article for the query.</u> Simply put, <strong>if the correct article is cited, the LLM has likely given the correct answer. </strong>In pure accuracy terms: we count a hit if the generated answer contains the correct citation article, and we count a miss if it does not. This way GRACE <u>eliminates the need</u> for expensive evaluation methodologies like <u>LLM-as-a-Judge</u>.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://helvia.ai/labs/content/images/2024/12/Screenshot-2024-12-06-at-3.40.15-PM.png" class="kg-image" alt="How to evaluate RAG with GRACE using classification metrics" loading="lazy" width="703" height="405" srcset="https://helvia.ai/labs/content/images/size/w600/2024/12/Screenshot-2024-12-06-at-3.40.15-PM.png 600w, https://helvia.ai/labs/content/images/2024/12/Screenshot-2024-12-06-at-3.40.15-PM.png 703w"><figcaption><span style="white-space: pre-wrap;">Difference between Typical RAG and Grounded RAG+C. In typical RAG, the LLM-generated answer is a complex task since the answer is dependent on many arbitrary chunks. In Grounded RAG+C, the self-contained documents of a Knowledge Base can be cited individually from the LLM. Thus, we can evaluate if the LLM-generated answer is correct if the LLM picked the correct citation. We call this evaluation method GRACE: Grounded Retrieval-Augmented Citation EValuation.</span></figcaption></figure><p><strong>The cornerstone of GRACE is the way the Knowledge Base (KB) is organized in the Grounded RAG+C approach</strong>. Instead of arbitrary chunks, we split the KB into <strong>self-contained articles</strong>. A self-contained article is structured so that it provides <u>complete information on a topic (i.e., the article is &quot;grounded&quot;),</u> allowing the LLM to answer user questions without <em>citing</em> or needing to rely on additional articles. </p><p>Let&#x2019;s consider the previous example of a user asking about their vacation days. The user query is <em>&quot;How often can I take a vacation?&quot;</em> Following Grounded RAG+C the retriever retrieves the top 3 relevant <em>self-contained</em> articles (instead of arbitrary chunks):</p><ul><li><strong>ID 17:</strong> <em>D. Employee Benefits - 1. Vacation Benefits (PTO) </em><ul><li>(this self-contained article includes previous chunks #1, #2, and others)</li></ul></li><li><strong>ID 20:</strong><em> D. Employee Benefits - 4. Other Types of Leave (Maternity, etc.)</em><ul><li>(this self-contained article includes previous chunks #3, #4, and others)</li></ul></li><li><strong>ID 66:</strong> <em>H. FAQ - 2. Platform Requests to HR</em><ul><li>(this self-contained article includes previous chunks #5 and others)</li></ul></li></ul><p></p><p>Then, the LLM is prompted and selects <strong>ID 17</strong> as the most relevant article, generating the response based on this self-contained article:<br><em>&quot;There is no limit to how often you can take a vacation as long as you still have PTO days left. Vacation days must be approved by the department. <strong>[ID: 17]</strong>&quot;</em></p><p><u>By grounding responses in a single cited source</u>, Grounded RAG+C enables the straightforward evaluation of GenAI chatbot outputs. Essentially, the <strong>design of Grounded RAG+C converts the complex evaluation problem</strong> to a <strong>multi-class classification task of comparing citations (GRACE), where we can use simple and explainable metrics like accuracy, etc.</strong> In the Grounded RAG+C architecture, all we need to do is:</p><ol><li>Split the Knowledge Base into self-contained articles to be embedded in the vector database instead of smaller chunks (more on that later)</li><li>Instruct the LLM to select exactly one article and report it in the generated response</li></ol><p></p><p>If these two things are done, then, using classic regular expressions or a structured JSON output, we can extract the citation ID that the LLM selected to base it&apos;s response on. Then <strong>we can measure a &quot;correct&quot; answer simply by verifying whether the LLM cited the article <u>[ID: 17]</u> in its response or not (GRACE)</strong>.<strong> </strong><u>If the LLM returned some other cited article, then we automatically know that the answer should be classified as &quot;wrong&quot;</u>, since that other article does not contain relevant information to that user query. <u>This is due to our self-contained design in the Knowledge Base.</u> In typical chunking strategies, this is not possible, since the answer is split to many chunks and you do not have that &quot;user query to correct article&quot; alignment.</p><h3 id="but-wait-what-if-the-llm-indeed-selects-and-cites-the-correct-self-contained-article-but-hallucinates-in-its-answer-can-that-happen">But, wait... what if the LLM indeed selects and cites the correct self-contained article, but hallucinates in its answer? Can that happen?</h3><p>Theoretically, yes. However, when using a leading model such as OpenAI&apos;s GPT-4o, you &quot;ground&quot; the model on a self-contained business document inside the instruction prompt using RAG, and, practically, hallucinations do not happen. To validate this, we even ran additional experiments including some smaller, weaker LLMs. After checking the results manually, they verify our intuition: <u>if the LLM selects the correct self-contained article in Grounded RAG+C, then the LLM also provides a correct answer to the user query.</u></p><h2 id="design-and-preparation-of-a-knowledge-base-kb-with-self-contained-articles"><strong>Design and Preparation of a Knowledge Base (KB) with self-contained articles</strong></h2><p>As noted previously, for GRACE to work, the knowledge base should be optimized in a certain way. This starts with <u>splitting raw company documents into grounded, self-contained articles</u> that can be embedded in a vector database. Without this crucial step, the system cannot reliably ground responses or support metrics like accuracy. <u>This is the core element that enables our evaluation technique, GRACE, to work</u>. </p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://helvia.ai/labs/content/images/2024/11/example_of_self_contained_KB_cropped.png" class="kg-image" alt="How to evaluate RAG with GRACE using classification metrics" loading="lazy" width="695" height="374" srcset="https://helvia.ai/labs/content/images/size/w600/2024/11/example_of_self_contained_KB_cropped.png 600w, https://helvia.ai/labs/content/images/2024/11/example_of_self_contained_KB_cropped.png 695w"><figcaption><i><em class="italic" style="white-space: pre-wrap;">Here is how our internal HR Knowledge Base looks like after preprocessing it. For all topics like Organization Description or Work Conditions &amp; Hours (left side), there are self-contained articles (right side). These articles are the ones used in the retrieval phase of the Grounded RAG+C &quot;architecture&quot;, which helps us evaluate LLMs using citations (GRACE). Since most knowledge bases come in a single .pdf or .doc file, we have built automatic tools to preprocess such documents into a KB with self-contained articles, like the one here.</em></i></figcaption></figure><p><strong>We believe that splitting/chunking complex documents into self-contained articles allows the system to work better</strong>, i.e., have better retrieval and response generation. This is an ongoing research direction currently. For instance, check JinaAI&apos;s benchmarks on &quot;Finding Optimal Breakpoints In Long Documents&quot; at <a href="https://jina.ai/news/finding-optimal-breakpoints-in-long-documents-using-small-language-models?ref=helvia.ai">https://jina.ai/news/finding-optimal-breakpoints-in-long-documents-using-small-language-models</a>.</p><p>Of course, splitting the documents into self-contained articles will take more time than just chunking at an arbitrary multi-sentence boundary. To address that, we collaborate closely with our customers and have developed automated, human-in-the-loop tools to streamline the process.</p><h2 id="using-grace-to-get-results-in-a-real-world-grounded-ragc-dataset">Using GRACE to get results in a real-world Grounded RAG+C dataset </h2><p>By utilizing the Grounded RAG+C architecture (i.e., splitting the documents to grounded and self-contained articles about one topic), we can use GRACE to compare predicted vs. annotated citations. Having that done, we can now calculate, in scale, and at very low cost, how good an LLM is at providing answers to the user queries. All we need to do is have a mapping (annotation) of the user query to the self-contained article containing this information for our test set. <strong>If the LLM picks the correct article, then it knows how to ground its response there and responds correctly.</strong> We can then measure the accuracy of the LLM.</p><p>At Helvia, we built our own real-world benchmarks in order to assess the performance of LLMs. Here is an example of how different LLMs score in our interal HR support chatbot, which operates in our own HR documents (as seen in the previous section). For the test set, we have manually compiled<strong> over ~700 hard-difficulty real-world user queries</strong> <strong>and linked them with the &quot;correct self-contained article&quot; they should be matched with.</strong> In this example, in the retrieval, we use OpenAI&apos;s <em>text-embedding-3-large</em> model with <em>1024</em> dimensions and we use the top 3 self-contained articles returned each time as context to our RAG+C system.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://helvia.ai/labs/content/images/2025/03/Screenshot-2025-03-26-at-11.35.57-AM.png" class="kg-image" alt="How to evaluate RAG with GRACE using classification metrics" loading="lazy" width="1500" height="618" srcset="https://helvia.ai/labs/content/images/size/w600/2025/03/Screenshot-2025-03-26-at-11.35.57-AM.png 600w, https://helvia.ai/labs/content/images/size/w1000/2025/03/Screenshot-2025-03-26-at-11.35.57-AM.png 1000w, https://helvia.ai/labs/content/images/2025/03/Screenshot-2025-03-26-at-11.35.57-AM.png 1500w" sizes="(min-width: 720px) 720px"><figcaption><i><em class="italic" style="white-space: pre-wrap;">Grounded RAG with Citations enables us to measure the accuracy of LLMs in our GenAI chatbots using citations (GRACE), instead of using expensive methodologies like LLM-as-a-Judge. As one would expect, OpenAI&apos;s most expensive model engine (GPT-4, GPT-o1) are top in performance, while interestingly, Google&apos;s small model, Gemini 1.5 Flash is also really competitive. On the other side, smaller models like Llama 3.1-8b and Mistral-7b fail to identify correctly the citation articles that contain the answers for most user queries.</em></i><span style="white-space: pre-wrap;"> See the complete leaderboard with more experiments at </span><a href="https://helvia.ai/labs/grace-leaderboard/"><span style="white-space: pre-wrap;">https://helvia.ai/labs/grace-leaderboard/</span></a><span style="white-space: pre-wrap;">.</span></figcaption></figure><h2 id="bonus-more-reasons-to-do-grounded-ragc">Bonus: More reasons to do Grounded RAG+C</h2><p>Using Grounded RAG with Citations has additional advantages, other than evaluating the citations:</p><ol><li>&#x1F310;<strong> Streamlining Action Workflows: </strong>With citations included in the responses, we can automate various actions through APIs. For instance, if a user receives an answer related to a citation article about &quot;Support Issues&quot;, we can automatically send a tailored email to follow up on that.</li><li>&#x1F91D;<strong> User Transparency: </strong>If you asked ChatGPT for something <u>crucial</u>, would you trust it if you couldn&apos;t verify it?<strong> </strong>Providing citations allows users to cross-check answers.</li><li>&#x2705; <strong>No more LLM hallucinations: </strong>The LLM is <em>explicitly prompted</em> to answer with <u>citation-grounded responses.</u> If it can&apos;t find relevant and concrete information inside an article, it will be conservative and it will not respond to, thus, decreasing hallucinations. </li></ol><h2 id="takeaways">Takeaways</h2><ul><li>&#x1F680; We created <strong>GRACE</strong>, which stands for <em>Grounded Retrieval-Augmented Citation Evaluation. </em>GRACE helps us <strong>evaluate LLM performance in GenAI RAG-based chatbots by comparing predicted vs. annotated citations in LLM-generated answers.</strong></li><li>&#x1F50D; In order to evaluate RAG with GRACE, you need to do two certain things: a) <u>optimize your Knowledge Base to have self-contained articles</u> that can be used to answer user questions of one specific topic, and, <u>second, instructing the LLM explicitly to pick the one single best article (and its citation) to answer the user question.</u> This chatbot design builds upon typical RAG and we call it &quot;Grounded RAG with Citations&quot; (Grounded RAG+C), since we &quot;ground&quot; the LLMs to use self-contained documents and their citations.</li><li>&#x1F4A1;GRACE works like this: <strong>If the LLM selects and cites the correct article, then the provided answer is likely (automatically!) correct.</strong> <u>GRACE</u> (and the Grounded RAG+C chatbot design) <u>enable low-cost, accurate LLM performance measurement</u> without expensive methods like LLM-as-a-Judge or outdated methods like BLEURT. As a downside, though, it needs annotations beforehand, which could be skipped in LLM-as-a-Judge.</li><li>&#x1F4CA; We use this strategy since it allows us to perform <u>easy comparison of different LLM models</u> using straightforward metrics like accuracy. In our real-world HR dataset, we found leading proprietary models like <u>GPT-4 and Google&apos;s Gemini Flash to have the best accuracy.</u> However, <u>smaller open-weight models like Mistral-7b and Llama-3.1-8b instruct had the worst performance, failing to answer around 50% of the user questions.</u></li><li>&#x1F52C; See more experiments at our GRACE leaderboard: <a href="https://helvia.ai/labs/grace-leaderboard/">https://helvia.ai/labs/grace-leaderboard/</a></li></ul><p></p><p>In the next blogpost of this series, we are going to dive deeper into more findings from our own benchmarks, along with some more GRACE metrics we designed, which allow us to understand the chatbot&apos;s answer from different point-of-views.</p>]]></content:encoded></item><item><title><![CDATA[GR-NLP-TOOLKIT: An Open-Source NLP Toolkit for Modern Greek]]></title><description><![CDATA[https://arxiv.org/pdf/2412.08520]]></description><link>https://helvia.ai/labs/gr-nlp-toolkit-an-open-source-nlp-toolkit-for-modern-greek/</link><guid isPermaLink="false">678924b2c0d4bf0008c63fe5</guid><category><![CDATA[publication_pdf]]></category><dc:creator><![CDATA[Lefteris Loukas]]></dc:creator><pubDate>Thu, 16 Jan 2025 12:56:00 GMT</pubDate><media:content url="https://helvia.ai/labs/content/images/2025/01/gr_nlp_toolkit.png" medium="image"/><content:encoded><![CDATA[<img src="https://helvia.ai/labs/content/images/2025/01/gr_nlp_toolkit.png" alt="GR-NLP-TOOLKIT: An Open-Source NLP Toolkit for Modern Greek"><p>@ COLING 2025</p>]]></content:encoded></item><item><title><![CDATA[Still all Greeklish to me: Greeklish to Greek Transliteration]]></title><description><![CDATA[https://aclanthology.org/2024.lrec-main.1330.pdf]]></description><link>https://helvia.ai/labs/still-all-greeklish-to-me-greeklish-to-greek-transliteration/</link><guid isPermaLink="false">67892413c0d4bf0008c63fd5</guid><category><![CDATA[publication_pdf]]></category><dc:creator><![CDATA[Stavros Vassos]]></dc:creator><pubDate>Mon, 20 May 2024 15:23:00 GMT</pubDate><media:content url="https://helvia.ai/labs/content/images/2025/01/still_all_greeklisth_to_me.png" medium="image"/><content:encoded><![CDATA[<img src="https://helvia.ai/labs/content/images/2025/01/still_all_greeklisth_to_me.png" alt="Still all Greeklish to me: Greeklish to Greek Transliteration"><p>@ LREC-COLING 2024</p>]]></content:encoded></item><item><title><![CDATA[Cache me if you Can: an Online Cost-aware Teacher-Student Framework to Reduce the Calls to Large Language Models (EMNLP 2023)]]></title><description><![CDATA[We propose a framework for reducing calls to LLMs by caching previous LLM responses and using them to train a local inexpensive model. We measure the tradeoff between performance and cost. Experimental results show that significant cost savings can be obtained with only slightly lower performance.]]></description><link>https://helvia.ai/labs/cache-me-if-you-can-an-online-cost-aware-teacher-student-framework-to-reduce-the-calls-to-large-language-models/</link><guid isPermaLink="false">654e04bdcb95db0008ec1920</guid><category><![CDATA[Posts]]></category><dc:creator><![CDATA[Ilias Stogiannidis]]></dc:creator><pubDate>Mon, 19 Feb 2024 10:27:00 GMT</pubDate><media:content url="https://helvia.ai/labs/content/images/2024/01/EMNLP_2023_Wide.png" medium="image"/><content:encoded><![CDATA[<img src="https://helvia.ai/labs/content/images/2024/01/EMNLP_2023_Wide.png" alt="Cache me if you Can: an Online Cost-aware Teacher-Student Framework to Reduce the Calls to Large Language Models (EMNLP 2023)"><p><em>Ilias Stogiannidis, Stavros Vassos, Prodromos Malakasiotis, Ion Androutsopoulos</em></p>

<!--kg-card-begin: html-->
<div class="myBTNdiv" style="text-align: center;">
<a href="https://aclanthology.org/2023.findings-emnlp.1000/?ref=helvia.ai" class="myButton">Paper</a>
  
<a href="https://github.com/stoyian/OCaTS?ref=helvia.ai" class="myButton">Code</a>
</div>
<!--kg-card-end: html-->
<h2 id="abstract">Abstract</h2>
<p>Prompting Large Language Models (LLMs) performs impressively in zero- and few-shot settings. Hence, small and medium-sized enterprises (SMEs) that cannot afford the cost of creating large task-specific training datasets, but also the cost of pretraining their own LLMs, are increasingly turning to third-party services that allow them to prompt LLMs. However, such services currently require a payment per call, which becomes a significant operating expense (OpEx). Furthermore, customer inputs are often very similar over time, hence SMEs end-up prompting LLMs with very similar instances. We propose a framework that allows reducing the calls to LLMs by caching previous LLM responses and using them to train a local inexpensive model on the SME side. The framework includes criteria for deciding when to trust the local model or call the LLM, and a methodology to tune the criteria and measure the tradeoff between performance and cost. For experimental purposes, we instantiate our framework with two LLMs, GPT-3.5 or GPT-4, and two inexpensive students, a k-NN classifier or a Multi-Layer Perceptron, using two common business tasks, intent recognition and sentiment analysis. Experimental results indicate that significant OpEx savings can be obtained with only slightly lower performance.</p>
<h2 id="architecture">Architecture</h2>
<figure>
    <img src="https://helvia.ai/labs/content/images/2023/11/architecture_new-1-1.png" alt="Cache me if you Can: an Online Cost-aware Teacher-Student Framework to Reduce the Calls to Large Language Models (EMNLP 2023)">
    <figcaption>
        <p>This is the OCaTS architecture. The incoming customer query is first processed by the student model. If some criteria are met, we provide the student&apos;s output to the customer. If not we prompt the teacher to respond. The teacher&apos;s output then is cached alongside the query, and they are used to periodically retrain the student. </p>
    </figcaption>
</figure>
<h2 id="framework">Framework</h2>
<p>We present <em>OCaTS</em> (Online Cost-aware Teacher Student Framework), a framework designed to train a local inexpensive model (student) using the responses of a more expensive model (teacher) in an online setting. Our approach is inspired by the teacher-student schema, but with the additional consideration of the cost associated with utilizing the teacher. This makes OCaTS a suitable solution for small and medium enterprises that want to leverage powerful and easily accessible Large Language Models via API, while minimizing operational expenses (OpEx). OCaTS consists of three main components: a <em>teacher</em>, which is typically a resource-intensive model that produces high-quality results; a <em>student</em>, which is a cost-effective model that is much smaller and simpler than the teacher; and a <em>cache</em>, which is a repository of incoming queries that have already been processed by the teacher.</p>
<h2 id="cost-awareness">Cost-awareness</h2>
<p>To integrate the cost aspect into the framework, we introduce a novel evaluation measure for such settings, called <em>discounted metric</em>. This metric, denoted as $\hat{\phi}$, aims to capture the trade-off between performance and cost. It is computed using the following equation: $$\hat{\phi} = \phi - \lambda \cdot \rho = \phi - \lambda \cdot \frac{M}{N}.$$<br>
In this equation, $\phi$ represents a conventional evaluation metric such as accuracy. Parameter $\lambda$ is a weighting factor that determines the importance of cost (higher values indicate that cost is considered more significant for the SME). The variables $M$ and $N$ correspond to the total number of calls made to the teacher model and the total number of queries handled, respectively. The discounted metric penalizes the overall performance of the framework based on the rate of calls made to the teacher model and the associated cost for the company. Intuitively, by making this metric the objective of the framework, it learns to maximize performance by allowing the student to respond only when confident enough and prompt the teacher for their response otherwise.</p>
<h2 id="choosing-between-student-teacher">Choosing between Student &amp; Teacher</h2>
<p>We focus on applying the framework on a text classification problem. In order to determine whether to rely on the student&apos;s response or prompt the teacher to respond, the framework incorporates two criteria inspired by Active Learning. If both criteria meet a certain threshold, the student&apos;s response is trusted; otherwise, the query is delegated to the teacher for handling.<br>
<br> The <strong>first criterion</strong> is to ensure the representativeness of the cached queries considered by the teacher. This is achieved by determining the similarity between the new query and the $k$ most similar cached queries. Let the <em>weighted centroid vector</em> $c$ of the $k$ nearest neighbors be $c = \sum_{i=1}^{k}\hat{w}_i \cdot v_i$ and $\hat{w}_i = w_i/\sum_{j=1}^{k} w_j$, where $w_i$ represents the weight assigned by a distance weighting algorithm to the $i$-th neighbor, and $v_i$ corresponds to the vector representation of the neighbor. The first criterion states that $c$ must be below a threshold $t_c$. Essentially, this condition ensures that the student has previous experience with similar cached queries.<br>
<br> The <strong>second criterion</strong> is to ensure the confidence of the cached queries considered by the teacher. To establish the second condition let $C$ represent the set of labels (classes) of the text classification problem. The probability $p_c$ for each $c \in C$ is defined as follows: $$p_c = \frac{\exp(W_c)}{\sum_{c&apos; \in C} \exp(W_{c&apos;})},$$ where $W_c$ can be the weight assigned by the $k$-NN algorithm or the logits of an MLP. The <em>entropy</em> $\mathcal{H}$ of the label probabilities $p_c$ is given by: $$\mathcal{H} = -\sum_{c \in C} p_c \log{p_c}.$$ The second criterion states that $\mathcal{H}$ must be below a threshold $t_\mathcal{H}$. Essentially, this condition ensures that the student is confident about the its response.</p>
<h2 id="results">Results</h2>
<p>We evaluate the framework in an intent recognition task for four indicative $\lambda$ values, which determines the importance of cost in the discounted metric $\hat{\phi}$ we introduced. We utilize the <a href="https://huggingface.co/datasets/banking77?ref=helvia.ai">Banking77 dataset</a>, a basic k-NN student, and GPT-4 as the teacher. As depicted in the figure below, OCaTS effectively manages the tradeoff between the frequency of contacting the teacher and the level of accuracy. Specifically:</p>
<ul>
<li><strong>Left part: Calls to the Teacher</strong>
<ul>
<li>Using OCaTS significantly reduces the calls to the teacher; hence, OpEx.</li>
<li>As $\lambda$ increases, the number of calls made to the teacher decreases.</li>
</ul>
</li>
<li><strong>Middle part: Trade-off between accuracy &amp; OpEx</strong>
<ul>
<li>At $\lambda=0.05$, OCaTS achieves accuracy close to GPT-4 teacher (83.05% vs. 82.68%) with only one-third of teacher calls (1050 out of 3080).</li>
<li>Increasing $\lambda$ leads to a decrease in accuracy but a smaller number of teacher calls.</li>
</ul>
</li>
<li><strong>Right part: Discounted Accuracy ($\hat\phi$) Comparison:</strong>
<ul>
<li>Right side of the figure compares discounted accuracy ($\hat\phi$) of OCaTS (solid lines) with always contacting GPT-4 teacher (dashed lines).</li>
<li>OCaTS consistently surpasses GPT-4 teacher&apos;s accuracy, emphasizing OpEx efficiency.</li>
</ul>
</li>
<li><strong>Conclusion on OCaTS Superiority:</strong>
<ul>
<li>OCaTS is superior in terms of OpEx compared to constantly reaching out to the teacher.</li>
<li>The difference favoring OCaTS becomes more pronounced as $\lambda$ increases, indicating a stronger focus on reducing OpEx.</li>
</ul>
</li>
</ul>
<figure>
    <img src="https://helvia.ai/labs/content/images/2023/11/knn-banking-1.png" alt="Cache me if you Can: an Online Cost-aware Teacher-Student Framework to Reduce the Calls to Large Language Models (EMNLP 2023)">
    <figcaption>
        <p>Number of calls to the teacher (left), accuracy (middle), discounted accuracy (right), using a GPT-4 teacher and a k-NN student, for various &#x3BB; values, on Banking77 data. The larger the &#x3BB; the more the SME prefers fewer calls at the expense of increased customer frustration. Dashed lines show the discounted accuracy when calling GPT-4 for all incoming queries. OCaTS has a better discounted accuracy than always calling the GPT-4 teacher.</p>
    </figcaption>
</figure>
<h2 id="takeaways">Takeaways</h2>
<p>This study is, to the best of our knowledge, the first study to optimize API requests to commercial LLMs according to a cost-aware metric. Some takeaways:</p>
<ul>
<li>We introduce a framework for decreasing API requests to commercial LLMs like OpenAI&apos;s GPT-4 while maintaining performance standards, by caching responses.</li>
<li>We introduce a discounted metric that measures the trade-off between performance and cost.</li>
<li>We employ a smaller and efficient student model to respond to queries similar to the ones previously handled by the teacher LLM.</li>
<li>In our experiments we match the performance of OpenAI GPT-4, scoring  only 0.37 percentage points less than GPT-4, while at the same time effectively cutting down the API costs by calling the LLM teacher for only one-third of the incoming queries (1050 out of 3080).</li>
</ul>
<h2 id="bibtex">Bibtex</h2>
<pre><code>@inproceedings{stogiannidis-etal-2023-cache,
    title = &quot;Cache me if you Can: an Online Cost-aware Teacher-Student framework to Reduce the Calls to Large Language Models&quot;,
    author = &quot;Stogiannidis, Ilias  and
      Vassos, Stavros  and
      Malakasiotis, Prodromos  and
      Androutsopoulos, Ion&quot;,
    editor = &quot;Bouamor, Houda  and
      Pino, Juan  and
      Bali, Kalika&quot;,
    booktitle = &quot;Findings of the Association for Computational Linguistics: EMNLP 2023&quot;,
    month = dec,
    year = &quot;2023&quot;,
    address = &quot;Singapore&quot;,
    publisher = &quot;Association for Computational Linguistics&quot;,
    url = &quot;https://aclanthology.org/2023.findings-emnlp.1000&quot;,
    pages = &quot;14999--15008&quot;
}
</code></pre>
<h2 id="acknoweledgements">Acknoweledgements</h2>
<p>This work was supported by Google&#x2019;s <a href="https://sites.research.google/trc/about/?ref=helvia.ai">TPU Research Cloud (TRC)</a> and was carried out in collaboration with <a href="https://nlp.cs.aueb.gr/?ref=helvia.ai">AUEB&apos;s NLP Group</a>.</p>
]]></content:encoded></item><item><title><![CDATA[Making LLMs Worth Every Penny: Resource-Limited Text Classification in Banking (ACM ICAIF 2023)]]></title><description><![CDATA[Standard Full-Data classifiers in NLP demand thousands of labeled examples, which is impractical in data-limited domains. Few-shot methods offer an alternative, utilizing contrastive learning techniques that can be effective with as little as 20 examples per class.]]></description><link>https://helvia.ai/labs/making-llms-worth-every-penny-resource-limited-text-classification-in-banking/</link><guid isPermaLink="false">656f38c348ed79000869e569</guid><category><![CDATA[Posts]]></category><dc:creator><![CDATA[Lefteris Loukas]]></dc:creator><pubDate>Thu, 07 Dec 2023 08:13:08 GMT</pubDate><media:content url="https://helvia.ai/labs/content/images/2023/12/LLM_Cost_Reduction_003.png" medium="image"/><content:encoded><![CDATA[<img src="https://helvia.ai/labs/content/images/2023/12/LLM_Cost_Reduction_003.png" alt="Making LLMs Worth Every Penny: Resource-Limited Text Classification in Banking (ACM ICAIF 2023)"><p><em>Lefteris Loukas, Ilias Stogiannidis, Odysseas Diamantopoulos, Prodromos Malakasiotis, Stavros Vassos</em></p>
<p>Read the full paper here: <a href="http://arxiv.org/abs/2311.06102?ref=helvia.ai">https://arxiv.org/abs/2311.06102</a></p>
<h2 id="abstract">Abstract</h2>
<p>Standard Full-Data classifiers in NLP demand thousands of labeled examples, which is impractical in data-limited domains. Few-shot methods offer an alternative, utilizing contrastive learning techniques that can be effective with as little as 20 examples per class. Similarly, Large Language Models (LLMs) like GPT-4 can perform effectively with just 1-5 examples per class. However, the performance-cost trade-offs of these methods remain underexplored, a critical concern for budget-limited organizations. Our work addresses this gap by studying the aforementioned approaches over the Banking77 financial intent detection dataset, including the evaluation of cutting-edge LLMs by OpenAI, Cohere, and Anthropic in a comprehensive set of few-shot scenarios. We complete the picture with two additional methods: first, a cost-effective querying method for LLMs based on retrieval-augmented generation (RAG), able to reduce operational costs multiple times compared to classic few-shot approaches, and second, a data augmentation method using GPT-4, able to improve performance in data-limited scenarios. Finally, to inspire future research, we provide a human expert&#x2019;s curated subset of Banking77, along with extensive error analysis.</p>
<h2 id="motivation">Motivation</h2>
<figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://helvia.ai/labs/content/images/2023/12/blogpost_motivation.png" class="kg-image" alt="Making LLMs Worth Every Penny: Resource-Limited Text Classification in Banking (ACM ICAIF 2023)" loading="lazy" width="860" height="631" srcset="https://helvia.ai/labs/content/images/size/w600/2023/12/blogpost_motivation.png 600w, https://helvia.ai/labs/content/images/2023/12/blogpost_motivation.png 860w" sizes="(min-width: 720px) 720px"><figcaption><span style="white-space: pre-wrap;">We study how we can approach text classification effectively in terms of both performance and cost. We use the Banking77 dataset (</span><a href="https://huggingface.co/datasets/PolyAI/banking77?ref=helvia.ai"><span style="white-space: pre-wrap;">https://huggingface.co/datasets/PolyAI/banking77</span></a><span style="white-space: pre-wrap;">), composed of customer support dialogs and their labels. We mainly study Few-shot Settings, where we have limited samples per class (resource-limited scenario), typically 1 to 20 samples per class. For the sake of completeness, we also present some results in the Full-Data Setting, where one can fine-tune models on thousands of samples (which is often impractical).</span></figcaption></figure><p>To the best of our knowledge, this is the first study on the performance-cost investigation of LLMs versus MLMs. Many companies tend to use the most modern models like proprietary LLMs (OpenAI GPT-4), which come at a pretty heavy cost without comparing their performance with cheaper, older models that might perform equally.</p>
<p>After benchmarking the performance-cost tradeoffs of LLMs and MLMs in <strong>Banking77</strong> (a real-life conversational dataset of a bank&apos;s customer support with 77 labels), we introduce a <strong>cost-effective LLM inference method</strong> based on active learning, similar to how <strong>RAG (Retrieval-Augmented Generation)</strong> is performed nowadays in question-answering chatbots. This is able to reduce LLM costs more than 3 times in real-life business settings. Then, we follow with an extra study showing <strong>how much synthetic data can one generate</strong> in such resource-limited scenarios.</p>
<h2 id="methodology-outline">Methodology Outline</h2>
<p>We tackle text classification in Few-Shot Settings (where we have limited samples per class) in 2 ways:</p>
<ul>
<li><strong>Contrastive Learning (SetFit)</strong> with Masked Language Models <strong>(MLMs)</strong></li>
<li><strong>In-Context Learning (Prompting)</strong> with Large Language Models <strong>(LLMs)</strong></li>
</ul>
<figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://helvia.ai/labs/content/images/2023/12/blogpost_setfit.png" class="kg-image" alt="Making LLMs Worth Every Penny: Resource-Limited Text Classification in Banking (ACM ICAIF 2023)" loading="lazy" width="971" height="218" srcset="https://helvia.ai/labs/content/images/size/w600/2023/12/blogpost_setfit.png 600w, https://helvia.ai/labs/content/images/2023/12/blogpost_setfit.png 971w" sizes="(min-width: 720px) 720px"><figcaption><span style="white-space: pre-wrap;">An overview of Contrastive Learning (SetFit), as used in MLMs. Setfit was first introduced by HuggingFace (Tunstall et al., 2022). It utilizes Sentence Transformers (like MPNet) in a Siamese + Supervised Fine-Tuning Manner by having an objective function to minimize the distance between samples of the same labels. The result is that it produces rich vector representations, even when providing only 10 to 20 samples per class for your text classification problem.</span></figcaption></figure><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://helvia.ai/labs/content/images/2023/12/blogpost_icl.png" class="kg-image" alt="Making LLMs Worth Every Penny: Resource-Limited Text Classification in Banking (ACM ICAIF 2023)" loading="lazy" width="833" height="400" srcset="https://helvia.ai/labs/content/images/size/w600/2023/12/blogpost_icl.png 600w, https://helvia.ai/labs/content/images/2023/12/blogpost_icl.png 833w" sizes="(min-width: 720px) 720px"><figcaption><span style="white-space: pre-wrap;">An overview of In-Context Learning, as used in LLMs.We leverage the pre-trained knowledge of LLMs and extend it with our specific task instructions and a few examples per class. This is done for each inference sample. We use a variety of proprietary LLMs, like OpenAI GPT-3.5 and GPT-4, Anthropic Claude 2, and Cohere&apos;s Command-Nightly.</span></figcaption></figure><h2 id="results-1">Results (#1)</h2>
<p>We then employ SetFit methodology on the MPNet-v2 model, a state-of-the-art sentence transformer based on BERT, according to <a href="https://sbert.net/?ref=helvia.ai">https://sbert.net/</a>.<br>
We also utilize In-Context Learning for multiple proprietary LLMs like OpenAI GPT-3.5, GPT-4, Anthropic Claude 1 &amp; 2, and, Cohere&apos;s Command-nightly.</p>
<p>For the MPNet models (and the SetFit technique), we use different settings of 3/5/10/15/20 samples per class, as SetFit typically requires around 10-20 samples to work well.</p>
<p>For the LLMs, we use 1 and 3 samples per class, due to context length limitations (OpenAI had 4K context length limitations at the time of the development). Also, for the LLMs, we use both random samples from the dataset and &quot;representative&quot; samples, as selected by a domain expert. The intuition here is that representative samples will outperform randomly sampled ones and we believe that it is feasible for a company to pick 3 &quot;good&quot; samples for each class in a dataset.</p>
<figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://helvia.ai/labs/content/images/2023/12/blogpost_results.png" class="kg-image" alt="Making LLMs Worth Every Penny: Resource-Limited Text Classification in Banking (ACM ICAIF 2023)" loading="lazy" width="577" height="677"><figcaption><span style="white-space: pre-wrap;">First, let&apos;s focus on LLMs. GPT-4 performs the best across 1-shot settings, outperforming competitors like Anthropic Claude and Cohere&apos;s Command-nightly. In the 3-shot setting, GPT-4 also works the best. Surprisingly, GPT-3.5&apos;s performance in the 3-shot setting drops, compared to the 1-shot setting, probably due to GPT-3.5 getting &quot;Lost In The Middle&quot; (</span><a href="https://arxiv.org/abs/2307.03172?ref=helvia.ai"><span style="white-space: pre-wrap;">https://arxiv.org/abs/2307.03172</span></a><span style="white-space: pre-wrap;">) when having a bigger context. As expected, the representative samples work better than random samples in all of our ablation experiments (using OpenAI models). On the other side of MLMs, MPNet might start with a low of 57.4 in the 1-shot setting (vs GPT-4&apos;s 80.4) but has a comparable 76.7 in the 3-shot setting (vs GPT-4&apos;s 83.1). After providing more samples to the MLM, something which is impossible to the LLMs (due to maximum 4K context capacity), the MPNet models reach a top 91.2 micro-F1 Score, which is 3 points lower than fine-tuning in the typical Full Data Setting with hundreds/thousands of samples per class (94.1)</span></figcaption></figure><h2 id="cost-analysis">Cost Analysis</h2>
<p>Proprietary LLMs might work well but they cost a lot, due to hefty costs in their API usage per token. Thus, apart from their performance, we analyze their costs. This is the first time that this industrial point-of-view (performance/cost tradeoff) is reported.</p>
<figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://helvia.ai/labs/content/images/2023/12/blogpost_costs.png" class="kg-image" alt="Making LLMs Worth Every Penny: Resource-Limited Text Classification in Banking (ACM ICAIF 2023)" loading="lazy" width="678" height="271" srcset="https://helvia.ai/labs/content/images/size/w600/2023/12/blogpost_costs.png 600w, https://helvia.ai/labs/content/images/2023/12/blogpost_costs.png 678w"><figcaption><span style="white-space: pre-wrap;">In the 1-shot setting, where we show 1 example per class to the LLM, GPT-4 has 80.4 F1 score but costs 620$, while Anthropic Claude 2 costs only 15$ but has 76.8$ micro-f1. It depends on you and your preference on which to choose (money over slight performance increase?). Also, in the 3-shot setting, GPT-4 outperforms GPT-3.5 by nearly 20 points, but costs around 10 times more. We perform 3,080 queries in the test set, one for each inference sample.</span></figcaption></figure><h2 id="rag-or-dynamic-few-shot-prompting-for-cost-effective-llm-inference">RAG (or Dynamic Few-Shot Prompting) for Cost-Effective LLM Inference</h2>
<p>Right now, for each class, we feed the LLM N examples per class (classic N-shot settings). For example, in the 3-shot settings and 77 classes, <strong>we feed the model</strong> 3x77 = <strong>231 samples, hitting the limit of the 4K context window and having a high API cost of the OpenAI and other LLM providers.</strong></p>
<p>Instead of feeding so many samples to the model each time we want to classify a test sample, we found out that during inference, <strong>we can retrieve only the top K similar (and their labels), and perform better while reducing the context size (and associated costs).</strong></p>
<p>This is called <strong>Dynamic Few-Shot Prompting</strong> since we dynamically change the examples we show to the LLM via the prompt or <strong>RAG (Retrieval-Augmented Generation)</strong>, since the LLM generates after the prompt is being augmented after a retrieval step (as seen in the classic question-answering tasks nowadays). We retrieve the most similar examples and their labels by utilizing the cosine similarity in the sentence embeddings (encoded through MPNet).</p>
<figure class="kg-card kg-image-card"><img src="https://helvia.ai/labs/content/images/2023/12/blogpost_rag_icl.png" class="kg-image" alt="Making LLMs Worth Every Penny: Resource-Limited Text Classification in Banking (ACM ICAIF 2023)" loading="lazy" width="605" height="572" srcset="https://helvia.ai/labs/content/images/size/w600/2023/12/blogpost_rag_icl.png 600w, https://helvia.ai/labs/content/images/2023/12/blogpost_rag_icl.png 605w"></figure><h2 id="results-2-with-ragdynamic-few-shot-prompting">Results (#2) with RAG/Dynamic Few-Shot Prompting</h2>
<p>After performing RAG (or Dynamic Few-Shot Prompting) with K=5/10/20 top similar examples (and their labels) from their training set, one call at a time for each inference/test sample, we also report the results and their (spoiler alert!) heavily reduced associated dollar costs.</p>
<figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://helvia.ai/labs/content/images/2023/12/blogpost_rag_examples-1.png" class="kg-image" alt="Making LLMs Worth Every Penny: Resource-Limited Text Classification in Banking (ACM ICAIF 2023)" loading="lazy" width="673" height="236" srcset="https://helvia.ai/labs/content/images/size/w600/2023/12/blogpost_rag_examples-1.png 600w, https://helvia.ai/labs/content/images/2023/12/blogpost_rag_examples-1.png 673w"><figcaption><span style="white-space: pre-wrap;">Seeing GPT-4 results with RAG (this table) and without RAG (previous table), it seems better (and cheaper) to use LLMs with this dynamic prompting approach (with 5/10/20 samples total), instead of having a classic Few-Shot approach where one shows 3x77 samples per class (231 samples total). Also, Claude 2 on K=20 similar (RAG) yields </span><u><span class="underline" style="white-space: pre-wrap;">85.5% on only 42$, out</span></u><span style="white-space: pre-wrap;"> vs. GPT-4&#x2019;s original </span><u><span class="underline" style="white-space: pre-wrap;">83.1% on 740$</span></u><span style="white-space: pre-wrap;"> (previous table) &#x1F92F; We perform 3,080 queries in the test set, one for each inference sample.</span></figcaption></figure><h2 id="extra-are-llms-capable-for-synthetic-data-generation">Extra: Are LLMs capable for synthetic data generation?</h2>
<p>Data augmentation or synthetic data generation is especially important since when one performs Few-Shot approaches, they are doing this mostly because they are data-limited. And as always, the more the data, the better.</p>
<p>So, we tested if we can trust LLMs for synthetic data generation and the answer is: <strong>yes, but up to a point.</strong></p>
<p>Previous reports show that data augmentation for tasks with large and overlapping label tasks is difficult (see <a href="https://aclanthology.org/2022.nlp4convai-1.5/?ref=helvia.ai">https://aclanthology.org/2022.nlp4convai-1.5/</a>). For this reason, we did a semantic clustering of the 77 labels and 3 of their examples into N=10 groups. Then, we fed each group to GPT-4 (label + 3 examples), asking it to generate 20 more.</p>
<p>&#x1F4A1; The intuition behind this is that the LLM will understand the overlapping differences of the 77 labels and their examples and will be able to create synthetic data which can be differentiated from one class to another.</p>
<p>After doing that, we put them to the test with the MPNet models (using the SetFit Few-Shot approach).</p>
<figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://helvia.ai/labs/content/images/2023/12/blogpost_synthetic_data.png" class="kg-image" alt="Making LLMs Worth Every Penny: Resource-Limited Text Classification in Banking (ACM ICAIF 2023)" loading="lazy" width="568" height="558"><figcaption><span style="white-space: pre-wrap;">In this result, we suppose that we have at least N=3 real samples per class, and we want to test and compare how synthetic/augmented data perform vs. actual real ones. Following the </span><b><strong style="white-space: pre-wrap;">black </strong></b><span style="white-space: pre-wrap;">line, we do see an increase when using the augmented 5 and 10 samples in the Few-Shot Scenario. However, the performance drops after 10 samples, which seems to be the sweet spot for this experiment. For reference reasons, we also have the real data plotted in green line, which indicate that real data are better than GPT-4 generated data.</span></figcaption></figure><h2 id="takeaways">Takeaways</h2>
<p>Our work provides a practical rule of thumb for text classification in settings with lots of classes, such as intent detection in chatbot use cases:</p>
<ul>
<li>If you have more than 5 examples per class, it&apos;s better to finetune a pretrained model such as MPNet using a contrastive learning technique such as SetFit.</li>
<li>If you have less than 5 examples per class, it&apos;s better to use LLMs.</li>
<li>To reduce the costs of LLMs, one can employ &quot;dynamic&quot; few-shot prompting (employing RAG) that performs better and costs a fraction of the regular few-shot prompting.</li>
<li>Synthetic data can be used to enhance performance, but we found that it hurts the results after incorporating N=7 synthetic examples. As expected though, real data is much better than GPT-4 generated data.</li>
</ul>
<h2 id="citation">Citation</h2>
<pre><code>@inproceedings{10.1145/3604237.3626891,
author = {Loukas, Lefteris and Stogiannidis, Ilias and Diamantopoulos, Odysseas and Malakasiotis, Prodromos and Vassos, Stavros},
title = {Making LLMs Worth Every Penny: Resource-Limited Text Classification in Banking},
year = {2023},
isbn = {9798400702402},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
url = {https://doi.org/10.1145/3604237.3626891},
doi = {10.1145/3604237.3626891},
pages = {392&#x2013;400},
numpages = {9},
keywords = {Anthropic, Cohere, OpenAI, LLMs, NLP, Claude, GPT, Few-shot},
location = {Brooklyn, NY, USA},
series = {ICAIF &apos;23}
}
</code></pre>
<h2 id="resources">Resources</h2>
<ul>
<li>Paper: <a href="https://arxiv.org/abs/2311.06102?ref=helvia.ai">https://arxiv.org/abs/2311.06102</a></li>
<li>Kudos (ACM Showcase) Blogpost: <a href="https://www.growkudos.com/publications/10.1145%25252F3604237.3626891/reader?ref=helvia.ai">https://www.growkudos.com/publications/10.1145%25252F3604237.3626891/reader</a></li>
<li>Dataset (Banking77): <a href="https://huggingface.co/datasets/PolyAI/banking77?ref=helvia.ai">https://huggingface.co/datasets/PolyAI/banking77</a></li>
<li>Representative Samples curated by a domain expert (3 samples per class): <a href="https://huggingface.co/datasets/helvia/banking77-representative-samples?ref=helvia.ai">https://huggingface.co/datasets/helvia/banking77-representative-samples</a></li>
</ul>
<h3 id="acknowledgments">Acknowledgments</h3>
<p>This work has received funding from European Union&#x2019;s Horizon 2020 research and innovation programme under grant agreement No 101021714 (&quot;LAW GAME&quot;). Also, we would like to sincerely thank the Hellenic Artificial Intelligence Society (EETN) for their sponsorship.</p>
]]></content:encoded></item><item><title><![CDATA[Cache me if you Can: an Online Cost-aware Teacher-Student Framework to Reduce the Calls to Large Language Models]]></title><description><![CDATA[https://aclanthology.org/2023.findings-emnlp.1000.pdf]]></description><link>https://helvia.ai/labs/cache-me-if-you-can-an-online-cost-aware-teacher-student-framework-to-reduce-the-calls-to-large-language-models-2/</link><guid isPermaLink="false">67892577c0d4bf0008c63ffb</guid><category><![CDATA[publication_pdf]]></category><dc:creator><![CDATA[Stavros Vassos]]></dc:creator><pubDate>Wed, 06 Dec 2023 15:28:00 GMT</pubDate><media:content url="https://helvia.ai/labs/content/images/2025/01/cache_me_if_you_can.png" medium="image"/><content:encoded><![CDATA[<img src="https://helvia.ai/labs/content/images/2025/01/cache_me_if_you_can.png" alt="Cache me if you Can: an Online Cost-aware Teacher-Student Framework to Reduce the Calls to Large Language Models"><p>@ EMNLP 2023</p>]]></content:encoded></item><item><title><![CDATA[Making LLMs Worth Every Penny: Resource-Limited Text Classification in Banking]]></title><description><![CDATA[https://arxiv.org/pdf/2311.06102]]></description><link>https://helvia.ai/labs/making-llms-worth-every-penny-resource-limited-text-classification-in-banking-2/</link><guid isPermaLink="false">6789251ac0d4bf0008c63ff0</guid><category><![CDATA[publication_pdf]]></category><dc:creator><![CDATA[Lefteris Loukas]]></dc:creator><pubDate>Sat, 25 Nov 2023 15:27:00 GMT</pubDate><media:content url="https://helvia.ai/labs/content/images/2025/01/making_llms_worth_any_penny.png" medium="image"/><content:encoded><![CDATA[<img src="https://helvia.ai/labs/content/images/2025/01/making_llms_worth_any_penny.png" alt="Making LLMs Worth Every Penny: Resource-Limited Text Classification in Banking"><p>@ ACM ICAIF 2023</p>]]></content:encoded></item><item><title><![CDATA[AI-assisted Serious Games: Dialogue Management with Generative AI]]></title><description><![CDATA[https://public-storage.helvia.ai/labs/EDGE2023_PanopoulouAversaVassos.pdf]]></description><link>https://helvia.ai/labs/ai-assisted-serious-games-dialogue-management-with-generative-ai/</link><guid isPermaLink="false">678e5564f76c900008e6d266</guid><category><![CDATA[publication_pdf]]></category><dc:creator><![CDATA[Stavros Vassos]]></dc:creator><pubDate>Thu, 19 Oct 2023 13:53:00 GMT</pubDate><media:content url="https://helvia.ai/labs/content/images/2025/01/Screenshot-2025-01-20-at-5.53.23-PM.png" medium="image"/><content:encoded><![CDATA[<img src="https://helvia.ai/labs/content/images/2025/01/Screenshot-2025-01-20-at-5.53.23-PM.png" alt="AI-assisted Serious Games: Dialogue Management with Generative AI"><p>@ EDGE 2023</p>]]></content:encoded></item><item><title><![CDATA[AI models for classifying green plastics patents]]></title><description><![CDATA[Helvia's Stavros Vassos (CEO) and Odysseas Papadiamantopoulos (ML Engineer) joined the AI4EPO team to develop novel AI models for the European Patent Office CodeFest on Green Plastics and won first place.]]></description><link>https://helvia.ai/labs/ai-models-for-classifying-green-plastics-patents/</link><guid isPermaLink="false">6622228957e5a60008e0ce82</guid><category><![CDATA[Competitions]]></category><dc:creator><![CDATA[Stavros Vassos]]></dc:creator><pubDate>Thu, 23 Feb 2023 14:57:00 GMT</pubDate><media:content url="https://helvia.ai/labs/content/images/2024/04/AI4EPO-Green-Plastics-EPO-Codefest.png" medium="image"/><content:encoded><![CDATA[<img src="https://helvia.ai/labs/content/images/2024/04/AI4EPO-Green-Plastics-EPO-Codefest.png" alt="AI models for classifying green plastics patents"><p>The AI4EPO team developed novel AI models for the European Patent Office CodeFest on Green Plastics.</p><p>Responding to the European Patent Office (EPO) first ever CodeFest on Green Plastics, Helvia&apos;s CEO Dr. Stavros Vassos and ML Engineer Odysseas Diamantopoulos joined forces with Dr. Dimitrios Skraparlis from EPO, NL and Dr. Prodromos Malakasiotis from AUEB, GR, forming the AI4EPO team. The purpose was to apply state-of-the-art AI to develop models for automating the classification of patents as green plastics, tackling one of today&apos;s key sustainability challenges.</p><figure class="kg-card kg-image-card"><img src="https://lh4.googleusercontent.com/LF21nz6MggBxse72n3ynzn8P0eKLmUkuiIYgebZrT77eB4r4TC8_mJQxl_KZGX6STWJtwNql1RACOQoPwmrKnC65ejXuDr06lyzsDs6w5RevM3Vwh6HeojumA5YS1Wsy9vzqloFTppqJpi3xjlR-qxE" class="kg-image" alt="AI models for classifying green plastics patents" loading="lazy"></figure><h2 id="the-challenges-and-the-approach">The challenges and the approach</h2><p>The team first had to agree on the definition of &#x2018;green plastics&#x2019;. As there is no standard definition, the team decided to rely on an EPO report and a green plastics cartography, as identified by experts.</p><p>The other challenge was that there are no labeled data on patent examples that belong to green plastics. To tackle this, the team generated lists of patents based on the cartography of the report and labeled them with the respective categories.</p><p>The third challenge was that the patents are too long, and there is no standard method to extract brief relevant information. The approach for this was to use automated summarization, as well as combinations of full-text title, abstract, description, and claims.</p><h2 id="the-methodology">The methodology</h2><p>The methodology the team followed consists of the below six steps:</p><p>1. Define green plastics</p><p>2. Label patent examples with respect to green plastics categories</p><p>3. Preprocess patents to extract a &#x201C;patent DNA&#x201D; per example</p><p>4. Train state-of-the-art AI pipelines for text classification</p><p>5. Evaluate the results and select the winning approach</p><p>6. Refine the winning approach toward a practical MVP<br></p><h2 id="1-define-green-plastics">1. Define green plastics</h2><p>The team  relied on the categorization (cartography) laid-out by the experts of the study &#x201C;<a href="https://documents.epo.org/projects/babylon/eponet.nsf/0/069F978FE569055EC125876F004FFBB1/$File/patents_for_tomorrows_plastics_study_en.pdf?ref=helvia.ai">Patents for tomorrow&#x2019;s plastics</a>&#x201D;.</p><figure class="kg-card kg-image-card"><img src="https://lh5.googleusercontent.com/zXoukZEsBYd63tJ_3vMq0R-BxvfHA3cUpYtu_0kvDFEDIMFUxTE6eXMWaz4NTPdKN2MDjohCGHjOP0mnKvZxzRx7wuTVgPEBvQ0AM44OlLf95fXoK6tiHIzy7oU8PAahAei0wMxm6aJ19hZ1q4eAH-0" class="kg-image" alt="AI models for classifying green plastics patents" loading="lazy"></figure><h2 id="2-label-patent-examples">2. Label patent examples</h2><p>To label the patent examples, the team curated a list of green plastics examples by executing queries on Google patent advanced search for each 3rd level entry of the cartography. Google patent advanced search was chosen because of its open support for searching the full-text of patents using Boolean syntax, proximity operators, wildcards and classification markings. The created google patent queries combine CPC subclass allocations and keyword constructs carefully selected to correspond to primary search strategies with similar or narrower search scope among the published queries used in the study &#x201C;Patents for tomorrow&#x2019;s plastics&#x201D;.</p><p>Complexity constraints of google patents were worked-around through careful query and query-part building.</p><p>Following that, they created lists of &#x201C;near-miss&#x201D; examples to be used as negative examples that don&#x2019;t belong to green plastics. The queries used combined CPC subclass allocations with  targeted keyword negations.</p><p>The resulting data set effectively built upon samples of queries and CPC allocations generated and verified by human experts.</p><figure class="kg-card kg-image-card"><img src="https://lh3.googleusercontent.com/H4OtVmqNZJCGrolIxUwi-tudoRoIOZrsv0zBSrmmBQCTvF-UjYU2pjpLnQXp8ssD8EhENBe56QSvN4Eu_yXxuN0ydfhfxi2KueQHxtnJdKmWa2ZOPs6LAQlzvO08mn97hHrdD0-9Ut4aSvFWWe0B7t4" class="kg-image" alt="AI models for classifying green plastics patents" loading="lazy"></figure><h2 id="3-preprocess-patent-examplesextracting-a-%E2%80%9Cpatent-dna%E2%80%9D">3. Preprocess patent examples - extracting a &#x201C;patent DNA&#x201D;</h2><p>To preprocess patent examples, the team had to follow the below steps:</p><ul><li>For each patent ID extract the title, abstract, description, and claims as text along with metadata using the EPO OPS service</li><li>Translate* to English for all parts not available in English</li><li>Summarize** title &amp; abstract into 75 words, description into 180 words and claims into 150 words</li></ul><p>The result was a new balanced dataset for green plastics classification with total examples including 4.3k patents, 2.2k positive and 2.1k negative. </p><p>The dataset includes three versions of extracted &#x201C;patent DNA&#x201D; for each patent,  small (400 words), medium (1000 words), and large (1500 words) using summaries and full-text, with a total size of 597 MB. The three sizes of &#x201C;patent DNA&#x201D; enables the application of AI language models of varying complexity.</p><figure class="kg-card kg-image-card"><img src="https://helvia.ai/blog/content/images/2023/02/image.png" class="kg-image" alt="AI models for classifying green plastics patents" loading="lazy" width="888" height="482"></figure><p>[* Google Translate was used for automated translation ]</p><p>[** OpenAI davinci-003 was used for automated summarization ]</p><h2 id="4-train-state-of-the-art-ai-pipelines">4. Train state-of-the-art AI pipelines</h2><p>To train the AI pipelines the team harnessed the power of Large Language Models (LLMs) using OpenAI and Cohere managed infrastructure and API:</p><ul><li>Zero-shot: no examples, only a definition of the task is given to LLM</li><li>Few-shot (in-context) learning: 1 or 2 examples are given per class to LLM, multiple trials are executed, and majority vote is considered</li><li>Fine-tuning: dataset is used to finetune LLM</li><li>Custom MLP neural network: dataset is used to train a Multi-Layer Perceptron that employs LLM embeddings for its first layer</li></ul><p>In addition, there were two pipelines per approach:</p><ul><li>Binary: decide whether a patent is green plastics or not (yes/no)</li><li>Multi-label: decide which 2nd and 3rd cartography level a patent belongs to (pick a class or NEG otherwise)<br></li></ul><figure class="kg-card kg-image-card"><img src="https://lh3.googleusercontent.com/ylkg-km83XSJX7mVm6oL3lchY30Sur7E20Hv-nUobm_R1l7scbjPjw4Kzuv_xT6KUQQ1_uyR7VyeS_3XbIafBFfQSK20UeGfbABS7kkR9mMEZyiVz0DcAaV3P8pfwxvFSbmfQN4kPDjrdNYFrq8KUys" class="kg-image" alt="AI models for classifying green plastics patents" loading="lazy"></figure><h2 id="5-evaluate-the-results-and-select-the-winning-approach">5. Evaluate the results and select the winning approach</h2><p>The winning approach was <em>E2 &#x2013; MLP with ada-002 embeddings</em>, which was trained on the dataset for multi-label classification.</p><figure class="kg-card kg-image-card"><img src="https://lh6.googleusercontent.com/E-jspbevBkyJveU8UrZp12JIQWzTTlb6nxoo0yv9ekNcDP6aPnp_XEzOTKSo180Nob80xMyMTT2ASkJ0RqIVApIoLRT5bfs6VsTisBiBydvtdAI22MdlAOxL1fCU505-yXhX-kLv5SRjdbsT6arLTYM" class="kg-image" alt="AI models for classifying green plastics patents" loading="lazy"></figure><p>Note that in the table above for E2 and E3 we report the &#x201C;aggregate&#x201D; results, meaning that the AI model was trained to select a category of 2nd or 3rd level, but we only count whether it selected correctly that the patent belongs to green plastics or not with high confidence. In this way we get the binary decision (&#x201C;Is it green plastics or not?&#x201D;) along with some hints about why the model thinks it is classified in this way.</p><p>The evaluation findings showed that:</p><ul><li>Automated summaries are weak: Crucial details for deciding green plastics seem to be missing. As a result, smaller models such as the BERT family that accept up to ~350 words are not expected to work well with automated summaries</li><li>Text generation LLMs do not perform well: Perhaps significantly larger datasets are needed; fine-tuning with 4.3k examples it was not possible to get decent performance</li><li>Text classification LLM embeddings are powerful: Using a custom Multi-layer Perceptron on top leads to near perfect binary classification, i.e. deciding if patent belongs to green plastics</li><li>Multi-label classification performs similar to binary: With multi-label classification we can also get an explanation of the yes response in terms of the 2nd or 3rd level cartography classes<br></li></ul><p>The table below shows some indicative results using E2 that also provides an explanation:</p><figure class="kg-card kg-image-card"><img src="https://lh5.googleusercontent.com/ZHKAZzwUWVINtDQou0GV1LwTOS4zdUWcTMweCy33mCfXj5dkM-uQWme73sLmt6husU5tV_gYqa47Wm-0_0X-WlV2FLOanWXK_Rnu9kc6JN7AePUTiBSbCtaeEGKx3vlj5aFx6CEg0aeC_Dk3YSz_-M8" class="kg-image" alt="AI models for classifying green plastics patents" loading="lazy"></figure><h2 id="6-refine-the-winning-approach-toward-a-practical-mvp"><br>6. Refine the winning approach toward a practical MVP</h2><p>The use of the &#x201C;patent DNA&#x201D; of various sizes enables the exploration of cost-accuracy tradeoffs. The team further investigated further modifications of the winning solution, including the use of medium-sized patent DNA. Using a medium-sized patent DNA, approach E5 was introduced which aims at a lower cost/latency in production due to smaller tokens input. Compared against the winner (E2), the results were the following:</p><ul><li>E5 cost savings vs E2: ~30% smaller input token counts</li><li>E5 accuracy penalty vs E2: small on binary decision (96.69% vs 98.8%), but significant on 2nd-level decision as the following reports show</li></ul><figure class="kg-card kg-image-card"><img src="https://lh4.googleusercontent.com/pI9F80piAhu02VQEb_lSj0E7EhnscSrG34A5c2_5OvPVCoG5Mp9gBQ3wN4nqth0WkM_MtHijzsddL71VtnakZUQVCD3lCkVD1EyZYdCQ_c9VlNTZtPNBJKB06D0ws6bkbp96MbBwZopHLHGP2EBJerU" class="kg-image" alt="AI models for classifying green plastics patents" loading="lazy"></figure><h2 id="conclusions">Conclusions</h2><p>The solution contains a comprehensive analysis of traditional and modern, state-of-the-art models and approaches, utilizing all available published expert information (green plastics cartography, queries, CPC subclasses) to create a new dataset. All proposed and tested AI pipelines of AI4EPO are by design, directly transferable to other base models and datasets. </p><p>The team proposes E2 that employs state-of-the-art LLM embeddings*, combined with a custom Multi-Layer-Perceptron neural network, producing excellent results on binary yes/no decisions, i.e. detecting whether a patent relates to green plastics or not. In addition, it offers information on <em>why </em>by providing classification to cartography entries of green plastics.</p><p>[* OpenAI model text-embedding-ada-002, published on 15/12/2022]</p><h2 id="next-steps">Next steps</h2><p>The next steps include evaluation of the results on ground truth data using green plastics experts, employing a &#x201C;Human in the loop&#x201D; approach for generating a premium dataset and continuous improvement, following the experience of a similar project (A challenge on large-scale biomedical semantic indexing and question answering http://bioasq.org/).</p><p>Large dataset generation may be further streamlined and optimized using powerful EPO internal tools. Additionally, further input token size (&#x201C;patent DNA&#x201D;) optimization approaches can further optimize performance-accuracy tradeoffs.</p><p>Lastly, generating a premium dataset may further facilitate the multi-class approach and reduce the confusion between green plastics categories.</p>]]></content:encoded></item><item><title><![CDATA[Transformation through Provocation? Designing a ‘Bot of Conviction’ to Challenge Conceptions and Evoke Critical Reflection]]></title><description><![CDATA[https://saraperry.wordpress.com/wp-content/uploads/2019/05/roussou_et_al_2019_chipaper627.pdf]]></description><link>https://helvia.ai/labs/transformation-through-provocation-designing-a-bot-of-conviction-to-challenge-conceptions-and-evoke-critical-reflection/</link><guid isPermaLink="false">678a38c7e237550008b809ea</guid><category><![CDATA[publication_pdf]]></category><dc:creator><![CDATA[Stavros Vassos]]></dc:creator><pubDate>Sat, 04 May 2019 11:02:00 GMT</pubDate><media:content url="https://helvia.ai/labs/content/images/2025/01/Screenshot-2025-01-17-at-1.07.52-PM.png" medium="image"/><content:encoded><![CDATA[<img src="https://helvia.ai/labs/content/images/2025/01/Screenshot-2025-01-17-at-1.07.52-PM.png" alt="Transformation through Provocation? Designing a &#x2018;Bot of Conviction&#x2019; to Challenge Conceptions and Evoke Critical Reflection"><p>@ CHI 2019</p>]]></content:encoded></item></channel></rss>