<?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 Mubashir Iqbal on Medium]]></title>
        <description><![CDATA[Stories by Mubashir Iqbal on Medium]]></description>
        <link>https://medium.com/@mubashiri656?source=rss-7cfed3874fd3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*sv97nNNfznO2yKlG</url>
            <title>Stories by Mubashir Iqbal on Medium</title>
            <link>https://medium.com/@mubashiri656?source=rss-7cfed3874fd3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 07:51:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mubashiri656/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[Olostep Parsers Turn URLs Into Stable JSON Contracts]]></title>
            <link>https://medium.com/olostep/olostep-parsers-turn-urls-into-stable-json-contracts-17798c50d442?source=rss-7cfed3874fd3------2</link>
            <guid isPermaLink="false">https://medium.com/p/17798c50d442</guid>
            <category><![CDATA[scalability]]></category>
            <category><![CDATA[parser]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[ai-agent]]></category>
            <dc:creator><![CDATA[Mubashir Iqbal]]></dc:creator>
            <pubDate>Thu, 19 Feb 2026 19:01:00 GMT</pubDate>
            <atom:updated>2026-02-19T19:01:00.963Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yRXDyMwfKYfDoUYwpXb0Bg.png" /></figure><p>Most scraping failures do not appear to be failures. The job succeeds, status is green, and the HTML still arrives.</p><p>Then your pipeline degrades quietly. The field you depend on goes missing. Price becomes null. Email extraction returns an empty list. Dates shift format. Alerts stop firing, and enrichment records go empty. Reviewers stop trusting the system because everything looks healthy while the output gets worse.</p><p>That is the real shift: pages are not the product, fields are. Once you accept that, the fix is not more scraping. The fix is treating the output as a contract your systems can rely on.</p><h3><strong>What a parser gives you in practice</strong></h3><p>An <a href="https://docs.olostep.com/features/structured-content/parsers">Olostep Parser</a> is a field-first extractor. You provide a URL and request JSON. You get structured output with predictable keys, plus metadata you can store for provenance.</p><p>That provenance matters in production because when someone asks why a record looks wrong, you want traceability, not guesswork, and you can show exactly what was extracted and when.</p><p>A simple record you persist might look like this. It is your storage shape, not the full Olostep response.</p><pre>{<br>  &quot;url_to_scrape&quot;: &quot;https://example.com/contact&quot;,<br>  &quot;created&quot;: 1745673871,<br>  &quot;retrieve_id&quot;: &quot;ret_...&quot;,<br>  &quot;parser_id&quot;: &quot;@olostep/extract-emails&quot;,<br>  &quot;data&quot;: { &quot;emails&quot;: [&quot;team@example.com&quot;] }<br>}</pre><p>Olostep can return JSON inline json_content or provide a hosted file json_hosted_url when payloads are larger. That behavior is described in the <a href="https://docs.olostep.com/features/structured-content/parsers">Parsers documentation</a>.</p><h3><strong>Parsers vs LLM Extraction and The Hybrid Pattern</strong></h3><p>Olostep supports structured JSON through parsers and through <a href="https://docs.olostep.com/features/structured-content/llm-extraction">LLM Extraction</a>. They fit different situations.</p><p>If you have recurring runs and fields that must stay stable, parsers are a strong default.</p><p>If you have one-off pages, changing structures, or you need a custom schema quickly, LLM extraction is often the fastest way to prove the shape.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*U7WN4c7KMmVFLIpRO6UnrQ.png" /></figure><p>Many teams land on a hybrid. Parsers handle the hard fields that power downstream logic, while LLM extraction handles fuzzy enrichment, such as classification, normalization, and summaries. One expectation to set early is access, and Olostep notes that <a href="https://docs.olostep.com/features/structured-content/intro">LLM Extraction may require enablement</a>. Here is a practical way to think about the choice.</p><h3><strong>Prototype Mode Locks The Contract on One URL</strong></h3><p>Start with one URL and validate the JSON shape that downstream systems will depend on. This is where <a href="https://docs.olostep.com/features/scrapes/scrapes">Scrapes</a> work well; the snippet below is a minimal, runnable example with a hosted fallback.</p><pre>import requests, json<br><br>URL = &quot;https://example.com/contact&quot;<br>r = requests.post(<br>  &quot;https://api.olostep.com/v1/scrapes&quot;,<br>  headers={&quot;Authorization&quot;: &quot;Bearer &lt;API_KEY&gt;&quot;},<br>  json={<br>    &quot;url_to_scrape&quot;: URL,<br>    &quot;formats&quot;: [&quot;json&quot;],<br>    &quot;parser&quot;: {&quot;id&quot;: &quot;@olostep/extract-emails&quot;}<br>  }<br>).json()<br>res = r[&quot;result&quot;]<br>payload = res.get(&quot;json_content&quot;)<br>if payload:<br>  data = json.loads(payload) if isinstance(payload, str) else payload<br>elif res.get(&quot;json_hosted_url&quot;):<br>  data = requests.get(res[&quot;json_hosted_url&quot;]).json()<br>else:<br>  raise RuntimeError(&quot;No JSON returned&quot;)<br>print(data)</pre><p>Once this contract looks right, you are ready to scale without turning the blog into an endpoint walkthrough, because the downstream systems already have a stable shape to rely on.</p><h3><strong>Production Mode Scales With Batches</strong></h3><p>When you move from one URL to thousands, orchestration becomes the product. Olostep’s <a href="https://docs.olostep.com/features/batches/batches">Batches</a> workflow is built for that jump.</p><p>The docs describe a few production-oriented realities. You can run up to 10k URLs per batch, processing time is often described as roughly constant and commonly around five to eight minutes, and new accounts may be limited to 100 items per batch.</p><p>The production mental model stays simple: start a batch, get a batch id, poll the status until it completes, list batch items using cursor pagination to collect and retrieve ids, then fetch results later using the <a href="https://docs.olostep.com/api-reference/retrieve">Retrieve API</a>. For item listing, follow the <a href="https://docs.olostep.com/api-reference/batches/items">Batch Items endpoint</a>.</p><p>That flow gives you traceable outputs at scale, so you are not just scraping pages; you are producing records you can audit and reason about later.</p><h3><strong>Guardrails That Keep JSON Trustworthy</strong></h3><p>This is where most teams win or lose reliability, so first store provenance by default. Persist url, created, retrieve id, parser id, and batch or custom ids to make debugging and audits realistic instead of painful.</p><p>Second, handle large payloads explicitly. The <a href="https://docs.olostep.com/api-reference/retrieve">Retrieve docs</a> mention size limits and the size_exceeded behavior. They also note that hosted URLs expire in 7 days. Treat hosted output as a download link, not storage.</p><p>Third monitor field drift, not just job success. Track missing keys, null spikes per field, and shape changes. Those checks catch the quiet failures that erode trust.</p><h3><strong>If No Parser Fits</strong></h3><p>Start with <a href="https://docs.olostep.com/features/structured-content/llm-extraction">LLM Extraction</a> to prove the schema. If it becomes recurring or high-volume, request or build a custom parser to keep the contract stable. The custom path is discussed on the <a href="https://docs.olostep.com/features/structured-content/parsers">Parsers page</a>.</p><h3><strong>Key takeaways</strong></h3><ul><li>Treat parser output as a JSON contract that downstream systems can depend on.</li><li>Lock the contract to a single representative URL before you scale.</li><li>Use batches for volume and the Retrieve API for later access.</li><li>Persist provenance (url, created, retrieve id, parser id) to keep audits and debugging real.</li><li>Monitor field drift and store long-term output instead of relying on expiring hosted URLs.</li></ul><h3><strong>FAQs</strong></h3><h4>How do I avoid re-downloading hosted JSON after it expires</h4><p>Hosted URLs are temporary with 7 days window. Persist the parsed JSON you need in your own storage as part of your saved record.</p><h4><strong>Can I combine parsers with LLM extraction in one workflow</strong></h4><p>Yes. A common production pattern is parsers for stable fields like ids, prices, and emails, plus <a href="https://docs.olostep.com/features/structured-content/llm-extraction">LLM Extraction</a> for fuzzy fields like summaries, normalization, and classification.</p><h4><strong>What should I log so I can debug wrong outputs later</strong></h4><p>At minimum, log url, create, retrieve id, parser ID, or your LLM schema version, and the final parsed JSON. The <a href="https://docs.olostep.com/features/structured-content/parsers">Parsers documentation</a> outlines the metadata you can use to build a clean provenance trail.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17798c50d442" width="1" height="1" alt=""><hr><p><a href="https://medium.com/olostep/olostep-parsers-turn-urls-into-stable-json-contracts-17798c50d442">Olostep Parsers Turn URLs Into Stable JSON Contracts</a> was originally published in <a href="https://medium.com/olostep">Olostep</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Is Web Scraping and Why Is It Evolving Again]]></title>
            <link>https://medium.com/olostep/what-is-web-scraping-and-why-is-it-evolving-again-18db1b19f915?source=rss-7cfed3874fd3------2</link>
            <guid isPermaLink="false">https://medium.com/p/18db1b19f915</guid>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[ai-search-engine]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[ai-tools]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Mubashir Iqbal]]></dc:creator>
            <pubDate>Tue, 17 Feb 2026 07:38:08 GMT</pubDate>
            <atom:updated>2026-02-17T07:38:08.019Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0zi1HIl72o4dIYpWkHcYzg.png" /></figure><p>Search is turning into a conversation. A recent study found that <a href="https://eightohtwo.com/blog/2026-ai-search-behavior-study-ai-now-first-stop-for-search/">37 percent of consumers</a> begin their information searches with AI tools rather than traditional search engines. When AI becomes the first stop, freshness stops being optional.</p><p>Product docs change. Pricing pages update. Listings come and go. Policies get revised without notice. If your systems cannot capture those shifts reliably, analytics and AI apps drift. They still answer confidently, but the facts underneath are stale.</p><p>Web scraping matters because it turns a fast-moving web into refreshable data your internal systems can trust.</p><h3>What Web Scraping Means and What It Does Not</h3><p>Web scraping is the programmatic collection of publicly available web content and its conversion into usable data. The goal is not to store raw HTML. The goal is to extract what matters and deliver it in a shape your systems can reuse.</p><p>Scraping is valuable when it does four things.</p><ol><li>Extract the right fields.</li><li>Remove layout noise.</li><li>Structure outputs into predictable records.</li><li>Refresh on a schedule to keep data current.</li></ol><p>Scraping is also not unconstrained. Public does not mean unrestricted. Teams still need to respect access rules, pace requests responsibly, and collect only what is necessary.</p><h3>How Scraping Evolved</h3><p>Scraping has moved through phases.</p><p>DIY scripts worked for stable pages, but selectors broke whenever layouts changed.</p><p>Headless browsers handled dynamic sites, but operations got heavy. Compute rose, timeouts increased, and edge cases multiplied.</p><p>Today, scraping is operational. The hard part is not the extraction once. The hard part is keeping the extraction correct. Production scraping needs consistent outputs, monitoring, and validation.</p><h3>Why Scraping Matters More Now</h3><p>The web is still one of the best sources of fresh external signals, often updated before internal systems.</p><p>Pricing and availability can change daily. Vendor docs update quietly. Policy pages shift without warning. For many teams, these are direct inputs into revenue, customer trust, and risk decisions.</p><p>Staleness is also more visible now. When an AI assistant cites an old policy, users notice. When a sales brief pulls outdated specs, credibility drops. When a pricing monitor misses a change, the workflow breaks.</p><p>Scraping matters because it turns public information into data that downstream systems can use with confidence.</p><h3>Where Teams Struggle In Production</h3><p>Most scraping failures are not hard errors. Pipelines keep running while quality degrades.</p><p>Partial content is common. Modern pages can load key fields late, so a collector captures an incomplete view. Schema drift is another. A site renames a label or reorganizes sections. Your scraper still returns data, but the mapping becomes wrong.</p><p>Rate limits and transient failures create gaps. Without monitoring, those gaps stay hidden until someone downstream complains.</p><p>The biggest risk is silent decay. Missing fields, duplicates, stale snapshots, and mismatched values can look plausible. Then analytics and AI systems make decisions based on data that no longer reflects reality.</p><p>Add lightweight observability. Log what was fetched, what was extracted, and what was rejected. Keep sample snapshots for debugging so you can see what changed when a site template shifts.</p><h3>What Good Scraping Looks Like In 2026</h3><p>Good scraping in 2026 is not about volume. It is about reliability and trust. It starts with focus. Scrape only what answers the question, and avoid extra fields that add noise and make maintenance harder. Then treat refresh as a first-class decision. Match the cadence to the source&#39;s rate of change, and timestamp every record so freshness is measurable.</p><p>Validation is what keeps the pipeline honest. Require fields that must exist, and watch for missing values, duplicates, and sudden shifts in distributions. Track scrape success rate, field completeness, and freshness lag as core metrics, and investigate quickly when they move before downstream users notice drift.</p><p>Finally, keep provenance and control. Store the source URL, collection time, and identifiers that let you trace each record back to its origin. If scraped data feeds internal tools or AI apps, apply access control and data minimization, collecting only what you need and avoiding unnecessary personal data.</p><h3>Building A Repeatable Scraping Pipeline With An API Based Layer</h3><p>Once scraping moves beyond a demo, teams face a choice. Build and operate collectors, renderers, queues, retries, and extractors, or use an API layer that standardizes retrieval and extraction so you can focus on validation, refresh, and downstream use. This is especially helpful when multiple teams need the same sources and the same output contract.</p><p>This is where Olostep fits. Olostep positions itself as a web search, scraping, and crawling API designed for data and AI workflows. It is a data layer that helps teams retrieve web content and turn it into clean outputs they can use in pipelines.</p><h3>Batch Scraping For Scale</h3><p>Refreshing many pages is easier when you treat it as a job. Olostep provides a batch endpoint that lets you submit large sets of URLs in a single run. The docs describe support for<a href="https://docs.olostep.com/features/batches/batches?utm_source=chatgpt.com"> up to 10,000 URLs per batch</a>, which fits monitoring and large refresh workflows.</p><p>Batching also supports a retrieve later pattern. Submit the job, then fetch results when processing completes.</p><h3>Structured Extraction When You Need JSON</h3><p>Many pipelines require structured fields such as product name, price, rating, or a list of results. Olostep supports parsers that convert pages into structured JSON. The docs describe parsers as a way to<a href="https://docs.olostep.com/features/structured-content/parsers?utm_source=chatgpt.com"> </a><a href="https://docs.olostep.com/features/structured-content/parsers">convert unstructured data into structured data</a>, which is helpful when you need the same fields repeatedly across similar pages.</p><h3>A Practical Starting Path</h3><p>Start small and tighten the contract early.</p><p>Pick one use case and define success in terms of freshness and completeness. Identify the smallest URL set that answers the question. Decide whether you need clean text or structured JSON. Add checks for missing fields, duplicates, and anomalies. Set a refresh schedule and track timestamps and provenance. Once quality is stable, scale with batching.</p><h3>Key Takeaway</h3><p>Web scraping is evolving as discovery changes and freshness becomes a product requirement. The win is building a reliable pipeline that produces clean outputs, catches drift early, and refreshes on a schedule you can defend.</p><p>Start with one monitored use case, standardize retrieval and extraction early, and if you are evaluating Olostep, use the<a href="https://docs.olostep.com/features/batches/batches?utm_source=chatgpt.com"> Olostep batch workflow guide</a> to test on real pages you need to keep current.</p><h3>FAQ</h3><p><strong>1. Why is web scraping more important now?</strong><br>AI tools surface stale facts faster, so teams need fresh web data to keep analytics and AI outputs accurate.</p><p><strong>2. What makes scraping production grade in 2026?</strong><br>Targeted collection, refresh plans, validation metrics, and provenance so that drift is caught early and data stays defensible.</p><p><strong>3. When should I use an API layer like Olostep?</strong><br>When you need reliable retrieval, batching, and structured extraction without building and maintaining the full scraping stack.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18db1b19f915" width="1" height="1" alt=""><hr><p><a href="https://medium.com/olostep/what-is-web-scraping-and-why-is-it-evolving-again-18db1b19f915">What Is Web Scraping and Why Is It Evolving Again</a> was originally published in <a href="https://medium.com/olostep">Olostep</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Batch Scraping at Web Scale: Making Reliability the Default]]></title>
            <link>https://medium.com/olostep/batch-scraping-at-web-scale-making-reliability-the-default-6238417e5289?source=rss-7cfed3874fd3------2</link>
            <guid isPermaLink="false">https://medium.com/p/6238417e5289</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[python-webscraping]]></category>
            <category><![CDATA[web-scraping-tools]]></category>
            <category><![CDATA[data]]></category>
            <dc:creator><![CDATA[Mubashir Iqbal]]></dc:creator>
            <pubDate>Mon, 16 Feb 2026 06:37:03 GMT</pubDate>
            <atom:updated>2026-02-16T06:37:03.762Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*nA2Y50-SmNZuPSmXZBBEKw.png" /></figure><h3>Introduction</h3><p>At scale, scraping does not fail loudly. It fails quietly. Retries create duplicates, partial runs leave pages missing, and you only notice the breakage downstream. At that point, it is no longer a scraping problem. It is an orchestration problem.</p><p>The impact shows up fast. Teams burn time reconciling outputs, rerunning jobs that “mostly worked,” and manually proving that a dataset is complete. That cleanup inflates cost, slows delivery, and reduces confidence in the data. If you cannot explain what happened in a run, you cannot trust what it produced.</p><p>The core challenge is not fetching pages. It is running repeatable, auditable batch jobs.</p><p>This article explains the production challenges of batch scraping and a simple orchestration model that makes large runs predictable.</p><h3>Why Batch Scraping Breaks in Production</h3><h4>Retries create duplicates:</h4><p>Most pipelines retry at the request level. When a job restarts, inputs overlap, or a queue replays, you end up processing the same URL twice. The result looks “successful,” but your dataset is now polluted.</p><h4>Partial completion hides gaps:</h4><p>A batch can finish with some pages missing, and many systems do not make the missingness obvious. Teams only discover gaps later, when analyses fail, or customers ask why coverage is inconsistent.</p><h4>Payload variability breaks downstream:</h4><p>Even when the scrape “works,” the output is not consistent. Some pages are tiny, some are huge, some return blocked interstitials, and some change structure between runs. Downstream systems then fail on size, parsing, or schema assumptions.</p><p>At the core, scraping is often treated as a pile of independent requests rather than a bounded job with guarantees. Success is defined as “most pages returned,” not as complete, explainable coverage. That design choice makes duplicates easy to introduce, gaps hard to see, and recovery expensive.</p><p>This pattern mirrors a broader issue with data reliability. When missing or incorrect data becomes normal, teams shift from building to incident handling. Industry surveys on data quality consistently show <a href="https://www.montecarlodata.com/blog-data-quality-survey">rising data incidents and slow detection times</a>, reinforcing that reliability problems compound when workflows are not designed around explicit guarantees from the start.</p><h3>What “Reliable Batch Scraping” Actually Means</h3><p>Reliable batch scraping is not about a higher success rate on individual HTTP requests. It is about predictable outcomes at the job level.</p><p>In plain terms, reliability means:</p><ul><li>Each URL is processed once at the application level. Retries do not create duplicates.</li><li>Completion means coverage, not “best effort.” You can tell what is done and what is missing.</li><li>Results are retrievable later without re-scraping. You can fetch the content deterministically, on demand, in the format you need.</li></ul><p>This is a shift in mindset from page fetching to job orchestration. Once you treat a run as a job with inputs, states, and reconciliation, reliability stops being “vibes” and becomes a property of the workflow.</p><h3>Predictable Batch Workflow for Web-Scale Scraping</h3><p>You only need a few steps to make large runs predictable. The goal is to make duplicates hard, gaps visible, and recovery cheap.</p><h4>Step 1: Stabilize work identity:</h4><p>Normalize URLs and assign a stable identifier to each URL (e.g., a deterministic hash). When retries happen, you can detect overlap and prevent duplicate work from becoming duplicate output. This is the simplest path to “exactly once” behavior at the application layer.</p><h4>Step 2: Run bounded batches:</h4><p>Treat each batch as a complete unit of work with a fixed input list. Bounded jobs let you answer basic questions reliably: what was supposed to happen, what finished, and what did not. Olostep’s<a href="https://docs.olostep.com/features/batches/batches"> batch model</a> is designed around that contract, supporting up to 10,000 URLs per batch, with typical completion in approx 5 to 8 minutes, and guidance for running multiple batches in parallel for higher throughput.</p><h4>Step 3: Reconcile results:</h4><p>Do not eyeball them; reconcile them. After execution, list item outcomes and reconcile them against your intended input set. This is where missingness becomes explicit, because you can enumerate completed and failed items and walk results with cursor pagination instead of guessing from logs. Olostep supports this via<a href="https://docs.olostep.com/api-reference/batches/list"> Batch Items</a>.</p><h4>Step 4: Retrieve content deterministically:</h4><p>Separate execution from retrieval: run the batch first, then fetch content for each completed item when you need it and in the format you need. This keeps pipelines stable and lets you re-fetch later without rerunning the scrape. Olostep’s<a href="https://docs.olostep.com/api-reference/retrieve/retrieve"> Retrieve Content</a> supports format selection and returns hosted content URLs when payloads exceed limits, with size_exceeded indicating when content is hosted.</p><h4>Step 5: Retry only what is missing:</h4><p>Retry only the specific URLs that failed or never produced an outcome, using the same stable identifiers. This is the difference between recovery and reruns: you avoid paying twice for the same work, and you avoid injecting more duplicates when something goes wrong.</p><h3>How Olostep Is Solving This Issue</h3><p>Olostep’s batch model aligns with the reliability-first workflow above by making orchestration a first-class concern.</p><ul><li>Clear job boundaries: A batch is a defined unit of work with trackable completion, which makes it easier to reason about coverage and gaps at the run level.</li><li>Item-level outcomes you can reconcile: Batch items can be listed and paginated, which supports safe consumption patterns and makes auditing practical at scale.</li><li>Deterministic retrieval, decoupled from execution: You can run a batch once and retrieve results later via stable identifiers, reducing reruns and simplifying downstream systems.</li><li>Large outputs do not have to break pipelines: When content is large, hosted URLs can be used, so you do not have to push massive payloads through every step of your system. This pattern is reflected in Olostep responses that include hosted content fields for retrieval.</li></ul><p>The practical outcome is fewer surprises. Instead of “scrape and hope,” you get a workflow where coverage is checkable, duplicates are preventable, and retries are controlled.</p><h3>Conclusion</h3><p>Batch scraping failures are predictable and preventable once you treat scraping as orchestration, not extraction. The reliability work is job-level: bounded batches, stable identity, explicit reconciliation, and deterministic retrieval, so duplicates stay rare, and gaps stay visible.</p><h3>Key takeaways</h3><ul><li>Use bounded batches with a fixed input list.</li><li>Assign a stable identifier per normalized URL to prevent duplicates.</li><li>Reconcile outcomes vs inputs to make missing URLs obvious.</li><li>Separate execution from retrieval so results can be fetched later without reruns.</li><li>Retry only missing/failed URLs to recover cheaply and safely.</li></ul><p>If your team needs predictable batch scraping at scale, Olostep is built around this production model. Start with the<a href="https://docs.olostep.com/features/batches/batches"> batch workflow</a> and design your pipeline around job-level guarantees.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6238417e5289" width="1" height="1" alt=""><hr><p><a href="https://medium.com/olostep/batch-scraping-at-web-scale-making-reliability-the-default-6238417e5289">Batch Scraping at Web Scale: Making Reliability the Default</a> was originally published in <a href="https://medium.com/olostep">Olostep</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kolmogorov-Arnold Networks: A Game Changer or Just Another AI Experiment?]]></title>
            <link>https://medium.com/red-buffer/kolmogorov-arnold-networks-a-game-changer-or-just-another-ai-experiment-4736189f59b6?source=rss-7cfed3874fd3------2</link>
            <guid isPermaLink="false">https://medium.com/p/4736189f59b6</guid>
            <category><![CDATA[ai-revolution]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[kolmogorov-arnold-network]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Mubashir Iqbal]]></dc:creator>
            <pubDate>Fri, 11 Jul 2025 11:40:32 GMT</pubDate>
            <atom:updated>2025-07-11T11:40:32.583Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Q8wb6-BpCcWBdvRL.png" /><figcaption><a href="https://www.dailydoseofds.com/content/images/size/w1000/2024/05/image-156.png">Source</a></figcaption></figure><p>Kolmogorov-Arnold Networks (KANs) is an exciting new development in deep learning, pushing the boundaries of traditional models like Multi-Layer Perceptrons (MLPs). Inspired by the principles of the Kolmogorov-Arnold Representation Theorem, KANs introduce a novel approach to building neural networks. Unlike MLPs, which use fixed activation functions at each node (commonly referred to as “neurons”), KANs feature learnable activation functions on the connections between nodes (known as “edges”). Instead, each weight parameter is replaced by a univariate function, specifically a spline, which can easily switch between broad and detailed adjustments. This shift not only simplifies the handling of complex functions but also enhances the flexibility and interpretability of neural network architectures, marking a significant leap forward in AI technology.</p><h3>Historical Background</h3><p>Let’s delve into history to understand the KAN architecture. At the end of the 19th century, there was a competition between mathematicians and physicists to break down some higher-degree equations into simple equations that were easy to deal with and understand as those equations were mostly required for different industries to use. Some equations of specific degrees were solved by mathematicians, but some were not. This led to a question that was mentioned in <strong>23 Hilbert’s Problem </strong>as the thirteenth question: whether it is possible to break 7th-degree polynomials into simpler functions of 2 variables.</p><p>This question was there for a reason because if there could be a way to do this then working with and estimating complex functions could be made easier. Or in simple words we can describe multiple dimensions by breaking them into simple dimensions which would be easy to understand individually.</p><p>To solve this problem, two main theories were discovered:</p><ol><li><strong>Universal Approximation Theorem</strong></li><li><strong>Kolmogorov-Arnold Representation theorem</strong></li></ol><h3><strong>Universal Approximation Theorem:</strong></h3><p>It is the foundation of the <strong>Multi-Layer Perceptron (MLP)</strong>, also known as the traditional neural network architecture. It aims to approximate complex functions with the desired accuracy using a feed-forward network.</p><blockquote>“It states that the complex relationship between input and output (a complex function) can be estimated using a hidden layer with <em>n</em> neurons (<em>n</em> may vary depending on the problem), where a sigmoid or any other nonlinear function should be used as the activation function for nonlinear mapping.”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*c_itpDWnyQBoE_Eq" /><figcaption><a href="https://www.nicolamanzini.com/single-hidden-layer-neural-network/">Hidden layer is approximating the function</a></figcaption></figure><h3><strong>Kolmogorov–Arnold representation theorem:</strong></h3><p>Consider that your colleague has written a complex piece of code that performs multiple tasks. You have been assigned to review and understand it. However, the problem is that all these tasks are implemented in a non-standard way — without modules, classes, or functions. Would it be easier for you to analyze and understand this code, or would a well-structured version that follows the separation of concerns (i.e., one function per task) be more manageable?</p><p>You guessed it right — the code that is broken down into functions and classes will be much easier to understand and modify. This is exactly what the <strong>Kolmogorov-Arnold Theorem</strong> does.</p><blockquote>Any complex function, no matter how many different inputs it has, can be broken down into a combination of simpler, one-variable functions.</blockquote><p><strong>Mathematically</strong>, the theorem can be stated as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*lwpjz2CEg10EjRTPEeYubA.png" /></figure><p>where Φq​ and ϕqp ​ are continuous functions of one variable.</p><h3><strong>Kolmogorov Arnold Network</strong></h3><p>Now that we have a basic overview of the Kolmogorov-Arnold Theorem, we can understand why there was a great quest among the research community to develop a way to utilize the Kolmogorov–Arnold Representation Theorem for solving AI problems. This is because it could help train models more efficiently using significantly less data. Kolmogorov-Arnold Networks (KANs) address this challenge by modifying the theorem to enhance computational efficiency.</p><p>Now, let’s dive into how KANs have adapted the Kolmogorov–Arnold Theorem in their architecture.</p><h3>Mathematical Form of KAN</h3><p>Before going in more depth lets understand the Mathematical form of KAN in a better way.<br><br>Lets consider Housing pricing dataset</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/1*zF8tlJ42c2BPiN19p92PvQ.png" /></figure><p>The relation between price and features can be represented using a multivariate function, say <strong>F.</strong></p><blockquote>Price = f(φ_b(bedrooms) + φ_sq(area) + φ_a(age))</blockquote><blockquote>Price = f₁(φ_b(bedrooms) + φ_sq(area) + φ_a(age)) + … + fₙ(φ_b(bedrooms) + φ_sq(area) + φ_a(age))</blockquote><p>Instead of looking at price as a single formula, we break it down into multiple layers or steps, making it easier to interpret how each small function contributes to the final prediction. Each of these smaller functions captures the effect of bedrooms, area, and age separately, allowing us to understand their individual impact before combining them into the overall price estimation.</p><p>Now, look back at the formula of the Kolmogorov–Arnold Theorem — hopefully, it now makes sense. Take your time to grasp this concept.</p><p>This approach not only simplifies the representation of complex functions but also allows neural networks like KAN to achieve better computational efficiency and interpretability by breaking down high-dimensional problems into manageable components.</p><p><strong>Difference between KAN and Multi Layer Perceptron (MLPs):</strong></p><ul><li>MLPs have linear weights and they use activation functions on nodes for learning non linearity.</li><li>KAN uses learnable activation functions on edges(weights) due to which they don’t have any linear matrix.</li><li>KAN nodes only add incoming signals unlike MLPs nodes, which applies activation functions too.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*I6x10pxX2twNlEEW" /></figure><h3><strong>B-splines:</strong></h3><blockquote>B-Spline (Basis Spline) is a piecewise-defined polynomial function that provides a smooth curve while maintaining local control over shape adjustments. B-Splines are widely used in computer graphics, numerical analysis, and curve fitting.</blockquote><p>To understand why B-spline is used in KANs, Lets consider a case where there is only one composition, i.e., we need to focus only on the inner dot product of the main equation given above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/0*bc5VjYeIBBMZMNBJ" /></figure><p>Remember, these <strong>ϕ</strong> functions are not weights but univariate polynomial functions/equations, whose coefficients are trained using back propagation during training. However, instead of using simple equations, researchers have used B-splines due to their adaptive nature and efficiency.</p><p>Since data points represent positions in space, to find a curve passing through n points we need need polynomial of n-1, which could be solved by using using system of equation on (n x n) matrix, which is an expensive operation or if with back propagation, and with increasing number of points the resultant curve , although do pass from those points but extreme points starts going crazy as can be seen in this graph that just to pass through these data points the curve found through solving system of equation has moved more then what was required by data points pattern.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1011/1*3p1_9-kLApvoZ98g9vdb6w.png" /></figure><p>B-splines solve this issue by using part-wise functions( function defined from one point to other point in such a way that flow of graph stays smooth not pointy) give us more control over points to draw best smooth curve, while keeping the function differentiable which is core of learning through back propagation.<br>One of many other plus points of using B splines is that it gives control over the curve between points without affecting the other part of the curve. This is useful when we need to fine-tune a model for some specific scenario, unlike neural networks, which start to forget previously learned graphs on fine-tuning, these will only improve fine-tuning the relevant area instead of the whole knowledge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Ch2sbdSiui3X2T7uMRnSAQ.gif" /></figure><p>Fine-tuning the model with B splines will only adjust the graph between points which is required for that specific knowledge area instead of adjusting whole graph. On the other hand MLPs will adjust the complete poly curve only for changing the curve for one point which result in loss of previous learning related to other parts of graph.</p><h3>Conclusion</h3><p>Kolmogorov-Arnold Networks (KANs), while still in their early stages compared to MLPs, which matured with time using different techniques, introduce a revolutionary approach to deep learning by replacing traditional fixed activation functions with learnable functions on edges. Rooted in the Kolmogorov-Arnold Representation Theorem, KANs aim to break down complex functions into simpler, more interpretable components — similar to how modular programming improves code readability.</p><p>However, the true potential of KANs remains to be seen. Will they match the versatility of MLPs in deep learning? Can they efficiently learn from any kind of data? Only time will tell if this innovation aligns with industry needs.</p><p><strong>What are your thoughts?</strong> Do you see KANs shaping the future of AI, or will they remain a niche concept? <strong>Comment below!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4736189f59b6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/red-buffer/kolmogorov-arnold-networks-a-game-changer-or-just-another-ai-experiment-4736189f59b6">Kolmogorov-Arnold Networks: A Game Changer or Just Another AI Experiment?</a> was originally published in <a href="https://medium.com/red-buffer">Red Buffer</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ultimate Guide to Running Quantized LLMs on CPU with LLaMA.cpp]]></title>
            <link>https://medium.com/red-buffer/ultimate-guide-to-running-quantized-llms-on-cpu-with-llama-cpp-1a26c34bb6dd?source=rss-7cfed3874fd3------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a26c34bb6dd</guid>
            <category><![CDATA[quantization]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[edge-ai]]></category>
            <category><![CDATA[llama-cpp]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Mubashir Iqbal]]></dc:creator>
            <pubDate>Fri, 11 Jul 2025 11:34:40 GMT</pubDate>
            <atom:updated>2025-07-11T11:34:40.929Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cWRSMmSQcu7czvjP.png" /></figure><p>We are all witnessing the rapid evolution of Generative AI, with new Large Language Models (LLMs) emerging daily at various scales. However, running these models on local machines remains a challenge due to their high computational demands. LLaMA.cpp solves this problem by enabling the use of <strong>quantized models</strong>, which are significantly lighter while maintaining reasonable accuracy.</p><p>Llama.cpp is a light weight, open-source library, which was developed by <strong>Georgi Gerganov</strong> to enable LLMs inference possible on local machine. It supports running quantized models which are lower in precision and light in weight reducing memory requirements significantly. This allows efficient execution of LLMs without needing specialized hardware.</p><h3><strong>Running LLaMA.cpp using command line</strong></h3><h4><strong>Steps to Run Inference with LLaMA.cpp</strong></h4><ul><li>Clone and build Llama.cpp.</li><li>Download Quantized(GGUF) model of your choice.</li><li>Run Inference.</li></ul><h4><strong>Step 1: Install CMake (Required for Building LLaMA.cpp)</strong></h4><p>Make sure that cmake is installed. If not, run following commands to install</p><pre>sudo apt update<br>sudo apt install cmake</pre><h4><strong>Step 2: Clone and Build LLaMA.cpp</strong></h4><pre>git clone https://github.com/ggerganov/llama.cpp.git<br>cd llama.cpp/</pre><p>Once the cloning is completed, build llama.cpp using:</p><pre>cmake -B build<br>cmake --build build --config Release</pre><h4><strong>Step 3: Download a GGUF Quantized Model</strong></h4><p>Download the GGUF quantized model of your choice. Remember, The lower the quantization bit, the faster the model, but with reduced accuracy. Here <em>4 bit Small</em> version of Mistral-7B-Instruct is used.</p><pre># downloading the model<br>wget https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.1-GGUF/blob/main/mistral-7b-instruct-v0.1.Q4_K_S.gguf</pre><h4><strong>Step 4: Run Inference</strong></h4><p>After downloading the model you can run the inference. Make sure to pass the correct path of model.</p><pre>./build/bin/llama-cli -m ./mistral-7b-instruct-v0.1.Q3_K_M.gguf -p &quot;What is LLama.cpp?&quot; -ngl 128</pre><p>Here is the output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*o4Pl8uqvAWjB4YZ8RP19Cg.gif" /></figure><h3>Running LLaMA.cpp with Python Bindings</h3><p>LLaMA.cpp provides bindings for different programming languages, allowing easy integration of quantized LLMs into applications. Here, we explore python bindings.</p><h4><strong>Install Dependencies and Python Binding</strong></h4><p>Before installing the python bindings, ensure your system has the necessary tools.</p><pre># installing prerequistes<br>sudo apt update<br>sudo apt install -y gcc g++<br>export PATH=/usr/bin:$PATH<br>sudo apt install -y ninja-build</pre><pre># installing llama.cpp python binding<br>pip install llama-cpp-python</pre><h4><strong>Text Generation</strong></h4><pre>from llama_cpp import Llama<br><br>llm = Llama(<br>      model_path=&quot;mistral-7b-instruct-v0.1.Q3_K_M.gguf&quot;,<br>      # seed=1337, # Uncomment to set a specific seed<br>      n_ctx=2048, # control the context window<br>)<br>output = llm(<br>      &quot;Q: Name the planets in the solar system? A: &quot;, # Prompt<br>      max_tokens=32, # No of output tokens, set to None to generate up to the end of the context window<br>      stop=[&quot;Q:&quot;, &quot;\n&quot;], # Stop generating just before the model would generate a new question<br>      echo=True # Echo the prompt back in the output<br>)<br>print(output)</pre><pre># output<br>{&#39;id&#39;: &#39;cmpl-d7af42e9-9718-41e1-8b99-b23078c9d11d&#39;, &#39;object&#39;: &#39;text_completion&#39;, &#39;created&#39;: 1741072716, &#39;model&#39;: &#39;mistral-7b-instruct-v0.1.Q3_K_M.gguf&#39;, &#39;choices&#39;: [{&#39;text&#39;: &#39;Q: Name the planets in the solar system? A: 1. Mercury, 2. Venus, 3. Earth, 4. Mars, 5. Jupiter, 6. Saturn&#39;, &#39;index&#39;: 0, &#39;logprobs&#39;: None, &#39;finish_reason&#39;: &#39;length&#39;}], &#39;usage&#39;: {&#39;prompt_tokens&#39;: 14, &#39;completion_tokens&#39;: 32, &#39;total_tokens&#39;: 46}}</pre><h4><strong>Creating Embedding with LLaMA.cpp</strong></h4><pre>llm = Llama(<br>      model_path=&quot;mistral-7b-instruct-v0.1.Q3_K_M.gguf&quot;,<br>      embedding = True,<br>)<br>text_embedding = llm.create_embedding(&quot;What&#39;s up buddy?&quot;)</pre><h3>Running Multimodal Vision LLMs in LLaMA.cpp</h3><p>LLaMA.cpp now supports list of opensource multi-modals as well through quantization. Unlike simple LLMs, llama.cpp python have separate wrappers for each vision mode. You can find list of model and their chat-handler <a href="https://github.com/abetlen/llama-cpp-python/tree/main?tab=readme-ov-file#multi-modal-models">here</a>.</p><p>In this guide, we will be using MiniCPM, an opensource MLLM, which is supported in llama.cpp.</p><h4><strong>Understanding the Required Models</strong></h4><p>To run Vision LLMs, you need to download two models:</p><p><strong>1. GGUF Model (Text Generator)</strong></p><ul><li>This is the main language model.</li><li>Different quantized versions (e.g., Q3_K_L, Q4_K_M) are available for optimized performance.</li></ul><p><strong>2. MMProj Model (Vision Encoder)</strong></p><ul><li>This acts as a bridge between the image encoder and the LLM.</li><li>It translates images into a format the LLM can understand.</li><li>These models are usually not quantized and available only in full precision <em>(</em><strong><em>fp16</em></strong><em>)</em>.</li></ul><h4><strong>Step 1: Download the Required Models</strong></h4><p>Download both GGUF (quantized) and MMProj (full precision) models from Hugging Face.</p><pre># gguf model<br>wget https://huggingface.co/openbmb/MiniCPM-V-2_6-gguf/resolve/main/ggml-model-Q3_K_L.gguf</pre><pre># mmproj model<br>wget https://huggingface.co/openbmb/MiniCPM-V-2_6-gguf/resolve/main/mmproj-model-f16.gguf</pre><h4><strong>Step 2: Load the Models</strong></h4><p>Provided mmproj models path to Chat handler and gguf models path to Llama.</p><pre>from llama_cpp import Llama<br>from llama_cpp.llama_chat_format import MiniCPMv26ChatHandler<br>chat_handler = MiniCPMv26ChatHandler(clip_model_path=&quot;mmproj-model-f16.gguf&quot;)</pre><pre>llm = Llama(<br>  model_path=&quot;ggml-model-Q3_K_L.gguf.1&quot;,<br>  chat_handler=chat_handler,<br>  n_ctx=2048, # n_ctx should be increased to accommodate the image embedding<br>)</pre><h4><strong>Step 3: Generate a Response for an Image</strong></h4><pre>response = llm.create_chat_completion(<br>    messages = [<br>        {&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You are an assistant who perfectly describes images.&quot;},<br>        {<br>            &quot;role&quot;: &quot;user&quot;,<br>            &quot;content&quot;: [<br>                {&quot;type&quot; : &quot;text&quot;, &quot;text&quot;: &quot;Describe the image?&quot;},<br>                {&quot;type&quot;: &quot;image_url&quot;, &quot;image_url&quot;: {&quot;url&quot;: &quot;https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg&quot; } }<br>            ]<br>        }<br>    ]<br>)<br><br>print(response[&quot;choices&quot;][0][&quot;message&quot;][&quot;content&quot;])</pre><pre>The image depicts a serene landscape featuring a wooden boardwalk that cuts through a lush, green field. The sky above is a beautiful blue with scattered white clouds. The boardwalk appears to be leading towards a line of trees in the distance, creating a sense of depth and perspective. The overall scene is tranquil and inviting, suggesting a peaceful outdoor setting, possibly a nature reserve or a park.</pre><p>To pass local image to the model, it should be first converted to base64 encoded data and then passed to url parameter.</p><pre>import base64<br><br>def image_to_base64_data_uri(file_path):<br>    with open(file_path, &quot;rb&quot;) as img_file:<br>        base64_data = base64.b64encode(img_file.read()).decode(&#39;utf-8&#39;)<br>        return f&quot;data:image/png;base64,{base64_data}&quot;<br># pass your image path to this<br>data_uri = image_to_base64_data_uri(file_path)<br><br>response = llm.create_chat_completion(<br>    messages = [<br>        {&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You are an assistant who perfectly describes images.&quot;},<br>        {<br>            &quot;role&quot;: &quot;user&quot;,<br>            &quot;content&quot;: [<br>                {&quot;type&quot; : &quot;text&quot;, &quot;text&quot;: &quot;Describe the image?&quot;},<br>                {&quot;type&quot;: &quot;image_url&quot;, &quot;image_url&quot;: {&quot;url&quot;: data_uri}}<br>            ]<br>        }<br>    ]<br>)<br><br>print(response[&quot;choices&quot;][0][&quot;message&quot;][&quot;content&quot;])</pre><p>We have now seen that with LLaMA.cpp, you can run powerful LLMs, in quantized version, right on your local machine — no fancy hardware needed. Whether you’re generating text or diving into multimodal AI with vision models, you’re all set to experiment and build.</p><h3><strong>References:</strong></h3><ul><li><a href="https://github.com/abetlen/llama-cpp-python">GitHub - abetlen/llama-cpp-python: Python bindings for llama.cpp</a></li><li><a href="https://github.com/ggml-org/llama.cpp">GitHub - ggml-org/llama.cpp: LLM inference in C/C++</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a26c34bb6dd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/red-buffer/ultimate-guide-to-running-quantized-llms-on-cpu-with-llama-cpp-1a26c34bb6dd">Ultimate Guide to Running Quantized LLMs on CPU with LLaMA.cpp</a> was originally published in <a href="https://medium.com/red-buffer">Red Buffer</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DeepSeek R1 Training Explained]]></title>
            <link>https://medium.com/red-buffer/deepseek-r1-training-explained-e6c197f1ac23?source=rss-7cfed3874fd3------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6c197f1ac23</guid>
            <category><![CDATA[reasoning-model]]></category>
            <category><![CDATA[deepseek-r1]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[deepseek]]></category>
            <dc:creator><![CDATA[Mubashir Iqbal]]></dc:creator>
            <pubDate>Fri, 04 Apr 2025 10:24:05 GMT</pubDate>
            <atom:updated>2025-04-04T10:24:05.128Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0OZ83-HcPaGNFP13L9oPFQ.png" /></figure><p>Once in a while there comes an update in community which sets the path for future research. Same is the case with release of DeepSeek Reasoning Model R1. It has not just set the benchmarks for upcoming researches but has also introduced the use of pure Reinforcement Learning in training the reasoning models. Moreover, by making these models and training procedures public, DeepSeek has enabled both industry and research community to drive further innovation and make LLMs smarter.</p><h4>Context: How DeepSeek-R1 is Different</h4><p>A question that we all have in our minds: Why does the release of DeepSeek matter? Why is it more than just another LLM release? In fact, the real innovation lies in how they have used pure Reinforcement Learning in post-training LLMs, unlike others who used Reinforcement Learning with Human Feedback (RLHF).</p><p>Before delving into training methodology we need a basic understanding of the difference between supervised learning and reinforcement learning.</p><h4>Difference Between Reinforcement and Supervised Learning</h4><p>In supervised learning, a model learns by mimicking the distribution of training data, relying on labeled examples. The objective is to minimize a predefined loss function, ensuring the model produces outputs that closely match the correct responses.</p><p>In reinforcement learning (RL), instead of learning from fixed examples, the model actively explores and improves through trial and error. It evaluates its own responses, compares different outcomes, and refines its approach based on rewards rather than direct supervision. The reward function in RL plays a role similar to a loss function in supervised learning, but with a key difference:</p><ul><li>In supervised learning, the goal is to minimize the loss.</li><li>In reinforcement learning, the goal is to maximize the reward to encourage better performance.</li></ul><p>The policy model then uses these rewards to determine the best direction for optimization and updates itself and model accordingly to improve future responses.</p><p>This distinction allows RL based models to develop their own strategies to improve, rather than just replicating patterns seen in training data.</p><p><strong>Foundation: The DeepSeek V3-Base Model</strong><br> DeepSeek-R1 Zero and DeepSeek R1 both are fine-tuned from the DeepSeek V3-base model, which had already been trained on vast internet data. This provided a strong pretrained foundation, allowing the RL process to focus on enhancing reasoning abilities rather than starting from scratch.</p><h3>Training Pipelines</h3><p>Now that we have set the foundation, we will delve deep into the training pipelines of DeepSeek-R1 Zero, DeepSeek-R1 (main release), and the distilled training of other open-source models using R1.</p><h3>Deepseek-R1 Zero:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BXGzyBiHJI9qgub4VSSU9w.png" /></figure><p>Unlike traditional LLMs, it was purely trained using Reinforcement Learning, which saved the cost and time usually required for generating supervised data. Instead, it relied on self-evaluation, continuously refining its responses by comparing its own outputs with the format guided in prompt template(Table 1) and identifying the most effective response patterns.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KEASFxit0LjJUnJUL3w-Dg.png" /><figcaption>Table 1: Template for DeepSeek-R1-Zero</figcaption></figure><p>To fine-tune the base model using RL, we need to understand two key components that were used in fine-tuning :</p><ul><li>Reward Model: which generates reward based on accuracy of the output and format guided in the template.</li><li>Policy Model: which based on generated reward decide the learning direction for both model and itself.</li></ul><p>DeepSeek implemented Group Relative Policy Optimization (GRPO) as its policy model. GRPO operates by:</p><ul><li>Generating multiple responses for a given prompt using a previous checkpoint.</li><li>Comparing the reward scores for each response using the reward model.</li><li>Using those rewards to update LLM weights and policy model i.e., itself.</li></ul><h4>Training DeepSeek-R1 Zero</h4><p>For training DeepSeek-R1 Zero DeepSeek V3-base model was fine-tuned by using a predefined template (Table-1), where the prompt was replaced with a specific reasoning question before being given to the model. This allowed the model to freely explore different reasoning steps, paths, and response lengths, while ensuring that the structured format was maintained.</p><p>This relaxation in response generation helped the model self-evaluate more effectively, leading to longer, more refined outputs. By looking at Table-2 and Table-3, we can observe that increase in output length played a direct role in improving performance. Not just that, Table-2 shows how DeepSeek-R1 Zero was able to match <strong>OpenAI’s o1–0912</strong> in performance, all without any supervised fine-tuning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pPfGEzjJ6fTcdVdTJdpVWQ.png" /><figcaption>Table-2: Accuracy of DeepSeek-R1-Zero during training.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0887Gx0TulQvV724G7WjGA.png" /><figcaption>Table-3: DeepSeek response length evolution. Dark blue line is the average length. While, light blue shows the variation in responses lengths</figcaption></figure><p>Interesting thing to notice here is how R1 Zero is improvising and evolving on its own by just increasing test-time computation and increasing reasoning length to allocate more time to thinking. There is an intriguing moment mentioned in the paper where an interesting <strong>“aha moment” </strong>appeared in response during training, highlighting the ability to self reflect.</p><blockquote>“This moment is not only an “aha moment” for the model but also for the researchers observing its behavior. It underscores the power and beauty of reinforcement learning: rather than explicitly teaching the model on how to solve a problem, we simply provide it with the right incentives, and it autonomously develops advanced problem-solving strategies.”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JGQEEAEN2BJkD-6URn7VTw.png" /><figcaption>Table-4: Aha-moment</figcaption></figure><h4>DeepSeek R1-Zero Limitations</h4><p>DeepSeek R1 has highlighted the potential of pure RL in training LLMs by exhibiting strong reasoning skills and high accuracy but it came with its own limitation. While developing reasoning in responses it starts to neglect making responses readable and generate answers containing multiple languages.</p><p>To counter these issues DeepSeek R1 was trained, introducing a model which is safe and more aligned to humans preferences.</p><h3>Deepseek-R1: Smarter and Human Aligned</h3><p>Unlike R1-Zero, R1 was trained in five steps</p><ol><li><strong>DeepSeek-V3 Base</strong> + SFT (Cold Start Data) → <strong>Checkpoint 1</strong></li><li><strong>Checkpoint 1</strong> + RL (GRPO + Language Consistency) → <strong>Checkpoint 2</strong></li><li><strong>Checkpoint 2</strong> used to Generate Data (Rejection Sampling)</li><li><strong>DeepSeek-V3 Base</strong> + SFT (Generated Data + Other Data) → <strong>Checkpoint 3</strong></li><li><strong>Checkpoint 3</strong> + RL (Reasoning + Preference Rewards) → <strong>DeepSeek-R1</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0OZ83-HcPaGNFP13L9oPFQ.png" /></figure><h4><strong>Step 1: Generating Cold Start Data and Fine tuning V3-Base:</strong></h4><p>To prevent model from generating responses that have inconstant language and the format which is not readable, DeepSeek constructed a small dataset having long Chain of Thoughts(COT) answers to fine tune the DeepSeek V3-Base. This dataset was generated using LLMs by few shots prompting, simple prompts guiding model to return detailed chain of thought answer and gathering DeepSeek R1-Zero response that are readable, to make sure the data align dataset was reviewed by humans. Using this V3-Base was fine tuned. We will say this checkpoint as Checpoint-1 as this checkpoint will be used onward.</p><h4>Step 2: Reinforcement Learning to Enhance Reasoning:</h4><p>Same training process was applied to train Checkpoint-1, which was used to train R1-Zero. Except the reward which now do not only focus on output reasoning format but also language consistency, which reduce model performance, to make sure that model produce consistent language in a response. Lets call resultant checkpoint Checkpoint-2.</p><h4>Step 3 : Selecting The Best Responses and Supervised Fine-Tuning:</h4><p>This step was designed to generate dataset which will be used in subsequent steps. Previously, the cold start dataset was created to align model with human preference and introducing reasoning capabilities. However, in this step two kind of data was generated using Checkpoint-2.</p><ul><li>Reasoning data generated using prompting checkpoint-2. Unlike, step 1 where the only focus was to dataset which could be evaluated using rule based reward( like math and coding problems). Here both kind of dataset was generated one that could be check based on rules and other non technical fields where answer could not be rewarded using rule base rewards. To deal with such kind of data DeepSeek have used deepseek-V3 as generational reward generator. for this kind 600k samples were collected.</li><li>Non Reasoning Data: In this step DeepSeek focused on data where answer is straight forward like facts. For this category 200k samples were generated.</li></ul><h4>Step 4: Fine Tuning DeepSeek-V3 Base</h4><p>This dataset of 800k samples were then used to fine tune DeepSeek V3-Base model say checkpoint 4.</p><h4>Step 5:Reinforcement Learning</h4><p>Now that the model has an inbuilt ability to generate reasoning-based answers, this step refines its reasoning skills and aligns responses with human preferences, ensuring they are helpful and harmless. Checkpoint 4 was further trained in this step using Reinforcement Learning (RL) with different reward mechanisms:</p><ul><li>For coding, logical, and mathematical problems, the same rule-based reward system as in DeepSeek-R1 Zero was used.</li><li>For general data, a reward model was used to assess how much a human would prefer the response. Although the paper does not explicitly explain how this reward model works for this model, it appears that DeepSeek-V3 was used for this purpose.</li><li>For helpfulness, only final summaries (answers) were considered.</li><li>For harmlessness, both reasoning steps and the final summary were evaluated.</li></ul><p>Multiple prompts were used in both scenarios, and the final round of training combined all these reward mechanisms. The resulting model was named DeepSeek-R1, the signature reasoning model of DeepSeek.</p><h3>DeepSeek Distilled Models</h3><p>These model were not fine tuned in actual sense of distillation models. Instead, 800k sample of data was generated using DeepSeek R1 for same inputs that were in step 3 of DeepSeek R1 training.</p><p>This dataset was then used to fine-tune open-source models such as Llama, and Qwen, transferring DeepSeek-R1’s reasoning capabilities to smaller models.</p><h3>Conclusion</h3><p>The release of DeepSeek-R1 marks a significant shift in how reasoning models are trained, highlighting the power of pure Reinforcement Learning over traditional human-guided approaches. Yet, to make the model practically usable, supervised fine-tuning was still necessary. This suggests that in the near future, we might see a model fully trained through RL alone — achieving accuracy, helpfulness, and harmlessness without relying on supervised fine-tuning. Exciting advancements are undoubtedly on the horizon.</p><p>What are your thoughts? Drop your comments and share ideas on what the next steps in this field might be!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6c197f1ac23" width="1" height="1" alt=""><hr><p><a href="https://medium.com/red-buffer/deepseek-r1-training-explained-e6c197f1ac23">DeepSeek R1 Training Explained</a> was originally published in <a href="https://medium.com/red-buffer">Red Buffer</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unlocking the Power of Vector Databases: Getting Started with Qdrant]]></title>
            <link>https://medium.com/@mubashiri656/unlocking-the-power-of-vector-databases-getting-started-with-qdrant-b6f0dfa61a81?source=rss-7cfed3874fd3------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6f0dfa61a81</guid>
            <category><![CDATA[data-storage]]></category>
            <category><![CDATA[vector-database]]></category>
            <category><![CDATA[semantic-search]]></category>
            <category><![CDATA[qdrant-setup]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Mubashir Iqbal]]></dc:creator>
            <pubDate>Sun, 04 Aug 2024 08:02:00 GMT</pubDate>
            <atom:updated>2024-08-04T08:02:00.727Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/310/1*I0_R4dEIwspgrfKjFC7vlQ.jpeg" /></figure><p>Have you ever wondered if it’s possible to store different types of data — whether images, text, or audio — in the same format? If so, imagine how much easier it would be to search databases for relevant information, even if the information spans different categories, like finding the best image using a text query. This is where vector databases come into play.</p><h3>Vector Databases</h3><p>Vector databases store data in the form of vectors or embeddings. This innovative approach allows for efficient storage and retrieval of diverse data types by converting them into numerical representations in a multidimensional space. This enables advanced similarity analysis using semantics, which is particularly useful in developing search and recommendation systems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*7HY9vgXeJRnNKCzNYtCunw.png" /><figcaption><a href="https://medium.com/@qdrant/what-is-a-vector-database-qdrant-fb8cd9b3b524">Credits</a></figcaption></figure><h3>Structure of Data in Vector Databases</h3><p>In vector databases, as shown in the image above, data is stored with a unique structure:</p><ol><li><strong>Unique Row ID</strong>: Each entry in the database is associated with a unique identifier.</li><li><strong>Vector Embeddings</strong>: These are numerical representations of the data, capturing the essential features in a multidimensional space.</li><li><strong>Payload</strong>: This includes metadata about the data, such as descriptions, titles, url or other attributes. The payload is used to show the actual data based on the similarity search of embeddings.</li></ol><h3>What is Qdrant?</h3><p>Qdrant is an open-source vector database designed for efficient and scalable similarity search. It supports real-time vector search and provides features such as HNSW (Hierarchical Navigable Small World) indexing, which optimizes the search process.</p><h4><strong>Use Cases</strong></h4><p>Qdrant is used in various applications, including:</p><ul><li>Recommendation systems</li><li>Semantic search</li><li>Image and video retrieval</li></ul><h3>Getting Started with Qdrant</h3><p>To start using Qdrant, the easiest way is to use Docker. Ensure you have Docker installed and running on your system</p><p>Start with pulling docker image</p><pre># Pull the Qdrant image from Docker Hub<br>docker pull qdrant/qdrant</pre><pre># Run the Qdrant container, mapping port 6333 to expose the Qdrant HTTP API<br>docker run -p 6333:6333 qdrant/qdrant</pre><p>This command will start the Qdrant container and expose it on port 6333. You can access Qdrant locally at <a href="http://localhost:6333/dashboard">http://localhost:6333/dashboard</a><a href="http://localhost:6333.">.</a></p><p>Now that Qdrant is running, you’ll need to install the client libraries to interact with it.</p><pre># faker is used to create fake data<br>!pip install numpy qdrant-client faker</pre><p><strong>Importing Libraries</strong></p><pre>from qdrant_client import QdrantClient<br>from qdrant_client.http import models<br>import numpy as np<br>from faker import Faker</pre><p><strong>Connect to Qdrant</strong></p><pre>client  = QdrantClient(host=&quot;localhost&quot;,port=6333)<br>client</pre><p><strong>Create Collection</strong></p><p>To create a collection where the size of the vector is <strong>100</strong> and the metric used for similarity calculation<strong> </strong>is <strong>cosine</strong>:</p><pre>collection_name = &quot;practice_collection&quot;<br>client.create_collection(<br>    collection_name=collection_name,<br>    vectors_config = models.VectorParams(size=100,distance=models.Distance.COSINE)<br>)</pre><p>Since we are learning, you might try to create a collection with the same name that you have already used before. This will generate an error. To avoid this, use recreate_collection. This method deletes any existing collection with the same name and recreates it, preventing any errors:</p><pre>collection_name = &quot;practice_collection&quot;<br>client.recreate_collection(<br>    collection_name=collection_name,<br>    vectors_config = models.VectorParams(size=100,distance=models.Distance.COSINE)<br>)</pre><h3>Create Fake Data</h3><p>As we are learning, so we need dummy data to interact with vector database.</p><pre># random thousand vectors of size 100<br>vectors = np.random.uniform(low=-1,high=1,size=(1000,100))<br># indexes for each datapoint<br>indx = list(range(len(vectors)))</pre><pre># creating fake metadata on books for payloads<br>fake = Faker()<br>fake_payload =[]<br>for i in range(len(vectors)):<br>    fake_payload.append(<br>        {<br>            &quot;writer&quot;:fake.name(),<br>            &quot;Title&quot; : &quot; &quot; .join(fake.words()),<br>            &quot;url&quot;   : fake.url(),<br>            &quot;country&quot;: fake.country(),<br>            &quot;publishing_year&quot;: fake.year()<br>        }<br>        ) <br># show first 3 payloads<br>fake_payload[:3]</pre><p>Output would be something like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sF5GesGDEOXKXjt2x7Mi3g.png" /></figure><h3><strong>Uploading Data to Vector Database</strong></h3><p>Now we need to upload the data that we created to database so that we can interact with it.</p><pre># adding dummy ids,vectors,and payload to collection<br>client.upsert(<br>    collection_name=collection_name,<br>    points=models.Batch(<br>        ids = indx,<br>        vectors= vectors.tolist(),<br>        payloads=fake_payload<br>    )<br>)</pre><p>Now you can retrieve data points from collection.</p><pre># retrieving specific indexes without vectors<br>client.retrieve(<br>    collection_name=collection_name,<br>    ids = [3,646,83] # indexes of data points we want to retrieve<br>    # , with_vectors=True    #This option will return vectors as well<br>)</pre><h3>Semantic Search</h3><p>Consider a user search for books similar to think and grow rich,so we need to show books that are the best match to it.</p><pre># vectorized form of think and grow rich<br>think_grow_rich = np.random.uniform(size=(100))</pre><pre>client.search(<br>    collection_name=collection_name,<br>    query_vector= think_grow_rich,<br>    limit=3 # limit the number of matches to return<br>)<br># score in results show the similarity score</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1013/1*V4xonEnhuPSWa8AOGXbE0A.png" /></figure><h3>Search with Criteria</h3><p>Consider you want to retrieve only results that are from Indonesia, This could be done by doing the following.</p><pre># Defining criteria<br>indonesia_books= models.Filter(<br>    must =[<br>        models.FieldCondition(<br>            key = &quot;country&quot;,match = models.MatchValue(value=&#39;Indonesia&#39;)<br>        )<br>    ]<br>)<br># searching with the defined criteria<br><br>client.search(<br>    collection_name=collection_name,<br>    query_vector=think_grow_rich,<br>    query_filter=indonesia_books,<br>    limit=3<br>)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1013/1*QXtEqc4y5ZJ1QxsGlS-lQw.png" /></figure><h3>Recommendation</h3><p>Consider, a user is using your platform related to books, and you have the data about books he liked and the books he did not like. You can recommend the user the best relevant books for him to stay connected with your platform.</p><p>All you have to do is just provide the indexes of the books he liked to parameter positive and the books he did not like to negative .</p><pre>recommendations = client.recommend(<br>        collection_name=collection_name,<br>        positive=[9, 491, 700],  # IDs of books user likes<br>        negative=[63, 321],  # IDs of books user did not like<br>        query_filter=models.Filter(<br>            must=[models.FieldCondition(<br>                key=&quot;country&quot;,<br>                match=models.MatchValue(value=&quot;Spain&quot;)<br>            )]<br>        ),<br>        limit=2<br>    )<br><br>recommendations</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1013/1*pUh2sxDa0vcJ-lHk7y4GfQ.png" /></figure><h3>Conclusion</h3><p>These kinds of features make it easy for us to handle data in vector form, especially in the era where Large Language Models (LLMs) are a hot topic. LLMs often utilize Retrieval-Augmented Generation (RAG) techniques, which rely heavily on vector databases to provide users with the most relevant and up-to-date knowledge, even if that information wasn’t available when the model was initially trained.</p><p>This whole article serves as a basic introduction. For a more detailed understanding, I recommend referring to the <a href="https://qdrant.tech/documentation/concepts/search/">official documentation</a> to gain an in-depth knowledge of Qdrant and its capabilities.</p><p>If you have reached here, you are doing wonderfully in learning and updating yourself. I keep posting articles designed to keep things simple yet understandable. So, follow me and give claps, as it provides the motivation to keep posting.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6f0dfa61a81" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unlocking Video Sentiment Analysis: Training and Deploying with Transformers and Gradio]]></title>
            <link>https://medium.com/@mubashiri656/unlocking-video-sentiment-analysis-training-and-deploying-with-transformers-and-gradio-bfffc67c78fd?source=rss-7cfed3874fd3------2</link>
            <guid isPermaLink="false">https://medium.com/p/bfffc67c78fd</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[sentiment-analysis]]></category>
            <category><![CDATA[bart]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[video-analytics]]></category>
            <dc:creator><![CDATA[Mubashir Iqbal]]></dc:creator>
            <pubDate>Mon, 29 Jul 2024 19:19:02 GMT</pubDate>
            <atom:updated>2024-07-29T19:19:02.003Z</atom:updated>
            <content:encoded><![CDATA[<p>Understanding the emotional tone of videos can provide deep insights, whether it’s for customer feedback or monitoring social media. In this guide, we’ll show you how to train a sentiment analysis model on video transcriptions using Hugging Face’s transformers and deploy it with Gradio for an interactive experience.</p><h3><strong>Introduction</strong></h3><p>Sentiment analysis is a powerful tool for gauging the emotional tone in text data. By analyzing video transcriptions, we can understand the sentiments conveyed in videos. This guide will take you through the steps to build and deploy a sentiment analysis model using transformers and Gradio.</p><p><strong>Setting Up the Environment</strong></p><p>First, let’s install the necessary libraries. Open your terminal and run:</p><pre>pip install torch transformers datasets pandas gradio</pre><p><strong>Why BART?</strong></p><p>We chose BART (`facebook/bart-base`) for this task because of its robust performance in natural language processing tasks. BART is a denoising autoencoder for pretraining sequence-to-sequence models, which excels in tasks involving text generation and classification. Its transformer architecture allows it to handle complex text structures efficiently, making it ideal for sentiment analysis of video transcriptions.</p><p><strong>Training the Model</strong></p><p>1. <strong>Load Data</strong>: Start by loading a dataset of video transcriptions with associated sentiment labels.</p><pre>import pandas as pd<br> from datasets import Dataset<br>filepath = &quot;path/to/dataset.csv&quot;<br> data = pd.read_csv(filepath)<br> data.drop(columns=[&quot;Unnamed: 0&quot;], inplace=True)<br> label = {&quot;Negative&quot;: 0, &quot;Positive&quot;: 1}<br> data[&#39;Sentiment&#39;] = data[&#39;Sentiment&#39;].map(label)<br> df_hf = Dataset.from_pandas(data).train_test_split(test_size=0.1)<br> df_hf[&quot;validation&quot;] = df_hf.pop(&quot;test&quot;)</pre><p>2. <strong>Load Tokenizer and Model</strong>: Use `facebook/bart-base` for our sentiment analysis model.</p><pre>from transformers import AutoTokenizer, AutoModelForSequenceClassification<br>model_name = &#39;facebook/bart-base&#39;<br> tokenizer = AutoTokenizer.from_pretrained(model_name)<br> model = AutoModelForSequenceClassification.from_pretrained(model_name, num_labels=2</pre><p>3. <strong>Prepare Data Loaders</strong>: Tokenize the data and prepare it for training.</p><pre>from transformers import DataCollatorWithPadding<br> from torch.utils.data import DataLoader<br>def tokenize_function(batch):<br> return tokenizer(batch[&#39;Transcription&#39;], truncation=True, padding=True)<br>tokenized_df_hf = df_hf.map(tokenize_function, batched=True)<br> tokenized_df_hf = tokenized_df_hf.remove_columns([&#39;Transcription&#39;]).rename_column(&quot;Sentiment&quot;, &quot;labels&quot;).with_format(&#39;torch&#39;)<br> collator = DataCollatorWithPadding(tokenizer=tokenizer)<br> train_dataloader = DataLoader(tokenized_df_hf[&#39;train&#39;], batch_size=16, shuffle=True, collate_fn=collator)<br> val_dataloader = DataLoader(tokenized_df_hf[&#39;validation&#39;], batch_size=16, collate_fn=collator)</pre><p>4. <strong>Train &amp; Evaluating the Model</strong>: Set up training parameters and train your model.</p><pre>def train_and_evaluate(model, train_dataloader, val_dataloader, num_epochs, lr):<br>    device = torch.device(&quot;cuda&quot;) if torch.cuda.is_available() else torch.device(&quot;cpu&quot;)<br>    model.to(device)<br>    <br>    os.environ[&quot;TOKENIZERS_PARALLELISM&quot;] = &quot;false&quot;<br>    <br>    optimizer = torch.optim.AdamW(model.parameters(), lr=lr)<br>    num_of_steps = num_epochs * len(train_dataloader)<br>    lr_scheduler = get_scheduler(<br>        &quot;linear&quot;,<br>        optimizer=optimizer,<br>        num_warmup_steps=0,<br>        num_training_steps=num_of_steps<br>    )<br>    <br>    for epoch in range(num_epochs):<br>        model.train()<br>        train_loss = 0<br>        for batch in train_dataloader:<br>            batch = {k: v.to(device) for k, v in batch.items()}<br>            outputs = model(**batch)<br>            loss = outputs.loss<br>            loss.backward()<br>            optimizer.step()<br>            lr_scheduler.step()<br>            optimizer.zero_grad()<br>            train_loss += loss.item()<br>        <br>        avg_train_loss = train_loss / len(train_dataloader)<br>        <br>        model.eval()<br>        val_loss = 0<br>        preds = []<br>        labels = []<br>        with torch.no_grad():<br>            for batch in val_dataloader:<br>                batch = {k: v.to(device) for k, v in batch.items()}<br>                outputs = model(**batch)<br>                loss = outputs.loss<br>                val_loss += loss.item()<br>                preds.append(outputs.logits.cpu().numpy())<br>                labels.append(batch[&#39;labels&#39;].cpu().numpy())<br>        <br>        preds = np.concatenate(preds, axis=0)<br>        labels = np.concatenate(labels, axis=0)<br>        avg_val_loss = val_loss / len(val_dataloader)<br>        accuracy, precision, recall, f1 = compute_metrics(preds, labels)<br>        <br>        print(f&quot;Epoch {epoch + 1}/{num_epochs}, Train Loss: {avg_train_loss:.4f}, Val Loss: {avg_val_loss:.4f}&quot;)<br>        print(f&quot;Accuracy: {accuracy:.4f}, Precision: {precision:.4f}, Recall: {recall:.4f}, F1 Score: {f1:.4f}&quot;)</pre><h3>Deploying with Gradio</h3><p>1. <strong>Create a Prediction Function: </strong>Define a function to predict sentiment using the trained model.</p><p>from transformers import AutoTokenizer, AutoModelForSequenceClassification<br> import torch</p><pre>def predict_sentiment(text):<br>   model_dir = &quot;path/to/your/model&quot;<br>   tokenizer = AutoTokenizer.from_pretrained(model_dir)<br>   model = AutoModelForSequenceClassification.from_pretrained(model_dir)<br>   inputs = tokenizer(text, return_tensors=&quot;pt&quot;, truncation=True, padding=True, max_length=512)<br>   with torch.no_grad():<br>     outputs = model(**inputs)<br>     logits = outputs.logits<br>     predicted_class_id = torch.argmax(logits, dim=1).item()<br>     return &quot;Positive&quot; if predicted_class_id == 1 else &quot;Negative&quot;</pre><p>2. Building the Gradio Interface: Create an interactive interface to input text and get predictions.</p><pre>import gradio as gr<br>from predict import predict_sentiment<br><br># Create the Gradio interface<br>iface = gr.Interface(<br>    fn=predict_sentiment,             # Directly use predict_sentiment<br>    inputs=gr.Textbox(<br>        lines=10, <br>        placeholder=&quot;Paste the transcription of the video here...&quot;, <br>        label=&quot;Video Transcription&quot;,<br>        interactive=True,  # Make it interactive for user input<br>    ),<br>    outputs=gr.Label(label=&quot;Sentiment Prediction&quot;),  # Use a label for output<br>    title=&quot;Video Sentiment Analysis&quot;,  # Title of the interface<br>    description=&quot;Enter the transcription of a video to predict its sentiment.&quot;,<br>    theme=&quot;compact&quot;,  # Use a compact theme for a cleaner look<br>    css=&quot;&quot;&quot;<br>    .gradio-container {<br>        display: flex;<br>        flex-direction: column;<br>        align-items: center;<br>        justify-content: center;<br>        min-height: 100vh;  /* Ensures the content is vertically centered */<br>    }<br>    .input-textbox, .output-label {<br>        margin: 10px;  /* Adds spacing between the input and output boxes */<br>        width: 80%;  /* Makes the boxes responsive */<br>        max-width: 800px;  /* Limits the maximum width for large screens */<br>    }<br>    .footer { display: none; }  /* Hides the footer */<br>    .input-textbox { <br>        border: 2px solid #4A90E2; <br>        border-radius: 8px; <br>    }  /* Style the input box */<br>    .output-label { <br>        font-size: 18px; <br>        font-weight: bold; <br>        color: #333; <br>    }  /* Style the output label */<br>    &quot;&quot;&quot;,  # Add custom CSS for additional styling<br>)<br><br># Launch the Gradio interface<br>if __name__ == &quot;__main__&quot;:<br>    iface.launch(share=True)</pre><h3>Conclusion</h3><p>With this setup, you have a powerful sentiment analysis tool that’s easy to train and deploy. By leveraging transformers for the heavy lifting and Gradio for the user interface, you can quickly create interactive and useful applications that provide valuable insights from video transcriptions.</p><h3>Publish on Hugging Face Spaces</h3><p>Lastly, you can publish your Gradio app on Hugging Face Spaces for easy sharing. Simply create a new Space, upload your project files, and it will handle the rest. You can check out the deployed model and interface on Hugging Face Spaces under the name <strong>Mubashir412/Video_Transcription_Classification</strong>.</p><p>By following these steps, you can harness the power of sentiment analysis to better understand textual data, providing valuable insights and driving smarter decisions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bfffc67c78fd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Transformer Network from Scratch]]></title>
            <link>https://medium.com/@mubashiri656/building-a-transformer-network-from-scratch-29a19362273d?source=rss-7cfed3874fd3------2</link>
            <guid isPermaLink="false">https://medium.com/p/29a19362273d</guid>
            <category><![CDATA[transformers]]></category>
            <category><![CDATA[code-transformer]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[naturallanguageprocessing]]></category>
            <category><![CDATA[code-from-scratch]]></category>
            <dc:creator><![CDATA[Mubashir Iqbal]]></dc:creator>
            <pubDate>Wed, 24 Jul 2024 18:17:10 GMT</pubDate>
            <atom:updated>2024-07-24T18:17:10.254Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a Transformer from Scratch: A Beginner’s Guide</h3><p>Transformers are the backbone of many cutting-edge models in machine learning today. You might be familiar with the Transformer model from the famous paper <strong><em>“Attention Is All You Need,”</em></strong> but diving into its details can be overwhelming. To simplify this, I have crafted a guide that walks you through a Transformer network implementation using PyTorch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*6HJJIfkorTlVi-gkvXJe-g.jpeg" /></figure><p>This article is inspired by insights gained from watching two key resources: <strong>Andrej Karpathy’s</strong> <a href="https://www.youtube.com/watch?v=kCc8FmEb1nY">video</a> that provided a clear understanding of how Transformers work, and <strong>Aladdin Persson’s</strong> <a href="https://www.youtube.com/watch?v=U0s0f995w14">video</a>, which filled in the gaps by explaining their practical implementation. Together, these videos have shaped this comprehensive guide, designed to bridge theory and practice. Whether you’re a beginner eager to grasp the fundamentals or someone looking to deepen your understanding, this article will offer valuable insights into the transformative power of Transformers. If you find this guide helpful, I highly recommend checking out the videos from <strong>Andrej Karpathy</strong>and <strong>Aladdin Persson </strong>to enrich your learning experience further.</p><h3>What is a Transformer?</h3><p>Before diving into the code, let’s break down what a Transformer is. At its core, the Transformer is a model designed to handle sequences of data. Unlike older models like RNNs and LSTMs, Transformers use attention mechanisms to process sequences in parallel, making them highly efficient.</p><p>The Transformer architecture is built around two main components: the <strong>Encoder</strong> and the <strong>Decoder</strong>. The Encoder reads, processes and compress the input data, while the decoder generates the output using the information from the encoder and the target data.</p><h3><strong>Building Blocks of Our Transformer</strong></h3><p>We’ll start by creating some essential components of the Transformer: Self-Attention, Transformer Blocks, and the Encoder and Decoder.</p><p><strong>1. Self-Attention Mechanism</strong></p><p>Self-attention is like a superpower for Transformers, crucial for understanding the entire model’s flow. Picture it as a high-tech magnifying glass that zooms in on important details while filtering out the noise. The mechanism operates by generating Query, Key, and Value vectors for each token. It then calculates attention scores to determine the importance of each token within the context. This process enables the model to process information in parallel, speeding up computations and enhancing efficiency. The result is a model that can easily understand complex relationships and long-range dependencies.</p><p>Curious about how this fascinating mechanism works in more detail? Check out my article, <a href="https://medium.com/@mubashiri656/transformers-simplified-understanding-self-attention-with-easy-analogies-9464585459ce"><strong>“Self-Attention: Understanding with Easy Analogies,” </strong></a>for an engaging breakdown!</p><p>Here’s the code of the Self-Attention mechanism:</p><pre>import torch<br>import torch.nn as nn<br><br>class SelfAttention(nn.Module):<br>    def __init__(self, embed_size, heads):<br>        super(SelfAttention, self).__init__()<br>        self.embed_size = embed_size<br>        self.heads = heads<br>        self.head_dim = embed_size // heads<br><br>        assert self.head_dim * heads == embed_size, &quot;Embedding size must be divisible by heads&quot;<br><br>        self.values = nn.Linear(embed_size, embed_size)<br>        self.keys = nn.Linear(embed_size, embed_size)<br>        self.queries = nn.Linear(embed_size, embed_size)<br>        self.fc_out = nn.Linear(embed_size, embed_size)<br><br>    def forward(self, values, keys, query, mask):<br>        N = query.shape[0]<br>        value_len, key_len, query_len = values.shape[1], keys.shape[1], query.shape[1]<br><br>        values = self.values(values)<br>        keys = self.keys(keys)<br>        queries = self.queries(query)<br><br>        values = values.reshape(N, value_len, self.heads, self.head_dim)<br>        keys = keys.reshape(N, key_len, self.heads, self.head_dim)<br>        queries = queries.reshape(N, query_len, self.heads, self.head_dim)<br><br>        energy = torch.einsum(&quot;nqhd,nkhd-&gt;nhqk&quot;, [queries, keys])<br>        <br>        if mask is not None:<br>            energy = energy.masked_fill(mask == 0, float(&quot;-1e20&quot;))<br><br>        attention = torch.softmax(energy / (self.embed_size ** (1 / 2)), dim=3)<br>        out = torch.einsum(&quot;nhql,nlhd-&gt;nqhd&quot;, [attention, values]).reshape(N, query_len, self.heads * self.head_dim)<br>        out = self.fc_out(out)<br><br>        return out</pre><p><strong>2. Transformer Block</strong></p><p>Transformer block uses SelfAttention to calculate attention and then perform residual connection and normalization with feedforward for processing the information further</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/211/1*TudGIVS_lZ_Xhsyu876FYA.jpeg" /><figcaption>Transformer Block</figcaption></figure><pre>class TransformerBlock(nn.Module):<br>    def __init__(self, embed_size, heads, dropout, forward_expansion):<br>        super(TransformerBlock, self).__init__()<br>        self.attention = SelfAttention(embed_size, heads)<br>        self.norm1 = nn.LayerNorm(embed_size)<br>        self.norm2 = nn.LayerNorm(embed_size)<br><br>        self.feed_forward = nn.Sequential(<br>            nn.Linear(embed_size, forward_expansion * embed_size),<br>            nn.ReLU(),<br>            nn.Linear(forward_expansion * embed_size, embed_size),<br>        )<br><br>        self.dropout = nn.Dropout(dropout)<br><br>    def forward(self, value, key, query, mask):<br>        attention = self.attention(value, key, query, mask)<br>        x = self.dropout(self.norm1(attention + query))<br>        forward = self.feed_forward(x)<br>        out = self.dropout(self.norm2(forward + x))<br>        return out</pre><p><strong>3. Encoder</strong></p><p>An Encoder Block consists of just a single Transformer Block. To enhance the model’s ability to capture and understand complex patterns in the input data, multiple Encoder Blocks are stacked together. The first Encoder Block requires proper input embeddings and positional encodings to effectively process the input data. The Encoder class facilitates this process by managing the stacking of multiple Encoder Blocks, ensuring that each block builds on the previous one to provide a richer and more comprehensive understanding of the input.</p><pre>class Encoder(nn.Module):<br>    def __init__(self, src_vocab_size, embed_size, num_layers, heads, device, forward_expansion, dropout, max_length):<br>        super(Encoder, self).__init__()<br>        self.embed_size = embed_size<br>        self.device = device<br>        self.word_embedding = nn.Embedding(src_vocab_size, embed_size)<br>        self.position_embedding = nn.Embedding(max_length, embed_size)<br>        self.layers = nn.ModuleList(<br>            [TransformerBlock(embed_size, heads, dropout, forward_expansion) for _ in range(num_layers)]<br>        )<br>        self.dropout = nn.Dropout(dropout)<br><br>    def forward(self, x, mask):<br>        N, seq_length = x.shape<br>        positions = torch.arange(0, seq_length).expand(N, seq_length).to(self.device)<br>        out = self.dropout(self.word_embedding(x) + self.position_embedding(positions))<br><br>        for layer in self.layers:<br>            out = layer(out, out, out, mask)<br>        return out</pre><p><strong>4. Decoder</strong></p><p>The decoder maps inputs to outputs based on the encoder’s understanding. Decoder block has two unique features:</p><p><strong>Masked self-attention:</strong> Each word can only interact with preceding words, allowing it to predict future words without knowing them in advance.<br><strong>Transformer Block:</strong> The transformer block in the decoder uses queries from masked self-attention and keys/values from the encoder’s final block, integrating the encoder’s context into its predictions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/221/1*YsesG_BStdnPKqtpf1OQZw.jpeg" /><figcaption>Decoder Block : Masked Self Attention + Transformer Block</figcaption></figure><pre>class DecoderBlock(nn.Module):<br>    def __init__(self, embed_size, heads, forward_expansion, dropout, device):<br>        super(DecoderBlock, self).__init__()<br>        self.norm = nn.LayerNorm(embed_size)<br>        self.attention = SelfAttention(embed_size, heads=heads)<br>        self.transformer_block = TransformerBlock(<br>            embed_size, heads, dropout, forward_expansion<br>        )<br>        self.dropout = nn.Dropout(dropout)<br><br>    def forward(self, x, value, key, src_mask, trg_mask):<br>        attention = self.attention(x, x, x, trg_mask)<br>        query = self.dropout(self.norm(attention + x))<br>        out = self.transformer_block(value, key, query, src_mask)<br>        return out</pre><p>Decoder is a stack of decoder blocks multiple time for better decoding of information.</p><pre>class Decoder(nn.Module):<br>    def __init__(<br>        self,<br>        trg_vocab_size,<br>        embed_size,<br>        num_layers,<br>        heads,<br>        forward_expansion,<br>        dropout,<br>        device,<br>        max_length,<br>    ):<br>        super(Decoder, self).__init__()<br>        self.device = device<br>        self.word_embedding = nn.Embedding(trg_vocab_size, embed_size)<br>        self.position_embedding = nn.Embedding(max_length, embed_size)<br><br>        self.layers = nn.ModuleList(<br>            [<br>                DecoderBlock(embed_size, heads, forward_expansion, dropout, device)<br>                for _ in range(num_layers)<br>            ]<br>        )<br>        self.fc_out = nn.Linear(embed_size, trg_vocab_size)<br>        self.dropout = nn.Dropout(dropout)<br><br>    def forward(self, x, enc_out, src_mask, trg_mask):<br>        N, seq_length = x.shape<br>        positions = torch.arange(0, seq_length).expand(N, seq_length).to(self.device)<br>        x = self.dropout((self.word_embedding(x) + self.position_embedding(positions)))<br><br>        for layer in self.layers:<br>            x = layer(x, enc_out, enc_out, src_mask, trg_mask)<br><br>        out = self.fc_out(x)<br><br>        return out</pre><p><strong>5. Putting It All Together</strong><br>At last, the complete transformer model seamlessly integrates the Encoder and Decoder, facilitating smooth communication between the two components for efficient processing and output generation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*UoJozf3rtgjgTrK6bwu-mw.jpeg" /></figure><pre>class Transformer(nn.Module):<br>    def __init__(<br>        self,<br>        src_vocab_size,<br>        trg_vocab_size,<br>        src_pad_idx,<br>        trg_pad_idx,<br>        embed_size=512,<br>        num_layers=6,<br>        forward_expansion=4,<br>        heads=8,<br>        dropout=0,<br>        device=&quot;cpu&quot;,<br>        max_length=100,<br>    ):<br><br>        super(Transformer, self).__init__()<br><br>        self.encoder = Encoder(<br>            src_vocab_size,<br>            embed_size,<br>            num_layers,<br>            heads,<br>            device,<br>            forward_expansion,<br>            dropout,<br>            max_length,<br>        )<br><br>        self.decoder = Decoder(<br>            trg_vocab_size,<br>            embed_size,<br>            num_layers,<br>            heads,<br>            forward_expansion,<br>            dropout,<br>            device,<br>            max_length,<br>        )<br><br>        self.src_pad_idx = src_pad_idx<br>        self.trg_pad_idx = trg_pad_idx<br>        self.device = device<br><br>    def make_src_mask(self, src):<br>        src_mask = (src != self.src_pad_idx).unsqueeze(1).unsqueeze(2)<br>        # (N, 1, 1, src_len)<br>        return src_mask.to(self.device)<br><br>    def make_trg_mask(self, trg):<br>        N, trg_len = trg.shape<br>        trg_mask = torch.tril(torch.ones((trg_len, trg_len))).expand(<br>            N, 1, trg_len, trg_len<br>        )<br><br>        return trg_mask.to(self.device)<br><br>    def forward(self, src, trg):<br>        src_mask = self.make_src_mask(src)<br>        trg_mask = self.make_trg_mask(trg)<br>        enc_src = self.encoder(src, src_mask)<br>        out = self.decoder(trg, enc_src, src_mask, trg_mask)<br>        return out</pre><p><strong>6. Testing Our Model</strong></p><p>To see our Transformer in action, here’s a quick test:</p><pre><br>if __name__ == &quot;__main__&quot;:<br>    device = torch.device(&quot;cuda&quot; if torch.cuda.is_available() else &quot;cpu&quot;)<br>    print(device)<br><br>    x = torch.tensor([[1, 5, 6, 4, 3, 9, 5, 2, 0], [1, 8, 7, 3, 4, 5, 6, 7, 2]]).to(<br>        device<br>    )<br>    trg = torch.tensor([[1, 7, 4, 3, 5, 9, 2, 0], [1, 5, 6, 2, 4, 7, 6, 2]]).to(device)<br><br>    src_pad_idx = 0<br>    trg_pad_idx = 0<br>    src_vocab_size = 10<br>    trg_vocab_size = 10<br>    model = Transformer(src_vocab_size, trg_vocab_size, src_pad_idx, trg_pad_idx, device=device).to(<br>        device<br>    )<br>    out = model(x, trg[:, :-1])<br>    print(out.shape)</pre><p>This code snippet will initialize the model and provide an output shape for a sample input.</p><h3><strong>Conclusion</strong></h3><p>Congratulations! You’ve just built a Transformer model from scratch. This implementation covers the basics and should give you a solid foundation.</p><p>If you found this review helpful and are curious to learn more about complex topics explained simply, follow my updates here. Enjoyed the read? Don’t forget to hit the clap button up to 10 times to show your support!😀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29a19362273d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Self-Attention: Understanding with Easy Analogies]]></title>
            <link>https://medium.com/@mubashiri656/transformers-simplified-understanding-self-attention-with-easy-analogies-9464585459ce?source=rss-7cfed3874fd3------2</link>
            <guid isPermaLink="false">https://medium.com/p/9464585459ce</guid>
            <category><![CDATA[self-attention]]></category>
            <category><![CDATA[non-technical]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[transformers]]></category>
            <dc:creator><![CDATA[Mubashir Iqbal]]></dc:creator>
            <pubDate>Tue, 02 Jul 2024 05:28:16 GMT</pubDate>
            <atom:updated>2024-07-02T05:57:27.935Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wGaqSdPHeUkscdrk_Cqk0A.jpeg" /><figcaption><a href="https://www.domain499.com/wp-content/uploads/2023/08/Best-Online-Masters-in-HCI-Human-Computer-Interaction-featured-image.jpg">Image by Domain499</a></figcaption></figure><p>In the rapidly changing field of Natural Language Processing (NLP) ,where community has long faced the challenges of making existing NLP models efficient in terms of training time of sequential data, difficulty in using parallelism and limitations in capturing long range context from sequence. Introduction of Transformers was a major break through and moment of joy for the community, because it overcame some longstanding challenges in the Natural Language Processing(NLP).</p><p><strong>Key Advantages &amp; Innovation of Self Attention in Transformers:</strong></p><ul><li><strong>Introduced Parallelism: </strong>One of the main challenges in the previous NLP models for sequences was the time of training and computation they take because of not having ability to do computation as they took input time step by time step i.e., to not get to next value of sequence until it has processed the previous values. Transformer introduced parallelism which resulted in efficient computation time of model.</li><li><strong>Maintaining Sequential Knowledge : </strong>Biggest challenge in the way of parallelism was how to capture the context from sequence as all of the inputs will be processed at same time so how model will know the order or sequence. Transformers solved this issue by using positional embeddings.</li><li><strong>Enhancing Long Range Context: </strong>Earlier models struggled to capture long term context i.e., if something come at the end of long sequence but it is directly related to what came at the start of sequence then model struggles to capture it’s understanding, which was significant limitation in sequence models.</li></ul><h3>Core Components of Transformer:</h3><p>Briefly saying, whole transformer is about two things,</p><ul><li>Self Attention (key innovation of transformers)</li><li>Feed Forward Network</li></ul><p>Here we are going to discuss the <strong>Self Attention </strong>only.</p><h3>What is Attention?</h3><p>Attention is a mechanism that helps model to in analyzing which parts are the most relevant and how much focus/weight should be assigned to each element/token in a sequence. This empower models to prioritize tokens based on the context and their relevance.</p><p>In more simple words, its like a magnifying glass which zoom and enlarge those parts which are more relevant for model to pay attention to them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PKDJ2fclwDUa3y-cxg7qUw.jpeg" /></figure><h3>But How Self Attention Works?🤔</h3><p>Consider the scenario that you are searching for some topic on YouTube, lets say “What are Neural Networks”. To learn and understand the topic the order of execution would be</p><ul><li>Search the topic in search bar on YouTube, Say: <strong>Query(Q)</strong>.</li><li>Filter/Choose the most relevant title, Say: <strong>Key (K)</strong>.</li><li>Choosing and retrieving most relevant content from video, Say: <strong>Value(V)</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*AxpzIMf-ryWSjLXSVTFNvw.png" /><figcaption>Source: <a href="https://www.researchgate.net/publication/366868653/figure/fig1/AS:11431281111093580@1672880964239/Flowchart-of-the-the-self-attention-module.ppm">Research Gate</a></figcaption></figure><p>That’s exactly how Self Attention works. To make 3 vectors of each word using different matrix assigned for relevant task. And computing similarity (just like it was in YouTube search case) using dot product of Query(Q) of the word and Key(K) vectors of other words. Normalizing them to get idea of how much weightage to give to the values of each word/token in sequence. And multiplying those normalize values to get the attention value for the word. This is how each model find attention of each token and pass it to feed forward network for further processing.</p><h3>Multi-Head Attention:</h3><p>To make most value out of sequence, just like we do by searching different queries and watching different videos on YouTube for in depth understanding, transformers use multi head attention i.e., to have more than one sets of Query(Q), Key(K) and Value(V) matrices , to capture detailed context of the sequence by different queries/angles. Each head capture different context from different perspective to enhance the results.</p><h3>Conclusion</h3><p>Looking forward, self-attention stands as a pivotal innovation not just in natural language processing but also in other domains like computer vision. Its sophisticated handling of data, coupled with the ability to preserve sequence order and enhance long-distance contextual understanding, lays the groundwork for more advanced AI language applications. This technology not only addresses previous limitations but also paves the way for exploring new, more complex language interactions, revolutionizing our expectations of machine capabilities in understanding and interacting with human language.</p><p>If you found this review helpful and are curious to learn more about complex topics explained simply, follow my updates here. Enjoyed the read? Don’t forget to hit the clap button up to 10 times to show your support!😀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9464585459ce" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>