<?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 Hemang Baldha on Medium]]></title>
        <description><![CDATA[Stories by Hemang Baldha on Medium]]></description>
        <link>https://medium.com/@hemang9705?source=rss-130abf8e7bb9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*KCgkf8DF-UDBqjtmvhHbTg.png</url>
            <title>Stories by Hemang Baldha on Medium</title>
            <link>https://medium.com/@hemang9705?source=rss-130abf8e7bb9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 08:42:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hemang9705/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[What is a Voice Agent? Why Latency Is the Product, Not a Side Detail]]></title>
            <link>https://medium.com/@hemang9705/what-is-a-voice-agent-why-latency-is-the-product-not-a-side-detail-580c376679d5?source=rss-130abf8e7bb9------2</link>
            <guid isPermaLink="false">https://medium.com/p/580c376679d5</guid>
            <category><![CDATA[conversational-ai]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[speech-recognition]]></category>
            <category><![CDATA[ai-voice-agent]]></category>
            <category><![CDATA[text-to-speech]]></category>
            <dc:creator><![CDATA[Hemang Baldha]]></dc:creator>
            <pubDate>Mon, 26 Oct 2026 04:31:03 GMT</pubDate>
            <atom:updated>2026-10-26T04:31:03.350Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BJGkhmWMJcVVT753rJybzg.png" /></figure><p><em>“Hello? … Are you still there?”</em></p><p>You have probably said this to a bot at least once. You asked a question, and then nothing happened. Two seconds of silence. You were about to repeat yourself when it finally started talking, right as you started talking again. Now you are both speaking at once, and one of you is a computer.</p><p>Nothing was technically broken. The bot understood you. The answer was even correct. And yet the call felt wrong. So here is the question worth asking: <strong>if the answer was right, why did the conversation feel so bad?</strong></p><p>The reason is that a voice agent is not judged only on what it says. It is judged on <em>when</em> it says it. <strong>Timing is part of the answer.</strong></p><p>In this article we will look at what a voice agent actually is, what happens between the moment you stop talking and the moment you hear a reply, where the time goes, and why speed is a feature you design for from day one. Simple explanations, real examples, a little bit of code, and no dense research papers.</p><h3>Before We Talk About Voice Agents</h3><p>Try this with a friend: ask them a simple question, like “What did you have for lunch?” and ask them to wait 1.5 seconds before answering. Repeat it a few times, and the conversation will start to feel awkward.</p><p>That is because human conversations move fast. Research across <strong>10 languages </strong>found that people usually respond within just <strong>200–300 milliseconds</strong> <a href="https://www.pnas.org/doi/10.1073/pnas.0903616106">(Stivers et al., 2009)</a>. We dont wait for someone to finish speaking before thinking about our reply. We listen, think, and prepare our response simultaneously.</p><p><strong>A voice agent has to do the same thing, except it has a lot more work to handle.</strong></p><h3>What is a Voice Agent?</h3><p>A voice agent is software you can talk to naturally. It listens, understands what you mean, decides how to respond, and speaks back.</p><p>Think of it as a relay race. Instead of one system doing everything, several specialists pass the work along:</p><ol><li><strong>Ears</strong>: Detect when you speak and stop.</li><li><strong>Transcriber</strong>: Turn your speech into text.</li><li><strong>Brain</strong>: Understand your words and decide what to say.</li><li><strong>Mouth</strong>: Turn the reply into speech.</li></ol><p>Sounds simple, right? The hard part is getting all four to work together fast enough that the conversation feels natural, not like waiting in a queue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lIonIjA6NhQDsOtnOk2QEg.png" /></figure><h3>Meet the Four Stages</h3><h3>1. The Ears: Voice Activity Detection (VAD)</h3><p>First, the system needs to know when you are speaking and when you stop. That is the job of <strong>Voice Activity Detection (VAD)</strong>. But a short pause does not always mean you’re done talking. If you say, “My number is nine eight…..” and pause, the system needs to know you are still thinking. Getting this right is harder than it sounds.</p><p>I explored this in my blog on <a href="https://hemangbaldha.com/blogs/building-a-deep-learning-based-voice-activity-detection-model-from-scratch">building a deep-learning-based VAD from scratch</a>.</p><h3>2. The Transcriber: Speech-to-Text (STT)</h3><p>STT converts your speech into text. A good system works <strong>while you are still speaking</strong>, sending partial transcripts to the next stage instead of waiting until you have finished.</p><h3>3. The Brain: The LLM</h3><p>The LLM reads your words, understands the context, and decides how to respond. It can also use tools, like checking your calendar or looking up an order. The key metric is <strong>time to first token (TTFT)</strong>: how quickly the model starts generating its reply. In a conversation, that first response matters more than you might think.</p><h3>4. The Mouth: Text-to-Speech (TTS)</h3><p>Finally, TTS turns the reply into speech. Streaming TTS can start speaking before the LLM has finished generating the entire response, making the conversation feel faster and more natural. <strong>The catch?</strong> These stages do not work in isolation. They need to work together efficiently, or even a smart voice agent will feel painfully slow.</p><h3>Latency Is a Feature, Not a Detail</h3><p>Most teams build the feature first and optimise speed later. For voice agents, that approach gets things backwards.</p><p><strong>The same answer can feel intelligent or frustrating, depending on how quickly it arrives.</strong></p><p>As a rough rule of thumb:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZEOfs2tQWbWmGTMU7LCL9w.png" /></figure><p>These are not strict limits, but they highlight an important point: <strong>users experience latency before they experience intelligence.</strong> A smaller model that responds quickly can feel more capable than a powerful model that keeps them waiting. And not every delay comes from the model. Network conditions, server location, and telephony can add hundreds of milliseconds before your AI even gets a chance to respond.</p><p>That’s why latency is not something you fix at the end. You design for real time interaction from the beginning, then choose the best model that fits within that budget.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r1DcOk1S6vk1LDULikIZLg.png" /></figure><h3>Where Does the Time Actually Go?</h3><p>Imagine a voice agent where every stage waits for the previous one to finish. First, it waits for you to stop speaking. Then STT transcribes your sentence, the LLM generates a reply, and TTS turns it into audio.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MZBa8aUHU_d9Yxrfw66oVw.png" /></figure><p>That is like using a walkie-talkie: you speak, wait, and finally hear a response. The solution is not just making every stage faster. It is making them <strong>work in parallel through streaming</strong>. STT transcribes while you speak. The LLM generates its reply token by token. TTS starts speaking before the entire response is ready.</p><p>Instead of adding every stage’s delay together, the system overlaps their work. With careful engineering, a first audible response in roughly 400–800 ms can be achievable, depending on the model, network, and turn-taking logic.</p><p><strong>The real trick is not just speed. It’s eliminating unnecessary waiting.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wm6erp4FEEAGLWlOK_vjeA.png" /></figure><h3>The Hidden Delay: Knowing When You’re Done</h3><p>One of the biggest sources of delay is not the LLM. It is figuring out when you have finished speaking.</p><p>The simplest approach is a <strong>silence timer</strong>. If you stop speaking for 500 ms, the agent assumes that you are done. But shorten that timer, and it may interrupt you. Lengthen it, and you are stuck waiting.</p><p>Think about the difference between “Yes…” and “Yes, my number is nine eight seven…” A pause doesn’t always mean the same thing. That’s where <strong>semantic turn detection</strong> comes in. Instead of only measuring silence, a model uses speech context to estimate whether you have finished your thought. Tools like Pipecat’s Smart Turn, LiveKit’s turn detector, and OpenAI’s semantic VAD help handle this problem.</p><p>There is another trick called <strong>eager prefill</strong>: the agent starts preparing a reply before you are definitely done speaking. If you are finished, it saves time. If you continue, the agent discards that work. You get a faster response, but potentially more computation. <strong>Every millisecond saved has a trade-off.</strong> Building a good voice agent means deciding which delays to remove, which to tolerate, and when speed is worth the extra cost.</p><h3>Interruptions: People Talk Over Each Other</h3><p>People interrupt. We say “yeah,” “wait, no,” or change our minds halfway through a sentence. A voice agent needs to handle this naturally.</p><p>When you speak while the agent is talking, it is called <strong>barge-in</strong>. The agent must stop playback, cancel ongoing generation, clear queued audio, and start listening again. Any delay makes it feel like the agent is not paying attention. But not every sound is an interruption. A quiet “mm-hm” might mean you are listening, while a cough or background noise means nothing at all. The system must distinguish between them.</p><p>There is another subtle problem: <strong>the agent must remember only what it actually said.</strong> Suppose it starts explaining something, but you interrupt halfway through. If its conversation history includes the words you never heard, it may wrongly assume you already know them. A natural voice agent does not just need to speak quickly. It needs to listen, adapt, and keep track of what actually happened.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GmwaZdk7z9mFuoBgTk_x9Q.png" /></figure><h3>What Goes Wrong in the Real World</h3><p>A voice agent might work perfectly in a quiet demo. Put it on a real phone call, and things get messy.</p><p><strong>Noise and echo.</strong> Fans, traffic, and background conversations can confuse speech recognition. Speakerphones create another problem: the agent may hear its own voice and accidentally respond to itself.</p><p><strong>Bad audio and wrong words.</strong> Phone calls often have lower audio quality than clean recordings. A transcriber might mistake “fifteen” for “fifty,” and the LLM could confidently act on the wrong information. Getting names, dates, and phone numbers right matters more than achieving a good average accuracy score.</p><p><strong>Slow tools.</strong> Checking a calendar or database can add hundreds of milliseconds. A useful trick is to say, “Let me check that for you,” while the lookup runs, rather than leaving the caller in silence.</p><p><strong>Robotic speech.</strong> Even a fast, accurate agent can feel unnatural if it speaks like it is reading a document. Voice responses need shorter sentences, natural wording, and numbers that sound right when spoken. Drive-thrus are a good example of how difficult real-world voice AI can be. Engines, wind, noisy speakers, and customers changing orders create a challenging environment. Some deployments have shown promise, while others have run into accuracy problems.</p><p><strong>The lesson is simple: a voice agent must work outside the demo.</strong> Speed matters, but so do accuracy, noise handling, and the ability to recover when something goes wrong.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ibizhXCbITtr7ud_V_apHA.png" /></figure><h3>A Conversation, Millisecond by Millisecond</h3><p>Imagine someone says, “Can you book me a dentist appointment tomorrow at four?”</p><p>Here is what happens behind the scenes:</p><ol><li><strong>While they speak:</strong> VAD detects speech, and streaming STT starts transcribing.</li><li><strong>They finish:</strong> Turn detection decides whether the request is complete.</li><li><strong>The LLM responds:</strong> It calls a calendar tool to check availability.</li><li><strong>While the tool runs:</strong> The agent can say, “Sure, let me check that for you.”</li><li><strong>The calendar responds:</strong> The agent offers the available slot and asks for confirmation.</li><li><strong>The caller says yes:</strong> The agent handles the interruption and updates its conversation history.</li></ol><p>The goal is simple: <strong>keep the conversation moving without making the user wait unnecessarily.</strong></p><h3>Cascade or Speech-to-Speech?</h3><p>There are two main ways to build a voice agent.</p><p>A <strong>cascade architecture</strong> uses separate STT, LLM, and TTS components. A <strong>speech-to-speech model</strong> processes audio directly and generates spoken responses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_IvwT4JfDp0S72msoY8fqA.png" /></figure><p>Cascades offer more control and visibility into each stage. Speech-to-speech can make conversations more natural by preserving information that text alone cannot capture. Neither approach automatically wins on speed. Actual latency depends on the model, streaming strategy, network, and tool usage.</p><p><strong>The right architecture is the one that meets your latency, accuracy, and control requirements, not simply the one with the newest model.</strong></p><h3>What It Costs</h3><p>Voice agents can be more expensive than their headline pricing suggests. You may pay separately for speech recognition, the LLM, text-to-speech, and telephony. Depending on the setup, estimates can reach <strong>$0.10–$0.20 per minute or more</strong>.</p><p>But the most useful metric is not cost per minute. It’s <strong>cost per successfully completed task</strong>. A cheaper agent that repeatedly fails may cost more in the long run.</p><h3>A Short Checklist</h3><p>Before shipping a voice agent, make sure you:</p><ul><li><strong>Stream everything</strong> and allow each stage to be cancelled.</li><li><strong>Choose a fast model</strong> based on time-to-first-token, not just benchmark scores.</li><li><strong>Use semantic turn detection</strong> to reduce awkward pauses.</li><li><strong>Keep infrastructure close together</strong> to minimise network delays.</li><li><strong>Speak while tools run</strong> instead of leaving the caller in silence.</li><li><strong>Handle interruptions properly</strong>, including tracking what the user actually heard.</li><li><strong>Write for the ear</strong>, using natural, short sentences.</li><li><strong>Measure p95 and p99 latency</strong> for each stage, not just averages.</li><li><strong>Test with real-world conditions</strong>, including noise, accents, and poor phone audio.</li></ul><p>The goal is not simply to build an agent that can talk. It is to build one that responds naturally, handles mistakes, and earns the user’s trust.</p><h3>Final Thoughts</h3><p>A voice agent is more than the model powering it. It is the entire conversation: how quickly it responds, how naturally it speaks, and how gracefully it handles interruptions. A brilliant answer that arrives two seconds late can feel worse than a good answer that arrives at the right moment. <strong>Latency is not just a technical metric. Its part of the user experience. </strong>So, the next time a voice agent feels surprisingly natural, do not just ask how smart its model is. Ask yourself: <strong>How long did it make you wait?</strong></p><h3>Sources</h3><p>Figures from vendor and engineering blogs are marked as claims in the text. The turn-taking research is peer reviewed. I could not find independent benchmarks for speech-to-speech latency or for phone-number errors.</p><ol><li>Stivers et al. (2009), <a href="https://www.pnas.org/doi/10.1073/pnas.0903616106">Universals and cultural variation in turn-taking in conversation</a>, PNAS 106(26)</li><li>LiveKit, <a href="https://livekit.com/blog/voice-agent-architecture-stt-llm-tts-pipelines-explained">Voice agent architecture: STT, LLM, and TTS pipelines explained</a></li><li>LiveKit, <a href="https://livekit.com/blog/sequential-pipeline-architecture-voice-agents">Sequential pipeline architecture for voice agents</a></li><li>LiveKit, <a href="https://livekit.com/blog/turn-detection-and-interruption-handling">Turn detection and interruption handling</a></li><li>Deepgram, <a href="https://deepgram.com/learn/voice-agent-architecture-stt-llm-tts-pipeline-design">Voice Agent Architecture: STT, LLM, and TTS Pipeline Guide</a></li><li>Daily, <a href="https://www.daily.co/blog/announcing-smart-turn-v3-with-cpu-inference-in-just-12ms/">Announcing Smart Turn v3, with CPU inference in just 12ms</a></li><li>OpenAI, <a href="https://developers.openai.com/api/docs/guides/realtime-vad">Realtime API: voice activity detection</a></li><li><a href="http://tianpan.co/">tianpan.co</a>, <a href="https://tianpan.co/blog/2026-04-09-voice-ai-production-300ms-latency-budget">Voice AI in Production: Engineering the 300ms Latency Budget</a></li><li><a href="http://tianpan.co/">tianpan.co</a>, <a href="https://tianpan.co/blog/2026-05-10-voice-agent-turn-taking-250ms-threshold-reshapes-architecture">Voice Agent Turn-Taking: The 250ms Threshold</a></li><li>Gradium, <a href="https://gradium.ai/content/cascaded-voice-agent-vs-speech-to-speech-2026">Cascaded Voice Agents vs Speech-to-Speech in 2026</a></li><li>Coval, <a href="https://www.coval.ai/blog/tts-latency-benchmark-2026/">TTS latency benchmark</a></li><li>Kili Technology, <a href="https://kili-technology.com/blog/asr-models-guide-word-error-rate-benchmarks-and-failure-modes-2026">ASR models guide: word error rate benchmarks and failure modes</a></li><li>The Drive, <a href="https://www.thedrive.com/news/clunky-ai-voiced-drive-thrus-are-already-here-and-getting-orders-wrong">Clunky AI-voiced drive-thrus are already here and getting orders wrong</a></li><li>Speechify, <a href="https://speechify.ai/blog/best-voice-agent-platforms-2026">Best Voice Agent Platforms 2026: compared on real all-in cost</a></li></ol><p>Read on my website by clicking <a href="https://hemangbaldha.com/blogs/what-is-a-voice-agent-why-latency-is-the-product-not-a-side-detail">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=580c376679d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mamba vs Transformers: The Growing Notebook vs the Fixed State (and Mamba 3)]]></title>
            <link>https://medium.com/@hemang9705/mamba-vs-transformers-the-growing-notebook-vs-the-fixed-state-and-mamba-3-2ec048cba6e6?source=rss-130abf8e7bb9------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ec048cba6e6</guid>
            <category><![CDATA[mamba3]]></category>
            <category><![CDATA[mamba]]></category>
            <category><![CDATA[transformers]]></category>
            <category><![CDATA[llm-inference]]></category>
            <category><![CDATA[state-space-model]]></category>
            <dc:creator><![CDATA[Hemang Baldha]]></dc:creator>
            <pubDate>Mon, 28 Sep 2026 06:01:01 GMT</pubDate>
            <atom:updated>2026-09-28T06:01:01.732Z</atom:updated>
            <content:encoded><![CDATA[<p>Why does longer context still hurt latency and memory even when everyone says their model is “efficient”?</p><p><strong>Two families</strong> answer that question differently. Transformers keep a growing notebook of keys and values so every new token can look anything up. Mamba compresses history into a fixed-size state so time stays linear and decode stays lean. Mamba 3 pushes that second idea harder for inference. In 2026, pure Transformers still run most production stacks (with better kernels and caching), while hybrids mix both on purpose.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OnwJAEkTizAVY_zXwGF3Bg.png" /></figure><h3>Two ways to remember a long sequence</h3><p>A Transformer’s core move is scaled dot-product self-attention : every position can attend to every other. Training parallelizes well, that is the <strong>Vaswani et al. (2017)</strong> design.</p><p>The catch is cost. Naive self-attention is O(T²) in sequence length T for both time and memory. At decode time you usually cache keys and values (the KV cache). That cache is the notebook, it grows with context, and long context attention often dominates latency.</p><p>An <strong>SSM</strong>(State space model) / <strong>Mamba </strong>model makes a different bet. History gets folded into a fixed-size state. One sticky note that gets rewritten as tokens arrive. You trade “look up anything in the notebook” for “update a compressed summary.” Cartesia’s framing of Mamba 3 puts it bluntly: fixed-state models compress history. Transformers keep a growing KV “database.”</p><h3>What Transformers struggle with and how we patch them</h3><p><strong>Problem 1</strong>: Quadratic attention compute and memory as T grows (the FlashAttention paper restates this cost).</p><p><strong>Problem 2</strong>: Autoregressive decode with a KV cache. Memory grows with context, and attention work grows with it too. The Mamba 3 authors restate the same shape which is quadratic compute plus linear KV memory at inference.</p><p>Production did not throw Transformers away. It patched them.</p><ul><li><strong>FlashAttention (Dao et al.)</strong> is IO aware exact attention via tiling. Their paper reports <strong>~3× speedup</strong> on GPT-2 at sequence length 1K, same math, smarter memory movement.</li><li>Flash Decoding speeds long-context generation. The PyTorch blog cites up to <strong>~8× faster</strong> generation in a CodeLlama-34B example.</li><li>Prompt / prefix caching reuses already processed prefixes so you do not pay again (Anthropic and OpenAI both document this).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ipv2IzLUAsruRVNrHMRFpg.png" /></figure><p>These patches help a lot. They do not erase the fundamental scaling shape.</p><h3>Mamba’s bet: selective state spaces (1 → 2 → 3)</h3><p>Earlier subquadratic sequence models often lagged attention on language. <strong>Gu &amp; Dao (Mamba-1)</strong> argue the gap was weak content-based reasoning, the model could not <strong>“select” what to keep</strong>.</p><p>Mamba 1 makes the SSM parameters input-dependent (selective Δ, B, C) and uses a hardware-aware parallel scan. The abstract claims <strong>~5× higher inference throughput</strong> than Transformers, linear scaling in length, and a Mamba-3B that matches roughly 2×size Transformers on language modeling.</p><p>Mamba 2 (SSD) links SSMs to structured attention / semiseparable matrices. It restricts A to scalar×identity and uses heads that play nicely with matmuls. The paper reports the core layer<strong> ~2–8× faster</strong> to train than Mamba-1’s selective SSM. On The Pile, their 2.7B claims match or beat prior Mamba and same data Pythia baselines.</p><p>The Mamba 3 paper still names the old SSM pains: quality–efficiency tradeoffs, weak state tracking, and linear decode that is still memory bound on real hardware.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1NfYNwrxpJ5A5ZiQE5890A.png" /></figure><p>Official code lives in <a href="https://github.com/state-spaces/mamba">state-spaces/mamba</a> — Mamba, Mamba2, and Mamba3 modules. Mamba 3 is the inference-first chapter of the same family.</p><h3>Mamba 3: three upgrades that matter at decode</h3><p>Paper: Lahoti et al., <a href="https://arxiv.org/abs/2603.15569">arXiv:2603.15569</a> (submitted March 2026).</p><h3>Three pillars:</h3><ol><li><strong>Exp-trapezoidal discretization :</strong> generalizes Mamba-1/2’s exponential-Euler update. Set λₜ = 1 and you recover Euler; λₜ = 1/2 is classical trapezoid.</li><li><strong>Complex-valued / data-dependent RoPE-like state</strong> <strong>: </strong>the paper reports near-perfect synthetic arithmetic and state-tracking where Mamba-2 and a Mamba 3 path without that RoPE-like state sit near random.</li><li><strong>MIMO vs SISO :</strong> richer state updates. Authors claim MIMO with state size N = 64 matches Mamba-2 N = 128 perplexity (“half state &gt; half latency”). MIMO can use <strong>up to ~4× </strong>decode FLOPs at fixed state size with similar wall-clock.</li></ol><p><strong>SISO</strong> = <strong>Single Input Single Output</strong>.</p><p><strong>MIMO</strong> = <strong>Multiple Input Multiple Output</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VHCex3ROXZdqvnskWu8OKw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RJAlQqJQcpmD5-0Gogb3_Q.png" /></figure><p>H100, batch 128, sequence length 16,384. Model sizes differ.</p><p>Kernels: mamba_ssm/modules/mamba3.py (is_mimo, mimo_rank, d_state). Install from source for Mamba 3.</p><p>One more signal from the authors / Cartesia: they expect linear layers to mostly ship with global self-attention for language models going forward. That tees up hybrids.</p><h3>2026 reality: Transformers, Mamba 3, and hybrids</h3><p>Transformers remain the production default propped up by FlashAttention, Flash-Decoding, and prompt caching. If you need mature tooling and flexible retrieval, this is still the safe path.</p><p>Pure SSM / Mamba is strongest when you care about linear scaling and decode throughput. Mamba 3 SISO/MIMO around 1.5B is open via state-spaces/mamba, with Cartesia’s latency numbers as a public reference point. Hybrids are the practical middle, keep some global attention for retrieval, use SSM / linear layers for length and efficiency.</p><h3>Named examples from the research:</h3><ul><li><strong>Jamba (AI21):</strong> Transformer + Mamba + MoE; roughly 1 attention : 7 Mamba; up to 256K context; their blog cites ~3× throughput vs Mixtral 8x7B on long contexts and ~140K context on one GPU.</li><li><strong>Zamba:</strong> Mamba backbone plus one shared global attention every six layers (7B).</li><li><strong>Hymba:</strong> parallel attention + SSM heads; Hymba-1.5B claims beat Llama-3.2–3B average accuracy with an 11.67× smaller cache and 3.49× throughput (paper-reported).</li><li><strong>Griffin (DeepMind):</strong> gated linear recurrence (Hawk / RG-LRU) plus local attention. Paper claims Llama-2-level quality with far fewer tokens, scaled to 14B.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ny3J014KVrWvPtjgNhud1g.png" /></figure><h3>How to choose (short):</h3><ul><li>Need the notebook : flexible lookup, ecosystem, and “just ship it”? Stay on Transformers and use the patches.</li><li>Need the sticky note : linear time and lean decode, and you will live with compressed state? Look at Mamba 3.</li><li>Need both retrieval and length? Start with a hybrid (Jamba/Zamba/Hymba/Griffin-style), which is also where the Mamba 3 authors themselves point for language models.</li></ul><p>The quadratic tax did not vanish. We either pay it smarter and compress harder or split the difference.</p><h3>Sources</h3><ol><li><a href="https://arxiv.org/abs/1706.03762">Attention Is All You Need</a></li><li><a href="https://arxiv.org/abs/2312.00752">Mamba: Linear-Time Sequence Modeling with Selective State Spaces</a></li><li><a href="https://arxiv.org/abs/2405.21060">Transformers are SSMs (Mamba-2 / SSD)</a></li><li><a href="https://arxiv.org/abs/2603.15569">Mamba 3: Improved Sequence Modeling using State Space Principles</a></li><li><a href="https://www.cartesia.ai/blog/mamba-3">Mamba 3: An Inference-First State Space Model (Cartesia)</a></li><li><a href="https://github.com/state-spaces/mamba">state-spaces/mamba</a></li></ol><p><strong>Read on Portfolio</strong> : <a href="https://hemangbaldha.com/blogs/mamba-vs-transformers">https://hemangbaldha.com/blogs/mamba-vs-transformers</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ec048cba6e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is a Text-to-SQL Harness?]]></title>
            <link>https://medium.com/@hemang9705/what-is-a-text-to-sql-harness-20cbe820de50?source=rss-130abf8e7bb9------2</link>
            <guid isPermaLink="false">https://medium.com/p/20cbe820de50</guid>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[text-to-sql]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Hemang Baldha]]></dc:creator>
            <pubDate>Wed, 09 Sep 2026 04:11:00 GMT</pubDate>
            <atom:updated>2026-09-09T11:43:40.403Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L7G12atQn6KePOrOpQ5oFQ.png" /></figure><p>“Can’t ChatGPT already write SQL?”</p><p>It can. Ask any modern model for a query and it hands you something that looks professional within seconds. Correct indentation, sensible joins, a neat little GROUP BY at the bottom. It looks like something a senior analyst would write.</p><p>So here is the question worth asking:</p><p>If the model is already this good, why does every serious text-to-SQL product ship thousands of lines of code wrapped around that single model call?</p><p>The answer is that generating SQL was never the hard part. Generating SQL that is safe to run against someone’s real database, that actually answers the question they asked, and that fails in a way you can explain to them. That is the hard part.</p><p>All of that machinery around the model has a name. It is called a <strong>harness</strong>.</p><p>In this article we will look at what a text to SQL harness is, what each piece of it does, and why removing any one of them breaks something. Simple explanations, real SQL examples, and no dense research papers.</p><h3>Before We Talk About the Harness</h3><p>Try a small experiment.<br>Open ChatGPT and ask it this, without giving it any other information: “Who are my top 10 customers by lifetime value?”<br>It will answer. Confidently. You will get something like this :</p><pre>SELECT c.customer_name,<br>SUM(`total_amount`) AS lifetime_value<br>FROM customers c<br>JOIN orders o ON o.customer_id = c.customer_id<br>GROUP BY c.customer_name<br>ORDER BY lifetime_value DESC<br>LIMIT 10;</pre><p>Read that query again. It s clean. The join is right. The aggregation makes sense. If you saw it in a code review you would probably approve it. There is just one problem. The model has never seen your database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Yj2vhZLqVamE7_gp2Nw6Q.png" /></figure><p>It does not know if your table is called customers or Customer. It doesn&#39;t know whether total_amount exists, or whether your order totals are actually stored per line item and have to be calculated as unit_price * quantity. It does not know that you keep cancelled orders in the same table and everyone on your team knows to filter them out.<br>It guessed. It guessed in a very educated, very plausible way, and it wrote a query that will either crash or, much worse, quietly return a number that is wrong.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h7DLve0fmsx134IS7pLU1w.png" /></figure><p>That gap between SQL that looks right and SQL that is right is the entire reason a harness exists</p><h3>What is a Text-to-SQL Harness?</h3><p>A harness is everything that <strong>surrounds the model</strong>.<br>The model does one job : it turns a question and some schema information into a SQL string. Thats it. The harness does everything else. It decides whether the question is even worth answering. It finds the right tables. It checks the SQL before anything runs. It runs the query safely. It retries intelligently when something fails, and it records what happened so you can go back and read it later.<br>Think of it like a kitchen.<br>The model is the chef. A very fast chef who has cooked millions of meals and can produce a dish in seconds. But a chef alone is not a restaurant. A restaurant also has someone taking the order and checking it makes sense, someone fetching the right ingredients from storage, someone tasting the dish before it goes out, and someone who sends it back when its wrong.</p><p>The harness is the restaurant. The model is just the chef. Most demos you see online are only the chef. That is why they are so impressive and so fragile at the same time.</p><h3>Writing SQL is not the Same as Answering the Question</h3><p>This is the part beginners find surprising.<br>A query can be perfectly valid SQL, run without a single error, return a tidy table of results, and still be completely wrong. Say someone asks:<br>“<strong>How much revenue did we make from each region last year?</strong>”<br>And the model writes this:</p><pre>SELECT r.region_name, COUNT(o.order_id) AS total<br>FROM orders o<br>JOIN regions r ON r.region_id = o.region_id<br>GROUP BY r.region_name;</pre><p>It runs. It returns rows. It has a column helpfully labelled total. Everyone is happy.<br>Except it counted orders instead of summing revenue, and nobody filtered to last year.<br>The database has no opinion about this. Databases dont check whether your query matches your intent, they only check whether your query is legal. Legal and correct are two very different things, and the whole middle section of a harness exists to tell them apart.</p><h3>Why Do We Need a Harness?</h3><p>Imagine shipping text-to-SQL with no harness at all. A question comes in, the model writes SQL, you run it against production. Several things go wrong almost immediately.<br>Someone types <strong>“hi”</strong> and you spend money generating a query for it. Someone asks about a table that does not exist and they get a raw database error in the UI. The model invents a column name and the whole thing crashes. Someone asks a question whose answer genuinely is zero rows, and the system retries five times trying to <strong>“fix” </strong>a query that was correct all along.<br>And then the one that actually keeps people awake at night. Your application takes text typed by a user, sends it to a language model, and runs the output against a live database. If nothing sits between those two steps, you have handed a stranger a SQL console.<br>A harness turns each of those from an incident into a handled case.</p><h3>Not Every Question Deserves a Query</h3><p>The first thing a good harness does is decide whether to continue at all.<br>This is called routing, and its a cheaper and more important than it sounds. Before any SQL is written, the system looks at what the question actually contains. Does it name anything to look up? Does it name anything to measure? Are there any tables in this database that could plausibly answer it?<br>If someone types “<strong>hi, how’s it going?</strong>”, there is nothing to build a query from. The right response is to say so, politely and instantly, and stop.<br>There is a temptation to treat this as rude. Surely we should at least try? But trying costs money and produces nonsense. A system that answers <strong>“hi” </strong>with a SQL query is not being helpful, it is being confused in an expensive way.<br>Good routing also catches the boring cases. No tables loaded for this database yet. Schema never processed. These have clear, honest answers that dont require a model at all.</p><h3>The Model Cannot Guess Your Schema</h3><p>Once we have decided the question is worth answering, the model needs to know what its working with.<br>You might think the answer is simple. Give it the whole schema. Just paste every table and column into the prompt.<br>That works fine on a toy database with six tables. Real databases have hundreds, sometimes thousands. You cannot fit them in a prompt, and even if you could, burying the three relevant tables inside four hundred irrelevant ones makes the model worse, not better.<br>So instead the harness searches. It takes the question, finds the handful of tables most likely to be relevant, and shows the model only those, with their real column names, their types, and how they connect to each other.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vPB4fEBOE-vXvUtvKaXkjQ.png" /></figure><p>This is the single highest leverage part of the whole system. Give the model the right three tables and it usually writes a good query on the first try. Give it the wrong three and no amount of clever prompting saves you.The model is not guessing anymore,but it can only ever be as right as the tables you handed it.</p><h3>Three Checks Before Anything Runs</h3><p>Now the model has written a draft. This is the moment where an unharnessed system would just run it.<br><strong>A harness does not</strong>. It checks first, in a specific order, and the order is the whole point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gfAmw8wE1meWH8Jm9CeLOw.png" /></figure><p><strong>Does it parse, and is it allowed?</strong> The first check is pure code, no model involved. Is this a single read-only SELECT? Does it only touch the tables we actually gave it? This is the check that stops the nightmare scenario:</p><pre>DROP TABLE customers;</pre><p>and the subtler one:</p><pre>SELECT * FROM internal_user_credentials;</pre><p>Neither of those is in the tables we retrieved, so neither one gets anywhere near a database connection. This check is fast, free and deterministic, which is exactly why it goes first.<br><strong>Does it answer the question?</strong> The second check asks a model to review the draft against the original question and the schema. This is what catches COUNT where you wanted SUM, or a missing date filter, or a join that silently drops rows. It is slower and it costs a call, which is why it only runs on SQL that already passed the free check.<br><strong>Does the database accept it?</strong> The last check runs the query for real, read-only, with a row limit and a timeout. This is the only source of ground truth in the entire system. The parser knows grammar. The reviewer has an opinion. Only the actual database knows whether that column exists and whether that join resolves.</p><h3>When a Query Fails, Ask Again Properly</h3><p>Here’s where a harness gets genuinely clever. When a check fails, you do not just try again and hope. Retrying the same prompt gets you the same answer. That is the same how these models work. Instead you tell the model exactly what went wrong.<br>The database says column &quot;customername&quot; does not exist. That failure goes back to the model as context, here is the SQL you wrote, here is the exact error, try again. The second attempt is a different prompt with more information in it, so it has a real chance of being different and better. That is a repair loop, and it is not the same thing as a retry. A retry hopes the network behaves. A repair loop learns from a specific, named failure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lvUcJBQQk5ROpW0MXxFYfQ.png" /></figure><p>But it has to know when to stop, and knowing when to stop is most of the skill.</p><ul><li><strong>Stop after a few attempts.</strong> Each one costs real money. The ceiling should be low.</li><li><strong>Stop when nothing changed.</strong> If the rewrite comes back byte for byte identical to the last one, the model has locked onto an answer. A third attempt produces the same thing.</li><li><strong>Stop when it isn’t fixable.</strong> A refused connection or a missing permission is not something rewriting SQL can solve. Feeding “<strong>connection refused</strong>” to a query generator just burns tokens.</li><li><strong>Stop when time runs out.</strong> One slow database should not hold a request open forever. And one thing it must never do. Never repair a query that returned zero rows. Zero rows is very often the true answer.</li></ul><h3>Letting the Database Have the Last Word</h3><p>Running the query is the one step where a bug stops being embarrassing and starts being dangerous. So it gets its own rules. Run it inside a read only transaction that is rolled back no matter what happens. Even if something slipped past every earlier check, it cannot write.<br>Set two timeouts, not one. A server side timeout makes the database stop working. A client side timeout only makes your app stop waiting, which leaves a runaway query quietly burning someone else’s CPU.<br>Cap the rows. Nobody needs four million rows rendered in a browser tab. And use a read only database user. Every check above is a wall you built. A read only credential is the wall the database builds for you, and it’s the only one still standing if you make a mistake in the other ones.</p><h3>How Do You Know the Harness Is Working?</h3><p>This is the question people skip, and it is the one that separates a demo from a product.<br>You cannot improve a system you can not measure. So you write down a set of questions you already know the answers to, run them through the harness on a schedule, and score the results. The obvious approach is to compare the generated SQL against a “<strong>correct</strong>” query, string for string. <strong>Don’t</strong>. Two perfectly correct queries can differ in alias names, join order, whitespace, or whether they used a CTE or a subquery. String matching measures the models stylistic consistency rather than its correctness, and it turns your test suite red every time you tweak a prompt. A suite that cries wolf gets ignored within a week.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v6UKSV9l01s9YiaJk2nHxg.png" /></figure><p>That last one is the interesting one, and it is the one people forget. Counting attempts measures the harness, not the model. A system that gets the right answer on the first try and a system that gets there on the third are both <strong>“correct”</strong>, but they cost very different amounts and they feel very different to use.<br>Your first score is not a grade, it is a <strong>baseline</strong>. It gives you a number to beat, and more usefully it tells you where the points are going, whether you are losing them on retrieval, on the checks, or on attempts. Then you change one thing, run it again, and watch the number move. Without that loop you are not improving a system. You are editing prompts and hoping.</p><h3>Final Thoughts</h3><p>The model is the <strong>smallest part of a text2SQL</strong> system.<br>That sounds wrong the first time you hear it, because the model is the part doing the impressive looking thing. But go back to the query at the top of this article, the clean, professional, completely made-up one. The model produced that in under a second. Everything that turns it into an answer you would actually show your finance team happens somewhere else. It happens in the routing that decides the question is real. In the retrieval that finds the right three tables out of four hundred. In the checks that run before anything touches a database.</p><p>In the repair loop that knows the difference between a fixable mistake and a hopeless one. All of it is the difference between a demo and something people trust with their data.</p><p>So the next time you see a text-to-SQL demo write a beautiful query in two seconds, the interesting question isn not <strong>“how did it write that?”</strong><br>It’s <strong>“what would have happened if it were wrong?”</strong></p><p><strong>Github</strong> : <a href="https://github.com/Hemang-patel-9/sql-harness">https://github.com/Hemang-patel-9/sql-harness</a><br><strong>Portfolio blog</strong> : <a href="https://hemangbaldha.com/blogs/what-is-a-text-to-sql-harness">https://hemangbaldha.com/blogs/what-is-a-text-to-sql-harness</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20cbe820de50" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Deep Learning-Based Voice Activity Detection Model from Scratch]]></title>
            <link>https://medium.com/@hemang9705/building-a-deep-learning-based-voice-activity-detection-model-from-scratch-6ff789e6b58b?source=rss-130abf8e7bb9------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ff789e6b58b</guid>
            <category><![CDATA[audio-processing]]></category>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[speech-processing]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[voice-activity-detection]]></category>
            <dc:creator><![CDATA[Hemang Baldha]]></dc:creator>
            <pubDate>Thu, 13 Aug 2026 05:31:01 GMT</pubDate>
            <atom:updated>2026-08-13T05:31:01.428Z</atom:updated>
            <content:encoded><![CDATA[<p>Building a Deep Learning-Based Voice Activity Detection Model from Scratch</p><p>In my <a href="https://hemangbaldha.com/blogs/what-is-voice-activity-detection-vad">previous post</a>, I explained <strong>what Voice Activity Detection (VAD) is and why it matters</strong>.</p><p>This time, I wanted to go one step further. Instead of using an existing VAD, <strong>I built my own deep learning-based VAD from scratch</strong>. The goal was simple: build a small model that can detect speech in noisy audio, work in real time, and be easy to deploy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*psGW-nra7rj-zxTgM3MyFg.png" /></figure><h3>Why Deep Learning?</h3><p>I had already built three traditional VADs based on:</p><ul><li><strong>Energy</strong></li><li><strong>Zero Crossing Rate</strong></li><li><strong>Spectral Features</strong></li></ul><p>They are fast and surprisingly useful, especially in clean environments. But they also have obvious limitations. A whisper can have very little energy. Music can have a strong spectral structure. Background noise can sometimes be louder than the speaker. At some point, adding another threshold does not solve the real problem. So instead of manually defining what speech should look like, I have decided to <strong>let a neural network learn it from data (publicaly available)</strong>.</p><h3>The Biggest Challenge Wasn’t the Model</h3><p>The first question was not:</p><blockquote><strong><em>“Which neural network should I use?”</em></strong></blockquote><p>It was:</p><blockquote><strong><em>“Where do I get good labels?”</em></strong></blockquote><p>A VAD needs speech/non-speech labels at very small time intervals. Manually labeling thousands of hours of audio was not realistic. So I used a different approach.</p><p><strong>Label the clean audio first, then add the noise.</strong></p><p>I used clean speech recordings to create initial labels with an energy-based detector. Then I mixed them with traffic, fans, cafes, reverberation, and other noises.</p><p>The audio became difficult. The labels stayed correct. That gave me <strong>difficult training examples without manually labeling every noisy recording</strong>.</p><h3>Creating Realistic Training Data</h3><p>Each training example is a <strong>4-second synthetic scene</strong>.</p><p>I randomly combine:</p><ul><li>Speech segments</li><li>Silence</li><li>Background noise</li><li>Room impulse responses</li><li>Different SNR levels</li><li>Low-pass filtering</li><li>Clipping</li></ul><p>The SNR ranges from <strong>-10 dB to 25 dB</strong>. Also some scenes contain <strong>no speech at all</strong>. This is important because a VAD that detects speech in an empty room is extremely annoying in real applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3e4iIU0bIWjmGrYjzQ2pSw.png" /></figure><h3>The Model</h3><p>The model works on <strong>64-bin log-mel spectrograms</strong>, rather than raw audio.</p><p>The main configuration is: ParameterValue</p><p>Sample Rate : <strong>16 kHz</strong></p><p>Window : <strong>30 ms</strong></p><p>Hop : <strong>10 ms</strong></p><p>Mel Bins : <strong>64</strong></p><p>FFT : <strong>480</strong></p><p>I also use center=False so the feature extractor does not look into the future. That is important for real-time inference. The architecture is a <strong>causal MarbleNet-style CNN + GRU</strong>:</p><p><strong>Log-Mel → Separable Convolutions → Residual Blocks → GRU → Speech Probability</strong></p><p>I deliberately kept it small because I wanted something that could run efficiently on a CPU, not just on a GPU.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JUuuoreYvYwEYHnKT898yA.png" /></figure><h3>Training</h3><p>The complete training pipeline runs on a <strong>single Kaggle P100 GPU</strong>.</p><p>The dataset contains approximately:</p><ul><li><strong>35 hours of speech</strong></li><li><strong>20 hours of noise</strong></li><li><strong>3,000 room impulse responses</strong></li></ul><p>Training takes roughly <strong>2 to 3 hours for 20 epochs</strong>. I also use boundary weighting and frequency masking to make training more robust.</p><h3>How Well Does It Work?</h3><p>On the held-out validation set: <strong>EER9.1%</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PKXLvfIsTe-5wTIXybBHlQ.png" /></figure><p>The F1 score remains <strong>0.835 even at -5 dB SNR</strong>, where the noise is louder than the speech.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EoLtO27vQlr9_2n8yqfgrg.png" /></figure><h3>Making It Work in Real Time</h3><p>Training a model is one thing. Making it work on a live microphone is another. The model is <strong>causal</strong>, so it does not need future audio. For streaming inference, I maintain two kinds of state:</p><p><strong>Convolution context:</strong> previous mel frames required by the convolution layers.</p><p><strong>GRU state:</strong> the recurrent memory from previous frames.</p><p>The important part is not sending the old frames through the GRU again. The GRU has already processed them. I also verified that <strong>streaming inference matches offline inference</strong>, with the difference kept below 1e-4.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DzAVxPIgwx26lpdFoLiG_g.png" /></figure><h3>From PyTorch to Production</h3><p>The model is trained in PyTorch, but the production backend runs it using <strong>ONNX Runtime</strong>.</p><p>The final pipeline is: <strong>Audio → NumPy Frontend → ONNX Runtime → Speech Probability</strong></p><p>I also export the exact frontend parameters used during training so the production system does not accidentally calculate different mel features. Before exporting the final model, I verify:</p><pre>assert front_err &lt; 1e-3<br>assert graph_err &lt; 1e-3<br>assert e2e &lt; 1e-3</pre><p>This checks the NumPy frontend, ONNX model, and streaming pipeline against the original PyTorch implementation.</p><h3>Source Code</h3><p>The complete project is open source.</p><p><strong>GitHub: </strong><a href="https://github.com/Hemang-patel-9/vad-from-scratch">https://github.com/Hemang-patel-9/vad-from-scratch</a></p><p>The trained model is also available to download, and the VAD can be tested through the live web application.</p><h3>Final Thoughts</h3><p>The biggest thing I learned from this project is that <strong>the model itself was only one part of the problem</strong>.</p><p>The harder questions were:</p><p><strong>How do you create reliable labels?</strong></p><p><strong>How do you generate realistic training data?</strong></p><p><strong>How do you evaluate the model honestly?</strong></p><p><strong>How do you make offline and streaming inference behave the same?</strong></p><p><strong>How do you make sure the production model is actually the model you evaluated?</strong></p><p>The neural network is relatively small. The engineering around it is where most of the interesting work happened. And that is probably the biggest lesson I took from building my own VAD:</p><blockquote><strong><em>Building the model is only one part of building the system.</em></strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ff789e6b58b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Voice Activity Detection (VAD)? A Beginner-Friendly Guide with Real-Life Examples]]></title>
            <link>https://medium.com/@hemang9705/what-is-voice-activity-detection-vad-a-beginner-friendly-guide-with-real-life-examples-c89e89740c7d?source=rss-130abf8e7bb9------2</link>
            <guid isPermaLink="false">https://medium.com/p/c89e89740c7d</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[audio-processing]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[voice-activity-detection]]></category>
            <category><![CDATA[speech-processing]]></category>
            <dc:creator><![CDATA[Hemang Baldha]]></dc:creator>
            <pubDate>Mon, 03 Aug 2026 04:34:07 GMT</pubDate>
            <atom:updated>2026-08-03T09:22:27.757Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dxuOJuFRd65tDkKiQnLM0w.png" /></figure><h3>Before We Talk About Voice AI</h3><p>Try a small experiment.</p><p>Open the voice recorder on your phone and let it record for 10 minutes. Do not say anything. Just leave it on your desk.</p><p>When you listen to the recording later, you will gonna notice something interesting.</p><p>You’ll hear the fan spinning in the background, keyboard clicks, someone walking past the room, a vehicle outside, maybe even a dog barking somewhere in the distance. Most of the recording is not speech at all. It’s simply the world around you making noise.</p><p>Now think about using Google Assistant or Alexa.</p><p>You say,</p><blockquote><em>“What’s the weather today?”</em></blockquote><p>Within a second, it understands your question and responds. Somehow, it ignores the fan, the keyboard, the traffic and every other sound happening around you.</p><p>How?</p><p>Most people assume the speech recognition system is doing all the work.</p><p>It is not.</p><p>Before any AI can understand <strong>what</strong> you’re saying, it first needs to answer a much simpler question:</p><blockquote><strong><em>“Is someone actually speaking or not?”</em></strong></blockquote><p>That simple decision is made by a technology called <strong>Voice Activity Detection</strong> or simply <strong>VAD</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pOxbz1hhJeBL0MpLHUycsg.png" /></figure><h3>What is Voice Activity Detection?</h3><p>Voice activity detection is one of the first modules used in almost every speech recognition system today, and its job is surprisingly straightforward. It does not understand speech, translate anything, answer queries, or generate text. All it does is analyze an incoming audio signal and decide whether that audio contains human speech. That’s the entire task — one decision, made over and over again: speech, or not speech.</p><p>Simple as it sounds, this is one of the most crucial stages in any speech-based application, because a mistake here carries forward into every module that follows.</p><p>Think of voice activity detection as a company’s receptionist. Before anyone enters the office, the receptionist identifies the visitor and directs them to the right department. VAD does the same thing for audio: before the speech recognition model is ever called, it decides that whether the incoming sound is worth processing at all.</p><h3>Reading Audio Is not the Same as Understanding It</h3><p>Imagine you’re sitting in a cafe with a friend. People are talking around you, coffee machines are hissing, and music plays softly in the background. Even with all of that happening, you can still focus on your friend’s voice without much effort right? Your brain naturally filters out the sounds that don’t matter.</p><p>Computers don’t have this ability. To a computer, everything coming from a microphone is simply a stream of numbers. It has no idea whether those numbers represent someone’s voice, a car horn, or complete silence. Left on its own, it tries to process everything equally.</p><p>That’s exactly the problem voice activity detection solves.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MVNH8XT4aQVKwzqXlzVrdw.png" /></figure><h3>Why Do We Need VAD?</h3><p>Imagine building a speech assistant without voice activity detection. Every second, it would try to make sense of the air conditioner humming, keyboard typing, traffic outside, footsteps, a door closing, background music and even sometimes complete silence. Instead of focusing only on your voice, the system wastes time and computing power on sounds that carry no useful information.</p><p>This creates several problems. The system becomes slower, because its going to processing audio it never needed to touch. It consumes more computing power, which drives up cost. And background noise can confuse the speech recognition model itself, reducing accuracy.</p><p>By filtering out everything except speech, VAD lets the rest of the AI pipeline run faster, cheaper, and more accurately. Sometimes the smallest component has the biggest impact.</p><h3>Speech and Noise Are Not the Same</h3><p>One of the biggest challenges in speech processing is separating speech from everything else.</p><p>Consider the following sounds:</p><p><strong>Speech</strong></p><ul><li>Normal conversation</li><li>Reading aloud</li><li>Voice commands</li><li>Phone calls</li><li>Singing</li></ul><p><strong>Noise</strong></p><ul><li>Keyboard typing</li><li>Fan noise</li><li>Traffic</li><li>Rain</li><li>Dog barking</li><li>Door closing</li><li>Air conditioner</li><li>Footsteps</li></ul><p>Humans recognize this difference almost instantly but you don’t <em>decide</em> that the dog barking is not a part of the conversation, you simply hear it that way. Computers have no such instinct. They need an algorithm to make that call.</p><p>That is exactly what voice activity detection is designed to do.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GJbidjB3h5h3UWA9OW4dTw.png" /></figure><h3>Where Do We Use Voice Activity Detection?</h3><p>Although most people have never heard of VAD, they use it almost every day. Whenever a device listens to your voice, there’s a good chance voice activity detection is running quietly in the background.</p><p>Some common examples include:</p><ul><li>Google Assistant</li><li>Siri</li><li>Alexa</li><li>ChatGPT Voice Mode</li><li>WhatsApp voice notes</li><li>Zoom meetings</li><li>Microsoft Teams</li><li>Google Meet</li><li>Speech-to-text applications</li><li>Call centers</li></ul><p>In all of these applications, VAD decides when speech starts and when it ends before any further processing happens. Without it, these systems would spend most of their time listening to noise instead of people.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cPpvInPlYV4DrtzvezRl4Q.png" /></figure><h3>How Does Voice Activity Detection Fit into the AI Pipeline?</h3><p>Most beginners imagine that speech recognition begins the moment someone starts talking. In reality, another system starts working first.</p><p>A typical speech AI pipeline looks like this:</p><ol><li>The microphone captures all surrounding audio.</li><li>Voice activity detection checks whether speech exists.</li><li>Only the speech segment moves on to the speech recognition model.</li><li>The recognized text is sent to an AI model like ChatGPT.</li><li>The AI generates a response.</li></ol><p>Without VAD, every stage after it becomes less efficient. That’s why voice activity detection is often called the gatekeeper of speech AI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*012g3yI0kamPgJmVMl2Eyg.png" /></figure><h3>Different Ways to Detect Speech</h3><p>Over the years, researchers have developed different techniques to determine whether someone is speaking. Each approach solves the same problem in a different way.</p><p><strong>Energy-Based VAD</strong></p><p>This is the simplest approach. It measures how loud the audio signal is. If the sound crosses a predefined threshold, it assumes someone is speaking. It is extremely fast, but it struggles in noisy environments.</p><p><strong>Rule-Based VAD</strong></p><p>Instead of relying on loudness alone, this method looks at several characteristics of the audio, such as energy, frequency, and other signal properties. It performs better than energy-based VAD while remaining relatively lightweight.</p><p><strong>Deep Learning-Based VAD</strong></p><p>Modern systems use neural networks trained on thousands of hours of speech recordings. Instead of following manually defined rules, the model learns the difference between speech and noise directly from data. This approach is far more robust and is widely used in today’s commercial speech applications.</p><p>We will explore each of these approaches in detail later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hdevgq09PefN-zIkZZ1kqg.png" /></figure><h3>Final Thoughts</h3><p>Voice activity detection isn not the most famous part of artificial intelligence, but it’s one of the most essential. Before an AI assistant understands your question, before subtitles appear during a meeting, and before your voice is converted into text, another system quietly decides whether you’re speaking at all.</p><p>That system is voice activity detection.</p><p>It may only answer a simple yes-or-no question, but that small decision saves computation, improves accuracy, reduces processing time, and makes modern voice applications feel seamless.</p><p>So the next time you ask your phone a question or join an online meeting, remember that the first AI working behind the scenes isn’t the one generating the response. It’s the one deciding whether there’s a voice worth listening to.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c89e89740c7d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[BERT vs GPT: What’s the Difference? A Beginner-Friendly Guide with Real Examples]]></title>
            <link>https://medium.com/@hemang9705/bert-vs-gpt-whats-the-difference-a-beginner-friendly-guide-with-real-examples-73eebb8f6a04?source=rss-130abf8e7bb9------2</link>
            <guid isPermaLink="false">https://medium.com/p/73eebb8f6a04</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[gpt]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[transformers]]></category>
            <category><![CDATA[bert]]></category>
            <dc:creator><![CDATA[Hemang Baldha]]></dc:creator>
            <pubDate>Sun, 26 Jul 2026 12:49:48 GMT</pubDate>
            <atom:updated>2026-07-26T12:49:48.490Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cYpg3Cv77Y4ffcj-0sNJIg.png" /></figure><p><em>“If BERT is so powerful, why does everyone seem to talk only about GPT?”</em></p><p>If you’ve recently started exploring Artificial Intelligence, you’ve probably had this question at least once. Every blog, YouTube video, or LinkedIn post seems to revolve around GPT, while someone else insists that <strong>BERT is still the better choice for understanding language</strong>. It almost feels like the AI community can’t decide which one deserves the spotlight.</p><p>So, what’s the truth?</p><p>Is GPT simply the newer and better version of BERT? Has BERT become outdated? Or are they solving two completely different problems that often get confused?</p><p>The short answer is that <strong>BERT and GPT were built with different goals in mind</strong>. Comparing them without understanding those goals is a bit like comparing a detective with a novelist — both work with language, but they excel at entirely different tasks.</p><p>In this article, we will break down the differences using simple explanations, relatable examples, and real-world scenarios. No dense research papers, no confusing terminology. Just a practical understanding of when BERT shines, when GPT takes the lead, and why both continue to play an important role in modern AI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0FnRAJ_YVJp6HbdRz8tWRQ.png" /></figure><h3>Before We Dive into BERT and GPT</h3><p>Let’s start with a simple example.</p><p>Imagine a friend sends you this message:</p><blockquote><strong><em>“I saw her duck.”</em></strong></blockquote><p>Now, what does <strong>duck</strong> mean?</p><ul><li>Is it the bird?</li><li>Or does it mean she quickly bent down to avoid something?</li></ul><p>You probably figured out the correct meaning without even realizing it. Your brain naturally looked at the words around it and figured it out. We do this sort of thing everyday, while reading, listening, or talking, and it’s all second nature to us.</p><p>Now if you’re a computer, this wasn’t always the case. Sure you could recognize the words, but what were they actually saying? This is why we’ve said reading text wasn’t the problem, it was understanding it.</p><h3>The Real Challenge: Reading Is not the Same as Understanding</h3><p>Early Natural Language Processing (NLP) models were surprisingly good at recognizing words. They could identify patterns, count frequencies, and even match keywords. But when it came to understanding how words relate to each other, they often fell short.</p><p>Think of it like asking someone to read a novel one word at a time without letting them see the sentences before or after. They might recognize every word perfectly, yet completely miss the meaning of the story. That was the limitation of many early language models.</p><p>Researchers knew this approach was not enough. Language is all about relationships, context, and meaning, not just individual words.</p><p>Everything changed in 2017 with the introduction of the <strong>Transformer</strong> architecture by google deepmind. It gave AI a much better way to understand how words connect with one another, laying the foundation for the two models that would redefine modern NLP: <strong>BERT</strong> and <strong>GPT</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NU7_a-j6jYClGXC9zS-Zxw.png" /></figure><h3>Meet BERT</h3><p>Before GPT became the face of modern AI, there was <strong>BERT</strong>. A model that completely changed how computers understand language.</p><p>BERT stands for <strong>Bidirectional Encoder Representations from Transformers</strong>. It’s a mouthful, and honestly, researchers could have picked a shorter name. Fortunately, understanding BERT is much easier than pronouncing it.</p><p>The simplest and most straightforward explanation is that Google’s BERT is an amazing reader and understands the context. By the way, this algorithm differs significantly from traditional question-answering systems because it is not designed to answer questions directly. One should also note that this technology is not focused primarily on finding answers. One of the main features of BERT is the ability to understand exactly what has been said in a given piece of text.</p><p>In other words, if you ask BERT to read a sentence and tell you what it said, it will not jump to the nearest conclusion. This system needs time to analyze each word and the context in which it is used to understand the exact meaning of a phrase.</p><h3>What Makes BERT Different?</h3><p>Consider this sentence:</p><blockquote><strong><em>“The bank was closed.”</em></strong></blockquote><p>Now ask yourself, what does <strong>bank</strong> mean here?</p><ul><li>Is it the edge of a river?</li><li>Or is it a financial institution?</li></ul><p>Without additional context, either answer could be correct.</p><p>This is exactly where BERT shines.</p><p>Unlike the previously developed language models, which mostly focused on analyzing the given text on the left side of the target word, BERT uses both texts on the left and right and makes a conclusion based on that. This is also called a bidrectional approach, as opposed to an unidirectional one used by other language models. This allows BERT to make assumptions about a word’s meaning based on the context that it appears in.</p><p>In other words, BERT is capable of understanding a given word by looking at both sides of it and analyzing the whole sentence. It is similar to a detective who only draws conclusions when they have enough evidence to point toward one particular suspect.</p><p>This approach is great for implementing tasks such as search, sentiment analysis, question-answering, or text classification, and it has proven to be significantly more accurate than the ones used before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YLF-Ux3OEEHl7vsBD3Gh5g.png" /></figure><h3>Then Came GPT</h3><p>While BERT focused on <strong>understanding</strong> language, researchers explored a different idea:</p><blockquote><strong><em>What if a model could generate text instead of just understanding it?</em></strong></blockquote><p>That question led to <strong>GPT</strong>, which stands for <strong>Generative Pre-trained Transformer</strong>.</p><p>Unlike BERT, GPT does not look at the entire sentence and make predictions about the word. Instead, it makes assumptions about the most likely word that would come next and uses that word to predict the following word. This process continues until a full sentence or a whole article is formed. In fact, this is how chatGPT works, it just gets really good at predicting the next word.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kpuiAwUby8tOD71rer8MWA.png" /></figure><h3>GPT Thinks Like Smart Autocomplete</h3><p>A simple way to understand GPT is to think of it as <strong>autocomplete, but far more intelligent</strong>.</p><p>Imagine you start a sentence:</p><blockquote><strong><em>“Once upon a time…”</em></strong></blockquote><p>GPT does not actually know the solution to the end of the story but makes predictions about the next word at each step. It uses these predictions as its answer, and so on and so forth, creating an entire response in whole.</p><p>Even though it appears that GPT is thinking, it is actually running through millions of potential subsequent words in light of everything it has been educated on previously. This is how it can be utilized to write articles, respond to inquiries, construct code, and engage in conversation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rGdFYkjBILCOJ8RYHwvupA.png" /></figure><h3>The Biggest Difference</h3><p>At first glance, BERT and GPT may seem similar because they’re both built on the Transformer architecture. The real difference lies in <strong>how they process language</strong>.</p><p>BERT is designed to <strong>understand</strong> text. It looks at the entire sentence before deciding what each word means. GPT, on the other hand, is designed to <strong>generate</strong> text. It predicts one word at a time, gradually building a complete sentence or paragraph.</p><p>In simple terms, <strong>BERT reads first, GPT writes first.</strong></p><h3>Can GPT Replace BERT?</h3><p>Not actually.</p><p>Many people assume GPT replaces BERT simply because its newer and more popular. But that’s like asking whether a detective can replace a novelist. Both work with language, but they have different strengths.</p><p>BERT excels at understanding context, while GPT excels at creating content. The better model is not the more popular one but it’s the one that’s designed for the task you want to solve.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IwafzwE0RmZhSNdHvn187A.png" /></figure><h3>Real-World Examples</h3><p>Let’s see where these models fit into everyday applications.</p><p>When you search for <strong>“best cafes near me open now,”</strong> the search engine first needs to understand what you are actually looking for before showing relevant results. Thats a language understanding problem, where models like <strong>BERT</strong> perform exceptionally well.</p><p>Now let’s say you ask an AI to <strong>“write a Python program to reverse a string”</strong>. The purpose here is not for you to understand what the user is saying, but rather to generate new content. Which is what GPT is for. Exactly as in the following example:</p><p>In the email spam classification task, the goal is to understand what the email is about, so that a model can be built to distinguish between spammy and non-spammy emails. On the other hand, if you ask <strong>“how to reverse a string in Python”</strong>, you’re asking to generate a text document, not understand what the user wrote.</p><h3>Which One Should You Learn First?</h3><p>If you’re beginning your NLP or AI journey, don’t jump straight into BERT or GPT. Start by understanding the <strong>Transformer architecture</strong>, since both models are built on it. Once you’re comfortable with the basics, learning <strong>BERT </strong>and <strong>GPT </strong>becomes much easier, and many modern language models will start to make sense.</p><h3>Final Thoughts</h3><p>BERT and GPT aren’t competing to replace each other — they are solving different problems.</p><p>BERT is built to <strong>understand</strong> language, while GPT is built to <strong>generate</strong> it. One analyzes context before making a decision, and the other creates text one word at a time.</p><p>The next time someone asks, <strong>“Which is better, BERT or GPT?”</strong>, the best response is another question:</p><blockquote><strong><em>“Better for what?”</em></strong></blockquote><p>In AI, choosing the right model is never about popularity — it’s about selecting the right tool for the job.</p><p><strong>🫣 Yes, yes… I know. I only spent a few tokens on this. Don’t tell my AI budget.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=73eebb8f6a04" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>