<?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 Venkata Dikshit on Medium]]></title>
        <description><![CDATA[Stories by Venkata Dikshit on Medium]]></description>
        <link>https://medium.com/@vdpappu?source=rss-53779724bdd6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*JmFMfFnACCzt8KFjkpDzPQ.png</url>
            <title>Stories by Venkata Dikshit on Medium</title>
            <link>https://medium.com/@vdpappu?source=rss-53779724bdd6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 17:44:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vdpappu/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[LoRA: The Underrated Key to Enterprise AI Efficiency]]></title>
            <link>https://medium.com/@vdpappu/lora-the-underrated-key-to-enterprise-ai-efficiency-154e7c8ce87d?source=rss-53779724bdd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/154e7c8ce87d</guid>
            <category><![CDATA[fine-tuning]]></category>
            <category><![CDATA[open-source-model]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[lora]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Venkata Dikshit]]></dc:creator>
            <pubDate>Sat, 21 Sep 2024 09:39:50 GMT</pubDate>
            <atom:updated>2024-09-21T09:39:50.781Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9LaH9aMYXg1RxhgQH9LvnA.jpeg" /></figure><h3>Enterprise AI: Progress and Roadblocks</h3><p>Generative AI is moving fast and transforming industries, but when <strong>scaling it across the enterprise</strong>, most companies are still figuring out how to do it right. A lot of organizations have started by plugging into <strong>LLM APIs</strong>, but honestly, that’s just the start. As AI becomes a critical part of enterprise strategy, it’s clear that <strong>simple API calls</strong> won’t cut it for the long haul. Companies need to look at <strong>more sustainable, scalable solutions</strong> that fit their unique needs. That’s where <strong>fine-tuning</strong> and methods like <strong>Low-Rank Adaptation (LoRA)</strong> make a real difference.</p><h3>The (Near) Future of Enterprise AI Efficiency: From APIs to Fine-Tuning</h3><p>Enterprises are adopting generative AI at an astonishing rate, with many relying on <strong>proprietary LLMs</strong> from providers like OpenAI and Anthropic. These APIs have opened the doors to integrating AI-powered solutions quickly, without the need for significant internal expertise. While this has unlocked new possibilities, as enterprises expand AI use across diverse workflows, this reliance on <strong>external LLMs</strong> brings substantial challenges.</p><p>While proprietary LLMs are undoubtedly powerful, their <strong>high cost</strong> makes them difficult to deploy widely across an organization. Moreover, <strong>data privacy</strong> is a major concern, especially in heavily regulated industries like banking and healthcare, where sending sensitive information to third-party cloud services is often a <strong>non-starter</strong>. This leaves a gap between <strong>what enterprises want</strong> and <strong>what’s feasible</strong> with their current AI strategies. For use cases like <strong>edge AI deployments</strong>, where network calls are expensive or impractical, relying solely on APIs is even more restrictive.</p><p>Enterprises are, in a sense, <strong>drinking from the GenAI firehose</strong>. They’ve jumped into the AI space rapidly, fueled by the excitement following <strong>ChatGPT’s breakthrough success</strong>. <a href="https://www.mckinsey.com/capabilities/quantumblack/our-insights/the-state-of-ai">A McKinsey report</a> shows that <strong>72% of enterprises</strong> now use AI, with <strong>65%</strong> specifically leveraging generative AI. However, despite these adoption rates, the reality is that most enterprises are still in the <strong>experimental phase</strong>, building solutions using <strong>prompt engineering</strong> and <strong>RAG applications</strong>. These methods, while easy to adopt, are often limited to <strong>high-value, core functions</strong> due to the <strong>high API costs</strong>, where clear ROI justifies the investment. As a result, many potential use cases remain unexplored.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V4aAg3P_FCGbFqDW7FLF7Q.png" /></figure><h4>Challenges with Open-Source Models</h4><p>Though many enterprises are turning to <strong>open-source LLMs</strong> as a more <strong>cost-effective</strong> and flexible alternative to proprietary APIs, these models present their own set of <strong>limitations</strong>, particularly when used in <strong>RAG</strong> and <strong>prompt engineering</strong> applications. Open-source models often <strong>lag behind </strong>in terms of <strong>accuracy</strong> and <strong>scalability</strong>, as seen in the chart below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T5cnIo9ZC-SRNtII6xtNGQ.png" /><figcaption><a href="https://www.databricks.com/blog/long-context-rag-performance-llms">https://www.databricks.com/blog/long-context-rag-performance-llms</a></figcaption></figure><p>This performance gap is especially problematic for industries dealing with <strong>complex, domain-specific tasks</strong> or those requiring <strong>contextual accuracy</strong> on across diverse use cases.</p><p>Additionally, most open-source models require <strong>significant fine-tuning</strong> to be effective in specialized workflows, which circles back to the need for fine-tuning as a core strategy for enterprises that wish to break free from the confines of both <strong>proprietary APIs</strong> and the limitations of <strong>open-source models</strong>.</p><h3>Finetuning is not a Cakewalk</h3><h4>What did it take OpenAI to build ChatGPT on GPT3?</h4><p>The answer lies in <strong>fine-tuning</strong> — a critical process that transformed GPT-3’s raw capabilities into the user-friendly, conversational agent we know today. Fine-tuning GPT-3 involved using a <strong>curated dataset</strong> of human-generated instruction sets, estimated to be between <strong>50,000 to 150,000 data points</strong>. While this may sound substantial, it’s just a fraction compared to GPT-3’s original <strong>570GB</strong> of training data.</p><pre><strong>Sample Instruction Data points:</strong></pre><pre><strong>[Sample-1]</strong><br><strong>Prompt:</strong><br>&quot;Explain the process of photosynthesis in simple terms for a 10-year-old.&quot;<br><strong>Ideal Response:</strong><br>&quot;Photosynthesis is how plants make their own food. They use sunlight, water, <br>and air to make sugar, which helps them grow. The leaves take in sunlight, <br>and the roots drink water from the soil. The air has something called <br>carbon dioxide, which the plant uses. With sunlight, water, and air, <br>the plant makes sugar and also releases oxygen, which we breathe.&quot;</pre><pre><strong>[Sample-2]<br>Prompt:</strong><br>&quot;Write a short email to your manager asking for a day off due to <br>a personal appointment.&quot;<br><strong>Ideal Response:</strong><br>&quot;Hi [Manager&#39;s Name],<br>I hope you&#39;re doing well. I wanted to let you know that I have a personal appointment next Friday and would like to request the day off if possible. Please let me know if this works for the team, and I can adjust accordingly.<br>Thank you for your understanding.<br>Best regards,<br>[Your Name]&quot;</pre><p>Fine-tuning is what <strong>steers a model’s behaviour</strong>, but it’s far from easy. Despite being around since methods like <a href="https://arxiv.org/pdf/1801.06146"><strong>ULMFit</strong></a> (which predated GPT-1), fine-tuning hasn’t gained widespread adoption in enterprise AI for several reasons:</p><ul><li><strong>Lack of Awareness</strong>: Many organizations weren’t aware of how fine-tuning could tailor models to their specific needs.</li><li><strong>Skill Gap</strong>: Fine-tuning required specialized <strong>deep learning expertise</strong>, which many companies lacked.</li><li><strong>High Costs</strong>: The computational resources, particularly <strong>GPU clusters</strong>, required for fine-tuning have been a significant barrier.</li><li><strong>Data Acquisition</strong>: Collecting and preparing the right datasets for fine-tuning is time-consuming and expensive.</li><li><strong>Unclear Value</strong>: Before models like ChatGPT, the business value of fine-tuning wasn’t always obvious, making it hard to justify the investment.</li></ul><p>These challenges have created significant friction for enterprises, making them hesitant to integrate fine-tuning into their AI strategies, despite its potential to impact their entire tech stack. As a result, many organizations have stuck with <strong>proprietary models</strong>, using <strong>RAG</strong> and <strong>prompt engineering</strong> to get by — often without a clear roadmap for scaling AI to meet more specific, complex business needs.</p><h3>Why Fine-Tuning Must Be a Part of Enterprise AI Strategy</h3><p>So, does that mean fine-tuning isn’t feasible for enterprise applications? Not quite. While <strong>prompt engineering</strong> lowers the skill barrier and reduces data requirements for specialized tasks, it doesn’t address the <strong>model costs</strong> or the <strong>complexity of RAG applications</strong>. As <strong>data security</strong> and <strong>privacy concerns</strong> take priority in almost all enterprise AI discussions, organizations are increasingly seeking <strong>more control</strong> over the models they deploy.</p><p>While <strong>open-source models</strong> seem promising for RAG applications, their performance often <strong>lags behind proprietary models </strong>as discussed earlier. If an organization chooses to deploy these open-source models, they would need <strong>32 NVIDIA A100 GPUs</strong> (80 GB on each card) for LLaMA-3.1–405b or <strong>four A100s</strong> for LLaMA-3.1–70B just for <strong>inference</strong> — a substantial infrastructure investment that is far from ideal.</p><p>While enterprises may not be pulling the plug on proprietary models anytime soon, it’s clear that having a <strong>Plan B</strong> or <strong>alternative strategy</strong> is crucial. AI leaders should consider adopting <strong>open-source models and fine-tuning</strong> as part of their long-term AI strategy. While there’s growing interest in open-source models, their performance is still not on par with proprietary counterparts, making <strong>fine-tuning</strong> a necessary component to improve task-specific performance and reduce <strong>overreliance on proprietary models</strong>. LoRA offers a scalable, low-cost alternative to full fine-tuning, allowing enterprises to adapt models efficiently without heavy resource demands.</p><h3>LoRA: Bringing Fine-Tuning Closer to Enterprise AI</h3><p>As enterprises push forward with AI adoption, <strong>efficient fine-tuning</strong> is becoming increasingly important. Traditional fine-tuning methods, while effective, can be <strong>costly</strong> and <strong>resource-intensive</strong>, particularly for large models like <strong>LLaMA</strong> or <strong>GPT family</strong> models. <strong>Low-Rank Adaptation (LoRA)</strong> addresses these challenges, offering a practical solution for fine-tuning by reducing the need for retraining the entire model. LoRA also mitigates some challenges faced in <strong>RAG workflows</strong> and can even be used alongside <strong>RAG</strong> to enhance performance. While LoRA may not replace RAG entirely, it provides a <strong>flexible, cost-effective alternative</strong> in scenarios like <strong>on-premise deployments</strong> or <strong>cost-constrained environments</strong>, enabling enterprises to scale AI efficiently.</p><h4>What are LoRAs?</h4><p>Low-rank adaptation is a technique designed to fine-tune large foundation models more efficiently by focusing on a small subset of their parameters. Instead of updating all the parameters in the model during fine-tuning, LoRA introduces low-rank matrices into certain layers of the model. These matrices are much smaller and easier to train, significantly reducing the computational cost and memory footprint. This allows for task-specific adaptation without retraining the entire model, making it ideal for limited resources or to fine-tune a model for multiple tasks without overwriting the original knowledge.</p><h4>Unpacking what LoRAs does</h4><p>Confused? Let’s break it down with an intuitive explanation using <strong>matrix multiplication</strong>, which is at the core of how deep learning models learn.</p><p>Deep Learning models learn by updating <strong>model weights</strong>, both during pre-training and fine-tuning. These weights are stored in large matrices, often with dimensions in the thousands. For example, the <strong>LLaMA-3.1–13B</strong> model has 13 billion full-precision weights across multiple layers.</p><p>Consider an intermediate weight matrix of size <strong>1024x768</strong> (containing <strong>786,432</strong> values). During fine-tuning, updating this matrix would require keeping an additional matrix of the same size to track changes. <strong>LoRA</strong> addresses this challenge by recognizing that fine-tuning often requires only minor adjustments to a small set of parameters.</p><p>The motivation behind <strong>LoRA</strong> is based on the observation that during fine-tuning, models often need only <strong>minor adjustments</strong> in a small number of parameters rather than updating the entire weight matrix. This has led to a couple of design decisions:</p><ol><li><strong>Track changes to weights</strong> instead of updating weights directly.</li><li><strong>Decomposes the large matrix of weight changes</strong> into two smaller matrices that contain the “trainable parameters.”</li></ol><p>Overwhelming? It’s a simple math. Multiplying two small matrics gives us a larger matrix:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z5SQBHn8uOt1agw0HGVZJg.png" /></figure><p>Now, flip this. A large matrix can be decomposed into two smaller matrics</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wv3fDyknaDqAuOBRD7A16A.png" /></figure><p>By decomposing a <strong>1024x768 matrix</strong> into two smaller matrices, LoRA can reduce the number of trainable parameters from <strong>786,432 to 1,792</strong> — a <strong>99.8% reduction</strong> in computational requirements.</p><h4>Fine-tuning Granularity</h4><p>The low-rank matrices(1X1024, 1X768) are updated through gradient descent during fine-tuning, without modifying the weights of the base model. The multiplied change matrix is added to the base model weights to get the final fine-tuned model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tgmsZEhpAT-jR2sZXTFqDQ.png" /></figure><p>Fine-tuning matrices of Rank 1 (1X1024, 1X768) makes a pretty big concession in granularity. The granularity can be improved by using higher-rank matrices for fine-tuning — for example, using [2X1024, 2X768] matrics instead of [1X1024, 1X768]. <strong>Higher granularity</strong> means the model can learn more effectively, leading to <strong>improved performance</strong> and better adaptation to task-specific requirements.</p><p>The table summarizes the number of trainable parameters with LoRA fine-tuning (across varying ranks) vs full-finetuning for the Llama-3B model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ox9fXTISt3OB5-0bJl3BUg.png" /></figure><h4>What’s the trade-off?</h4><p>While LoRA provides a significant reduction in the number of trainable parameters, there’s a <strong>trade-off</strong> in the form of <strong>information loss</strong> during matrix decomposition. Since LoRA reduces the full-weight matrix into smaller components, some details can be lost in the process. However, this loss is often minimal because deep learning models are highly <strong>over-parameterized</strong> — meaning they contain more parameters than necessary for the task. To mitigate information loss, <strong>higher-rank matrices</strong> can be used, ensuring more accurate approximations when fine-tuning.</p><blockquote>“Over-parameterized” means that these models are really bigger than they need to be for the training data, and not all of the parameters strictly matter. There is redundancy, robustness, and resiliency within the parameters.</blockquote><h4>How do these compute gains impact the performance?</h4><p>While LoRA and QLoRA drastically reduce the computational load during fine-tuning, the key question is whether these efficiency gains come at the cost of performance. The table below compares the performance of <strong>QLoRA</strong> (an improved version of LoRA) with <strong>full fine-tuning</strong> of the <strong>LLaMA-7B</strong> model across various tasks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dIeTcFCKTYfaseBJ1jXubw.png" /></figure><p>As you can see from the table, <strong>QLoRA achieves 95–99% of the performance</strong> of full fine-tuning across a variety of tasks, including <strong>question-answering, summarization, classification, and named entity recognition</strong>. These results demonstrate that while there is a <strong>slight drop in performance</strong>, the <strong>compute gains</strong> and <strong>resource efficiency</strong> far outweigh the marginal difference in accuracy for most enterprise use cases.</p><h4>Wrapping it Up</h4><p>LoRA offers enterprises a practical and cost-effective way to scale AI without the heavy resource demands of traditional fine-tuning. If you’re looking to unlock AI’s full potential, it’s worth giving LoRA a serious look.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=154e7c8ce87d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LoRA: The Underrated Key to Enterprise AI Efficiency]]></title>
            <link>https://medium.com/@vdpappu/loras-are-cool-288b5b04b37d?source=rss-53779724bdd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/288b5b04b37d</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[lora]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Venkata Dikshit]]></dc:creator>
            <pubDate>Thu, 19 Sep 2024 15:07:41 GMT</pubDate>
            <atom:updated>2024-09-20T13:15:21.229Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9LaH9aMYXg1RxhgQH9LvnA.jpeg" /></figure><h3>Enterprise AI: Progress and Roadblocks</h3><p>Generative AI is moving fast and transforming industries, but when <strong>scaling it across the enterprise</strong>, most companies are still figuring out how to do it right. A lot of organizations have started by plugging into <strong>LLM APIs</strong>, but honestly, that’s just the start. As AI becomes a critical part of enterprise strategy, it’s clear that <strong>simple API calls</strong> won’t cut it for the long haul. Companies need to look at <strong>more sustainable, scalable solutions</strong> that fit their unique needs. That’s where <strong>fine-tuning</strong> and methods like <strong>Low-Rank Adaptation (LoRA)</strong> make a real difference.</p><h3>The (Near) Future of Enterprise AI Efficiency: From APIs to Fine-Tuning</h3><p>Enterprises are adopting generative AI at an astonishing rate, with many relying on <strong>proprietary LLMs</strong> from providers like OpenAI and Anthropic. These APIs have opened the doors to integrating AI-powered solutions quickly, without the need for significant internal expertise. While this has unlocked new possibilities, as enterprises expand AI use across diverse workflows, this reliance on <strong>external LLMs</strong> brings substantial challenges.</p><p>While proprietary LLMs are undoubtedly powerful, their <strong>high cost</strong> makes them difficult to deploy widely across an organization. Moreover, <strong>data privacy</strong> is a major concern, especially in heavily regulated industries like banking and healthcare, where sending sensitive information to third-party cloud services is often a <strong>non-starter</strong>. This leaves a gap between <strong>what enterprises want</strong> and <strong>what’s feasible</strong> with their current AI strategies. For use cases like <strong>edge AI deployments</strong>, where network calls are expensive or impractical, relying solely on APIs is even more restrictive.</p><p>Enterprises are, in a sense, <strong>drinking from the GenAI firehose</strong>. They’ve jumped into the AI space rapidly, fueled by the excitement following <strong>ChatGPT’s breakthrough success</strong>. <a href="https://www.mckinsey.com/capabilities/quantumblack/our-insights/the-state-of-ai">A McKinsey report</a> shows that <strong>72% of enterprises</strong> now use AI, with <strong>65%</strong> specifically leveraging generative AI. However, despite these adoption rates, the reality is that most enterprises are still in the <strong>experimental phase</strong>, building solutions using <strong>prompt engineering</strong> and <strong>RAG applications</strong>. These methods, while easy to adopt, are often limited to <strong>high-value, core functions</strong> due to the <strong>high API costs</strong>, where clear ROI justifies the investment. As a result, many potential use cases remain unexplored.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V4aAg3P_FCGbFqDW7FLF7Q.png" /></figure><h4>Challenges with Open-Source Models</h4><p>Though many enterprises are turning to <strong>open-source LLMs</strong> as a more <strong>cost-effective</strong> and flexible alternative to proprietary APIs, these models present their own set of <strong>limitations</strong>, particularly when used in <strong>RAG</strong> and <strong>prompt engineering</strong> applications. Open-source models often <strong>lag behind </strong>in terms of <strong>accuracy</strong> and <strong>scalability</strong>, as seen in the chart below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T5cnIo9ZC-SRNtII6xtNGQ.png" /><figcaption><a href="https://www.databricks.com/blog/long-context-rag-performance-llms">https://www.databricks.com/blog/long-context-rag-performance-llms</a></figcaption></figure><p>This performance gap is especially problematic for industries dealing with <strong>complex, domain-specific tasks</strong> or those requiring <strong>contextual accuracy</strong> on across diverse use cases.</p><p>Additionally, most open-source models require <strong>significant fine-tuning</strong> to be effective in specialized workflows, which circles back to the need for fine-tuning as a core strategy for enterprises that wish to break free from the confines of both <strong>proprietary APIs</strong> and the limitations of <strong>open-source models</strong>.</p><h3>Finetuning is not a Cakewalk</h3><h4><strong>What did it take OpenAI to build ChatGPT on GPT3?</strong></h4><p>The answer lies in <strong>fine-tuning</strong> — a critical process that transformed GPT-3’s raw capabilities into the user-friendly, conversational agent we know today. Fine-tuning GPT-3 involved using a <strong>curated dataset</strong> of human-generated instruction sets, estimated to be between <strong>50,000 to 150,000 data points</strong>. While this may sound substantial, it’s just a fraction compared to GPT-3’s original <strong>570GB</strong> of training data.</p><pre><strong>Sample Instruction Data points:</strong><br><br><strong>[Sample-1]</strong><br><strong>Prompt:</strong><br>&quot;Explain the process of photosynthesis in simple terms for a 10-year-old.&quot;<br><strong>Ideal Response:</strong><br>&quot;Photosynthesis is how plants make their own food. They use sunlight, water, <br>and air to make sugar, which helps them grow. The leaves take in sunlight, <br>and the roots drink water from the soil. The air has something called <br>carbon dioxide, which the plant uses. With sunlight, water, and air, <br>the plant makes sugar and also releases oxygen, which we breathe.&quot;<br><br><strong>[Sample-2]<br>Prompt:</strong><br>&quot;Write a short email to your manager asking for a day off due to <br>a personal appointment.&quot;<br><strong>Ideal Response:</strong><br>&quot;Hi [Manager&#39;s Name],<br>I hope you&#39;re doing well. I wanted to let you know that I have a personal appointment next Friday and would like to request the day off if possible. Please let me know if this works for the team, and I can adjust accordingly.<br>Thank you for your understanding.<br>Best regards,<br>[Your Name]&quot;</pre><p>Fine-tuning is what <strong>steers a model’s behaviour</strong>, but it’s far from easy. Despite being around since methods like <a href="https://arxiv.org/pdf/1801.06146"><strong>ULMFit</strong></a> (which predated GPT-1), fine-tuning hasn’t gained widespread adoption in enterprise AI for several reasons:</p><ul><li><strong>Lack of Awareness</strong>: Many organizations weren’t aware of how fine-tuning could tailor models to their specific needs.</li><li><strong>Skill Gap</strong>: Fine-tuning required specialized <strong>deep learning expertise</strong>, which many companies lacked.</li><li><strong>High Costs</strong>: The computational resources, particularly <strong>GPU clusters</strong>, required for fine-tuning have been a significant barrier.</li><li><strong>Data Acquisition</strong>: Collecting and preparing the right datasets for fine-tuning is time-consuming and expensive.</li><li><strong>Unclear Value</strong>: Before models like ChatGPT, the business value of fine-tuning wasn’t always obvious, making it hard to justify the investment.</li></ul><p>These challenges have created significant friction for enterprises, making them hesitant to integrate fine-tuning into their AI strategies, despite its potential to impact their entire tech stack. As a result, many organizations have stuck with <strong>proprietary models</strong>, using <strong>RAG</strong> and <strong>prompt engineering</strong> to get by — often without a clear roadmap for scaling AI to meet more specific, complex business needs.</p><h3>Why Fine-Tuning Must Be a Part of Enterprise AI Strategy</h3><p>So, does that mean fine-tuning isn’t feasible for enterprise applications? Not quite. While <strong>prompt engineering</strong> lowers the skill barrier and reduces data requirements for specialized tasks, it doesn’t address the <strong>model costs</strong> or the <strong>complexity of RAG applications</strong>. As <strong>data security</strong> and <strong>privacy concerns</strong> take priority in almost all enterprise AI discussions, organizations are increasingly seeking <strong>more control</strong> over the models they deploy.</p><p>While <strong>open-source models</strong> seem promising for RAG applications, their performance often <strong>lags behind proprietary models </strong>as discussed earlier. If an organization chooses to deploy these open-source models, they would need <strong>32 NVIDIA A100 GPUs</strong> (80 GB on each card) for LLaMA-3.1–405b or <strong>four A100s</strong> for LLaMA-3.1–70B just for <strong>inference</strong> — a substantial infrastructure investment that is far from ideal.</p><p>While enterprises may not be pulling the plug on proprietary models anytime soon, it’s clear that having a <strong>Plan B</strong> or <strong>alternative strategy</strong> is crucial. AI leaders should consider adopting <strong>open-source models and fine-tuning</strong> as part of their long-term AI strategy. While there’s growing interest in open-source models, their performance is still not on par with proprietary counterparts, making <strong>fine-tuning</strong> a necessary component to improve task-specific performance and reduce <strong>overreliance on proprietary models</strong>. LoRA offers a scalable, low-cost alternative to full fine-tuning, allowing enterprises to adapt models efficiently without heavy resource demands.</p><h3>LoRA: Bringing Fine-Tuning Closer to Enterprise AI</h3><p>As enterprises push forward with AI adoption, <strong>efficient fine-tuning</strong> is becoming increasingly important. Traditional fine-tuning methods, while effective, can be <strong>costly</strong> and <strong>resource-intensive</strong>, particularly for large models like <strong>LLaMA</strong> or <strong>GPT family</strong> models. <strong>Low-Rank Adaptation (LoRA)</strong> addresses these challenges, offering a practical solution for fine-tuning by reducing the need for retraining the entire model. LoRA also mitigates some challenges faced in <strong>RAG workflows</strong> and can even be used alongside <strong>RAG</strong> to enhance performance. While LoRA may not replace RAG entirely, it provides a <strong>flexible, cost-effective alternative</strong> in scenarios like <strong>on-premise deployments</strong> or <strong>cost-constrained environments</strong>, enabling enterprises to scale AI efficiently.</p><h4>What are LoRAs?</h4><p>Low-rank adaptation is a technique designed to fine-tune large foundation models more efficiently by focusing on a small subset of their parameters. Instead of updating all the parameters in the model during fine-tuning, LoRA introduces low-rank matrices into certain layers of the model. These matrices are much smaller and easier to train, significantly reducing the computational cost and memory footprint. This allows for task-specific adaptation without retraining the entire model, making it ideal for limited resources or to fine-tune a model for multiple tasks without overwriting the original knowledge.</p><h4>Unpacking what LoRAs does</h4><p>Confused? Let’s break it down with an intuitive explanation using <strong>matrix multiplication</strong>, which is at the core of how deep learning models learn.</p><p>Deep Learning models learn by updating <strong>model weights</strong>, both during pre-training and fine-tuning. These weights are stored in large matrices, often with dimensions in the thousands. For example, the <strong>LLaMA-3.1–13B</strong> model has 13 billion full-precision weights across multiple layers.</p><p>Consider an intermediate weight matrix of size <strong>1024x768</strong> (containing <strong>786,432</strong> values). During fine-tuning, updating this matrix would require keeping an additional matrix of the same size to track changes. <strong>LoRA</strong> addresses this challenge by recognizing that fine-tuning often requires only minor adjustments to a small set of parameters.</p><p>The motivation behind <strong>LoRA</strong> is based on the observation that during fine-tuning, models often need only <strong>minor adjustments</strong> in a small number of parameters rather than updating the entire weight matrix. This has led to a couple of design decisions:</p><ol><li><strong>Track changes to weights</strong> instead of updating weights directly.</li><li><strong>Decomposes the large matrix of weight changes</strong> into two smaller matrices that contain the “trainable parameters.”</li></ol><p>Overwhelming? It’s a simple math. Multiplying two small matrics gives us a larger matrix:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z5SQBHn8uOt1agw0HGVZJg.png" /></figure><p>Now, flip this. A large matrix can be decomposed into two smaller matrics</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wv3fDyknaDqAuOBRD7A16A.png" /></figure><p>By decomposing a <strong>1024x768 matrix</strong> into two smaller matrices, LoRA can reduce the number of trainable parameters from <strong>786,432 to 1,792</strong> — a <strong>99.8% reduction</strong> in computational requirements.</p><h4>Fine-tuning Granularity</h4><p>The low-rank matrices(1X1024, 1X768) are updated through gradient descent during fine-tuning, without modifying the weights of the base model. The multiplied change matrix is added to the base model weights to get the final fine-tuned model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tgmsZEhpAT-jR2sZXTFqDQ.png" /></figure><p>Fine-tuning matrices of Rank 1 (1X1024, 1X768) makes a pretty big concession in granularity. The granularity can be improved by using higher-rank matrices for fine-tuning — for example, using [2X1024, 2X768] matrics instead of [1X1024, 1X768]. <strong>Higher granularity</strong> means the model can learn more effectively, leading to <strong>improved performance</strong> and better adaptation to task-specific requirements.</p><p>The table summarizes the number of trainable parameters with LoRA fine-tuning (across varying ranks) vs full-finetuning for the Llama-3B model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ox9fXTISt3OB5-0bJl3BUg.png" /></figure><h4>What’s the trade-off?</h4><p>While LoRA provides a significant reduction in the number of trainable parameters, there’s a <strong>trade-off</strong> in the form of <strong>information loss</strong> during matrix decomposition. Since LoRA reduces the full-weight matrix into smaller components, some details can be lost in the process. However, this loss is often minimal because deep learning models are highly <strong>over-parameterized</strong> — meaning they contain more parameters than necessary for the task. To mitigate information loss, <strong>higher-rank matrices</strong> can be used, ensuring more accurate approximations when fine-tuning.</p><blockquote>“Over-parameterized” means that these models are really bigger than they need to be for the training data, and not all of the parameters strictly matter. There is redundancy, robustness, and resiliency within the parameters.</blockquote><h4>How do these compute gains impact the performance?</h4><p>While LoRA and QLoRA drastically reduce the computational load during fine-tuning, the key question is whether these efficiency gains come at the cost of performance. The table below compares the performance of <strong>QLoRA</strong> (an improved version of LoRA) with <strong>full fine-tuning</strong> of the <strong>LLaMA-7B</strong> model across various tasks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dIeTcFCKTYfaseBJ1jXubw.png" /></figure><p>As you can see from the table, <strong>QLoRA achieves 95–99% of the performance</strong> of full fine-tuning across a variety of tasks, including <strong>question-answering, summarization, classification, and named entity recognition</strong>. These results demonstrate that while there is a <strong>slight drop in performance</strong>, the <strong>compute gains</strong> and <strong>resource efficiency</strong> far outweigh the marginal difference in accuracy for most enterprise use cases.</p><h4>Wrapping it Up</h4><p>LoRA offers enterprises a practical and cost-effective way to scale AI without the heavy resource demands of traditional fine-tuning. If you’re looking to unlock AI’s full potential, it’s worth giving LoRA a serious look.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=288b5b04b37d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Llama3 is Awesome]]></title>
            <link>https://medium.com/@vdpappu/llama3-is-awesome-06fff853a1f7?source=rss-53779724bdd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/06fff853a1f7</guid>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[llama-3]]></category>
            <dc:creator><![CDATA[Venkata Dikshit]]></dc:creator>
            <pubDate>Wed, 14 Aug 2024 11:31:53 GMT</pubDate>
            <atom:updated>2024-08-14T12:28:10.599Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3UZKQH58BHwssneAidtKZA.jpeg" /></figure><p>Llama3 is crushing it, and guess what? It’s open source!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yk-AlsducpkiDGmCfP5gXA.png" /><figcaption>Llama3 Benchmark Stats</figcaption></figure><p>The technical report they dropped has everything you need — every trick and recipe for training those massive Foundation models. But, fair warning: it’s a 90-page beast of a document.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*r2VLlwi8PWDw6DjA.gif" /></figure><h4>Who Really Needs This 90-Page Llama3 Report?</h4><p>Alright, let’s be honest — most of us aren’t exactly spending our days building Frontier models (and if you are, seriously, we should be friends). But even if you’re not in that elite club, this report is still packed with insights for the rest of us. It is one of the most detailed out there on Frontier Model training, covering pretty much everything you’d want to know about the process. It’s got something for everyone working on these models, no matter where you are in the stack. Whether you’re into data collection, training, evaluations, or even the nitty-gritty stuff like network infrastructure and Cuda Kernel tweaks, this report has you covered. They’ve also dug into the common errors and hiccups you might hit along the way and how Meta’s integrating Vision and speech into Llama3.</p><p>And here’s the kicker: they’ve spelt out the whole recipe for training Large Frontier Models — so if you’ve got a <a href="https://engineering.fb.com/2024/03/12/data-center-engineering/building-metas-genai-infrastructure/">24K H100 cluster</a> lying around, you’re good to go (pun totally intended).</p><p>Don’t worry, the report isn’t just for building Large Frontier Models — it’s also packed with practical tips on data collection and post-training alignment strategies, which are super handy if you’re working on fine-tuning models for specific tasks</p><h4>What is this post about?</h4><p>As someone with a deep interest in Language Models and having spent some time training models, certain aspects of Llama3 really stood out to me. This post pulls together the non-trivial pieces of the LLM training process — especially around Data Collection, Pre-training, and Post-training. <br>Now, most of us aren’t going to be training models of this scale (though, never say never), but the hacks in the report can be incredibly useful for fine-tuning smaller models for specific domains or tasks. Plus, the insights on data collection could level up how you prompt Frontier Models. In a nutshell, this post dives into some of the finer details of Llama3’s data collection, training, and alignment processes.</p><h3>Pre-training</h3><h4>Data</h4><ul><li>Llama3 pulls <strong>much of its data straight from the web</strong>, but not all data is created equal. To get the best results, they found that plain text — free of markdown formatting — works better since markdowns are shown to negatively impact the model performance</li><li>Llama3’s team goes through a serious <strong>deduplication process</strong> at multiple levels: URL, document, and line. This helps strip out the redundant web boilerplate (we all love to hate) — think navigation menus and cookie warnings — plus it cuts down on repeated high-quality text that could mess with the model’s learning process.</li><li><strong>Heuristic filtering — </strong>Running KL divergence on token distribution to weed out documents with too many outlier tokens that don’t fit the training corpus. This is crucial for a general-purpose model to ensure its responses are contextually accurate</li><li><strong>Model-based quality filtering — </strong>DistilRoberta scorer trained on web data annotated by Llama2 for evaluating the data quality.</li><li><strong>Code and Reasoning Data</strong> — DistilledRoberta again. Since code and math have a different token distribution compared to natural language, they use domain-specific HTML extraction, custom text features, and more heuristics to get the filtering right.</li></ul><h4>Data Mix for Model Training</h4><ul><li>Getting the right mix of data sources is crucial for building a high-quality Language Model. As benchmarks evolve, Foundation Model creators are zeroing in on the optimal data combinations to boost performance on evaluation metrics. And as these benchmarks continue to mature, teams will keep refining their approach to find the best data mix for hitting those performance targets.</li><li><strong>Scaling Laws</strong> — Rather than relying on heuristics, the team applied scaling laws to figure out the best data mix. They started by training smaller models on a candidate data mix and then predicted how a larger model would perform with that same mix.</li><li><strong>Annealing Data — </strong>Annealing is a technique used to enhance the performance of pre-trained models by continuously training them on small batches of high-quality data. The process involves upsampling these high-quality data sources during the final steps of an epoch while gradually reducing the learning rate to zero. This approach has proven to be effective, particularly in smaller models like Llama3 8B, where the impact is even more noticeable compared to the larger models.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*4MjI51R5nzQA4eBD8smIFA.png" /><figcaption>Llama3 Pre-training Data Mix</figcaption></figure><h4><strong>Key takeaways</strong></h4><ul><li><strong>Data Distribution</strong>: Reliable model performance hinges on how well the data is distributed. Llama3’s pre-training data mix is diverse, covering natural language, code, and mathematical reasoning. This mixture ensures the model develops a broad set of foundational skills.</li><li><strong>Diverse Data Exposure</strong>: Exposing the model to varied data distributions during pre-training is like teaching it language, logic, reasoning, and interpretation all at once. These foundational capabilities set the stage for the model to excel in downstream tasks like evaluation benchmarks and domain adaptation.</li><li><strong>Math, Reasoning, and Coding</strong>: These three together make up 42% of the data mix — a choice supported by solid evidence showing that math and coding data boost the model’s reasoning ability, even on tasks that aren’t directly related to code or math (<a href="https://arxiv.org/html/2405.20535v1">ref1</a>, <a href="https://www.reddit.com/r/singularity/comments/13gh7ik/large_language_models_trained_on_code_reason/">ref2</a>). This is crucial for practical applications of Frontier models, especially when multi-step reasoning (<a href="https://arxiv.org/pdf/2205.11916">let’s think step-by-step</a>), function-calling, and agentic behaviour are required.</li><li><strong>Non-English Corpus</strong>: With only 8% of the data in non-English languages, Llama3 will need significant fine-tuning — both before and after training — for any new language adoption.</li></ul><h4>Model Architecture &amp; Training</h4><p>Llama3’s architecture doesn’t stray far from its predecessors, Llama and Llama2 — it still relies on the standard dense transformer architecture. The real performance boosts come from the improved data quality, diversity, and a significant increase in training scale. For context, Llama2 was trained on 2 trillion tokens, while Llama3 takes it up a notch with 15.6 trillion tokens — a massive 7x increase. Along with that, the number of training parameters has jumped from 70 billion in Llama2 to 405 billion in Llama3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*_uSBbeJ3OdyecxJ5kd0RNw.png" /></figure><p>Llama3 405B is optimized for its size and compute ratio. Still, interestingly, smaller models trained longer than the compute-optimal duration outperformed those trained to be compute-optimal under the same inference budgets, indicating there’s still room for improvement.</p><p>One notable upgrade is the improved tokenizer, which enhances the compression rates on English data — from 3.17 to 3.94 characters per token. This means the model can process more text with the same amount of training compute. To illustrate:</p><p><strong>Old Tokenizer:</strong></p><ul><li>Phrase: “artificial intelligence”</li><li>Tokens: “arti” (4 chars), “ficial” (6 chars), “intelligence” (12 chars)</li><li>Total characters per token: (4 + 6 + 12) / 3 = 7.33 characters per token</li></ul><p><strong>New Tokenizer:</strong></p><ul><li>Phrase: “artificial intelligence”</li><li>Tokens: “artificial” (10 chars), “intelligence” (12 chars)</li><li>Total characters per token: (10 + 12) / 2 = 11 characters per token</li></ul><h4>Key takeaways</h4><ul><li><strong>Dense Transformers vs. Mixture-of-Experts</strong>: The paper settles the score — Llama3 sticks with Dense transformers, simplifying both the training and inference pipelines.</li><li><strong>Scaling Laws</strong>: While scaling laws generally predict pre-training performance based on the compute budget, Llama3’s experience shows they can sometimes underestimate the compute-optimal performance, as seen with the Llama3 7B model.</li><li><strong>Incremental Batch Sizing</strong>: This technique offers several benefits for training stability:<br>- Frequent updates in the early stages lead to faster learning.<br>- Smaller batches early on introduce noise to gradient updates, acting as a regularizer.<br>- Larger batches in the later stages help achieve faster convergence.</li><li><strong>Gradual Increase in Context Length</strong>: Gradually expanding context length during training is efficient for several reasons:<br>- It lowers the overall compute load, allowing for quicker iterations.<br>- Training incrementally ensures the model performs well across different context lengths, not just the longer ones. Skipping this step risks overfitting to longer contexts, slower convergence, and less frequent updates.</li></ul><h3>Post-training</h3><p>Post-training alignment is crucial for steering the model towards the desired behaviour in various downstream tasks. Essentially, Llama3 sticks to the standard post-training formula: Supervised finetuning (SFT) followed by Direct Preference Optimization (DPO). Additionally, a Reward model is trained to rate the model-generated data (synthetic data for training) for human preferences. <br>The complete training cycle involves several rounds of pre-training, with each round varying in data quality, diversity, or both.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C1xFjrjQIBTKzMegsmdh5A.png" /><figcaption>Llama3 Post-Training Alignment Workflow</figcaption></figure><p>The workflow above illustrates the Post-training and alignment process as detailed in the Llama3 report. This process is multi-step and iterative, with multiple models, each fine-tuned with a specific objective and data mix.</p><h4>Reward Model Training</h4><p>The reward model is trained on human preferences, specifically evaluating the prompt responses generated by two different model checkpoints. The goal is to optimize the reward model to rank these responses, providing an unnormalized preference score for each one. Annotators also step in to edit the preferred response, refining the alignment for certain prompts. As a result, each sample ends up with two or three responses — edited, chosen, and rejected. (workflow <em>ref: 1</em>)<br>Order of Human Preference:<strong> </strong><em>edited&gt;chosen&gt;rejected</em></p><pre><strong>Input Prompt:</strong><br>Explain the process of photosynthesis<br><br><strong>Response A:</strong><br>Photosynthesis is the process by which green plants, algae, and some bacteria convert light energy, usually from the sun, into chemical energy stored in glucose. This process occurs in the chloroplasts of plant cells, where chlorophyll captures light energy. Water (H₂O) and carbon dioxide (CO₂) are used as raw materials, and oxygen (O₂) is released as a byproduct. The overall equation is: 6CO₂ + 6H₂O + light energy → C₆H₁₂O₆ + 6O₂.<br><br><strong>Response B:</strong><br>Photosynthesis is a process that plants use to convert sunlight into energy. The sunlight is absorbed by chlorophyll in the plant cells, which then uses it to turn carbon dioxide from the air and water from the soil into glucose and oxygen. The glucose is used by the plant as energy, and oxygen is released as a waste product.<br><br><strong>Edited Response (A):</strong><br>Photosynthesis is the process by which green plants, algae, and some bacteria convert light energy, typically from the sun, into chemical energy stored in glucose. This transformation occurs in the chloroplasts of plant cells, where chlorophyll captures light energy. Water (H₂O) and carbon dioxide (CO₂) are absorbed and converted into glucose (C₆H₁₂O₆) and oxygen (O₂) as a byproduct. The overall reaction can be summarized by the equation: 6CO₂ + 6H₂O + light energy → C₆H₁₂O₆ + 6O₂. This glucose serves as a vital source of energy for growth and other essential functions in plants.<br><br>(Shuffle the responses to ensure that the model does not rely on the order to determine quality.)<br><br><strong>Final Prompt: Prompt+shuffled responses</strong><br>Explain the process of photosynthesis. Response 1: Photosynthesis is a process that plants use to convert sunlight into energy. The sunlight is absorbed by chlorophyll in the plant cells, which then uses it to turn carbon dioxide from the air and water from the soil into glucose and oxygen. The glucose is used by the plant as energy, and oxygen is released as a waste product. Response 2: Photosynthesis is the process by which green plants, algae, and some bacteria convert light energy, typically from the sun, into chemical energy stored in glucose. This transformation occurs in the chloroplasts of plant cells, where chlorophyll captures light energy. Water (H₂O) and carbon dioxide (CO₂) are absorbed and converted into glucose (C₆H₁₂O₆) and oxygen (O₂) as a byproduct. The overall reaction can be summarized by the equation: 6CO₂ + 6H₂O + light energy → C₆H₁₂O₆ + 6O₂. This glucose serves as a vital source of energy for growth and other essential functions in plants. Response 3: Photosynthesis is the process by which green plants, algae, and some bacteria convert light energy, usually from the sun, into chemical energy stored in glucose. This process occurs in the chloroplasts of plant cells, where chlorophyll captures light energy. Water (H₂O) and carbon dioxide (CO₂) are used as raw materials, and oxygen (O₂) is released as a byproduct. The overall equation is: 6CO₂ + 6H₂O + light energy → C₆H₁₂O₆ + 6O₂.</pre><p>The reward model is trained with various data mixes and alignment strategies, allowing it to develop strengths in different capabilities, such as code expertise, while also improving diversity in areas like helpfulness and safety. The model is trained using a multi-class ranking objective (edited, chosen, rejected), ensuring that the edited (or chosen) response consistently scores higher than the rejected one.</p><h4>Supervised Finetuning</h4><p>The pre-trained language model is fine-tuned using a standard cross-entropy loss applied to the target tokens (<em>ref: 2</em>). The following data sources are leveraged during the SFT step:<br>- <strong>Human-Annotated Prompts with Rejection-Sampled Responses:</strong> These prompts come from a collection of human annotations. Rejection sampling is employed, where the preference scores generated by the latest reward model are used to evaluate the responses created by the most recent aligned checkpoint. (<em>ref: 3</em>)<br>- <strong>Synthetic Data for Specific Capabilities:</strong> This data targets specific capabilities such as coding and language translation. Capability-specific models are trained by branching off from the main pre-training run and continuing the process on tokens relevant to those specific capabilities. (<em>ref: 4</em>)<br>- <strong>Limited Human-Curated Data</strong>: This data is used to fine-tune and adjust the model’s behaviour, ensuring it aligns with desired outcomes.</p><h4>Direct Preference Optimization</h4><p>The SFT’ed model is further refined for human alignment through Direct Preference Optimization (DPO). This process uses the most recent batches of preference data, collected from the best-performing model in the previous alignment rounds. Through this approach, DPO ensures that the training data aligns more closely with the distribution of the policy model being optimized in each round.</p><h4>Model Averaging &amp; Iterative Rounds</h4><p>The final model’s weights are averaged from models generated using different versions of data and hyperparameters at each stage. <br>This method is applied across six rounds, with each iteration enhancing data quality, thereby boosting the performance of the SFT models and aligning them more closely with various capabilities and human preferences.</p><h4>Key Takeaways from the Post-training process</h4><ul><li>The entire alignment process is iterative, with each round building on the previous one to improve training data quality, which in turn enhances model performance.</li><li>While traditional DPO-based fine-tuning doesn’t require a reward model, Llama3 incorporates one to generate and refine preference data. This significantly boosts the quality and scale of data collection, offering a promising direction for future research in synthetic data generation using LLMs.</li><li>Llama3’s shift from PPO (used in Llama2) to DPO effectively settles the debate between these two methods. Although PPO has its merits (<a href="https://cdn.openai.com/papers/gpt-4-system-card.pdf">GPT 4 uses PPO</a>), the scalability of DPO in supporting Llama3 405B model makes it the preferred choice for researchers and organizations aiming to simplify the post-training process.</li><li>Introducing capability-specific datasets plays a crucial role in boosting downstream performance on benchmarks and real-world applications. Llama3 is fine-tuned for various capabilities, including coding, multilinguality, math and reasoning, long context, tool use, factuality, and steerability.</li><li>Different data collection and transformation strategies are employed for each capability that Llama3 is fine-tuned for. While this post doesn’t dive into the specifics, practitioners are encouraged to refer to the Llama3 technical report for detailed insights into these processes.</li></ul><h3>Parting Thoughts</h3><p>If the insights shared in this post pique your interest, I highly recommend diving into the Llama3 technical report. It’s packed with valuable information and has something for everyone exploring opportunities with large language models. And if you’re working on any interesting use cases or have ideas that could benefit from LLMs, I’m all ears — feel free to reach out! I’d love to dive into a discussion and explore the possibilities together.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=06fff853a1f7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Emergent Abilities in Large Language Models]]></title>
            <link>https://medium.com/@vdpappu/emergent-abilities-in-large-language-models-458e837e4a35?source=rss-53779724bdd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/458e837e4a35</guid>
            <dc:creator><![CDATA[Venkata Dikshit]]></dc:creator>
            <pubDate>Fri, 09 Jun 2023 01:20:54 GMT</pubDate>
            <atom:updated>2023-06-09T01:28:14.078Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VMvw8wu4k3A_98wkwK5Ddw.png" /></figure><p>Language models, particularly those in the GPT family, have experienced a fascinating evolution over the past six years. This progression is evident in how these models have been evaluated and benchmarked, shifting from using standard benchmark datasets to incorporating additional data sources for assessing capabilities not covered in traditional benchmarks. With GPT-4, OpenAI has introduced a <a href="https://ai.facebook.com/blog/system-cards-a-new-resource-for-understanding-how-ai-systems-work/">System Card</a> that outlines safety challenges, model limitations, capabilities, and potential implications users should be mindful of. Although these considerations apply to all generative models, the GPT-4 System Card serves as a valuable reference for evaluating the safety, addressing challenges, and managing unintended consequences arising from the models’ capabilities and limitations.</p><p>A key concern that stood out to me in the System Card was the emergent behaviour of these models. So, in this blog post, I’m going to break down what emergent behaviour in foundation models is all about, and what it means for app developers and organizations that use large foundation models in their products or organizational functions.</p><h4>What is Emergent Behavior?</h4><p>Emergent Behavior refers to unexpected patterns or behaviours that arise from the complex interactions within an AI model, rather than being explicitly programmed by the developers. Emergent behaviour can lead to novel outputs or insights, but it does not imply that the AI system has consciousness or human-like intelligence.</p><p>Let’s just be clear, Emergent Behavior is not AGI or Sentience or Singularity. Why? That’s beyond the scope of this post, but <a href="https://www.turing.ac.uk/events/dangers-stochastic-parrots">this page</a> on Stochastic Parrots should give a sense of why it is not. Simply put, emergent behaviour represents models’ ability to infer and represent properties of the agent that produced the data by just having access to the text produced by human agents, with no direct evidence of the internal states of the agents that produced them.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FN5c2X8vhfBE%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DN5c2X8vhfBE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FN5c2X8vhfBE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/5241a6bd7f6b318078181462da13689c/href">https://medium.com/media/5241a6bd7f6b318078181462da13689c/href</a></iframe><p>Working at <a href="https://www.solarwinds.com/">SolarWinds</a>, I couldn’t stop myself from drawing an analogy from the Observability world. If observability is the ability to infer the internal states or conditions of a system based on its external outputs or behaviours, then emergent behaviour in foundational models can be seen as their ability to simulate a person’s behaviour using only the text generated by that person, without direct knowledge of the individual’s thoughts, emotions, or other underlying factors.</p><blockquote>It’s like I binge-read Taleb, chatted with his pals, and suddenly, I’m a mini-Taleb! Hilarious, isn’t it? Well, I wasn’t trained or told to be Taleb, but here I am, channeling his vibes!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*k_cSXMkUmK2zS_zTRs-ypQ.png" /></figure><h4>Evidence of the Emergent Behaviors in Foundation Models</h4><p><strong>Fun (or scary?) fact — </strong>Alignment Research Center (ARC), which tested GPT-4 for safety and alignment tested for its ability to carry out actions to autonomously replicate and gather resources — a risk that, while speculative, may become possible with sufficiently advanced AI systems — with the conclusion that the current model is probably not yet capable of autonomously doing so.</p><p>Setting aside the checks and balances of GPT-4 testing, one might wonder: Is there evidence of emergent behaviour in Large Language Models (LLMs)? The answer is yes. The study of emergent behaviour has been a focus of research for decades now, and evidence of emergent behaviours in LLMs has been observed as early as the introduction of GPT-2.</p><p>Frederic Besse, a Research Engineer from DeepMind <a href="https://www.engraved.blog/">managed to simulate an entire Linux environment within ChatGPT</a> (running on GPT 3.5). Few interesting takeaways:</p><ul><li>GPT 3.5 can assume the role of a Linux machine and respond to “Linux command” prompts</li><li>It pretended to be browsing <a href="https://chat.openai.com/chat">https://chat.openai.com/chat</a> and knows that it is accessing an LLM like itself and that it can ask questions and get responses</li><li>Finally, ask the bot hosted at <a href="https://chat.openai.com/chat">https://chat.openai.com/chat</a> to pretend like a Linux terminal</li></ul><p>So, in a nutshell, we have a Linux VM inside a ChatBot that is accessing a hosted ChatBot and asking it to pretend like a Linux VM</p><p>Could this behaviour be merely a result of GPT-3 functioning as a Stochastic Parrot? The simulation of a virtual machine could potentially be a byproduct of its training on a vast corpus of text data, which may have included descriptions or transcripts of interactions within Linux environments. It has learned the patterns associated with such interactions and is now capable of generating text that mirrors these patterns when presented with appropriate prompts. The noteworthy aspect here is its capacity to do so in a context-sensitive manner, generating suitable responses to a diverse array of prompts, even without having been exposed to similar data sets during training. This represents a significant advancement in the evolution of AI systems</p><p>Sam has an answer to this Dilemma</p><h3>Sam Altman on Twitter: &quot;i am a stochastic parrot, and so r u / Twitter&quot;</h3><p>i am a stochastic parrot, and so r u</p><p>The Linux VM simulation is just one of the thought-provoking examples of Emergent behaviour. Please check the References section on some of the work done across academia and industry to understand the Emergent Behavior of LLMs.</p><h4>What “Emergence” Means for Enterprises and app developers</h4><p>The emergent capabilities of LLMs come into play in many ways. In some instances, they can replace traditional fine-tuning tasks and transform them into a few-shot learning problem where context can be provided as a simple prompt. This process cuts down on extensive training times and resources, making it an attractive alternative to traditional methods.</p><p>While this is not a “one-size-fits-all” solution, Machine Learning Engineers should do a sanity check to ascertain if few-shot learning is suitable for their needs before deciding to extensively fine-tune the LLMs</p><p>A not-so-exhaustive checklist or thumb rule to understand where Emergent Behavior can help:</p><p><strong>Organizations can leverage the Emergent behaviour of the models if:</strong></p><ul><li>Model size or computational resources are not significant constraints.</li><li>You have limited access to task-specific labelled data, or acquiring such data is costly/difficult.</li><li>The desired output is more open-ended, and diverse, or requires a broader understanding of language than might be achieved through fine-tuning alone.</li></ul><p>In my view, many organizational use cases hinge on fundamental capabilities such as text understanding, summarization, and extracting action items. It’s noteworthy that these capabilities are often emergent abilities in Large Language Models (LLMs).</p><h4>Future of Emergent Behavior</h4><p>Predicting the evolution of emergent behaviour in future Large Language Models (LLMs) is challenging. However, there are optimistic forecasts <a href="https://arxiv.org/abs/2303.12712">suggesting that emergent behaviour could be a significant milestone towards Artificial General Intelligence (AGI)</a>. Conversely, some argue that <a href="https://arxiv.org/abs/2304.15004">emergent behaviour is nothing more than a mirage</a>. Despite these differing views, enterprises and application developers continue to leverage the emergent capabilities of LLMs. These capabilities are increasingly being used as a substitute for task-specific fine-tuning in numerous language applications.</p><p>I am personally excited about some of the more practical applications of emergent behaviours.</p><ul><li><strong>Advanced Conversational Agents</strong> — Chatbots will be able to handle a wider range of inquiries, understand the context better, and provide more useful and relevant responses</li><li><strong>Personalized Learning</strong> — language model will be able to adjust its explanations to the user’s level of understanding, or suggest learning resources based on what it understands about the user’s knowledge and interests. <a href="https://www.khanacademy.org/khan-labs">Khanmigo</a> is already doing this.</li><li><strong>Smart Search Engines — </strong>interpreting ambiguous queries, improved and more frequent answers instead of page links to relevant pages</li><li><strong>Productivity Tools / Improved Content Creation and Editin</strong>g — everything above in an enterprise setup</li></ul><p>While the capabilities we’ve discussed are not exhaustive, they provide a glimpse into the potential of large language models like GPT-4. As these models continue to evolve, we can expect to see a proliferation of even more sophisticated emergent abilities in the days to come.</p><h4>Wrapping Up</h4><p>The hype around Large Language Models such as GPT-4 cannot be separated from their emergent behaviours. Whether these behaviours are simply the result of stochastic learning or signify a genuine milestone towards Artificial General Intelligence remains a topic of ongoing debate. As the Generative AI landscape evolves, it becomes increasingly critical for organizations and app developers to explore and leverage these emergent capabilities.</p><h4>References:</h4><p><a href="https://www.reddit.com/r/singularity/comments/12gwxsh/gpt_emergent_behavior_and_where_we_are_headed/">https://www.reddit.com/r/singularity/comments/12gwxsh/gpt_emergent_behavior_and_where_we_are_headed/</a></p><p><a href="https://www.assemblyai.com/blog/emergent-abilities-of-large-language-models/">https://www.assemblyai.com/blog/emergent-abilities-of-large-language-models/</a></p><p><a href="https://hai.stanford.edu/news/examining-emergent-abilities-large-language-models">https://hai.stanford.edu/news/examining-emergent-abilities-large-language-models</a></p><p><a href="https://arxiv.org/pdf/2302.10329.pdf">https://arxiv.org/pdf/2302.10329.pdf</a></p><p><a href="https://arxiv.org/pdf/2212.01681.pdf">https://arxiv.org/pdf/2212.01681.pdf</a></p><p><a href="https://link.springer.com/chapter/10.1007/978-3-030-86144-5_3">https://link.springer.com/chapter/10.1007/978-3-030-86144-5_3</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=458e837e4a35" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From GPT to GPT-4: Tracing the Transformative Journey of GPT]]></title>
            <link>https://medium.com/@vdpappu/from-gpt-to-gpt-4-tracing-the-transformative-journey-of-gpt-c3fb0407fd31?source=rss-53779724bdd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3fb0407fd31</guid>
            <category><![CDATA[agi]]></category>
            <category><![CDATA[gpt-4]]></category>
            <category><![CDATA[language-model]]></category>
            <category><![CDATA[generative-ai]]></category>
            <dc:creator><![CDATA[Venkata Dikshit]]></dc:creator>
            <pubDate>Sun, 23 Apr 2023 00:35:47 GMT</pubDate>
            <atom:updated>2023-04-23T00:35:47.470Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9c1sL4Y8BtpX7xgmH8Pa-Q.jpeg" /></figure><p>As an ML practitioner, I have witnessed the evolution of GPT over the past five years. GPT marked an intriguing paradigm shift when it was first introduced. Until then, the debate about whether unsupervised pre-training could enhance the performance of supervised NLU tasks remained unresolved. GPT was significant not only because it made a strong case for unsupervised pre-training but also because it pushed the state-of-the-art scores for 9 of the 12 datasets used in its evaluation. Looking back, GPT offered a glimpse of the potential that could be unlocked through unsupervised pretraining in the realm of natural language processing.</p><p>Back then, something else happened too:</p><p><a href="https://youtube.com/shorts/955PcO2kS_o?feature=share">CEO Of OpenAI Was LAUGHED at</a></p><p>In this post, we will explore the progression of the GPT series by examining each iteration in comparison to its predecessor, ultimately showcasing how it has become one of the most widely used and discussed trends in the history of Artificial Intelligence.</p><h4>GPT to GPT-2 — Zero-shot learning becomes mainstream</h4><ul><li><strong>Model Size:</strong> 117 million parameters vs. 1.5 billion parameters</li><li><strong>Training Dataset:</strong> BooksCorpus dataset (~4–5 GB) vs. WebText (~40 GB)</li><li><strong>Decoder Layers:</strong> 12 vs. 48 (in GPT-2 extra-large model)</li></ul><p>While GPT was a significant proof of concept and showed promise, it was GPT-2 that truly showcased the generalization capabilities of Language Models.</p><ul><li>Prompt engineering, as we know it today, took off in the form of zero-shot learning capabilities exhibited by GPT-2.</li><li>GPT-2 is able to generate coherent text and provide correct responses for NLP tasks like text completion, machine translation, summarization, Q&amp;A, etc.</li></ul><p>While it is evident that increasing model size, training data, and the number of layers have contributed to the improvements, OpenAI has incorporated a host of other changes:</p><ul><li><strong>Architectural improvements:</strong> Modified initialization, layer normalization, and positional encoding schemes.</li><li><strong>Preprocessing and tokenization:</strong> Byte pair encoding (BPE) allowed GPT-2 to better handle a diverse range of text inputs.</li><li><strong>Training techniques:</strong> Improved training processes and optimizations for better convergence.</li></ul><p>The improvements due to these changes are evident because GPT-2 (small), which has the same number of parameters as GPT, has shown significant performance gains that could be attributed to these changes.</p><p>At <a href="http://etherlabs.io/">Ether Labs</a> (acquired by Atlassian), while working on some of the NLP tasks, GPT was a ray of hope for the capabilities it demonstrated. Unsupervised fine-tuning on a next-word prediction task with our custom data, and using the resulting model for semantic similarity tasks, was an Aha moment for our team.</p><p>Back in 2021, while working on a multi-modal NLP solution, tackling text summarization proved a tough challenge, especially due to the lack of labelled data. We used GPT-2 and achieved convincing results with relatively low effort. Although the initial outcomes included occasional gibberish text, fine-tuning the parameters and making prompt adjustments significantly improved the results. I must admit that, at the time, I never anticipated that prompt engineering would become such a crucial factor in the widespread adoption of large language models.</p><h4>GPT-2 to GPT-3 — Mastering zero-shot, few-shot and in-context learning</h4><p>In addition to perfecting text generation in response to prompts, GPT-3 has shed light on the social, ethical, and environmental implications of powerful language models. It highlights the potential for misuse, emphasizing the need for caution, awareness, and responsible deployment to address these challenges and ensure the safe advancement of AI technologies.</p><ul><li><strong>Model Size:</strong> 1.5 billion parameters vs. 175 billion parameters</li><li><strong>Training Dataset:</strong> WebText (~40 GB) vs. Common Crawl, web text, and other sources (~400 GB)</li><li><strong>Decoder Layers:</strong> 48 vs. 96 (respective extra-large models)</li></ul><p>While GPT-3 does incorporate algorithm and training optimizations such as sparse attention, layer norm positioning, and initialization, it’s important to recognize that the primary driver behind its enhanced performance lies in the increase in scale, specifically model size, the number of decoder layers, and training data. Although these additional tweaks contribute to its overall performance improvements, their role is relatively minor. Furthermore, the evaluation of GPT-3 using a more diverse set of benchmarks showcases its broader range of capabilities as compared to its predecessors, solidifying its position as a highly versatile language model.</p><p>In my opinion, the introduction of few-shot learning and enhanced in-context learning were significant advancements in GPT-3’s capabilities, showcasing the future potential of large language models.</p><h4>GPT-3 to GPT-4 — Sparks of AGI</h4><p>Well, I couldn’t summarize this transition better. So are the OpenAI folks. Unlike the predecessors, the GPT-4 paper has no title and was just called the Technical Report. Does that mean anything? There is a lot:</p><ul><li>GPT-4 is multimodal and can accept image and text inputs</li><li>Has the ability to reason which was not the case with its predecessors</li><li>Evaluated on professional and academic exams, often beating most candidates all while breaking the SOTA numbers of standard evaluation benchmarks</li><li>Trained using insanely large volumes of data and compute resources — no official numbers posted</li><li>Beyond Language, GPT-4 can solve novel and difficult tasks that span mathematics, coding, vision, medicine, law, psychology and more, without needing any special prompting.</li><li>OpenAI spent way more time on the post-training alignment process to make the model behave more predictable on a wide range of tasks. In other words, OpenAI has spent more time caging the beast than building the beast itself</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9SzytorstjdNebGZV4qLLw.png" /></figure><p><strong>Limitations</strong></p><ul><li>Despite its capabilities, GPT-4 has similar limitations to earlier GPT models: it is not fully reliable (e.g. can suffer from “hallucinations”), has a limited context window, and does not learn from experience.</li><li>GPT-4 occasionally fails to execute tasks that require planning and breaking the task into multiple steps before responding back. This could be attributed to the GPT’s feed-forward auto-regressive architecture.</li></ul><h4>Conclusion and looking ahead</h4><p>As we reflect on the evolution of GPT models, it’s clear that their development has had a significant impact on the field of AI, with each iteration paving the way for new advancements and applications. Quoting Sam Altman, the CEO of OpenAI, and Max Tegmark, a renowned author, we can gain insight into the future of AI:</p><p><strong>[Sam Altman]</strong> “GPT-4 is a system that we’ll look back at and say was a very early AI. It’s slow, it’s buggy, and it doesn’t do a lot of things very well, but neither did the very earliest computers. Still, they pointed a path to something that is going to be really important in our lives.”</p><p><strong>[Max Tegmark]</strong> “This is a baby AI, and there are going to be other systems from the same or other companies that will be way more powerful. They are going to take all of these ideas from these babies, and before we know it, we’re going to be like those last Neanderthals who were pretty disappointed when they realized that they were getting replaced.”</p><p>Altman’s statement highlights that, despite GPT-4’s limitations and shortcomings, it serves as an important step toward the development of more advanced AI systems that will play an increasingly important role in our lives. On the other hand, Tegmark’s cautionary reminder emphasizes the need for responsible development and consideration of the potential consequences AI may have on society.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3fb0407fd31" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GPT-3: Whats/Hows/Where]]></title>
            <link>https://medium.com/analytics-vidhya/gpt-3-whats-hows-where-bdc15d204867?source=rss-53779724bdd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdc15d204867</guid>
            <category><![CDATA[gpt-3]]></category>
            <category><![CDATA[gpt]]></category>
            <category><![CDATA[language-model]]></category>
            <category><![CDATA[artificial-general-intell]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Venkata Dikshit]]></dc:creator>
            <pubDate>Tue, 28 Jul 2020 04:11:56 GMT</pubDate>
            <atom:updated>2020-08-09T13:35:28.718Z</atom:updated>
            <content:encoded><![CDATA[<h3>GPT-3: Whats, Hows &amp; The Takeaways</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*9pt5d4D7aGJqUqpra1tMzg.png" /><figcaption>GPT-3 is Massive!!</figcaption></figure><p>When I first heard about GPT-3, my first impression was that it must be GPT-2 + more compute + more data. This isn’t a bad expectation given that GPT-2 itself is GPT + more compute + more data + few smart hacks. Turns out, this is true with GPT-3 too. But, this doesn’t undermine the feat GPT-3 and its predecessors have achieved over the past 3 years. Blindly feeding in more to the Language Models isn’t beneficial after a certain limit and would attract a host of engineering/data/compliance challenges to deal with.</p><p>This post discusses the following:</p><ul><li>How GPT-3 is a commendable attempt in achieving generality in the text-based tasks and a hopeful contribution towards AGI using novel learning paradigms — <a href="https://arxiv.org/pdf/1706.03762.pdf">Transformer Architectures</a> and In-context Learning(<a href="https://arxiv.org/pdf/1703.03400.pdf">Meta-Learning</a>)</li><li>Adapting some of the best practices and cues from the literature that would come in handy for ML practitioners working on Language Modelling for practical applications</li></ul><h3>Thoughts on GPT-3</h3><p>Looking beyond the GPT nomenclature into the names of the corresponding white papers, we get a sense of how GPT models have progressed over time and their contributions compared to the predecessors.</p><ul><li><a href="https://s3-us-west-2.amazonaws.com/openai-assets/research-covers/language-unsupervised/language_understanding_paper.pdf">Improving Language Understanding</a> (GPT) — <strong>117M parameters</strong> — <strong>~400MB in size</strong></li><li><a href="https://cdn.openai.com/better-language-models/language_models_are_unsupervised_multitask_learners.pdf">Language Models are Unsupervised Multitask Learners</a> (GPT-2)— <strong>1.5B parameters </strong>—<strong> ~5GB in size</strong></li><li><a href="https://arxiv.org/pdf/2005.14165.pdf">Language Models are Few-Shot learners</a> (GPT-3) — <strong>175B parameters</strong> — ~<strong>500GB in size</strong></li></ul><p>Surprisingly (or not?), the core of the learning component remained same across all iterations — <strong>A unidirectional Language modelling objective</strong> despite the proven recent enhancements to it (for example <a href="https://arxiv.org/pdf/1810.04805.pdf">BERT</a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*yyb4yBP6M2k6JJhWI-WPlA.png" /><figcaption>Learning joint probabilities over symbols as a product of conditional probabilities</figcaption></figure><p>Quoting the architectural changes for the sake of completeness:</p><p><strong>GPT to GPT-2</strong></p><blockquote>The model largely follows the details of the OpenAI GPT model (Radford et al., 2018) with a few modifications. Layer normalization (Ba et al., 2016) was moved to the input of each sub-block, similar to a pre-activation residual network (He et al., 2016) and an additional layer normalization was added after the final selfattention block. A modified initialization which accounts for the accumulation on the residual path with model depth is used. We scale the weights of residual layers at initialization by a factor of 1/ √ N where N is the number of residual layers. The vocabulary is expanded to 50,257. We also increase the context size from 512 to 1024 tokens and a larger batchsize of 512 is used.</blockquote><p><strong>GPT-2 to GPT-3</strong></p><blockquote>Our basic pre-training approach, including model, data, and training, is similar to the process described in GPT-2, with relatively straightforward scaling up of the model size, dataset size and diversity, and length of training. Our use of in-context learning is also similar to GPT-2, but in this work we systematically explore different settings for learning within the context. We use the same model and architecture as GPT-2 [RWC+19], including the modified initialization, pre-normalization, and reversible tokenization described therein, with the exception that we use alternating dense and locally banded sparse attention patterns in the layers of the transformer, similar to the Sparse Transformer.</blockquote><p>From the usability standpoint:</p><ul><li>GPT-2 has focused on <strong>Zero-shot </strong>setting where the Language Model’s ability to perform certain tasks is tested directly after optimizing for the stated Language Modelling objective</li><li>GPT-3 has focused on more practical and scalable paradigms — <strong>One-shot</strong> and <strong>Few-shot </strong>settings along with the zero-shot. This has enabled GPT-3 to top the SOTA charts by significant margins compared to most task-specific fine-tuning models</li></ul><p>More on Meta-learning, zero-shot, few-shot learning in a separate post.</p><h4>GPT-3 and Generalization</h4><p>At high-level, task-specific learners are optimized for <strong>p(output|input) </strong>and the generalization is achieved by optimizing for <strong>p(output|input, task). </strong>Recent architectures achieve this by specifying input, output and task specifications all as a sequence of symbols. For example, a translation request can be formulated as (<em>translate to french, english text, french text) </em>and a reading comprehension task as (<em>answer the question, document, question, answer) — </em><strong>In-context learning</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cFA675tMeirJikbGwnnPoQ.png" /><figcaption>Aggregated performance of GPT-3 on 42 labelled tasks — Demonstrating its In-context learning capabilities</figcaption></figure><p>GPT-3 builds upon the recent claims that sufficiently large transformer architectures improve the text synthesis and downstream performance across multiple tasks and the evidence that log loss, which correlates well with many downstream tasks, follows a smooth trend of improvement with scale. GPT-3 hypothesized and proved that <em>Since in-context learning involves absorbing many skills and tasks within the parameters of the model, it is plausible that in-context learning abilities might show similarly strong gains with scale.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*vkq9gKPa9RyA2_BPaao7TQ.png" /><figcaption>Zero-shot, one-shot and Few-shot illustrations showing inference time behaviour of GPT-3</figcaption></figure><ul><li>During inference, the model expects a set of examples (context, sample input and the outputs) to bootstrap the model into the current problem setting</li><li>GPT-3 uses these examples to infer on the new query input without back-propagating the gradients in the process</li><li>The inference time behaviour of the model depends on the problem type</li><li>For example, On tasks that involve choosing one correct completion from several options, we provide K examples of context plus correct completion, followed by one example of context only, and compare the LM likelihood of each completion. For most tasks we compare the per-token likelihood (to normalize for length), however on a small number of datasets (ARC, OpenBookQA, and RACE) we gain additional benefit as measured on the development set by normalizing by the unconditional probability of each completion, by computing <em>P(completion|context)/P(completion|answer context)</em>, where answer context is the string “Answer: “ or “A: “ and is used to prompt that the completion should be an answer but is otherwise generic.</li></ul><h3><strong>Takeaways for ML Practitioners</strong></h3><h4><strong>For Potential GPT-3 Users</strong></h4><p>While it’s not feasible to put an extensive list of cases where GPT-3 can and cannot be used, it&#39;s worth considering these pointers while taking the call. These suggestions are based on the assumption that we are not going to get access to the GPT-3 feature vectors of the input text anytime soon unless they open-source the whole GPT-3 model.</p><ul><li>If your use case has a lot to do with free text available over the internet and/or the datasets used for GPT-3 training are related to your use cases, the use case is similar to those tasks where GPT-3 shows considerable results, you can give it a try</li><li>If your use case requires open + proprietary data and the use cases are aligned with the GPT-3 setup, the GPT-3 usage might be limited or case-specific</li><li>For the cases driven entirely by proprietary data OOTB GPT-3 might not of much practical help</li></ul><h4>For ML Engineers and hackers</h4><p>The key takeaway for me is that the core of GPT-3 being classical Language modelling objective and yet beating the SOTA charts with little/no supervision is really encouraging</p><ul><li>When you have enough data to fine-tune GPT like architectures with Language Model objectives, we can achieve phenomenal results on custom data sets</li><li>LM adaptation needs carefully babysitting the fine-tuning process and identifying unsupervised auxiliary tasks that boost the fine-tuned model performance</li><li>It enormously helps to establish the correlation between log loss and the target use cases. As observed in GPT-3 and other recent papers, log loss is correlated with most text downstream tasks — this should cover a majority of problems that we address today</li><li>For the use cases where the data is not easily accessible for human inspection, blind fine-tuning of Language Model by observing the log loss and performance on auxiliary tasks is a viable sniff test and a way to leverage the data rather settling to using the OOTB language models on restricted data. For more help on picking the auxiliary tasks and reference papers, check the attached posts (a bit dated, but should be a good starting point)</li><li>Building a reliable feature extractor is key to most text tasks where labelled data is sparse. GPT-3 and its predecessors outlines how this can be achieved. Refer to <a href="https://s3-us-west-2.amazonaws.com/openai-assets/research-covers/language-unsupervised/language_understanding_paper.pdf">GPT</a> paper for the approach and <a href="https://cdn.openai.com/better-language-models/language_models_are_unsupervised_multitask_learners.pdf">GPT-2</a>, <a href="https://arxiv.org/pdf/2005.14165.pdf">GPT-3</a> for useful hacks and improvements</li></ul><ul><li><a href="https://medium.com/ether-labs/https-medium-com-ether-labs-attention-architecture-1-60caf491fc8e">[Part-1] Which Attention(architecture) do you need?</a></li><li><a href="https://medium.com/ether-labs/part-2-which-attention-architecture-do-you-need-c327aaa771f8">[Part-2] Which Attention(architecture) do you need?</a></li></ul><h3>Conclusion</h3><p>While GPT-3 comes with its own set of limitations has a lot of scope for improvements, it’s a phenomenal feat in terms of model size, training data size and smart training strategies. While fine-tuning and handling such large scale models is not yet in the reach of most ML practitioners, the key takeaway is that GPT-3 and its predecessors reinforce the fact that the fundamental Language modelling paradigm in itself sufficient for most downstream tasks where availability of labelled dataset is a challenge.</p><p>Happy to discuss if you have any use cases that could be addressed with Language Models and fine-tuning.</p><p>Happy Learning!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdc15d204867" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/gpt-3-whats-hows-where-bdc15d204867">GPT-3: Whats/Hows/Where</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Part-2] Which Attention(architecture) do you need?]]></title>
            <link>https://medium.com/ether-labs/part-2-which-attention-architecture-do-you-need-c327aaa771f8?source=rss-53779724bdd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/c327aaa771f8</guid>
            <category><![CDATA[gpt]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[ethermeet]]></category>
            <category><![CDATA[slack]]></category>
            <category><![CDATA[bert]]></category>
            <dc:creator><![CDATA[Venkata Dikshit]]></dc:creator>
            <pubDate>Tue, 13 Aug 2019 11:31:01 GMT</pubDate>
            <atom:updated>2019-08-13T11:31:01.263Z</atom:updated>
            <content:encoded><![CDATA[<p>At <a href="http://www.etherlabs.io/">EtherLabs</a>, we build AI-first collaboration products. Checkout <a href="http://www.etherlabs.io/">EtherMeet</a>, AI-based video conferencing service for teams who use Slack.</p><figure><img alt="At EtherMeet (www.etherlabs.io), we apply advanced AI to make video conferences smarter and more relevant." src="https://cdn-images-1.medium.com/max/1024/1*uBaxAKy6fcmr5NyxlK4iVA.jpeg" /><figcaption>Attention Architectures at EtherLabs</figcaption></figure><p><a href="https://medium.com/ether-labs/https-medium-com-ether-labs-attention-architecture-1-60caf491fc8e">Part-1 of this two-part series</a> covered the GPT and BERT based architectures — upper two quadrants in [fig-1]. This post covers the architectures from the lower quadrants — XLNet, MASS and GPT-2 (yes, again) to better understand all the <a href="https://www.theguardian.com/technology/2019/feb/14/elon-musk-backed-ai-writes-convincing-news-fiction">hype around it</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T7CkvOjCe3zKTNzEGtlYXA.png" /><figcaption>[fig-1] Transformer-based models segregated by their architectural design</figcaption></figure><h3>GPT-2 and XLNet</h3><p>These two are current state-of-the-art across multiple language tasks and notorious for their data and resource consumption — <a href="https://blog.floydhub.com/gpt2/">[1]</a>, <a href="https://www.reddit.com/r/MachineLearning/comments/c59ikz/r_it_costs_245000_to_train_the_xlnet_model512_tpu/">[2]</a>. These two architectures address some of the limitations of their predecessors — GPT and BERT respectively.</p><p>Before we delve into the details of these architectures, we need to be aware of some of the technical terms:</p><p><strong>Auto-regression Language modeling — </strong>A classical language modeling approach, where the objective is to maximize the likelihood of a sequence of words under the forward autoregressive factorization. GPT is based on left-to-right auto-regression factorization</p><p><strong>Auto-encoder Language modeling — </strong>Aims to reconstruct the input sequence of text and in the process learning the likelihood of word sequences. BERT is based on a variant of auto-encoder called Denoising auto-encoder where the sequence is reconstructed from the corrupted version of the actual input sequence. BERT uses a modified AE approach that predicts only the masked words instead of the entire sequence</p><p><strong>Permutation Language modeling — </strong>A variant of auto-regression approach where instead of using only the right-to-left and/or right-to-left factorization, we use all combination of word sequences possible ie. for a sequence x of length T, there are T! different orders to perform a valid autoregressive factorization. This is an efficient way of encoding deep bi-directional representations of token sequences.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LsPeekhQmG_4dGfn8UnZ_Q.png" /><figcaption>[fig-2] Using different factorization sequences as mentioned in the <a href="https://arxiv.org/pdf/1906.08237.pdf">XLNet paper</a></figcaption></figure><p>For example, consider a sequence of length 4 and predicting the token x3 given the same input sequence x but under different factorization orders. [fig-2] shows the combinations in which representations of x3 can be learnt</p><p><strong>XLNet — </strong>Uses <a href="https://arxiv.org/pdf/1901.02860.pdf">Transformer-XL</a> based pre-training paradigm that addresses the following limitations of AR and AE based approaches:</p><p><strong>Independence Assumption</strong> — BERT inherently assumes conditional independence between all the masked tokens as they are separately reconstructed thereby limiting its learning capabilities. In comparison, AR-based models factorize the sequence probabilities using product rule that holds universally without such an independence assumption</p><p><strong>Input noise</strong> — The input to BERT contains artificial symbols like [MASK] that never occur in downstream tasks, which creates a pretrain-finetune discrepancy. Replacing [MASK] with original tokens as mentioned in the original paper does not solve the problem because original tokens can be only used with a small probability. In comparison, AR language modelling does not rely on any input corruption and does not suffer from this issue</p><p><strong>Context dependency — </strong>The AR representation hθ(x1:t−1) is only conditioned on the tokens up to position t (i.e. tokens to the left), while the BERT representation Hθ(x)t has access to the contextual information on both sides. As a result, the BERT objective allows the model to be pretrained to better capture the bidirectional context</p><p>XLNet brings in the best of both worlds — bi-directional capabilities of BERT and fully dependent factorization of AR models.</p><p><strong>XLNet Architecture details</strong></p><ul><li><strong>XLNet uses permutation language model</strong> — during permutation, only the factorization order is permuted and not the sequence — we use the same positional encodings of the original sequence instead of calculating them for permuted sequence. Check out section-3.5 in “<a href="https://www.reddit.com/r/learnmachinelearning/comments/9e4j4q/positional_encoding_in_transformer_model/">Attention is all you need</a>” for details on positional embeddings</li><li><strong>Target-aware representations</strong> — giving XLNet objective additional information about which position it will predict. This is achieved using the Two-Stream Self-Attention as discussed in the paper</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j7gs0Z7CI0iR9e_EeXheuA.png" /><figcaption>XLNet base Objective function with the target position</figcaption></figure><ul><li><strong>Adaptations from Transformer-XL architecture — </strong>The key adaptation from Transformer-XL is the <strong>recurrence mechanism</strong> into the proposed permutation setting and enable the model to reuse hidden states from previous segments. Suppose we have two segments taken from a long sequence s; i.e., x˜ = s1:T and x = sT +1:2T . Let z˜ and z be permutations of [1 · · · T] and [T + 1 · · · 2T] respectively. Then, based on the permutation z˜, we process the first segment and then cache the obtained content representations h˜(m) for each layer m. Then, for the next segment x, the attention update with memory can be written as:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PZfpDg8tydGlpW5M6cFKXg.png" /></figure><p>This allows caching and reusing the memory without knowing the factorization order of the previous segment. In expectation, the model learns to utilize the memory overall factorization orders of the last segment.</p><p><strong>GPT-2 — </strong>Architecturally, GPT-2 is not a major deviation from its predecessor. In the discussion to follow, we highlight some of the notable aspects of GPT-2</p><ul><li>It uses WebText as the pre-training text — a collection of all outbound Reddit links with at least three karma. The input token representations are <a href="https://www.aclweb.org/anthology/P16-1162">Byte Pair Encodings</a> which effectively interpolates between word level inputs for frequent symbol sequences and character level inputs for infrequent symbol sequences. With this approach, GPT-2 gets rid of conventional Language Modelling pre-processing steps such as lowercasing, tokenization, and out-of-vocabulary tokens which restrict the space of model-able strings. This allows GPT/GPT-2 to be evaluated on any dataset regardless of pre-processing, tokenization, or vocab size.</li><li>GPT-2 has an expanded vocab compared to GPT and is trained with a context window of 1024 instead of 512 and a larger batch size of 512 — tons of GPUs!!</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*CkqIX3cuowI6fnITng6vDQ.png" /><figcaption>[table-1] GPT-2 architecture experiments with different model sizes</figcaption></figure><ul><li>[table-1] shows models of 4 different sizes. The final GPT-2 architecture is a 48 layer transformer architecture with feature dimensions of 1600 and has ~5X more parameters compared to its predecessor</li><li>GPT-2 hasn’t reported the fine-tuning performance on various datasets instead reported the zero-shot performance on eight datasets out of which it has improved the state-of-the-art in seven tasks. This establishes the baseline for GPT-2 performance and any dataset/task fine-tuning will only improve the performance.</li><li>GPT-2 fails to address the inefficiencies of its uni-directional representations that fail to capture the full context of the text. So, the reported success of GPT-2 should be attributed to the choice of data sources and the ~1.5 B learnable parameters</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*udBO-BDqj0hy45GN" /><figcaption>Image Source: <a href="https://blog.floydhub.com/gpt2/">https://blog.floydhub.com/gpt2/</a></figcaption></figure><h3>MASS</h3><p><strong>Ma</strong>sked <strong>S</strong>equence to <strong>S</strong>equence Pre-training for Language Generation, proposes an extended version of BERT where the objective is modified to predict a series of tokens (aka. fragments) instead of predicting the random tokens as proposed in BERT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-guZp0BJ9Yfx0PWJFF5C1A.png" /><figcaption>MASS Encoder-Decoder framework</figcaption></figure><ul><li>MASS objective makes it outperform most of the current approaches in language generation tasks — by jointly training the encoder and decoder</li><li>The MASS encoder is forced to understand the meaning of unmasked tokens in the context of generating them during the decoder phase</li><li>During decoding, the unmasked tokens from the encoder are masked thereby forcing the decoder to predict the encoder masked tokens only from the encoder output instead of relying on the previous token (not part of the fragment)</li><li>MASS addresses the masked token conditional independence of BERT but fails to achieve the deep bi-directional contextuality as stated in XLNet</li></ul><h3>Conclusion</h3><p>In this two-part series, we have covered various Transformer based architectures, highlighting their architectural difference, training objects and other significant aspects. These architectures have pushed the limits of text understanding engines and fast heading towards generalized understanding and enabling faster task-specific adaptation through effective pre-training strategies. More to come on Language Models, NLP, Geometric Deep Learning, Knowledge Graphs, contextual search and recommendations. Stay tuned!!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FS5ZLrGVZ0So&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DS5ZLrGVZ0So&amp;image=http%3A%2F%2Fi.ytimg.com%2Fvi%2FS5ZLrGVZ0So%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f8d486bfb235c4348fe016cab69d6e19/href">https://medium.com/media/f8d486bfb235c4348fe016cab69d6e19/href</a></iframe><blockquote>Checkout <a href="http://www.etherlabs.io/">EtherMeet</a>, an AI-enabled video conferencing service for teams who use Slack.</blockquote><blockquote>Sign up at <a href="http://etherlabs.io/">etherlabs.io</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c327aaa771f8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ether-labs/part-2-which-attention-architecture-do-you-need-c327aaa771f8">[Part-2] Which Attention(architecture) do you need?</a> was originally published in <a href="https://medium.com/ether-labs">ETHER Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Part-1] Which Attention(architecture) do you need?]]></title>
            <link>https://medium.com/ether-labs/https-medium-com-ether-labs-attention-architecture-1-60caf491fc8e?source=rss-53779724bdd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/60caf491fc8e</guid>
            <category><![CDATA[video-conferencing]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[ethermeet]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[slack]]></category>
            <dc:creator><![CDATA[Venkata Dikshit]]></dc:creator>
            <pubDate>Mon, 05 Aug 2019 11:31:02 GMT</pubDate>
            <atom:updated>2019-08-05T11:31:02.438Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AW5Zsr9SddLeITQ9SI-Wog.png" /></figure><p>When we started working on text tasks at <a href="http://www.etherlabs.io/">Ether Labs</a>, Neural Transfer Learning on the text was still in its nascent stages and we relied on multiple training paradigms for different tasks — Summarization, text similarity, key-phrase extraction, NER etc. The source data being same, this looked redundant and we have played around with approaches to build reusable feature extractor that can be used across multiple tasks. Word/paragraph embeddings are flexible enough to address some of these tasks but their learning capabilities are no match to the deeper architectures. Task-specific Language model fine-tuning has brought in the ImageNet like fine-tuning capabilities to text and paving way for general text understanding. We were quick to adopt this approach, thanks to <a href="https://arxiv.org/pdf/1801.06146.pdf">Howard and Ruder, 2018</a>, we have achieved significant improvements across multiple tasks.</p><p>Our natural next step in adopting cutting edge learning paradigms is Transformer based architectures. The improvements are evident, and there were no second thoughts about replacing our existing Language Model. Of late, Google, Microsoft and Open AI are pushing the performance limits on <a href="https://www.nyu.edu/projects/bowman/glue.pdf">GLUE</a> tasks with their transformer-based learning paradigms. In this post and the next, we highlight the differences between recently proposed transformer-based architectures and enable NLP practitioners to choose the right architecture for their tasks.</p><h3>Introduction</h3><p>Transformer aka. self-attention architectures, proposed by <a href="https://arxiv.org/pdf/1706.03762.pdf">Vaswani et al.</a> in “<strong><em>Attention is All you need</em></strong>” is attention only architectures to draw global dependencies between input and output. This Self-attention/intra-attention mechanism works by relating different positions of a single sequence in order to compute a representation of the sequence. For a detailed explanation on transformers refer to <a href="http://jalammar.github.io/illustrated-transformer/">The Illustrated Transformer</a>, <a href="http://nlp.seas.harvard.edu/2018/04/03/attention.html">The Annotated Transformer</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T7CkvOjCe3zKTNzEGtlYXA.png" /><figcaption>[fig-1] Transformer-based models segregated by their architectural design</figcaption></figure><p>Above snapshot shows some of the recently proposed transformer-based architectures. While at their core, every architecture based on multi-headed self-attention, they are different in the following aspects:</p><ul><li>Left-to-right vs. bi-directional contexts</li><li>Pre-training tasks</li><li>Usage of auxiliary tasks</li><li>Generalization strategies adopted</li></ul><p>The models in the same quadrant are not necessarily similar in all aspects — they can be similar in the way they are different from models in other quadrants. For example, GPT-2 is architecturally close to GPT and is similar to XLNet for its emphasis on generalization. This is the best possible grouping I could think of at this point.</p><blockquote>In the literature, the <em>Left-to-right</em> context networks are called “Transformer Decoders” and <em>bi-directional </em>context networks are called “Transformer Encoder”</blockquote><h3>GPT and GPT-2</h3><p>GPT/GPT-2 architecture is a decoder only architecture where every token can attend only attend the tokens to its left in the self-attention layers. <strong><em>The pre-training</em></strong> is based on typical language modelling setup — likelihood maximum of token sequences using <a href="https://arxiv.org/pdf/1801.10198.pdf"><em>multi-layer Transformer decoder</em></a></p><blockquote>Given an unsupervised corpus of tokens U = {u1, . . . , un}, we use a standard language modeling objective to maximize the following likelihood</blockquote><p>The pre-training parameters can be adapted to the supervised tasks by feeding the inputs through the pre-trained model to obtain the final transformer block’s activation, which is then fed into an added linear output layer to predict the label. Including language modelling as an auxiliary objective to the fine-tuning helped in learning by improving generalization of supervised tasks and faster convergence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*hJDM95Pxk5sz-iW58FQ6yg.png" /><figcaption>Learning objective for supervised tasks</figcaption></figure><p>Architecturally, GPT-2 remain the same with the following modifications:</p><ul><li>Position of layer-normalization</li><li>Modified initialization</li><li>Expanded vocabulary and increased context and batch sizes</li></ul><h4>Usability</h4><p>GPT architecture is effective in featurizing longer text sequences due to its Language model training objective. This can be handy for generating paragraph/document level embeddings.</p><h4>Limitations</h4><p>GPT and GPT-2 fail to capture the full representation of a word due to its usage of left-to-right only context. This yields sub-optimal performance on the token-level tasks such as question answering where bi-directional context is required.</p><h3>BERT and MT-DNN</h3><p><strong>BERT</strong> — <strong>B</strong>idirectional <strong>E</strong>ncoder <strong>R</strong>epresentations from <strong>T</strong>ransformers has pushed the SOTA across various text tasks by addressing the limitations of GPT by going bidirectional and using two novel pre-training tasks:</p><ul><li><strong>Masked LM</strong> — Randomly mask some of the tokens from the input, and the objective is to predict the original vocabulary id of the masked word based only on its context. Masked LM has is not restricted to left-to-right context as the masked token is predicted based on all the unmasked tokens irrespective of their position in the sentence</li><li><strong>Next Sentence Prediction — </strong>A binary classifier based fine-tuning to predict whether a sentence pair can occur in a sequence. This fine-tuning helps to address NLP tasks involving two or more inputs — Question Answering, Natural Language Inference etc.</li></ul><p>Task-specific fine-tuning is same as in GPT with minor modifications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CcP0-nU6JV8HdgyvbeAWAg.png" /><figcaption>[fig-2] BERT Pre-training input for Masked LM + NSP</figcaption></figure><p><strong>MT-DNN — M</strong>ulti-<strong>T</strong>ask <strong>D</strong>eep <strong>N</strong>eural <strong>N</strong>etworks takes inspiration from BERT for pre-training and uses novel Multi-task learning approach for fine-tuning.</p><blockquote>Multi-Task Learning (MTL) is inspired by human learning activities where people often apply the knowledge learned from previous tasks to help learn a new task. For example, it is easier for a person who knows how to ski to learn skating than the one who does not. Similarly, it is useful for multiple (related) tasks to be learned jointly so that the knowledge learned in one task can benefit other tasks.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rx928AiinRDmRTPBiCJpvQ.png" /><figcaption>[fig-3] Overview of MT-DNN Learning strategy</figcaption></figure><p>[fig-3] shows the learning strategy of MT-DNN — during fine-tuning each batch uses one of the pre-selected objective functions to optimize on instead of one. The performance gains for MT-DNN come from this fine-tuning strategy which gives MT-DNN ability to use learnings from one fine-tuning task in others, unlike GPT and BERT where task-specific fine-tuning independent of other tasks. This generalized learning strategy aligns with the task agnostic learning paradigm. Please refer to this <a href="https://bair.berkeley.edu/blog/2017/07/18/learning-to-learn/">link</a> for more details</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*VK9hUMHgoGGU3qKq1gb-Ow.png" /><figcaption>Model Agnostic Meta-learning approach</figcaption></figure><p><em>MAML trains over a wide range of tasks. It trains for a representation that can be quickly adapted to a new task, via a few gradient steps. The meta-learner seeks to find an initialization that is not only useful for adapting to various problems but also can be adapted quickly (in a small number of steps) and efficiently (using only a few examples).</em></p><h4>Usability</h4><p>BERT addresses the limitations of GPT using both left-to-right and right-to-left context for learning token representations in a sentence. This makes BERT efficient for most text tasks — Q&amp;A, sentence similarity, POS tagging etc.</p><h4><strong>Limitations</strong></h4><ul><li>BERT suffers from a training-inference mismatch as the [MASK] token used during Masked LM training does not appear during inference. This is alleviated to some extent using the following strategy:</li></ul><blockquote>A downside is that we are creating a mismatch between pre-training and fine-tuning, since the [MASK] token does not appear during fine-tuning. To mitigate this, we do not always replace “masked” words with the actual [MASK] token. The training data generator chooses 15% of the token positions at random for prediction. If the i-th token is chosen, we replace the i-th token with (1) the [MASK] token 80% of the time (2) a random token 10% of the time (3) the unchanged i-th token 10% of the time. Then, Ti will be used to predict the original token with cross entropy loss.</blockquote><ul><li>One more constraint on learning capabilities of BERT is that it assumes conditional independence between the masked tokens and this limits the quality of sentence representations learnt by BERT.</li><li>BERT is not effective for encoding longer text sequence as the pre-training tasks are restricted to the sentence level tasks.</li></ul><h3>Contd.</h3><p>In Part-2, we will cover rest of the Transformer based architectures from [fig-1] — discuss how they address the limitations of GPT and BERT based approaches, the path forward for generalized text understanding and lot more.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FS5ZLrGVZ0So&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DS5ZLrGVZ0So&amp;image=http%3A%2F%2Fi.ytimg.com%2Fvi%2FS5ZLrGVZ0So%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f8d486bfb235c4348fe016cab69d6e19/href">https://medium.com/media/f8d486bfb235c4348fe016cab69d6e19/href</a></iframe><blockquote>Checkout EtherMeet, an AI-enabled video conferencing service for teams who use Slack.</blockquote><blockquote>Sign up at <a href="http://etherlabs.io/">etherlabs.io</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60caf491fc8e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ether-labs/https-medium-com-ether-labs-attention-architecture-1-60caf491fc8e">[Part-1] Which Attention(architecture) do you need?</a> was originally published in <a href="https://medium.com/ether-labs">ETHER Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[BERT for unsupervised text tasks]]></title>
            <link>https://medium.com/ether-labs/bert-for-unsupervised-text-tasks-fa6e9ce5d133?source=rss-53779724bdd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa6e9ce5d133</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[ethermeet]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[bert]]></category>
            <dc:creator><![CDATA[Venkata Dikshit]]></dc:creator>
            <pubDate>Thu, 18 Jul 2019 11:31:01 GMT</pubDate>
            <atom:updated>2019-07-18T11:31:01.331Z</atom:updated>
            <content:encoded><![CDATA[<p>This post discusses how we use BERT and similar self-attention architectures to address various text crunching tasks at <a href="https://etherlabs.io/">Ether Labs</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O3_6-5GQvlBQFYLtFDfSbA.jpeg" /></figure><p>Self-attention architectures have caught the attention of NLP practitioners in recent years, first proposed in <a href="https://arxiv.org/pdf/1706.03762.pdf">Vaswani et al</a>., where the authors have used <strong>multi-headed</strong> self-attention architecture for machine translation tasks</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BzL6kyBXsH4fzLveUaYstA.png" /><figcaption>BERT’s Attention of the word ‘It’ in one of the layers</figcaption></figure><blockquote>Multi-headed attention enhances the ability of the network by giving attention layer multiple subspace representations — each head weights are randomly initialised and after training, each set is used to project input embedding into different representation subspace</blockquote><p><strong>BERT Architecture Overview</strong></p><ul><li>BERT’s model architecture is a multi-layer bidirectional Transformer encoder based on the original implementation described in <a href="https://arxiv.org/pdf/1706.03762.pdf">Vaswani et al</a>.</li><li>Each word in BERT gets “n_layers*(num_heads*attn.vector) “ representations that capture the representation of the word in the current context</li><li>For example, in BERT base: n_layers = 12, N_heads = 12, attn.vector = dim(64)</li><li>In this case, we have 12X12X(64) representational sub-spaces for each word to leverage</li><li>This leaves us with a challenge and opportunity to leverage such rich representations unlike any other LM architectures proposed earlier</li></ul><h3>Sentence relatedness with BERT</h3><p>BERT representations can be double-edged sword gives the richness in its representations. In our experiments with BERT, we have observed that it can often be misleading with conventional similarity metrics like cosine similarity. For example, consider pair-wise cosine similarities in below case (from the BERT model fine-tuned for HR-related discussions):</p><blockquote><strong>text1:</strong> Performance appraisals are both one of the most crucial parts of a successful business, and one of the most ignored.</blockquote><blockquote><strong>text2:</strong> On the other, actual HR and business team leaders sometimes have a lackadaisical “I just do it because I have to” attitude.</blockquote><blockquote><strong>text3:</strong> If your organization still sees employee appraisals as a concept they need to showcase just so they can “fit in” with other companies who do the same thing, change is the order of the day. How can you do that in a way that everyone likes?</blockquote><blockquote>text1&lt;&gt;text2–0.613270938396454</blockquote><blockquote>text1&lt;&gt;text3–0.634544332325459</blockquote><blockquote>text2&lt;&gt;text3–0.772294402122498</blockquote><p>A metric that ranks text1&lt;&gt;text3 higher than any other pair would be desirable. How do we get there?</p><p>OOTB, BERT is pre-trained using two unsupervised tasks, <strong>Masked LM</strong> and <strong>Next Sentence Prediction (NSP)</strong> tasks.</p><p><strong>Masked LM</strong> is a spin-up version of conventional language model training setup — next word prediction task. For more details, please refer to section 3.1 in the <a href="https://arxiv.org/pdf/1810.04805.pdf">original paper</a>.</p><p><strong>Next Sentence Prediction (NSP)</strong> task is a novel approach proposed by authors to capture the relationship between sentences, beyond the similarity.</p><p>For the above text pair relatedness challenge, NSP seems to be an obvious fit and to extend its abilities beyond a single sentence, we have formulated a new training task.</p><h4>From NSP to Context window</h4><p>In a context window setup, we label each pair of sentences occurring within a window of n sentences as 1 and zero otherwise. For example, consider the following paragraph:</p><blockquote>As a manager, it is important to develop several soft skills to keep your team charged. Invest time outside of work in developing effective communication skills and time management skills. Skills like these make it easier for your team to understand what you expect of them in a precise manner. Check in with your team members regularly to address any issues and to give feedback about their work to make it easier to do their job better. Encourage them to give you feedback and ask any questions as well. Effective communications can help you identify issues and nip them in the bud before they escalate into bigger problems.</blockquote><blockquote><strong>For context window n=3, </strong>we generate following training examples</blockquote><blockquote><em>Invest time outside of work in developing effective communication skills and time management skills. </em><strong><em>&lt;SEP&gt; </em></strong><em>Check in with your team members regularly to address any issues and to give feedback about their work to make it easier to do their job better. </em><strong><em>Label: 1</em></strong></blockquote><blockquote><em>As a manager, it is important to develop several soft skills to keep your team charged. </em><strong><em>&lt;SEP&gt; </em></strong><em>Effective communications can help you identify issues and nip them in the bud before they escalate into bigger problems. </em><strong><em>Label: 0</em></strong></blockquote><blockquote><em>Effective communications can help you identify issues and nip them in the bud before they escalate into bigger problems. </em><strong><em>&lt;SEP&gt; </em></strong><em>Check in with your team members regularly to address any issues and to give feedback about their work to make it easier to do their job better. </em><strong><em>Label: 1</em></strong></blockquote><p>This training paradigm enables the model to learn the relationship between sentences beyond the pair-wise proximity. After context window fine-tuning BERT on HR data, we got following pair-wise relatedness scores</p><p><em>text1&lt;&gt;text2–0.1215614</em></p><p><em>text1&lt;&gt;text3–0.899943</em></p><p><em>text2&lt;&gt;text3–0.480266</em></p><p>This captures the sentence relatedness beyond similarity. In practice, we use a weighted combination of cosine similarity and context window score to measure the relationship between two sentences.</p><h3>Document Embeddings</h3><p>Generating feature representations for large documents (for retrieval tasks) has always been a challenge for the NLP community. Approaches like concatenating sentence representations make them impractical for downstream tasks and averaging or any other aggregation approaches (like p-means word embeddings) fail beyond certain document limit. We have explored several ways to address these problems and found the following approaches to be effective:</p><h4>BERT+RNN Encoder</h4><p>We have set up a supervised task to encode the document representations taking inspiration from RNN/LSTM based sequence prediction tasks.</p><p><strong>[step-1] </strong>extract BERT features for each sentence in the document</p><p><strong>[step-2]</strong> train RNN/LSTM encoder to predict the next sentence feature vector in each time step</p><p><strong>[step-3] </strong>use final hidden state of the RNN/LSTM as the encoded representation of the document</p><p>This approach works effectively for smaller documents and is not effective for larger documents due to the limitations of RNN/LSTM architectures.</p><h4>Distributed Document Representations</h4><p>Generating a single feature vector for an entire document fails to capture the whole essence of the document even when using BERT like architectures. We have reformulated the problem of Document embedding to identify the candidate text segments within the document which in combination captures the maximum information content of the document. We use the following approaches to get the distributed representations — <strong>Feature clustering, Feature Graph Partitioning</strong></p><p><strong><em>Feature clustering</em></strong></p><p><strong>[step-1] </strong>split the candidate document into text chunks</p><p><strong>[step-2] </strong>extract BERT feature for each text chunk</p><p><strong>[step-3]</strong> run k-means clustering algorithm with relatedness score (discussed in the previous section) as a similarity metric on candidate document until convergence</p><p><strong>[step-4] </strong>use the text segments closest to each centroid as the document embedding candidate</p><p>A general rule of thumb is to have a large chunk size and a smaller number of clusters. In practice, these values can be fixed for a specific problem type</p><p><strong><em>Feature Graph Partitioning</em></strong></p><p><strong>[step-1] </strong>split the candidate document into text chunks</p><p><strong>[step-2] </strong>extract BERT feature for each text chunk</p><p><strong>[step-3] </strong>build a graph with nodes as text chunks and relatedness score between nodes as edge scores</p><p><strong>[step-4] </strong>run community detection algorithms (eg. <a href="https://neo4j.com/docs/graph-algorithms/current/algorithms/louvain/">The Louvain algorithm)</a> to extract community subgraphs</p><p><strong>[step-5] </strong>use graph metrics like node/edge centrality, PageRank to identify the influential node in each sub-graph — used as document embedding candidate</p><h3>Conclusion</h3><p>This post highlights some of the novel approaches to use BERT for various text tasks. These approaches can be easily adapted to various usecases with minimal effort. More to come on Language Models, NLP, Geometric Deep Learning, Knowledge Graphs, contextual search and recommendations. Stay tuned!!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FS5ZLrGVZ0So&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DS5ZLrGVZ0So&amp;image=http%3A%2F%2Fi.ytimg.com%2Fvi%2FS5ZLrGVZ0So%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f8d486bfb235c4348fe016cab69d6e19/href">https://medium.com/media/f8d486bfb235c4348fe016cab69d6e19/href</a></iframe><blockquote>Checkout EtherMeet, an AI-enabled video conferencing service for teams who use Slack.</blockquote><blockquote>Sign up at <a href="http://etherlabs.io/">etherlabs.io</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa6e9ce5d133" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ether-labs/bert-for-unsupervised-text-tasks-fa6e9ce5d133">BERT for unsupervised text tasks</a> was originally published in <a href="https://medium.com/ether-labs">ETHER Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>