<?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 Advait Shinde on Medium]]></title>
        <description><![CDATA[Stories by Advait Shinde on Medium]]></description>
        <link>https://medium.com/@advaitss11?source=rss-0ada2e05a420------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*C7Lp2XiE9eiGFGsuuiDcGw.jpeg</url>
            <title>Stories by Advait Shinde on Medium</title>
            <link>https://medium.com/@advaitss11?source=rss-0ada2e05a420------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 01:24:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@advaitss11/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[VLMs: Paradigms and Trade-offs]]></title>
            <link>https://medium.com/@advaitss11/vlms-paradigms-and-trade-offs-47e1b68668e7?source=rss-0ada2e05a420------2</link>
            <guid isPermaLink="false">https://medium.com/p/47e1b68668e7</guid>
            <category><![CDATA[vision-language-model]]></category>
            <category><![CDATA[llm-training]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[vlm]]></category>
            <dc:creator><![CDATA[Advait Shinde]]></dc:creator>
            <pubDate>Tue, 04 Aug 2026 02:10:26 GMT</pubDate>
            <atom:updated>2026-08-04T02:10:26.049Z</atom:updated>
            <content:encoded><![CDATA[<p>LLMs live in a tidy universe. Every input gets sliced into discrete tokens, each one a pointer into a finite vocabulary matrix ……. predictable, countable, cheap to reason about. Computer vision offers no such courtesy.</p><p>A single image is a continuous, multi-million-pixel matrix with no natural seams. For years, engineers bridged the two by bolting a linear projection layer between a vision encoder and a language model and calling it a day. That approach hits a wall the moment resolutions balloon and video enters the picture.</p><p>The real question isn’t whether to connect vision and language that problem was solved years ago. It’s <em>how</em> to inject visual features into a transformer’s forward pass without wrecking its linguistic reasoning or blowing through the hardware’s memory budget. Four architectural paradigms have emerged as answers, and each one encodes a different bet about where the compute should go.</p><h3>Paradigm 1: Latent space resampling</h3><p>Feeding thousands of raw visual patch embeddings straight into an LLM is a tax the model can’t afford. Self-attention scales quadratically with sequence length, so an uncompressed image can single-handedly eat the context window. The fix traces back to the Perceiver architecture: an asymmetric attention scheme that distills arbitrarily large inputs into a fixed, small set of latent vectors, shown to match ResNet-50/ViT-level ImageNet performance while attending directly to 50,000 raw pixels (<a href="https://arxiv.org/abs/2103.03206">Jaegle et al., 2021</a>).</p><p>DeepMind’s Flamingo operationalized this for vision-language work with the Perceiver Resampler: a bank of learned latent queries 64 in the reference implementation that cross-attend to the key/value features produced by a frozen vision encoder, always emitting the same number of output tokens regardless of image or video length (<a href="https://arxiv.org/abs/2204.14198">Alayrac et al., 2022</a>). The trickier engineering problem is getting those visual tokens <em>into</em> a frozen language model without destroying its pretrained weights. Flamingo’s answer is the gated cross-attention dense (XATTN-DENSE) layer, interleaved between the LM&#39;s existing blocks and trained from scratch, where a tanh-gated scalar initialized at zero ensures the augmented model is numerically identical to the unmodified LM at the start of training the visual pathway has to earn its influence gradually rather than being thrown in at full strength (<a href="https://arxiv.org/abs/2204.14198">Alayrac et al., 2022</a>). A masking scheme restricts each text token to cross-attend only to the single image or video clip immediately preceding it in the interleaved sequence not all prior images which is what lets a model trained on a handful of images per example generalize at inference to arbitrarily long interleaved sequences (<a href="https://arxiv.org/abs/2204.14198">Alayrac et al., 2022</a>). The three released sizes (Flamingo-3B, -9B, -80B) sit on top of frozen Chinchilla language models of 1.4B, 7B, and 70B parameters respectively, with only the resampler and cross-attention layers trained.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RP7w_xC4a9xAsVndnbCtlw.png" /></figure><p>The elegance here is architectural discipline: a fixed token footprint no matter how large the input. The cost is equally predictable cross-attention compression is lossy by construction, and high-frequency detail (small text, distant objects, fine texture) tends to get summarized away. OpenFlamingo is the faithful open replication of the recipe. Current research pushes toward <em>dynamic</em> token allocation, where a dense technical schematic might earn many more latent slots than a minimalist landscape, rather than fixing the budget at 64 regardless of content.</p><h3>Paradigm 2: Native unified vocabulary</h3><p>Most vision-language systems keep a dual-brain structure ,a vision encoder acting as the eye, stitched onto a language model acting as the mind. Early-fusion architectures reject that division, processing pixels and text in identical hidden layers from the first step.</p><p>Meta’s Chameleon is the clearest public example. Images pass through a discrete tokenizer that quantizes patches into indices from a learned codebook, conceptually descended from VQ-VAE/VQ-GAN-style discrete autoencoders; those indices are then spliced directly into the token stream alongside byte-pair-encoded text and processed by a single auto-regressive transformer with one shared vocabulary (<a href="https://arxiv.org/abs/2405.09818">Chameleon Team, 2024</a>). The payoff is genuine bidirectionality , because image and text tokens are indistinguishable to the model, the same weights that caption a picture can also generate one, in the same context window, in any order.</p><p>The cost is training stability, and Chameleon’s paper is refreshingly candid about how badly this can go. Because softmax normalization is invariant to a constant shift in the logits, and because text and image tokens have very different entropy profiles, the two modalities effectively compete by growing their activation norms, a failure mode the authors describe as slow norm growth that only manifests as loss divergence after 20–30% of training has already elapsed, making it expensive to catch (<a href="https://arxiv.org/pdf/2405.09818">arXiv:2405.09818</a>). Their fix combines query-key normalization (RMSNorm applied to queries and keys before the softmax) with, at the 34B scale, a Swin Transformer-style reordering of layer norms around the attention and feed-forward blocks; ablations showed QK-norm alone cut divergence substantially, dropout was sufficient to stabilize the 7B model, but only the norm-reordering, not dropout, stabilized the 34B model (<a href="https://arxiv.org/abs/2405.09818">Chameleon Team, 2024</a>; <a href="https://medium.com/@EleventhHourEnthusiast/chameleon-mixed-modal-early-fusion-foundation-models-cc63575bdb87">ablation detail</a>). With that recipe, Chameleon-34B matched or beat Llama-2 on text-only benchmarks while remaining competitive with Mixtral 8x7B and Gemini-Pro, despite carrying the extra burden of jointly modeling pixels (<a href="https://arxiv.org/abs/2405.09818">Chameleon Team, 2024</a>).</p><p>It’s worth being precise about the frontier systems here: OpenAI has stated that GPT-4o was trained end-to-end as a single network across text, vision, and audio, with all modalities processed by the same weights rather than routed through separate bolted-on encoders (<a href="https://openai.com/index/hello-gpt-4o/">OpenAI, 2024</a>). Neither OpenAI nor Google has published the tokenizer or stabilization details for GPT-4o or the Gemini line the way Meta did for Chameleon, so “early-fusion” is the right conceptual bucket for these systems, but the specific engineering codebook design, normalization scheme, loss balancing remains undisclosed. Ongoing academic work targets exactly the problem Chameleon exposed: normalization and loss-balancing schemes that prevent one modality’s gradient statistics from overwhelming another’s during joint pretraining.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7JpdgC02UU-KlH9E7K1mdA.png" /></figure><h3>Paradigm 3: Dynamic high-resolution tiling</h3><p>Show a model a 4K document or a dense circuit diagram, and downsampling to a fixed low-resolution canvas destroys the very information you wanted read. But encode that image at full resolution and you generate enough tokens to blow the context window regardless. Two different engineering answers have emerged, and it’s worth distinguishing them rather than collapsing them into one idea.</p><p>NVIDIA’s NVLM family tackles it with an explicit two-stream split, building on the dynamic high-resolution (DHR) tiling introduced by InternVL: an input image is matched to the closest of several predefined aspect ratios, cut into up to six non-overlapping 448×448 tiles, plus one extra downscaled thumbnail tile that preserves global layout (<a href="https://arxiv.org/abs/2409.11402">NVIDIA, 2024</a>; <a href="https://towardsdatascience.com/a-walkthrough-of-nvidias-latest-multi-modal-llm-family-fdc067b59596/">DHR walkthrough</a>). Each tile is encoded independently by a frozen InternViT-6B backbone into 1,024 tokens, downsampled to 256 via pixel shuffle, and because concatenating flattened tile tokens without any signal would leave the LLM unable to infer the tiling geometry, NVLM inserts explicit text-based tile tags (&lt;tile_1&gt;, &lt;tile_2&gt;, …) into the sequence to mark where each tile begins and how it fits into the full grid (<a href="https://arxiv.org/html/2409.11402v1">NVIDIA, 2024</a>). NVLM actually ships three variants of this idea: NVLM-D feeds every tile token directly into the decoder&#39;s self-attention; NVLM-X routes tiles through Flamingo-style gated cross-attention instead, cutting sequence length at the cost of extra parameters; NVLM-H splits the difference, sending only the thumbnail into self-attention for cheap global reasoning while the detail tiles go through gated cross-attention for fine-grained grounding (<a href="https://arxiv.org/pdf/2409.11402">NVIDIA, 2024</a>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-7uArZ0fAO7Yc8iMGncHRA.png" /></figure><p>Qwen2-VL takes a related but architecturally distinct route it calls Naive Dynamic Resolution: rather than cropping into a global-plus-tiles hierarchy, it strips the vision transformer’s absolute position embeddings, adds 2D-RoPE so the encoder natively understands arbitrary aspect ratios, and packs the resulting variable-length patch sequence directly into the model after a lightweight MLP merges every 2×2 block of adjacent patches into one token a 224×224 image compresses to just 66 tokens before reaching the LLM (<a href="https://arxiv.org/pdf/2409.12191">Wang et al., 2024</a>). A companion mechanism, Multimodal Rotary Position Embedding (M-RoPE), decomposes positional encoding into temporal, height, and width components so the same scheme covers single images, multi-image sequences, and video without a separate architecture for each (<a href="https://arxiv.org/abs/2409.12191">Wang et al., 2024</a>).</p><p>Both approaches preserve sub-pixel clarity for OCR-grade tasks while keeping the LLM’s effective sequence length manageable, but the engineering complexity is real synchronizing tile coordinates, position embeddings, and cross-attention masks inside the transformer is a systems problem as much as a modeling one. Interleaved sequence schedulingmemory-mapping schemes that let multi-page, ultra-high-resolution documents get processed without exhausting GPU memory is where most of the current engineering effort in this paradigm is going.</p><h3>Paradigm 4: Parallel dual-encoders</h3><p>Sometimes a model doesn’t need to write a caption, it needs to match a text query against a billion images in under a millisecond. That’s a retrieval problem, not a generation problem, and dual-encoder architectures are built for exactly that trade.</p><p>OpenAI’s original CLIP trains an image transformer and a text transformer independently, with no cross-attention between them, projecting both into a shared embedding space and optimizing a symmetric contrastive (InfoNCE-style) softmax loss over a mini-batch of image-text pairs (<a href="https://en.wikipedia.org/wiki/Contrastive_Language-Image_Pre-training">Radford et al., 2021</a>). The catch is that this loss needs a <em>global</em> view of the batch: computing the softmax normalization requires materializing the full B×B matrix of pairwise similarities, which costs quadratic memory in batch size and forces two rounds of cross-device communication to gather image and text features before the loss can even be computed (<a href="https://arxiv.org/abs/2303.15343">Zhai et al., 2023</a>; <a href="https://ahmdtaha.medium.com/sigmoid-loss-for-language-image-pre-training-2dd5e7d1af84">implementation notes</a>).</p><p>Google’s SigLIP replaces that global softmax with a pairwise sigmoid loss: every image-text pair, positive or negative, is scored independently as a binary classification problem, so there’s no batch-wide normalization term and no B×B matrix to materialize each device only needs a local b×b chunk before a single cross-device sum (<a href="https://arxiv.org/abs/2303.15343">Zhai et al., 2023</a>). This isn’t just a memory optimization; it changes the loss landscape. Sigmoid loss significantly outperforms softmax at small batch sizes, and the memory savings let a base-sized SigLIP model fit twice the batch size of the equivalent CLIP model on the same four TPUv4 chips though both losses saturate at a surprisingly modest batch size of around 32k, with diminishing or even negative returns beyond that (<a href="https://arxiv.org/abs/2303.15343">Zhai et al., 2023</a>).</p><p>The efficiency gain is the entire point: billions of stored embeddings, searchable at matrix-multiplication speed, since the image tower’s outputs can be pre-computed and indexed entirely offline. What you give up is reasoning the two towers never exchange information, so a dual-encoder can confirm an image contains a dog but cannot describe what the dog is doing, why, or what happens next. The active research edge is dense object grounding: models like GLIP reformulate detection itself as a phrase-grounding problem, jointly training an image and text encoder with a deep cross-modal fusion so that region proposals are scored against words in a prompt rather than a fixed label set, letting a single model transfer to new detection vocabularies with zero or few examples (<a href="https://arxiv.org/abs/2112.03857">Li et al., 2021</a>). AlphaCLIP and similar work push further, conditioning the vision tower on a region mask so a single global embedding becomes a set of localizable, queryable embeddings, turning a search index into something closer to an open-vocabulary detector.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8_QlRe_HxpwV9KhxoBsK3Q.png" /></figure><h3>Choosing among them</h3><p>None of these four paradigms is a strict upgrade over the others, they sit at different points on a curve between fidelity, speed, and training stability, and picking one is really a bet about which failure mode you can tolerate.</p><p>Paradigm Key bottleneck Compute scaling Best fit Latent resampler Loses fine detail in the cross-attention squeeze Linear in latent query count Multi-frame video, surveillance Early-fusion Norm growth / softmax instability across modalities Quadratic in unified sequence length Mixed-modal interactive authoring Dynamic tiling Pipeline and coordinate-synchronization complexity Linear in tile count Dense documents, invoices, maps Dual-encoder No cross-modal reasoning capability Sub-linear via indexed lookup Billion-scale image search</p><p>A model that needs to reason about a scene wants a resampler or a tiling pipeline; a model that needs to <em>find</em> a scene among a billion others wants a dual-encoder and nothing more. The paradigms aren’t even mutually exclusive in production systems, it’s increasingly common to see a SigLIP-style encoder supplying the frozen backbone that a tiling or resampling pipeline then compresses for an LLM, stacking one paradigm’s strengths on top of another’s.</p><p><strong>References</strong></p><ul><li>Jaegle, A. et al. (2021). <a href="https://arxiv.org/abs/2103.03206">Perceiver: General Perception with Iterative Attention</a>. ICML 2021.</li><li>Alayrac, J-B. et al. (2022). <a href="https://arxiv.org/abs/2204.14198">Flamingo: a Visual Language Model for Few-Shot Learning</a>. NeurIPS 2022.</li><li>Chameleon Team (2024). <a href="https://arxiv.org/abs/2405.09818">Chameleon: Mixed-Modal Early-Fusion Foundation Models</a>. Meta FAIR.</li><li>OpenAI (2024). <a href="https://openai.com/index/hello-gpt-4o/">Hello GPT-4o</a>.</li><li>Dai, W. et al. (2024). <a href="https://arxiv.org/abs/2409.11402">NVLM: Open Frontier-Class Multimodal LLMs</a>. NVIDIA.</li><li>Wang, P. et al. (2024). <a href="https://arxiv.org/abs/2409.12191">Qwen2-VL: Enhancing Vision-Language Model’s Perception of the World at Any Resolution</a>.</li><li>Radford, A. et al. (2021). CLIP: Learning Transferable Visual Models From Natural Language Supervision. Summarized at <a href="https://en.wikipedia.org/wiki/Contrastive_Language-Image_Pre-training">Wikipedia</a>.</li><li>Zhai, X. et al. (2023). <a href="https://arxiv.org/abs/2303.15343">Sigmoid Loss for Language Image Pre-Training</a> (SigLIP). ICCV 2023.</li><li>Li, L. H. et al. (2021). <a href="https://arxiv.org/abs/2112.03857">Grounded Language-Image Pre-training</a> (GLIP). CVPR 2022.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47e1b68668e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CNNs : breakdown and breakthroughs from 1998 to 2019 !]]></title>
            <link>https://medium.com/@advaitss11/cnns-breakdown-and-breakthroughs-from-1998-to-2019-fa005da2cc76?source=rss-0ada2e05a420------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa005da2cc76</guid>
            <category><![CDATA[cnn]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[efficientnet]]></category>
            <category><![CDATA[resnet]]></category>
            <category><![CDATA[computer-vision]]></category>
            <dc:creator><![CDATA[Advait Shinde]]></dc:creator>
            <pubDate>Wed, 25 Mar 2026 06:22:24 GMT</pubDate>
            <atom:updated>2026-03-25T06:22:24.852Z</atom:updated>
            <content:encoded><![CDATA[<p>Convolutional neural networks got Deep Learning on the board. Before CNNs, deep learning was mainly comprised of Fully Connected Layers!</p><p>Which gives rise to really logical questions : <em>why images are hard for regular neural networks → what a convolutional neural network does instead → how it processes images layer by layer</em>. Here’s the full story.</p><h4>The problem: images are huge and spatial</h4><p>Imagine you have a small 32×32 pixel image (tiny, like an old video game sprite). Each pixel has 3 color values (Red, Green, Blue). That’s already <strong>32 × 32 × 3 = 3,072 numbers</strong> just for one tiny image.</p><p>A standard neural network (called a “Fully Connected” layer) takes all those numbers, mashes them into one long list, and connects <em>every single input</em> to <em>every single neuron</em>. For our tiny image that’s already 3,072 connections per neuron. Now imagine a real photo at 200×200 pixels — that’s <strong>120,000 connections per neuron</strong>. That’s a disaster for three reasons:</p><ol><li><strong>Too many parameters</strong> — millions of numbers to learn, which requires enormous amounts of data</li><li><strong>Overfitting</strong> — with so many parameters, the network just memorizes the training images instead of learning general patterns</li><li><strong>Spatial information is destroyed</strong> — when you flatten an image into a long list, you lose the fact that pixels <em>next to each other</em> are related. The network has no idea that the pixel at position 500 is right next to position 501.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*JZR0-zhdAjA5t_aS6obUeQ.png" /><figcaption>Here’s a visual of what “flattening” does to spatial structure</figcaption></figure><h4>The CNN solution: look at small patches, slide across the image</h4><p>Instead of connecting every pixel to every neuron, a CNN uses a <strong>filter</strong> (also called a kernel). Think of it like a tiny magnifying glass say, 5×5 pixels that slides across the whole image one patch at a time, asking “does this pattern exist here?”</p><p>A filter learns to detect one specific thing: maybe an edge, maybe a curve, maybe a specific color transition. Here’s the key insight:</p><blockquote><strong><em>A filter is the same for every position in the image.</em></strong><em> The “edge detector” filter works whether the edge is in the top-left corner or the bottom-right corner.</em></blockquote><p>This is called <strong>translation invariance</strong> a huge deal, because an object being in a slightly different position shouldn’t change what the network thinks it is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*Y9fldMbv78qNvhe-Iv9cVw.png" /><figcaption>how a filter slides across an image</figcaption></figure><h4>Multiple filters = multiple activation maps</h4><p>One filter detects one feature. But you want to detect <em>many</em> features edges, curves, colors, textures. So you use many filters at once.</p><p>With 6 filters on a 32×32 image, you get 6 activation maps stacked together a new “volume” that’s 28×28×6. Each slice of that volume is the answer to “where in the image did filter #N fire?”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*PxKZLCiT8sjLRjwei3Z14A.png" /><figcaption>Each filter produces its own map n“where are the edges?”, “where are the curves?”, etc.</figcaption></figure><h4>Pooling: shrinking things down without losing what matters</h4><p>After each conv layer you have a big stack of activation maps. That’s a lot of data. <strong>Pooling</strong> shrinks it down.</p><p>The most common type is <strong>Max Pooling</strong>: take a 2×2 window, slide it across the map, and keep only the <em>largest</em> value from each window. The intuition is: “I don’t care <em>exactly</em> where this feature was in this 2×2 patch . I just want to know if it was there at all.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*ZXtzJblRAoRfCDSf-RqTkw.png" /><figcaption>Shrinking makes the network faster (less data to process), and it makes features more robust to small shifts</figcaption></figure><h4>The full CNN pipeline</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*swnJ7N-AvZkt0OfTzNJCWg.png" /></figure><p>The early layers learn low-level stuff (edges, blobs, color patches). The later layers combine those into higher-level stuff (wheels, faces, fur). Only at the very end does a traditional fully connected layer come in but now it’s not looking at raw pixels, it’s looking at a compact, meaningful summary of features. That’s a much easier job.</p><h3>CNN architectures from 1998 to 2019</h3><h4>1. LeNet-5 (1998) — The pioneer</h4><p>LeNet-5 was built by Yann LeCun to read handwritten digits (like ZIP codes on envelopes). It introduced the basic blueprint that every CNN still follows today: <strong>Conv → Pool → Conv → Pool → Fully Connected</strong>. Nothing fancy, but it worked remarkably well for its time.</p><p>Won the Turing Award in 2018, essentially the Nobel Prize of computer science, for this work.</p><h4>2. AlexNet (2012) — The moment everything changed</h4><p>For years after LeNet, CNNs were kind of forgotten. Then in 2012, AlexNet entered the ImageNet competition (1.4 million images, 1000 categories) and absolutely destroyed the competition, cutting the error rate nearly in half compared to traditional methods. This is widely considered the moment that kicked off the modern deep learning era.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*_615_RcLTCrqyBCC-nG2GA.png" /><figcaption>AlexNet introduced several tricks that became standard practice for the entire field.</figcaption></figure><p>The ReLU innovation deserves special emphasis. Before AlexNet, networks used sigmoid or tanh functions which “squish” values and when you have many layers, gradients in backprop would essentially vanish. ReLU’s bluntness (“positive? pass it. negative? kill it.”) turned out to be exactly what deep networks needed.</p><h4>3. VGGNet (2014) — Deeper with tiny filters</h4><p>Oxford’s VGG group asked a simple question: <em>what if we just make the network deeper?</em> Their answer was VGG16 (16 layers) and VGG19 (19 layers) — far deeper than AlexNet’s 8.</p><p>The clever insight was using only tiny <strong>3×3 filters</strong> everywhere instead of the big 11×11 or 5×5 filters AlexNet used. Why does that work? Because stacking two 3×3 conv layers gives you the same <em>receptive field</em> (the area of the image being “seen”) as one 5×5, but with fewer parameters and more non-linearity in between. Three 3×3 layers ≈ one 7×7. Smaller filters, more layers, smarter network.</p><p>The downside: VGG16 is over 533MB because it kept three massive fully-connected layers at the end with 4096 neurons each. Great accuracy, terrible to deploy.</p><h4>4. GoogLeNet (2014) — Going wider, not just deeper</h4><p>While VGG went deep, Google went <em>wide</em>. Their insight: why pick one filter size? Use all of them at once.</p><p>The <strong>Inception module</strong> is the key idea — run 1×1, 3×3, and 5×5 filters <em>in parallel</em> on the same input, then stack all the results together. This way the network can detect both fine details (small filters) and broad shapes (large filters) at the same layer.</p><p>But there’s a problem: stacking all those outputs gets computationally expensive very fast. The solution was brilliant — <strong>1×1 convolutions as “bottlenecks”</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/1*3ow-QOz2TOdUNYwhxe7FHQ.png" /></figure><p>A <strong>1×1 convolution</strong> sounds useless ….. what does a 1-pixel filter even do? The answer is it doesn’t look at spatial patterns, it looks at <em>depth</em>. It combines the channels at a single position, letting the network reduce 256 channels down to 64 before the expensive 3×3 or 5×5 convolution. This slashed computation from 854M operations down to 358M a 58% saving\ while keeping essentially the same expressive power.</p><p>GoogLeNet also used <strong>auxiliary classifiers </strong>small classifiers plugged in at the middle of the network during training. The problem they solved is called the vanishing gradient: in a very deep network, the training signal from the loss at the end gets weaker and weaker as it travels back through all the layers. Plugging in extra loss signals at the middle gives the early layers a stronger gradient to learn from.</p><h4>5. ResNet (2015) …..The one that solved depth for good</h4><p>After AlexNet’s 8 layers and VGG’s 19, researchers tried going even deeper 50, 100, 150 layers. They discovered a frustrating problem: <strong>adding more layers made accuracy <em>worse</em>, not better</strong>, even on the training data itself. This wasn’t overfitting. Something was fundamentally broken.</p><p>The culprit is the <strong>vanishing gradient</strong> problem. During training, gradients travel backwards through every layer. Each layer multiplies the gradient by a number that’s often less than 1. After 100 multiplications, the gradient is essentially zero the early layers learn nothing.</p><p>ResNet’s fix was elegantly simple: <strong>skip connections</strong> (also called residual connections).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*nzVkdjsqJY9HC-RdHXlh2g.png" /></figure><p>The skip connection adds the <em>original input</em> directly to the output of the block. The network’s output becomes <strong>F(x) + x</strong> instead of just <strong>F(x)</strong>. This has two huge effects:</p><ul><li>During training, the gradient can flow directly back through the skip path, bypassing the convolutions entirely no vanishing</li><li>The layers only need to learn the <em>difference</em> (the residual) from the input, not a whole new transformation. It turns out learning small adjustments is much easier than learning from scratch</li></ul><p>With this trick, Microsoft trained a 152-layer network and won every major computer vision competition in 2015. ResNet is still one of the most commonly used architectures today.</p><h4>ResNet’s bottleneck block</h4><p>For very deep ResNets (50, 101, 152 layers), each residual block itself uses a bottleneck design the same 1×1 trick from GoogLeNet:</p><p><strong>256 channels → 1×1 conv shrinks to 64 → 3×3 conv (cheap now!) → 1×1 conv expands back to 256</strong></p><p>This “wide-narrow-wide” pattern lets you stack 150+ layers without the compute cost exploding.</p><h4>6. DenseNet (Densely Connected Convolutional Networks, 2016)</h4><p>Instead of adding feature maps (like ResNet), <strong>DenseNet</strong> concatenates them.</p><ul><li><strong>Key Innovation:</strong> Every layer receives the feature maps of all preceding layers as input within a “dense block”.</li><li><strong>Advantage:</strong> This maximizes feature reuse and significantly reduces the number of parameters compared to ResNet (e.g., DenseNet-264 is smaller than ResNet-101).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*00Ct6zD-0DrdhjeUfacrew.png" /><figcaption>Notice the layers get taller as you go right each one receives <em>more</em> inputs because it’s concatenating all previous feature maps. The growth rate k is how many new channels each layer adds. Because no feature ever gets thrown away, the network can be very thin and still powerful.</figcaption></figure><h4>7. EfficientNet (2019)</h4><p>The first family of models to systematically scale all dimensions depth, width, and resolution simultaneously.</p><ul><li><strong>Key Innovation:</strong> Uses <strong>Compound Scaling</strong> to find the optimal balance between these dimensions using a fixed set of scaling coefficients.</li><li><strong>Advantage:</strong> Achieves state-of-the-art accuracy with far fewer parameters and FLOPs than traditional models (e.g., EfficientNet-B0 is 10x more efficient than ResNet-50).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*7CXcjy5SgYCMg5fIO3bIDg.png" /><figcaption>The key intuition: scaling only depth gives you more abstraction but the network stays narrow so it misses rich features.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa005da2cc76" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Reinforcement Learning quietly runs your Recommender Systems!]]></title>
            <link>https://medium.com/@advaitss11/how-reinforcement-learning-quietly-runs-your-recommender-systems-b46601eab4cd?source=rss-0ada2e05a420------2</link>
            <guid isPermaLink="false">https://medium.com/p/b46601eab4cd</guid>
            <category><![CDATA[case-study]]></category>
            <category><![CDATA[recommendation-system]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[contextual-bandit]]></category>
            <category><![CDATA[reinforcement-learning]]></category>
            <dc:creator><![CDATA[Advait Shinde]]></dc:creator>
            <pubDate>Fri, 20 Mar 2026 22:33:52 GMT</pubDate>
            <atom:updated>2026-03-20T22:33:52.217Z</atom:updated>
            <content:encoded><![CDATA[<p>An article about use of multi-armed and contextual banditsthe algorithms that Netflix, Spotify, Stitch Fix, and DoorDash use to stop leaving reward on the table.</p><p>A/B tests dominate the Rec Sys industry!</p><h4>The problem with A/B tests:</h4><p>Picture a classic A/B test. You’ve got two recommendation strategies let’s say: A and B. You split your traffic 50/50, run the test for two weeks, declare a winner, and ship it. Clean. Rigorous.</p><p>Now zoom out and look at what actually happened. For the entire duration of the experiment, half your users were stuck with a suboptimal experience which is called regret.</p><h4>Bandits</h4><p>This is the core insight behind <em>bandit algorithms.</em> They borrow a concept from reinforcement learning ( sequential decision-making under uncertainty ) and apply it to the recommendation problem. Instead of a static split, you dynamically reallocate traffic toward what’s working, in real time, while still collecting the evidence you need to improve further.</p><p>A “multi-armed bandit” refers to a slot machine with multiple levers (“arms”), each with an unknown payout distribution. Your job is to figure out which levers pay off — without losing your shirt in the process. Replace “slot machine levers” with “recommendation strategies” or “content variants” and you have a very real industry problem.</p><h4>Multi Arm Bandits: Setup</h4><p>Let’s formalize the problem :</p><p>You have K arms (recommendation candidates, page layouts, content items — whatever you’re testing). Each arm has an unknown reward distribution with some true mean μk. At each round t, you pick an arm At, observe a reward Xt, and update your model. You play for T rounds total, and you want to maximize the cumulative reward across all rounds.</p><p>The key constraint: you only observe feedback for the arm you actually pull. You never get to know what would have happened if you’d chosen differently. This is called “bandit feedback,” as opposed to “full feedback,” and it’s what makes the problem hard and interesting.</p><p>Regret is the formal measure of how much you’re losing by not knowing the optimal arm from the start.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*kd5_JndKhyrpVF-B7F8xxA.png" /><figcaption>Fig 1 : The bandit feedback loop. The agent selects an arm, observes a reward, and updates its internal model. Unlike supervised learning, only the chosen arm’s reward is revealed.</figcaption></figure><h3>Exploration vs. Exploitation:</h3><p>You’ve found an arm that seems good. Should you keep pulling it, collecting reliable rewards? Or should you keep trying the others, on the chance that one of them is even better?</p><p>Too much exploration: you lose reward now, chasing arms that might not be better. Too much exploitation: you risk being stuck at a local optimum, confidently recommending something that’s merely decent when something excellent exists in the search space you never bothered to visit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*_glUqWj7RrdiHQKB-UXBaQ.png" /><figcaption>Fig2: The explore-exploit trade-off as a function of the exploration parameter ε. Pure exploitation risks getting stuck at a local optimum; pure exploration is needlessly costly.</figcaption></figure><h4>3 main algorithms:</h4><ol><li><strong>ε-greedy (and its cousin, ε-first)<br></strong>The simplest approach. With probability ε, choose a random arm (explore). With probability 1 − ε, choose the arm with the highest estimated mean reward (exploit).</li><li><strong>Upper Confidence Bound (UCB)<br></strong>The philosophy: “optimism in the face of uncertainty.” <br>UCB selects the arm with the highest <em>upper confidence bound, </em>a combination of its estimated mean reward and a bonus term that rewards uncertainty.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*N6e_xvYL7XT6q8KcDXsTkw.png" /><figcaption>Fig 3 : UCB in action. Early on, wide confidence intervals promote exploration. As the best arm is pulled more, its CI narrows and it dominates. The algorithm shifts from exploration to exploitation naturally.</figcaption></figure><p><strong>3. Thompson Sampling</strong></p><p>Where UCB is deterministic and frequentist, Thompson Sampling is probabilistic and Bayesian. Instead of building a confidence interval, you maintain a full <em>probability distribution</em> over your belief about each arm’s true reward.</p><p>For binary rewards (click / no click), the natural prior is a Beta distribution with parameters α (successes) and β (failures). At each round, you sample one value from each arm’s distribution and pick the arm with the highest sample. That’s the entire algorithm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*VyMlIvRdeMQ4__GFNFKWuA.png" /><figcaption>Fig 4: Thompson Sampling maintains a Beta distribution per arm. Arm A (many wins) has a peaked distribution near its true mean. Arm B (unexplored) has a flat prior and occasionally draws high samples, enabling exploration. Arm C (many losses) stays pinned near 0.</figcaption></figure><p>Quick Summary :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/1*aJM_bICS_1ygM-q7ZWR4Ag.png" /></figure><h3>Contextual bandits: bringing user identity into the loop</h3><p>Multi-armed bandits treat every user the same. An arm is either good or bad, and the algorithm converges on the best one for the average user. But recommender systems are, by definition, personalization problems. The best movie thumbnail for a horror fan is not the best one for someone who only watches documentaries.</p><p>Contextual bandits solve this by adding a context vector to the decision. At each round, the agent observes a feature vector xt (representing the user, the session, the device, the time of day — whatever’s relevant) and picks the arm that maximizes expected reward <em>given that context</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*RvvhKiSFucK4sqc6sPYkAw.png" /><figcaption>Fig5: Contextual bandit architecture. The context vector (user features, session signals) is fed into the policy model, which selects an arm conditioned on that context. Feedback updates the model with both the context and the observed reward.</figcaption></figure><h3>Industry Case Studies</h3><h4>1. Netflix : Artwork personalization at 300M subscribers</h4><p>Contextual bandits for per-member title image selection</p><p>The problem sounds deceptively simple: which thumbnail should Netflix show you for a given title?</p><p>Netflix frames this as a contextual bandit problem. The context vector encodes member features (titles played, genre preferences, country, device, time of day), plus signals from the traditional recommendation engine about how strongly it associates the member with the title. The arms are the available artwork variants for each title.</p><p>The reward function is a <em>proxy</em> for what Netflix actually cares about : <strong><em>long-term member satisfaction</em></strong>. Direct measurement of that is intractable, so the model predicts the probability that a member will “enjoy quality engagement” (a streaming threshold that goes beyond a brief click) given the context-artwork pair. This is a standard supervised classification problem, trained on {member, title, artwork} tuples labeled with play/no-play.</p><p>Exploration has a real cost: showing someone a suboptimal thumbnail is a slightly worse experience. But amortized across 300M members, the exploration cost per-member per-title is tiny. The system essentially A/B tests artworks at massive scale, with contextual personalization layered on top.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*etcKsD7pz0GOr3jUPvALdw.png" /><figcaption>Netflix choosing artwork to display via RL</figcaption></figure><h4>2. Stitch Fix: Thompson Sampling for fashion recommendations</h4><p>Bandits with convergence + self-correction for personal styling</p><p>Stitch Fix’s business model is essentially a recommendation problem with high stakes: each “fix” is a curated box of clothing sent to a client’s door. Getting the recommendations wrong means clothing that doesn’t fit, doesn’t suit the style, and comes back in a return box — a costly failure signal.</p><p>They use Thompson Sampling for its two prized properties: convergence (the algorithm asymptotically identifies the best arm) and instantaneous self-correction (if an arm’s performance suddenly degrades, the posterior updates quickly and the arm’s selection probability drops). This matters in fashion where trends shift and client preferences evolve.</p><p>The natural extension was to move from multi-armed to contextual bandits by incorporating client style signals and brand preferences as context. This allowed the model to learn that “a Thompson-sampled ‘best item’ for a minimalist is different from the best item for a maximalist” — personalization built directly into the bandit framework, not bolted on afterward.</p><p>One nuance worth flagging: in Stitch Fix’s setting, the “reward” signal (did the client keep the item?) is delayed by days. This is where Thompson Sampling’s robustness to delayed feedback shows its value it randomizes over actions even without fresh updates, avoiding the UCB pathology of repeatedly serving the same arm while waiting for scores to come in.</p><h4>3. Spotify: Calibrated content-type mixing on the Home page</h4><p>Neural contextual bandits for music vs. podcast slate composition</p><p>Spotify’s home page is a slate of “shelves” rows of recommended content. A key challenge: Spotify serves music, podcasts, and audiobooks, and a user’s optimal mix changes. A commuter might want podcasts in the morning but music when working out. A user exploring the platform needs enough podcast exposure to discover the format without drowning in it.</p><p>Prior approaches used static target distributions (“20% podcasts for everyone”) or user preference histories to set targets. The problem: history lags reality, and a fixed distribution ignores context. Spotify’s published work describes a neural contextual bandit that learns to prescribe the <em>optimal distribution of content types</em> for each user based on their current session context.</p><p>The reward function is tricky here. Spotify uses a binarization of streaming time — a threshold on how long a user engaged with content — as the reward signal for training. But they also experiment with more nuanced reward functions derived from co-clustering users and content into groups with similar behavior patterns, so that a 30-second stream of a podcast means something different than a 30-second stream of a 3-minute pop track.</p><p>User contextsession timerecent historygenre signals 600M+ users Neural Bandit (dist | context) predicts content-typedistribution for slateHome page slateMusic shelfMusicPod. ←80% music←music←20% pods</p><p>The deployed system showed increased user engagement alongside higher consumption of less mainstream content types suggesting the bandit is doing what it’s supposed to: personalizing the mix rather than defaulting everyone to the majority-preference ratio.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K988-uijTbGw-4G7Pszg3g.png" /><figcaption>Neural bandits</figcaption></figure><h3>What actually matters in production</h3><p>The literature on bandit algorithms is clean and elegant. Production is messier. A few things that consistently bite teams when they ship:</p><p>Delayed and partial feedback. In most real systems, you don’t observe rewards immediately. A click happens at T+0, but purchase intent might signal at T+24h, and long-term retention is T+30d. If you train on click CTR but actually care about lifetime value (as Stitch Fix does), you need proxy rewards that correlate with the true objective. This is harder than it sounds the proxy can be optimized in ways that diverge from the real metric.</p><p>Non-stationarity. User preferences drift. Fashion trends change. A global event changes what people want to watch on Netflix. Standard bandit algorithms assume stationary reward distributions the true mean of each arm stays constant. In practice, you need either sliding window estimates, discounting of old observations, or explicit change-point detection to handle this.</p><p>Exploration budget constraints. In some contexts (medical treatments, high-stakes financial decisions), exploration isn’t free — you can’t just “try something worse on purpose” to learn. Some applications implement hard constraints on how far exploration can deviate from the current best policy. Thompson Sampling with conservative priors is often used here.</p><p>The off-policy evaluation problem. When you want to evaluate a new bandit policy before deploying it, you can’t just run it live and measure regret — you’d be, well, running it live. Offline evaluation using historical logged data requires careful correction for the fact that the historical data was collected under a different policy. Inverse Propensity Weighting (IPW) and Doubly Robust estimators are the standard tools here, but they introduce their own variance-bias trade-offs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*PU_4ZZt3OTVqCuLeNJoHUA.png" /><figcaption>Production bandit architecture. Real-time serving sits on top; the feedback pipeline processes delayed rewards; offline training evaluates candidates via OPE before deploying new policy versions.</figcaption></figure><blockquote><em>“The most useful thing about bandits isn’t the specific algorithm. It’s the framing: making learning and deployment the same loop, not sequential phases.”</em></blockquote><p>Some Further reading + Sources :D</p><p>Netflix: <em>Artwork personalization at Netflix</em> — netflixtechblog.com</p><p>Stitch Fix: <em>Multi-Armed Bandits and the Stitch Fix Recommendation Problem</em> — multithreaded.stitchfix.com</p><p>DoorDash: <em>Using a multi-armed bandit with Thompson Sampling to identify responsive Dashers</em> — doordash.engineering</p><p>Eugene Yan: <em>Bandits for Recommender Systems</em> — eugeneyan.com</p><p>Spotify: <em>Calibrated recommendations with contextual bandits on Spotify homepage</em> — research.atspotify.com (2025)</p><p>Yahoo! Research: <em>A contextual-bandit approach to personalized news article recommendation</em> — Li et al., WWW 2010</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b46601eab4cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LLM Scaling laws and their relevance in 2026!]]></title>
            <link>https://medium.com/@advaitss11/llm-scaling-laws-and-their-relevance-in-2026-b7928e732b6d?source=rss-0ada2e05a420------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7928e732b6d</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[scaling-law]]></category>
            <category><![CDATA[chinchilla-scaling-laws]]></category>
            <category><![CDATA[llm-scaling-laws]]></category>
            <category><![CDATA[kaplan-scaling-law]]></category>
            <dc:creator><![CDATA[Advait Shinde]]></dc:creator>
            <pubDate>Sun, 25 Jan 2026 02:21:41 GMT</pubDate>
            <atom:updated>2026-01-25T02:21:41.403Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5OSYwMMNlreyMb9CqYNtaQ.png" /><figcaption>Generated via chat.com</figcaption></figure><p>We have all heard about Open AI / Kaplan Scaling laws and Chincilla scaling laws, but these were earlier in the decade, do the current state of the art LLMs still follow these laws? Or the data and new optimization techniques have made them obsolete?</p><p>Both formulas are trying to predict the same thing:</p><p><strong>How good a language model will be (measured by “loss”) as you change</strong></p><ul><li><strong>N</strong> = model size (usually number of parameters)</li><li><strong>D</strong> = training data size (usually number of tokens)</li></ul><p>Lower <strong>loss</strong> means better next-token prediction (and usually better downstream performance).</p><p>They differ mainly in <strong>how they combine the effects of model size and data</strong>.</p><h4>What “loss” means here</h4><p>Think of <strong>loss</strong> as “how surprised the model is on average” when it sees the next word on a held-out test set. Lower loss means the model assigns higher probability to correct next tokens.</p><p>These scaling laws are <strong>empirical fits</strong>: people train many models of different sizes on different dataset sizes, measure loss, then fit a simple equation that matches the trends.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/0*yAFP3xyfeR2spb9X.jpg" /><figcaption>Source: <a href="https://x.com/Francis_YAO_/status/1730022774473687084">https://x.com/Francis_YAO_/status/1730022774473687084</a></figcaption></figure><h3>GPT (Kaplan-style) scaling law</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/314/1*WUi8r-Belp-u_ouqnTTCLg.png" /></figure><ul><li><strong>Nc\N​​</strong>: compares your model size N to a reference scale Nc</li></ul><p>If N increases, this ratio shrinks, so loss goes down.</p><ul><li><strong>Dc/D:</strong> compares your data size DDD to a reference scale DcD_cDc​.</li></ul><p>If D increases, this ratio shrinks, so loss goes down.</p><ul><li><strong>αN, αD​</strong>: exponents that determine <em>how quickly</em> loss improves as you scale N or D</li></ul><h4>Scenario 1: Data Abundance</h4><p>D is huge, Dc / D is near 0, so: when you have plenty of data, <strong>performance is mainly limited by model size</strong>. [1]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*iVK1Rb_10rbfUNcESkXCbw.png" /></figure><h4>Scenario 2: Model is Huge</h4><p>If N is huge, the model-size term becomes tiny, so: <strong>performance is mainly limited by data</strong>. [1]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/252/1*T2uSq0Xkx8PlLiqOFVQO0w.png" /></figure><h3>Chinchilla scaling law</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/1*uec_hMLUOLOpGZ8ZNQsiWw.png" /></figure><h3>What each term means</h3><ul><li><strong>E</strong>: an <em>irreducible</em> baseline (you cannot drive loss below this with scaling alone, at least within the fitted regime).</li><li><strong>A/Nα</strong>: the part of the loss that comes from the model being too small.</li></ul><p>Bigger N makes this shrink as a power law.</p><ul><li><strong>B/Dβ​</strong>: the part of the loss that comes from not having enough data.</li></ul><p>Bigger D makes this shrink as a power law.</p><ul><li><strong>α,β</strong>: again control diminishing returns.</li></ul><h3>Same bottleneck story, simpler shape</h3><p>This also implies “whichever term is bigger dominates,” but it’s more explicitly decomposed:</p><ul><li>If N is small, A / Nα dominates.</li><li>If D is small, B / Dβ​ dominates.</li><li>If both are large, you approach E</li></ul><p>This form is commonly associated with the <strong>Chinchilla</strong> work on compute-optimal training. [2]</p><h4>Why people compare “GPT scaling” vs “Chinchilla scaling”</h4><p>The practical question is usually not “what happens if I increase both forever,” but:</p><p><strong>Given a fixed training compute budget, should I spend it on</strong></p><ul><li>a larger model (increase N), or</li><li>more training tokens (increase D), or</li><li>some balance?</li></ul><p>Chinchilla’s key result is that many big models were <strong>undertrained</strong> (too few tokens for their size), and that for compute-optimal training you should scale model size and tokens more evenly.</p><h3>Other foundational scaling formulas people use:</h3><ol><li>Single Axis power laws ( learning curves ) <a href="https://arxiv.org/abs/1712.00409">[3]</a></li><li>Joint additive model ( the common baseline ) <a href="https://arxiv.org/abs/2203.15556">[2]</a></li><li>Compute scaling (loss vs training compute) <a href="https://arxiv.org/abs/2001.08361">[1]</a></li></ol><p>Given a compute budget C, you can ask: what N and D minimize loss under that budget? Kaplan and Chinchilla both answer this, but with different conclusions about the best split.</p><ul><li>Kaplan-era guidance tended to favor relatively larger models for a given compute budget [1].</li><li>Chinchilla showed many large models were <strong>undertrained</strong> and that compute-optimal training uses <strong>more tokens per parameter</strong> than was common then [2] .</li></ul><h3>Are the GPT and Chinchilla formulas still relevant?</h3><p>Yes, as <strong>first-order planning tools</strong>, but with important caveats.</p><h4>Still relevant for</h4><ul><li><strong>Budgeting and forecasting</strong>: Power-law loss trends remain a practical way to extrapolate performance and compare training plans.</li><li><strong>Diagnosing bottlenecks</strong>: They still correctly capture the idea of “you are limited by model size or by data (or both).”</li><li><strong>Avoiding undertraining</strong>: The “tokens matter” correction from Chinchilla remains a core lesson in modern training decisions.</li></ul><h4>Where they are less reliable (and why people extend them)</h4><ul><li><strong>Data quality and repetition</strong>: Counting raw tokens can overstate how much “new information” you are adding; quality-aware scaling can fit better</li><li><strong>New data sources (synthetic, curated mixtures)</strong>: The scaling curve can shift with the generator, filtering, and mixture strategy.</li><li><strong>Different objectives</strong>: These laws primarily target <strong>pretraining loss</strong>. Instruction tuning and RL-style objectives can change the relationship between loss and user-visible capability, so you often refit separate curves per stage. (This is a limitation even in the original framing.)</li><li><strong>Different regimes</strong>: If you are genuinely data-limited, strategies and fitted exponents can differ from the classic “infinite data” intuition.</li></ul><h3>Real-world calculation: do modern models sit on the Chinchilla compute-optimal tradeoff?</h3><p>Numbers sourced from the original papers: GPT-3 <a href="https://ar5iv.org/pdf/2005.14165">[6]</a> token count , Chinchilla Table 1 for GPT-3/Gopher/Chinchilla <a href="https://ar5iv.org/pdf/2203.15556">[2]</a> , Gopher paper confirms 300B-token training [8], PaLM tokens <a href="https://jmlr.org/papers/volume24/22-1144/22-1144.pdf">[7]</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UTRPGc23bOUTznFmcv1ePA.png" /></figure><p><strong>What this shows</strong></p><ul><li><strong>GPT-3, Gopher, PaLM</strong>: very low tokens/param (about 1–2), far below 20 → strongly <strong>undertrained</strong> by Chinchilla’s compute-optimal criterion.</li><li><strong>Chinchilla</strong> lands exactly at 20 tokens/param by construction and was explicitly trained as the compute-optimal alternative at Gopher’s budget.</li><li>Chinchilla reports broad downstream wins vs larger models (including Gopher), matching the scaling prediction.</li></ul><p>This is the cleanest published “reality check” that the compute-optimal scaling idea worked.</p><h3>Open-weights (published N and D)</h3><p>Sources: Llama 3.1 405B trained on 15.6T tokens [9] , Qwen2.5 “flagship” and 18T tokens [10] , DeepSeek-V3 (671B total, 37B activated, 14.8T tokens) [11].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XvmwdP5hyof3wacZGJz2LQ.png" /></figure><p><strong>What this shows</strong></p><ul><li>The dense open models listed are mostly <strong>well above</strong> 20 tokens/param (often massively).</li><li>Under the strict “minimize loss for a fixed training FLOP budget” lens, that means they are “off” the Chinchilla compute frontier: for the <em>same</em> N⋅D, the frontier would pick a <strong>larger model and fewer tokens</strong> (see “Compute-opt Params*”).</li><li>This does <strong>not</strong> mean Chinchilla scaling “stopped working.” It usually means the training objective is not “best loss per training FLOP” alone. Common reasons:</li><li><strong>Inference cost constraints</strong>: smaller N is cheaper per token at serving time, so teams may spend extra training compute (more D) to get a stronger small model.</li><li><strong>Data abundance / quality strategy</strong>: if you have high-quality tokens, training longer can keep improving.</li><li><strong>Non-dense architectures</strong> (MoE): “parameters” is ambiguous. DeepSeek-V3 illustrates this: using <strong>activated</strong> params it looks extremely overtrained, but using <strong>total</strong> params it is close to the 20 tokens/param ratio. <br> This is exactly why dense scaling rules do not transfer cleanly to MoE without modification.</li></ul><h3>Bottom line from the calculation</h3><ul><li>For <strong>classic dense models with published training details</strong>, Chinchilla’s compute-optimal prediction very clearly matched reality (Chinchilla vs Gopher).</li><li>For <strong>modern open models</strong>, many are intentionally trained in a regime that is not “Chinchilla compute-optimal for training FLOPs,” typically because they optimize a broader cost function (training + inference + deployment constraints), and because architecture (MoE) changes what counts as “N.”</li><li>For <strong>today’s frontier closed models</strong> (for example GPT-4-class and newer), the key inputs you requested (true N, true D, and comparable pretraining loss) are generally not public, so a direct numerical check like the above is not possible from open information.</li></ul><h3>references i got the data from</h3><p><strong>[1]</strong> Jared Kaplan et al. “Scaling Laws for Neural Language Models.” arXiv:2001.08361 (2020). <br> <strong>[2]</strong> Jordan Hoffmann et al. “Training Compute-Optimal Large Language Models.” arXiv:2203.15556 (2022). <br> <strong>[3]</strong> Joel Hestness et al. “Deep Learning Scaling is Predictable, Empirically.” arXiv:1712.00409 (2017). <br>( removed 4,5) <br> <strong>[6]</strong> Tom B. Brown et al. “Language Models are Few-Shot Learners.” arXiv:2005.14165 (GPT-3) (2020). <br> <strong>[7]</strong> Aakanksha Chowdhery et al. “PaLM: Scaling Language Modeling with Pathways.” JMLR 24(240):1−113 (and arXiv:2204.02311) (2022). references</p><p><strong>[8]</strong> Jack W. Rae et al. “Scaling Language Models: Methods, Analysis &amp; Insights from Training Gopher.” arXiv:2112.11446 (2021). <br> <strong>[9]</strong> Llama Team (Meta). “The Llama 3 Herd of Models.” (contains “405B … 15.6T tokens” statement). <br> <strong>[10]</strong> Qwen Team. “Qwen2.5 Technical Report.” (pretraining scaled to 18T tokens). <br> <strong>[11]</strong> F. Wu et al. “DeepSeek-V3 Technical Report.” (671B total, 37B activated, 14.8T tokens). <br> <strong>[12]</strong> “Gemma 2: Improving Open Language Models at a Practical Size.” (27B trained on 13T tokens, etc.).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7928e732b6d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Finding the Perfect Replacement: How ML Recommender Systems can aid Valorant Transfers!]]></title>
            <link>https://medium.com/@advaitss11/finding-the-perfect-replacement-how-ml-recommender-systems-can-aid-valorant-transfers-766db9133d6d?source=rss-0ada2e05a420------2</link>
            <guid isPermaLink="false">https://medium.com/p/766db9133d6d</guid>
            <category><![CDATA[esports-news]]></category>
            <category><![CDATA[recommender-systems]]></category>
            <category><![CDATA[valorant]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[vct]]></category>
            <dc:creator><![CDATA[Advait Shinde]]></dc:creator>
            <pubDate>Tue, 28 Oct 2025 02:40:43 GMT</pubDate>
            <atom:updated>2025-10-28T02:40:43.207Z</atom:updated>
            <content:encoded><![CDATA[<h3>Finding the Perfect Replacement: How ML Recommender Systems aid Valorant Transfers</h3><p><em>A deep dive into player performance analytics and recommendation systems for the 2025 transfer season</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mY2-LzDfjORQHZWc.jpg" /><figcaption>Source:<a href="https://playvalorant.com/en-gb/news/esports/everything-you-need-to-know-champions-paris/">https://playvalorant.com/en-gb/news/esports/everything-you-need-to-know-champions-paris/</a></figcaption></figure><p><strong><em>skip to code: </em></strong><a href="https://github.com/adv-11/valorant-champions-recommender-system"><em>https://github.com/adv-11/valorant-champions-recommender-system</em></a></p><h3>Introduction: The Transfer Season Problem</h3><p>It’s that time of year again. Rosters are shuffling, contracts are expiring, and team managers are frantically trying to figure out: <em>“If we lose our star duelist, who the hell do we sign?”</em></p><p>Traditionally, this decision was made through scouting reports, scrims, and gut feelings. But what if we could do better? What if we could use data to find players who are genuinely similar in playstyle, not just in name recognition?</p><p>That’s exactly what I set out to explore using the Valorant Champions 2025 Paris tournament data. <strong>Spoiler: the results are pretty damn cool.</strong></p><h3>Part 1: Understanding the Data — What Makes a Great Duelist?</h3><p>Before we can build a recommendation system, we need to understand what we’re actually measuring. I analyzed <strong>81 players</strong> across the entire tournament, focusing on key performance metrics that define how duelists play.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LI1OBJH9wGpc7LfLGpceNg.png" /><figcaption>Source: self</figcaption></figure><h3>The Six Pillars of Duelist Performance</h3><p>Let me walk you through what the data revealed:</p><h4>1. Average Combat Score (ACS): The Overall Impact Metric</h4><p>ACS is like your GPA for Valorant — it combines kills, damage, and multikills into one number. Most players hovered around <strong>189–190 ACS</strong>, but the elites? They’re breaking 260.</p><p>The distribution was beautifully normal (bell curve), meaning there’s a clear skill hierarchy. <strong>aspas</strong> from MIBR topped the charts at <strong>261.6 ACS</strong> — an absolute monster performance.</p><p><strong>Key insight:</strong> ACS doesn’t lie. It’s the single best predictor of overall impact.</p><h4>2. Kill/Death Ratio (K/D): Staying Alive Matters</h4><p>Here’s something interesting: the average K/D across all players was almost exactly <strong>1.0</strong> (mean: 0.97). This makes sense — in a 5v5 game, for every kill there’s a death.</p><p>But the best duelists push this to <strong>1.4–1.6+</strong>. They’re not just getting kills; they’re surviving teamfights and creating numerical advantages.</p><p><strong>The correlation between K/D and ACS? A whopping 0.801.</strong> Translation: good K/D = high impact.</p><h4>3. Kills per Round (KPR): Consistency is King</h4><p>Most players average around <strong>0.66–0.67 kills per round</strong> (basically 2 kills every 3 rounds). The top performers push this to <strong>0.8–0.9</strong>.</p><p>What’s crucial here: KPR correlates <strong>0.967</strong> with ACS — the strongest correlation in the entire dataset. Want to predict a player’s impact? Look at their KPR.</p><h4>4. First Kills per Round (FKPR): The Entry Fragger’s Signature</h4><p>This is where duelists separate themselves. FKPR measures how often you get the first kill of the round — the most important kill in Valorant.</p><p>Most players sit around <strong>0.09–0.10</strong> (getting a first kill in ~10% of rounds). But true entry fraggers like <strong>aspas</strong> and <strong>kaajak</strong> push <strong>0.20+</strong> — they’re opening up rounds for their team <strong>twice as often</strong>.</p><p><strong>Interesting finding:</strong> FKPR showed near-zero correlation with headshot percentage (-0.00). Entry fragging isn’t about aim — it’s about <em>timing and positioning</em>.</p><h4>5. Headshot Percentage: The Aim Check</h4><p>The average headshot percentage across all players was <strong>28–29%</strong>. Basically, 1 in 3–4 kills are headshots.</p><p>What surprised me: HS% was only weakly correlated with overall performance (0.04 with ACS). Why? Because <strong>game sense &gt; pure aim</strong>. You can have 40% HS and still lose rounds if you’re out of position.</p><h4>6. KAST %: The Consistency Metric</h4><p>KAST measures how often you contribute to rounds (via Kill, Assist, Survive, or Trade). Most players sat at <strong>70% KAST</strong>, meaning they’re relevant in 7 out of 10 rounds.</p><p>Elite players push <strong>75%+</strong> — they almost never have “dead” rounds where they contribute nothing.</p><h3>The Economy Game: Does Money Win Rounds?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*keEibBDOHVR9Z347r2qFTw.png" /><figcaption>Source: Self</figcaption></figure><p>I also analyzed how buy types affect win rates:</p><ul><li><strong>Full Buy rounds:</strong> 54.2% win rate ✅</li><li><strong>Semi-Buy rounds:</strong> 51.9% win rate ⚡</li><li><strong>Eco rounds:</strong> 43.7% win rate 💀</li><li><strong>Semi-Eco rounds:</strong> 16.4% win rate ☠️</li></ul><p>The takeaway? <strong>Money matters, but not as much as you’d think.</strong> Eco rounds still win 44% of the time — that’s not insignificant. Good utility usage and site takes can overcome economic disadvantage.</p><p><strong>Pistol rounds are everything.</strong> Most teams won 1 pistol per map, and that single round determined economic momentum for the next 3–4 rounds.</p><h3>The Aggression Paradox</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0J7vm4zvGrieXIkUz7G0FA.png" /><figcaption>Source: Self</figcaption></figure><p>One of my favorite findings: I plotted <strong>FKPR vs FDPR</strong> (First Kills vs First Deaths) to visualize player aggression.</p><p>The red diagonal line represents “balanced” players (FK = FD). Above the line? You’re getting entries without dying first. Below? You’re feeding.</p><p><strong>The best duelists sit slightly ABOVE the line</strong> — they take aggressive first duels but win them more often than they lose them. Players like <strong>aspas</strong> and <strong>kaajak</strong> have this mastered.</p><h3>Top Performers: The Elite Eight</h3><p>Here are the players who statistically dominated the tournament:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*Jou3Bksd2ZVZkgr8O9T1Xw.png" /><figcaption>Source: Self</figcaption></figure><p><strong>aspas</strong> is in a league of his own — highest ACS, best K/D among top performers, and elite entry fragging.</p><h3>Part 2: Building the Recommender System — “Find Me Another zekken”</h3><p>Now here’s where it gets interesting. Armed with all this data, I built a <strong>duelist recommendation system</strong> specifically designed for the transfer season.</p><h3>What’s a Recommender System? (The 101)</h3><p>Think of Netflix recommending shows or Spotify suggesting songs. A recommender system analyzes patterns in data to suggest similar items.</p><p>In our case:</p><ul><li><strong>Input:</strong> A duelist player (e.g., “zekken”)</li><li><strong>Output:</strong> Top 5 most similar duelists from OTHER teams</li></ul><h3>The Technical Magic: Weighted Cosine Similarity</h3><p>Here’s how it works (non-technical version):</p><h4>Step 1: Define What Matters</h4><p>Not all stats are equally important. I created a weighted feature system with <strong>4 categories</strong>:</p><pre>Combat (35%):        ACS, ADR, K/D, KPR<br>Aggression (30%):    FKPR, FDPR  <br>Precision (15%):     Headshot %<br>Consistency (20%):   KAST%, Clutch%</pre><p><strong>Why these weights?</strong></p><ul><li><strong>Combat is king</strong> (35%) because raw fragging power is non-negotiable for duelists</li><li><strong>Aggression matters almost as much</strong> (30%) because duelists must create space</li><li><strong>Consistency</strong> (20%) separates pros from ranked demons</li><li><strong>Precision</strong> (15%) is least important — positioning &gt; aim</li></ul><h4>Step 2: Normalize the Data</h4><p>You can’t compare ACS (range: 140–260) directly with headshot % (range: 0.15–0.40). So I normalized everything to a 0–1 scale using StandardScaler.</p><h4>Step 3: Calculate Similarity</h4><p>I used <strong>cosine similarity</strong> — it measures the “angle” between two players in high-dimensional space.</p><h4>Step 4: Recommend and Visualise</h4><p>Run an iterative function to find similar players, and create a visualization dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FHgSuoejw--Q490OAg-aIQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RSLxBowAvmk740XE9Cxe4w.png" /><figcaption>(a) MiniBoo Replacements (b) Zekken Replacements</figcaption></figure><p>So SENTINELS should go for mada 👀, but he’s contract is solid, leaving Flashback to be a solid choice!</p><p>And HERETICS should go all out for the GX star ata ❗️</p><h3>The Bottom Line: Data-Driven Scouting is the Future</h3><p>Here’s what this project proved:</p><p><strong>1. Stats tell stories.</strong> ACS, FKPR, and K/D aren’t just numbers — they reveal playstyle, aggression, and impact.</p><p><strong>2. Not all duelists are created equal.</strong> The difference between a top-10 duelist and a mid-tier one is massive (40+ ACS gap).</p><p><strong>3. Money wins rounds, but skill wins games.</strong> Eco round win rates were surprisingly high (44%) — good teams can overcome economy disadvantages.</p><p><strong>4. Similarity can be quantified.</strong> With the right features and weights, you can find statistically similar players with 90%+ accuracy.</p><p><strong>5. The transfer market needs this.</strong> Teams currently rely on scouting and scrims. This system gives you data-backed alternatives in seconds.</p><h3>Try It Yourself:</h3><p>Github: <a href="https://github.com/adv-11/valorant-champions-recommender-system"><em>https://github.com/adv-11/valorant-champions-recommender-system</em></a></p><p>The entire system is built in Python using:</p><ul><li><strong>pandas</strong> for data manipulation</li><li><strong>scikit-learn</strong> for similarity calculations</li><li><strong>matplotlib/seaborn</strong> for visualizations</li></ul><p>You can input any duelist and get instant recommendations.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=766db9133d6d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unpacking the Google ADK: What Developers Need to Know]]></title>
            <link>https://medium.com/@advaitss11/google-adk-the-cleanest-simplest-easiest-agentic-framework-yet-1943552a0a13?source=rss-0ada2e05a420------2</link>
            <guid isPermaLink="false">https://medium.com/p/1943552a0a13</guid>
            <category><![CDATA[agentic-ai]]></category>
            <category><![CDATA[google-adk]]></category>
            <category><![CDATA[agents]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[genai]]></category>
            <dc:creator><![CDATA[Advait Shinde]]></dc:creator>
            <pubDate>Mon, 14 Apr 2025 09:00:26 GMT</pubDate>
            <atom:updated>2025-10-06T17:42:32.128Z</atom:updated>
            <content:encoded><![CDATA[<h3>Unpacking the Google ADK: What Developers Need to Know…</h3><p>Google just launched their open source agent development framework, and here are my takeaways, if interested, give this blog a read to know more :D</p><p><strong>My Google ADK takeaways:</strong></p><ul><li>The CLI is a big win, making it easy to start and debug.</li><li>Docs could be smoother by removing manual folder creation.</li><li>Flexibility of supporting many model providers like Gemini, GPT-4o, and Claude.</li><li>Async agents and conversation management feel overly complicated for developers.</li><li>Artifact management is a genuinely useful feature for stateful agents.</li><li>The different agent types (LLM, Sequential, Parallel, Loop) feel overengineered; a simpler, unified approach would be better. Custom agents are nice, but just plugging in a Python function would be ideal.</li><li>AgentTool is a smart and modular way to design agents.</li><li>Evaluating agents feels clunky and not intuitive.</li><li>Guardrail callbacks are a good idea but are currently too complex.</li><li>Session state management needs improvement as it’s not easy to use.</li><li>Callbacks are a strong foundation with a lot of potential for event-driven agents.</li></ul><p>The way AI is getting smarter these days means we really need good tools to help developers build systems that can think and act on their own. We call these smart systems “AI agents,” and they’re popping up everywhere, from helping with customer questions to analyzing complicated data. With the rise of really powerful language models, these agents can now understand and reason with language in ways we haven’t seen before.</p><p>That’s why Google came up with the Agent Development Kit (ADK). It’s a new open-source toolkit designed to make building these smart AI applications much easier. Think of it as a flexible and organized way to create and deploy AI agents. It works especially well with Google’s own AI technology, like their Gemini models. The ADK tries to take away some of the headaches of building agents, giving developers a simple way to start with basic AI tools from Google, but also providing the structure needed to build more complex agent systems that work together. So, we’re going to take a closer look at what the Google ADK is all about, how it’s put together, the different kinds of agents it lets you build, and how you can potentially create powerful systems with multiple agents working together.</p><p>Basically, the Agent Development Kit sees an “Agent” as a self-sufficient little worker that can achieve specific goals without needing constant instructions. These agents can do tasks, talk to users, use other tools to become even more capable, and even team up with other agents to solve bigger problems. The foundation for all agents in the ADK is something called the BaseAgent class. It&#39;s like the basic recipe, giving you a set of core features and a structure you can build upon to create specialized agents for whatever you need. By having this base, the ADK makes sure all agents follow a similar pattern, which helps keep things organized and makes it easier to manage your intelligent systems.</p><p>To help developers with different kinds of projects, the Agent Development Kit offers different categories of agents, each with its own strengths and best uses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lfVEcH8iAICGeYKFkswfdA.png" /><figcaption>Source: <a href="https://google.github.io/adk-docs/agents/">https://google.github.io/adk-docs/agents/</a></figcaption></figure><h3>Core Agent Categories</h3><p>ADK provides distinct agent categories to build sophisticated applications:</p><ol><li><strong>LLM Agents (</strong><strong>LlmAgent, </strong><strong>Agent)</strong>: These agents utilize Large Language Models (LLMs) as their core engine to understand natural language, reason, plan, generate responses, and dynamically decide how to proceed or which tools to use, making them ideal for flexible, language-centric tasks.</li><li><strong>Workflow Agents (</strong><strong>SequentialAgent, </strong><strong>ParallelAgent, </strong><strong>LoopAgent)</strong>: These specialized agents control the execution flow of other agents in predefined, deterministic patterns (sequence, parallel, or loop) without using an LLM for the flow control itself, perfect for structured processes needing predictable execution.</li><li><strong>Custom Agents</strong>: Created by extending BaseAgent directly, these agents allow you to implement unique operational logic, specific control flows, or specialized integrations not covered by the standard types, catering to highly tailored application requirements.</li></ol><h4><strong>LLM Agents: Harnessing the Power of Language Models</strong></h4><p>LLM Agents represent a core category within the ADK, leveraging the capabilities of Large Language Models (LLMs) for a multitude of intelligent tasks. These agents utilize LLMs as their central processing unit, enabling them to understand and generate natural language, reason through complex scenarios, devise plans to achieve goals, and dynamically determine the most appropriate course of action, including the selection and utilization of external tools. This inherent language understanding and reasoning capability makes LLM Agents particularly well-suited for tasks that are inherently language-centric, requiring a high degree of flexibility and adaptability. The ADK provides the LlmAgent and Agent classes as key components for building these intelligent entities. For instance, a developer might instantiate an LLM agent with a specific instruction set and a designated language model, such as Gemini Pro:</p><pre>from google.adk.agents import Agent<br>llm_agent = Agent(<br>    name=&quot;my_llm_agent&quot;,<br>    model=&quot;gemini-pro&quot;, # Or your preferred Gemini model<br>    instruction=&quot;You are a helpful assistant. Answer user questions concisely.&quot;,<br>)</pre><p>This illustrates the straightforward approach to creating an LLM-powered agent within the ADK, highlighting the framework’s emphasis on a code-first development experience. LLM Agents find their ideal application in scenarios that demand sophisticated natural language interaction, logical inference, and the ability to make context-aware decisions, such as in the development of chatbots, content generation tools, and intelligent virtual assistants.</p><h4><strong>Workflow Agents: Orchestrating Structured Processes</strong></h4><p>In contrast to the dynamic nature of LLM Agents, Workflow Agents in the ADK are designed to control the execution flow of other agents in a predefined and deterministic manner. These specialized agents do not rely on an LLM to manage the sequence of operations; instead, they follow a set of predefined patterns to orchestrate the actions of their constituent agents. The ADK offers three primary types of Workflow Agents: SequentialAgent, ParallelAgent, and LoopAgent. A SequentialAgent executes a series of other agents in a specific order, ensuring that each agent completes its task before the next one begins, making it ideal for processes where the output of one step serves as the input for the subsequent step. A ParallelAgent, on the other hand, can execute multiple agents simultaneously, significantly reducing the overall processing time for tasks that can be broken down into independent sub-tasks. Lastly, a LoopAgent allows for the repeated execution of one or more agents based on a defined condition, making it useful for iterative processes or when a task needs to be performed on multiple items. Workflow Agents are particularly well-suited for structured processes that require predictable and reliable execution, such as automated data processing pipelines, multi-step form submissions, or any scenario where a fixed sequence of actions needs to be performed. An example of a SequentialAgent orchestrating two individual task agents is shown below:</p><pre>from google.adk.agents import SequentialAgent, Agent<br><br># Define individual agents<br>task_agent_1 = Agent(name=&quot;task_one&quot;, instruction=&quot;Perform the first task.&quot;)<br>task_agent_2 = Agent(name=&quot;task_two&quot;, instruction=&quot;Perform the second task.&quot;)<br># Create a sequential agent to run them in order<br>workflow = SequentialAgent(<br>    name=&quot;my_sequential_workflow&quot;,<br>    sub_agents=[task_agent_1, task_agent_2]<br>)</pre><p>This demonstrates how Workflow Agents enable developers to structure complex operations by composing simpler, specialized agents into a defined execution flow.</p><h4><strong>Custom Agents: Building Tailored Solutions</strong></h4><p>For applications with highly specific requirements that cannot be met by the standard LLM or Workflow Agent types, the ADK allows developers to create Custom Agents. These agents are built by directly extending the BaseAgent class, providing complete control over their operational logic, control flow, and integration with external systems. This level of customization makes Custom Agents essential for scenarios that involve unique integrations with legacy systems, the implementation of proprietary algorithms, or the enforcement of very specific and complex business rules. The foundation of a Custom Agent involves defining a new class that inherits from BaseAgent and implementing the _run_async_impl method, which dictates the agent&#39;s behavior:</p><pre>from google.adk.agents import BaseAgent, InvocationContext, Event<br>from typing import AsyncGenerator<br><br>class MyCustomAgent(BaseAgent):<br>    def __init__(self, name: str, **kwargs):<br>        super().__init__(name=name, **kwargs)<br>        # Initialize any custom components or logic here<br>    async def _run_async_impl(self, ctx: InvocationContext) -&gt; AsyncGenerator[Event, None]:<br>        # Implement your unique operational logic here<br>        yield Event(type=&quot;custom_event&quot;, payload={&quot;message&quot;: f&quot;Custom agent &#39;{self.name}&#39; executed.&quot;})<br># Instantiate the custom agent<br>specialized_agent = MyCustomAgent(name=&quot;data_processor&quot;)p</pre><p>This illustrates the fundamental structure of a Custom Agent, where developers have the freedom to implement any desired functionality within the _run_async_impl method, allowing for the creation of highly specialized and tailored autonomous entities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fku_wpsvb4KDvfsSf7oPKg.png" /><figcaption>Custom Agent Architecture: <a href="https://google.github.io/adk-docs/agents/custom-agents/#why-use-them">Source</a>.</figcaption></figure><p>Choosing the right kind of agent in Google’s ADK is super important for making your AI application work well. Think of it like picking the right tool for the job. Each type of agent has its own special skills that make it better for certain tasks.</p><p>For example, <strong>LLM Agents</strong> are like the word wizards. Because they’re built on those big language models, they’re fantastic at understanding and using natural language, figuring things out, and writing text that sounds like a human wrote it. They’re really good at handling the subtle nuances of language and making decisions on the fly. However, because they’re so flexible, sometimes they might not behave exactly the same way every time.</p><p>Then you have <strong>Workflow Agents</strong>, which are more like project managers for your AI. They’re designed to handle tasks that need to happen in a specific order. They’re really good at making sure things run predictably, whether it’s doing one thing after another, doing multiple things at the same time, or repeating steps. This makes them perfect for managing other agents and making sure everything flows as planned.</p><p>Finally, there are <strong>Custom Agents</strong>. These are the ultimate DIY option. They let you write your own unique code in Python to do pretty much anything you want, including connecting to special systems. Whether a Custom Agent behaves predictably or not totally depends on how you build it, giving you complete control.</p><p>To give you a clearer picture, imagine this: If you wanted to build an AI that could write stories or poems based on what people tell it, an <strong>LLM Agent</strong> would be your best bet. If you were automating the process of releasing new software, where you need to build the code, test it, and then finally put it live in a specific order, a <strong>Workflow Agent</strong>, specifically one that does things in sequence, would be ideal. And if you needed an agent to grab specific information from a company’s internal system that isn’t accessible through regular tools, you could build a <strong>Custom Agent</strong> to do just that.</p><p>The key differences between these agent types can be summarized in the following table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*03wneaAnHzNijJ9QuR6FVw.png" /><figcaption>Ai generated: Gemini 2.0 Flash</figcaption></figure><p>Where the Google ADK really shines is when you start putting different types of agents together to build really smart systems. Think of it like assembling a team of specialists, each with their own unique skills. By using the strengths of each type of agent, you can create applications that can handle much more complex problems than a single agent could on its own.</p><p>This way of building things is really handy because it’s modular — you can build different parts separately and then put them together. It’s also scalable, meaning you can easily add more specialized agents as your needs grow. Plus, it makes your application more robust because different agents can handle different parts of the problem, and it gives you more flexibility to adapt if things change.</p><p>For example, you could have one agent (an LLM Agent) that understands what a user wants, another agent (a Workflow Agent) that manages the steps needed to fulfill that request, and yet another agent (a Custom Agent) that connects to a specific database to get some information needed along the way. They all work together!</p><p>Now that you have a basic idea of what the Google Agent Development Kit is all about, the next step is to dive in and start building your own intelligent agents. Luckily, there are a bunch of resources to help you out.</p><p>If you want to learn more about setting up and using those LLM Agents — like how to give them instructions, connect them to other tools, and use cool features like planning and writing code — the documentation has some really detailed guides. If you’re interested in organizing complex tasks, you should definitely check out how to use the SequentialAgent, ParallelAgent, and LoopAgent. And if you have very specific needs, you can learn how to build your own Custom Agents by extending the basic agent blueprint. Understanding how to combine all these different agent types into powerful multi-agent systems is also a key thing to learn. Finally, it’s worth looking into the different language models available and figuring out which one is the best fit for your agents.</p><p>Besides all that specific stuff, the ADK documentation also has some great resources to get you started, like quick start guides, step-by-step tutorials, and examples of different agents in action. There’s also an API reference that gives you all the technical details about every part of the ADK. Plus, the framework has a whole ecosystem of tools that you can easily connect to your agents, including built-in helpers, support for other useful software, and special connections to Google Cloud services. By exploring all these resources, you’ll get the hands-on knowledge you need to really make the most of the Google Agent Development Kit and build some truly smart AI applications.</p><p>Check out my <a href="https://github.com/adv-11/AgenticAIFrameworks">A<em>gentic AI repository</em></a> for cool projects, POCs and random experimentation</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1943552a0a13" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Behemouth, Maverick and Scout!]]></title>
            <link>https://medium.com/@advaitss11/behemouth-maverick-and-scout-aba4563e1028?source=rss-0ada2e05a420------2</link>
            <guid isPermaLink="false">https://medium.com/p/aba4563e1028</guid>
            <category><![CDATA[meta]]></category>
            <category><![CDATA[knowledge-distillation]]></category>
            <category><![CDATA[llama-4]]></category>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Advait Shinde]]></dc:creator>
            <pubDate>Mon, 07 Apr 2025 04:44:03 GMT</pubDate>
            <atom:updated>2025-04-07T05:03:07.637Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IR6JYdqf7va80owTau0nGQ.png" /></figure><h4>Prerequisites: What Is Knowledge Distillation?</h4><p>Before we dive deeper, let’s quickly talk about a concept at the heart of Llama 4’s training process: <strong>knowledge distillation</strong>.</p><p>At its core, knowledge distillation is about <strong>teaching a smaller model to behave like a larger, smarter one</strong>.</p><p>Here’s how it works:</p><ul><li>You first train a <strong>large, powerful model</strong> (called the <strong>teacher</strong>) — usually very expensive and time-consuming to build.</li><li>Then, instead of training a smaller model (the <strong>student</strong>) only on raw data, you also <strong>train it to mimic the outputs of the teacher model</strong>.</li><li>The student model tries to predict not just the correct answers, but also the <em>reasoning patterns</em>, <em>confidence scores</em>, and <em>subtle decision-making</em> of the teacher.</li></ul><p>Think of it like a student in school learning not just the final answers from a textbook, but understanding <em>how</em> a brilliant professor thinks through problems.</p><p><strong>Why is this powerful?</strong></p><ul><li>It lets small models “inherit” the intelligence of much larger models.</li><li>The resulting student models are <strong>faster</strong>, <strong>lighter</strong>, and <strong>more efficient</strong>, while still maintaining much of the performance of their teachers.</li><li>It also helps models generalize better, meaning they can perform well even on new, unseen tasks.</li></ul><p>In the case of Llama 4, the <strong>Behemoth model</strong> acted as the teacher, helping Scout and Maverick reach remarkable levels of coding, reasoning, and multimodal understanding — without needing Behemoth’s massive infrastructure to run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/919/1*vbhVW2pbYgk0UYuQElM0Sg.png" /></figure><p>Meta just dropped their latest lineup of Llama models, and they’re pushing the boundaries of what open AI models can do. Whether you’re a researcher, developer, or just an AI enthusiast, there’s a lot to unpack with Llama 4 Scout, Maverick, and the preview of the giant, Llama 4 Behemoth. Let’s break it down.</p><h4>Visual Analogy: Knowledge Distillation</h4><p>🧠 Big Teacher Model<br> ↓<br> (Generates soft, nuanced outputs)<br> ↓<br> 🎯 Training Targets (soft labels)<br> ↓<br> 🧠 Smaller Student Model<br> (Learns both correct answers + teacher’s reasoning)</p><h4>Prerequisites: What Is Mixture of Experts (MOE) Architecture ?</h4><p>MoE (Mixture of Experts) is a model architecture that consists of several specialized “experts,” with only a small subset of them activated for each input. Instead of using the entire network for every task, MoE activates the most relevant experts based on the input. This selective activation allows for efficient scaling in large models, improving computational performance while maintaining high accuracy. MoE is particularly beneficial in tasks like natural language processing, where vast amounts of data and specialized knowledge are required.</p><h4>Visual Analogy: MOE</h4><p>📚 Big Model (expert in everything)<br> | <br> (For each task, only some experts are needed)<br> ↓<br> 👩‍🏫 Expert 1, Expert 2, Expert 3…<br> (Working on specific parts based on input)<br> ↓<br> 🌍 Final output (combination of expert knowledge)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ggRYw9DiC_8YQIC24Bvidg.png" /><figcaption>MOE — Source: <a href="https://ai.meta.com/blog/llama-4-multimodal-intelligence/">https://ai.meta.com/blog/llama-4-multimodal-intelligence/</a></figcaption></figure><h3>Meet the New Llamas: Scout, Maverick, and Behemoth</h3><p>Meta’s latest models are setting a new standard in the open-weight multimodal world.<br> Here’s the quick lineup:</p><ul><li><strong>Llama 4 Scout</strong>: A nimble, general-purpose 17B active parameter model with 16 experts, designed to fit on a single NVIDIA H100 GPU. Despite its size, Scout boasts a <em>10 million token</em> context window — an industry first. It’s small but mighty, outperforming other models like Gemma 3 and Gemini 2.0 Flash-Lite on key benchmarks.</li><li><strong>Llama 4 Maverick</strong>: Also a 17B active parameter model but built with 128 experts. Maverick takes it up a notch, beating the likes of GPT-4o and Gemini 2.0 Flash on multiple fronts. It even comes close to DeepSeek V3 on reasoning and coding tasks — all while using half the active parameters.</li><li><strong>Llama 4 Behemoth</strong> (preview): A colossal model with <em>288B active parameters</em> and nearly 2 trillion total parameters. Behemoth isn’t just flexing size — it’s actually outperforming GPT-4.5 and Claude 3 Sonnet on several STEM benchmarks. While it’s still in training, early signs show it’s becoming one of the smartest models ever built.</li></ul><h3>So, What’s New and Exciting?</h3><h3>1. Learning from the Giants</h3><p>Meta used <strong>knowledge distillation</strong> to train Scout and Maverick.<br> In simple terms, it’s like having a genius teacher (Behemoth) guide the learning of smaller students (Scout and Maverick). Instead of starting from scratch, the smaller models learn to mimic the intelligence, reasoning skills, and nuanced decision-making of the bigger model.</p><p>Why does this matter?<br> Because it allows smaller models to perform at levels you’d usually only expect from massive, resource-hungry systems — but without the same hardware demands or latency.</p><h3>2. Mixture of Experts (MoE): Smart Specialization</h3><p>Both Scout and Maverick use a <strong>Mixture of Experts (MoE)</strong> architecture — a major leap.<br> Think of MoE like having a team of specialized mini-models (“experts”) inside the Llama. For each input, only a few of these experts activate. This makes the model far more efficient — you get the smarts of a much larger model, but with lower computational costs.</p><ul><li>Scout uses 16 experts.</li><li>Maverick, being beefier, uses 128 experts.</li></ul><p>This smart specialization helps deliver more power per parameter, enabling faster, smarter responses across text, code, and images.</p><h3>Under the Hood: New Architectural Innovations</h3><p>Meta didn’t just scale models up; they made serious architectural changes.<br> One standout feature is something called <strong>iRoPE</strong> — <em>interleaved Rotary Position Embeddings</em>.</p><p>In most large language models, “positional embeddings” help the model understand the order of words. Meta decided to drop the traditional approach and use <em>interleaved attention layers without positional embeddings</em> combined with iRoPE, allowing Llama 4 models to handle crazy long contexts — up to 10 million tokens. (For comparison, Llama 3 could handle 128K tokens.)</p><p>They also use <strong>temperature scaling during inference</strong> to enhance how well the model handles ultra-long inputs.</p><p><strong>What does all that mean in plain English?</strong><br> It means Llama 4 models can digest multiple documents, summarize huge codebases, and maintain memory over extremely long conversations — opening up serious possibilities for personal AI agents, legal document analysis, and massive knowledge retrieval.</p><h3>Multimodal Mastery: Understanding Text and Images</h3><p>Another big leap is multimodal capabilities.<br> Scout and Maverick aren’t just good at text — they’re trained to understand and reason over <em>images and video frame stills</em> too. They’ve been pre-trained with up to 48 images at a time, and post-trained with impressive results up to eight images during inference.</p><ul><li><strong>Visual reasoning</strong>: Interacting with multiple images alongside text prompts.</li><li><strong>Image grounding</strong>: Aligning user prompts with relevant regions inside images (e.g., “Find the cat in the image” and actually locating it).</li></ul><p>This pushes Llama models into new territory — making them strong candidates not just for chatbots, but for intelligent assistants in fields like healthcare, education, and engineering.</p><h3>Why This Matters</h3><p>The release of Llama 4 Scout and Maverick (and the preview of Behemoth) signals more than just bigger, better models — it’s about <strong>making cutting-edge AI widely available</strong>.</p><p>Meta’s commitment to open-sourcing these models means developers, researchers, and startups will have the tools they need to build smarter, more personalized AI systems without breaking the bank on hardware.</p><p>These Llama 4 models are now available for download via <a href="https://llama.com/">llama.com</a> and <a href="https://huggingface.co/">Hugging Face</a>.</p><p>The future of human-AI collaboration just got a whole lot more interesting — and it’s only getting started.</p><h3>Final Thoughts</h3><p>In a landscape where AI breakthroughs often feel locked behind corporate walls, Meta’s Llama 4 family stands out for being <em>open</em>, <em>scalable</em>, and <em>practically powerful</em>.<br> Whether you’re dreaming up the next-generation chatbot, creating a personalized tutor, or building enterprise-scale solutions, Llama 4 models are offering a powerful — and refreshingly accessible — foundation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aba4563e1028" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Revolutionizing AI Agents: LangMem Long Term Memory]]></title>
            <link>https://medium.com/@advaitss11/revolutionizing-ai-agents-langmem-long-term-memory-604611922ccf?source=rss-0ada2e05a420------2</link>
            <guid isPermaLink="false">https://medium.com/p/604611922ccf</guid>
            <category><![CDATA[langchain]]></category>
            <category><![CDATA[langgraph]]></category>
            <category><![CDATA[agentic-ai]]></category>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[langmem]]></category>
            <dc:creator><![CDATA[Advait Shinde]]></dc:creator>
            <pubDate>Mon, 17 Mar 2025 18:38:30 GMT</pubDate>
            <atom:updated>2025-03-17T18:38:30.771Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/760/0*0EmWIDl-Sn1DK7-z.png" /><figcaption>Source: <a href="https://blog.langchain.dev/langmem-sdk-launch/">https://blog.langchain.dev/langmem-sdk-launch/</a></figcaption></figure><p>Imagine an AI assistant that not only remembers your current conversation but also recalls your preferences, past experiences, and even adapts its behavior over time. In today’s fast‐paced digital world, the ability to remember details — just like a human — can transform an ordinary chatbot into a truly personalized helper. This is exactly what LangMem is designed to achieve.</p><p>LangMem is an innovative SDK that equips AI agents with long‑term memory. Whether it’s storing user facts, episodic experiences, or even evolving instructions (procedural memory), LangMem makes it possible for agents to learn and improve with every interaction.</p><h3>The Memory Challenge in AI Agents</h3><p>Traditional language models are inherently stateless. They excel at processing short-term conversation threads but quickly “forget” past interactions once a session ends. This limitation forces developers to either re-prompt agents or risk losing context over time. LangMem addresses this by introducing three core types of memory:</p><ul><li><strong>Semantic Memory:</strong> Stores core facts and user preferences (e.g., “User prefers dark mode” or “Alice works in marketing”). This knowledge forms a persistent base that the AI can reference during interactions.</li><li><strong>Episodic Memory:</strong> Captures complete experiences, including the context and reasoning behind an interaction. Think of it as a diary where the agent notes “what happened” and “how it was resolved.”</li><li><strong>Procedural Memory:</strong> Encodes behavioral patterns and evolving instructions. It’s like the agent’s operating manual that gets refined as it learns from feedback.</li></ul><p>These layers allow AI agents to operate with an awareness that goes far beyond the confines of a single conversation, paving the way for truly adaptive and personalized experiences.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*0-0lENrw5__dwm0jfU4V4A.png" /><figcaption>Source: <a href="https://blog.langchain.dev/langmem-sdk-launch/">https://blog.langchain.dev/langmem-sdk-launch/</a></figcaption></figure><h3>1. Semantic Memory</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*lo1Bh3Y9JE6_8gqhQGemGg.png" /><figcaption>Semantic Memory: Source: <a href="https://blog.langchain.dev/langmem-sdk-launch/">https://blog.langchain.dev/langmem-sdk-launch/</a></figcaption></figure><p><strong>Purpose:</strong><br> Semantic memory captures key facts and user preferences. For example, if a user states a preference like “I prefer dark mode” or mentions a specific fact such as “Alice is a data scientist,” this information is stored as a semantic fact for later retrieval.</p><p><strong>Example Code:</strong></p><pre>from langmem import create_memory_manager<br>from pydantic import BaseModel, Field<br><br># Define a schema for semantic memory: storing user preferences or facts.<br>class UserPreference(BaseModel):<br>    fact: str = Field(..., description=&quot;Key fact or preference&quot;)<br>    detail: str | None = Field(None, description=&quot;Additional context&quot;)<br># Create a memory manager for semantic memory extraction.<br>semantic_manager = create_memory_manager(<br>    &quot;anthropic:claude-3-5-sonnet-latest&quot;,<br>    schemas=[UserPreference],<br>    instructions=&quot;Extract key facts and preferences from the conversation.&quot;,<br>    enable_inserts=True<br>)<br># Sample conversation that contains semantic facts.<br>conversation = [<br>    {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;I really enjoy using dark mode on my devices.&quot;},<br>    {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;Got it!&quot;},<br>    {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;Also, I work as a data scientist at Acme Corp.&quot;},<br>]<br># Extract semantic memories.<br>semantic_memories = semantic_manager.invoke({&quot;messages&quot;: conversation})<br># Display the extracted semantic facts.<br>for mem in semantic_memories:<br>    print(mem)<br># Expected output (example):<br># ExtractedMemory(id=&#39;...&#39;, content=UserPreference(fact=&#39;User prefers dark mode&#39;, detail=None))<br># ExtractedMemory(id=&#39;...&#39;, content=UserPreference(fact=&#39;User works as a data scientist at Acme Corp&#39;, detail=None))</pre><p><em>In this example, the LangMem manager is configured to extract straightforward facts from the conversation — ideal for building a knowledge base of user preferences or facts.</em></p><h3>2. Episodic Memory</h3><p><strong>Purpose:</strong><br> Episodic memory captures the full context of an interaction, including the situation, the agent’s internal reasoning, the action taken, and the outcome. This “story” helps the agent learn from experiences.</p><p><strong>Example Code:</strong></p><pre>from langmem import create_memory_manager<br>from pydantic import BaseModel, Field<br><br># Define an Episode schema to capture full interaction details.<br>class Episode(BaseModel):<br>    observation: str = Field(..., description=&quot;Context or situation&quot;)<br>    thoughts: str = Field(..., description=&quot;Internal reasoning process&quot;)<br>    action: str = Field(..., description=&quot;Action taken by the agent&quot;)<br>    result: str = Field(..., description=&quot;Outcome of the action&quot;)<br># Create a memory manager for episodic memory.<br>episodic_manager = create_memory_manager(<br>    &quot;anthropic:claude-3-5-sonnet-latest&quot;,<br>    schemas=[Episode],<br>    instructions=&quot;Extract a detailed episode from the conversation including context, reasoning, action, and result.&quot;,<br>    enable_inserts=True<br>)<br># Sample conversation that provides context for an episodic memory.<br>conversation = [<br>    {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;What is a binary tree? I work with family trees, so maybe you can relate.&quot;},<br>    {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: (<br>        &quot;A binary tree is like a family tree, but each parent has at most 2 children. &quot;<br>        &quot;For example, think of Bob as the parent, with Amy and Carl as the children.&quot;<br>    )},<br>    {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;Oh, that makes sense! I see the analogy now.&quot;},<br>]<br># Extract episodic memory.<br>episodes = episodic_manager.invoke({&quot;messages&quot;: conversation})<br># Display the extracted episode.<br>for ep in episodes:<br>    print(ep)<br># Expected output (example):<br># ExtractedMemory(<br>#    id=&#39;...&#39;,<br>#    content=Episode(<br>#       observation=&quot;User asked about binary trees using a family tree analogy.&quot;,<br>#       thoughts=&quot;Using relatable examples helps bridge technical concepts.&quot;,<br>#       action=&quot;Explained binary trees with a simple family tree diagram.&quot;,<br>#       result=&quot;User acknowledged understanding with &#39;That makes sense!&#39;&quot;<br>#    )<br># </pre><p><em>This episodic example demonstrates how an agent can capture not just a fact, but the entire context — including the thought process behind an effective explanation.</em></p><h3>3. Procedural Memory</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*EGeLwskum1w21kGa_4_JNA.png" /><figcaption>Procedural Memory: Source: <a href="https://blog.langchain.dev/langmem-sdk-launch/">https://blog.langchain.dev/langmem-sdk-launch/</a></figcaption></figure><p><strong>Purpose:</strong><br> Procedural memory helps the agent refine its behavior by updating its core instructions based on past interactions. It adapts the agent’s internal “playbook” (or prompt) for improved performance over time.</p><p><strong>Example Code:</strong></p><pre>from langmem import create_prompt_optimizer<br># Create a prompt optimizer for procedural memory.<br>optimizer = create_prompt_optimizer(<br>    &quot;anthropic:claude-3-5-sonnet-latest&quot;,<br>    kind=&quot;metaprompt&quot;,<br>    config={&quot;max_reflection_steps&quot;: 3}<br>)<br># Define the initial system prompt.<br>initial_prompt = &quot;You are a helpful assistant.&quot;<br># Simulate a conversation trajectory and feedback.<br>trajectory = [<br>    [<br>        {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;Explain inheritance in Python.&quot;},<br>        {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;Inheritance allows classes to inherit features from other classes.&quot;},<br>        {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;Can you give me a concrete code example?&quot;}<br>    ],<br>    {&quot;user_score&quot;: 0.3, &quot;feedback&quot;: &quot;The explanation was too vague and lacked practical detail.&quot;}<br>]<br># Optimize the system prompt based on the conversation and feedback.<br>optimized_prompt = optimizer.invoke({<br>    &quot;trajectories&quot;: [(trajectory[0], trajectory[1])],<br>    &quot;prompt&quot;: initial_prompt<br>})<br>print(&quot;Optimized Prompt:&quot;)<br>print(optimized_prompt)<br># Expected output (example):<br># &quot;You are a helpful assistant with a knack for providing concrete examples. When explaining concepts like inheritance in Python, always include clear code samples and practical explanations.&quot;</pre><p><em>Here, procedural memory is represented by the evolving system prompt. The prompt optimizer uses feedback to refine how the agent should behave in future interactions.</em></p><h3>Unpacking LangMem SDK</h3><p>LangMem is a lightweight Python library that provides the tools to extract, update, and retrieve long‑term memories seamlessly. It works independently of any specific storage backend yet integrates natively with LangGraph’s persistent memory store. This flexibility means you can start with in‑memory storage for prototyping and switch to a more robust solution like a PostgreSQL‑backed store in production.</p><p>Key features include:</p><ul><li><strong>Core Memory API:</strong> Functions that extract relevant details from interactions.</li><li><strong>Memory Management Tools:</strong> Primitives that help your agent record, search, and consolidate memories during conversations.</li><li><strong>Prompt Optimization:</strong> Using feedback loops to update the system prompt so the agent can fine‑tune its behavior over time.</li></ul><p>LangMem’s modular design gives developers control over what to remember, how to update it, and when to recall stored memories — making it a game‑changer in the realm of AI personalization.</p><h3>Building “MemBot”: An AI Chatbot with Active Memory</h3><p>To illustrate LangMem in action, let’s build a prototype application — <strong>MemBot</strong>. This adaptive chatbot not only holds a conversation but also learns your preferences and adapts its responses accordingly.</p><h3>App Concept</h3><p>Imagine MemBot as your personal assistant. In day‑to‑day chats, it remembers details like your preferred interface (dark mode vs. light mode), favorite topics, and even past questions you asked. Over time, it refines its behavior based on your feedback, offering responses that feel truly tailored to you.</p><h3>Complex Code Example</h3><p>Below is an advanced Python example that integrates LangMem with a FastAPI server. In this example, we set up:</p><ul><li>An <strong>in‑memory store</strong> for quick prototyping.</li><li><strong>Memory management tools</strong> to extract and store both semantic and episodic memories.</li><li>A <strong>FastAPI endpoint</strong> to simulate a chat interface where MemBot can interact and learn.</li></ul><pre>from fastapi import FastAPI, Request<br>from pydantic import BaseModel, Field<br>from typing import List<br>import uvicorn<br><br># Import LangGraph components and LangMem tools<br>from langgraph.prebuilt import create_react_agent<br>from langgraph.store.memory import InMemoryStore<br>from langmem import create_manage_memory_tool, create_search_memory_tool, create_memory_manager<br>from langchain.chat_models import init_chat_model<br># Define a custom Pydantic model for episodic memory<br>class Episode(BaseModel):<br>    observation: str = Field(..., description=&quot;Context of the interaction&quot;)<br>    thoughts: str = Field(..., description=&quot;Agent&#39;s internal reasoning&quot;)<br>    action: str = Field(..., description=&quot;Action taken by the agent&quot;)<br>    result: str = Field(..., description=&quot;Outcome and feedback&quot;)<br># Initialize FastAPI app<br>app = FastAPI()<br># Set up an in-memory vector store for storing memories<br>store = InMemoryStore(<br>    index={<br>        &quot;dims&quot;: 1536,<br>        &quot;embed&quot;: &quot;openai:text-embedding-3-small&quot;,<br>    }<br>)<br># Create memory tools for managing and searching long-term memories<br>manage_memory_tool = create_manage_memory_tool(namespace=(&quot;memories&quot;,))<br>search_memory_tool = create_search_memory_tool(namespace=(&quot;memories&quot;,))<br># Create a react agent integrated with memory capabilities<br>agent = create_react_agent(<br>    &quot;anthropic:claude-3-5-sonnet-latest&quot;,<br>    tools=[manage_memory_tool, search_memory_tool],<br>    store=store,<br>)<br># Optionally, set up an episodic memory manager to capture detailed episodes<br>episode_manager = create_memory_manager(<br>    &quot;anthropic:claude-3-5-sonnet-latest&quot;,<br>    schemas=[Episode],<br>    instructions=&quot;Extract complete episodes capturing context, reasoning, action, and result.&quot;,<br>    enable_inserts=True,<br>)<br># Pydantic models for API requests<br>class Message(BaseModel):<br>    role: str<br>    content: str<br>class ChatRequest(BaseModel):<br>    messages: List[Message]<br>@app.post(&quot;/chat&quot;)<br>async def chat_endpoint(chat_request: ChatRequest):<br>    # Convert messages to dict format<br>    messages = [msg.dict() for msg in chat_request.messages]<br>    <br>    # Invoke the agent to process the conversation.<br>    # The agent will automatically extract and store relevant memories.<br>    response = agent.invoke({&quot;messages&quot;: messages})<br>    <br>    # Additionally, extract detailed episodic memory from this conversation<br>    episodes = episode_manager.invoke({&quot;messages&quot;: messages})<br>    if episodes:<br>        print(&quot;Extracted Episode Memory:&quot;, episodes[0])<br>    <br>    return response<br># Run the app using uvicorn if this script is executed directly.<br>if __name__ == &quot;__main__&quot;:<br>    uvicorn.run(app, host=&quot;0.0.0.0&quot;, port=8000)</pre><h3>Code Walkthrough</h3><ol><li><strong>Setting Up Storage and Tools:</strong><br> We start by creating an in‑memory vector store and initializing memory management tools. These tools ensure that important details are automatically recorded during each interaction.</li><li><strong>Building the Agent:</strong><br> The create_react_agent function wraps our language model (in this case, Anthropic’s Claude variant) with memory tools, allowing it to both manage and search for memories during conversation.</li><li><strong>Episodic Memory Manager:</strong><br> A custom Pydantic model (Episode) is defined to capture the full context and reasoning behind successful interactions. This episodic memory is then extracted after each chat interaction, providing rich insights for future reference.</li><li><strong>FastAPI Integration:</strong><br> Finally, we expose a /chat endpoint where users can send messages. The agent processes the conversation, stores relevant memories, and even prints out an extracted episode for debugging or logging purposes.</li></ol><p>This comprehensive integration illustrates how LangMem can empower an AI chatbot to remember user preferences and past interactions — making each conversation more informed and personalized.</p><h3>Advanced Memory Features and Use Cases| Future Scope</h3><p>Beyond our basic “MemBot,” LangMem unlocks several advanced capabilities:</p><ul><li><strong>Semantic Memory:</strong><br> Automatically captures facts and knowledge. For example, if a user mentions they “prefer dark mode,” that detail is stored and later recalled when discussing UI settings.</li><li><strong>Episodic Memory:</strong><br> By capturing entire interaction episodes, the agent learns not just facts but also effective communication strategies. This allows for fine-tuning responses based on what worked well in the past</li><li><strong>Procedural Memory:</strong><br> The SDK includes prompt optimizers that evolve the agent’s instructions over time. This means that if the agent repeatedly receives feedback on how to improve its explanations, its system prompt can be updated dynamically to enhance future responses.</li></ul><p>These memory types are not mutually exclusive; they work together to form a layered memory system that can handle a variety of applications — from customer support and personalized tutoring to interactive entertainment.</p><h3>The Future of Adaptive AI with LangMem</h3><p>Long-term memory is transforming how we build and interact with AI agents. By bridging the gap between fleeting interactions and persistent learning, LangMem sets the stage for truly adaptive AI systems. As more developers integrate these capabilities into their products, we can expect AI to become more proactive, personalized, and context-aware — improving efficiency in everything from enterprise workflows to daily personal tasks.</p><p>LangChain’s vision, as echoed by industry experts, is to evolve AI agents from simple reactive tools into dynamic assistants that learn and grow with each interaction. With SDKs like LangMem, the future of AI is not only about generating text — it’s about creating experiences that remember, adapt, and improve over time.</p><h3>Takeaways</h3><p>LangMem is more than just a library; it’s a leap toward AI agents that can remember past interactions, learn from experience, and continuously refine their behavior. Whether you’re building a personal assistant, a customer support chatbot, or an enterprise-grade AI solution, LangMem’s flexible memory management tools offer a robust foundation for creating truly adaptive systems.</p><p>Explore the <a href="https://langchain-ai.github.io/langmem/">official LangMem documentation</a></p><p>With this new approach, your AI agents won’t just respond — they’ll remember, learn, and evolve, ushering in a new era of personalized and intelligent interactions.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=604611922ccf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RAG without LangChain and LlamaIndex?]]></title>
            <link>https://medium.com/@advaitss11/rag-without-langchain-and-llamaindex-c1f70425dbe7?source=rss-0ada2e05a420------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1f70425dbe7</guid>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[retrieval-augmented-gen]]></category>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Advait Shinde]]></dc:creator>
            <pubDate>Sat, 04 Jan 2025 06:53:58 GMT</pubDate>
            <atom:updated>2025-01-17T03:15:36.765Z</atom:updated>
            <content:encoded><![CDATA[<p>Large Language Models are a subset of artificial intelligence that utilize deep learning techniques, particularly transformer architectures, to understand human language and generate content. These are trained on vast amounts of daata, enabling them to have proficiency at a multitude of tasks. LLMs leverage their vast training data to capture nuances of language, knowledge, etc. making them useful tools for a variety of applications.</p><p>An issue faced by LLM is the knowledge cut off date, this means that the data used for training may not have information about data generated after the cut-off date. For this Retrieval Augmented Generation (RAG) is used to enhance the capability of LLMs by integrating retrieval mechanisms into the generation process. Instead of solely relying on the knowledge base of the LLM, we can introduce our own documents which act as context to the LLM. This approach helps overcome limitations related to the cut-off date.</p><p>Frameworks like LangChain and LlamaIndex offer RAG with just a few lines of code integration and API keys. To understand this trending technique, we will implement every component of the RAG architecture using the transformers library. This will give any individual a detailed idea of how the high level functions offered by frameworks actually work.</p><h4>Setup</h4><p>The initial step is to import the necessary libraries required for building RAG from scratch. These include transformers for model handling, torch for tensor operations, and various utility libraries like numpy, os, re, uuid, and json.</p><pre>from transformers import AutoTokenizer, AutoModel<br>import torch<br>import numpy as np<br>import os<br>import re<br>import uuid<br>import json</pre><h3>Document Store</h3><p>To effectively manage and track document content in a RAG workflow, it’s important to link each piece of text with the document it came from.</p><p>The first step is to read all the documents from a specific folder and save their content into a variable called text. To keep track of where each piece of text comes from, the script uses the filenames to extract a unique identifier (called an SKU or stock-keeping unit). It does this by going through all the files in the folder using os.listdir(directory_path) and removing the file extensions to get just the SKU.</p><p>For each file, the script checks if it’s a valid file, it opens the file, reads its content using UTF-8 encoding, and stores it in text. Thus the text data is easy to access and clearly linked to its original document, making it well-organized and ready for use in the retrieval process.</p><pre>for filename in os.listdir(directory_path):<br>    file_path = os.path.join(directory_path, filename)<br>    base = os.path.basename(file_path)<br>    sku = os.path.splitext(base)[0]<br>    if os.path.isfile(file_path):<br>        with open(file_path, &#39;r&#39;, encoding=&#39;utf-8&#39;) as file:<br>            text = file.read()</pre><h3>Chunking</h3><p>Chunking is a very important step in building RAG. Chunks are nothing but small blocks of data that are easy to store and retrieve compared to the enitre document. The documents are large, we need to split them into reasonable sizes for efficient indexing and retrieval. We need to set the <em>chunk_size</em> that represents the number of tokens in each chunk.</p><p>The first step in chunking is to split text into paragraphs and then paragraphs into words.</p><pre>#init var<br>para_seperator = &quot;/n/n&quot;<br>separator=&quot; &quot;<br>paragraphs = re.split(para_seperator, text)<br>words = paragraph.split(separator)<br><br>chunk_size = 200<br>current_chunk_str = &quot;&quot;<br>chunk = []<br><br>#iterate over words<br>for word in words:<br><br>    #check if chunksize &gt; size , if yes make new chunk<br>    if current_chunk_str:<br>        new_chunk = current_chunk_str + separator + word<br>    else:<br>        new_chunk = current_chunk_str + word    <br>    if len(tokenizer.tokenize(new_chunk)) &lt;= chunk_size:<br>        current_chunk_str = new_chunk<br>    else:<br>        if current_chunk_str:<br>            chunk.append(current_chunk_str)<br>            current_chunk_str = word<br>if current_chunk_str:<br>                chunk.append(current_chunk_str)<br><br>#assign unique ID<br>for chunk in chunk:<br>    chunk_id = str(uuid.uuid4())</pre><h3>Indexing</h3><p>VectorDB are used to store embeddings of data, the chunks that we created will be stored as vectors (numeric values). Popular VectorDB are ChromaDB, FAISS, Pinecone, etc. To create a VectorDB, we need to obtain embeddings for each chunk’s text and map these embeddings to their corresponding chunk IDs and document IDs.</p><pre><br>def map_document_embeddings(documents, tokenizer, model):<br>    <br>    mapped_document_db = {}<br>    for id, dict_content in documents.items():<br>        mapped_embeddings = {}<br>        for content_id, text_content in dict_content.items():<br>            text = text_content.get(&quot;text&quot;)<br>            inputs = tokenizer(text, return_tensors=&quot;pt&quot;, padding=True, truncation=True)<br>            with torch.no_grad():<br>                embeddings = model(**inputs).last_hidden_state.mean(dim=1).squeeze().tolist()<br>            mapped_embeddings[content_id] = embeddings<br>        mapped_document_db[id] = mapped_embeddings<br>    return mapped_document_db</pre><p>This code converts the text from documents into machine-readable numerical formats (embeddings), organizes them by document and text piece, and stores them for later use, like searching or retrieval tasks.</p><h3>Retrieving</h3><p>For retrieving the answer to the query we will be using <strong>Cosine Similarity.</strong></p><p>First, we need chunk embeddings as these embedding vectors will typically have many dimensions so we will perform array operation on them using Numpy for calculating cosine similarity. For performing array operations we will parse chunks from the database keeping track of chunk ID and document ID.</p><p>We will perform : <br> Query Processing → Cosine Similarity Calculation → Ranking Results → Return Top Results</p><pre> <br>def compute_embeddings(query, tokenizer, model):<br>    query_inputs = tokenizer(query, return_tensors=&quot;pt&quot;, padding=True, truncation=True)<br>    query_embeddings = model(**query_inputs).last_hidden_state.mean(dim=1).squeeze()<br>    query_embeddings=query_embeddings.tolist()<br>    return query_embeddings<br><br>def calculate_cosine_similarity_score(query_embeddings, chunk_embeddings):<br>        normalized_query = np.linalg.norm(query_embeddings)<br>        normalized_chunk = np.linalg.norm(chunk_embeddings)<br>        if normalized_chunk == 0 or normalized_query == 0:<br>            score == 0<br>        else:<br>            score = np.dot(chunk_embeddings, query_embeddings)/ (normalized_chunk * normalized_query)  <br>        return score    <br><br><br>def retrieve_top_k_scores(query_embeddings, mapped_document_db, top_k):<br>    scores = {}<br><br>    for doc_id, chunk_dict in mapped_document_db.items():<br>        for chunk_id, chunk_embeddings in chunk_dict.items():<br>            chunk_embeddings = np.array(chunk_embeddings) <br>            score = calculate_cosine_similarity_score(query_embeddings, chunk_embeddings)<br>            scores[(doc_id, chunk_id )] = score <br>    sorted_scores = sorted(scores.items(), key=lambda item: item[1], reverse=True)[:top_k]<br><br>    return sorted_scores        <br><br>def retrieve_top_results(sorted_scores):<br>    top_results=[]<br>    for ((doc_id, chunk_id), score) in sorted_scores:<br>        results = (doc_id, chunk_id, score)<br>        top_results.append(results)<br>    return top_results</pre><p>This function takes a query and finds the most relevant pieces of text from a database of document embeddings. It compares the query to each chunk of text in the database using <strong>cosine similarity</strong>, which measures how similar two pieces of text are based on their embeddings. After calculating similarity scores, it ranks the chunks and returns the top results, including the document IDs, chunk IDs, and their relevance scores.</p><p>For easy retrieval, we will store document information and database data in JSON files.</p><pre><br>def save_json(path, data):<br>    with open(path, &#39;w&#39;) as f:<br>        json.dump(data, f, indent=4)<br><br>def read_json(path):<br>    with open(path, &#39;r&#39;) as f:<br>        data = json.load(f)<br>    return data</pre><p>Now we can easily extract text from the <em>doc_store.json</em> file using the relevant document ID and chunk ID obtained from the retrieved <em>top_results.</em></p><p>The sample.txt file I have used can be found here:</p><h3>LLM — MISTRAL AI</h3><p>For our Large language model, we will be using the Mistral models, which offer free API key without any credit card setup, and have integrations with the language framework.</p><p>Prompt :</p><pre>&#39;&#39;&#39;You are a search engine. You will be provided with some retrieved context, as well as the user query.<br><br>    Your job is to understand the query, and answer based on the retrieved context. If you can&#39;t find the answer, you can say &quot;I dont know&quot;.<br>    Here is context:<br><br>    &lt;context&gt;<br><br>    {context}<br><br>    &lt;/context&gt;<br><br>    Question: {question} &#39;&#39;&#39;<br></pre><p>The main function will look like :</p><pre><br>def main():<br>    directory_path = &quot;documents&quot;<br>    model_name = &quot;BAAI/bge-small-en-v1.5&quot;<br>    tokenizer = AutoTokenizer.from_pretrained(model_name)<br>    model = AutoModel.from_pretrained(model_name)<br>    chunk_size = 200<br>    para_seperator=&quot; /n /n&quot;<br>    separator=&quot; &quot;<br>    top_k = 2<br>    mistralai_model= ChatMistralAI (    model=&quot;mistral-large-latest&quot;, api_key= os.environ.get(&quot;MISTRAL_API_KEY&quot;))</pre><p>In this article, we built a Retrieval Augmented Generation (RAG) system from scratch to improve a language model’s ability to answer questions using private or specific data. The process includes important steps like reading documents from a folder, breaking large texts into smaller, manageable chunks, creating embeddings (numerical representations) for these chunks, and organizing them for easy retrieval. We use cosine similarity to find the most relevant information for a query and then combine this context with an LLM, in this case, Mistral AI models, to generate more accurate and helpful responses. This entire workflow was built without using high-level libraries like Llama or LangChain, helping us understand how RAG works behind the scenes.</p><p>Github: <a href="https://github.com/adv-11/RAG_from_scratch">https://github.com/adv-11/RAG_from_scratch</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1f70425dbe7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Flow Engineering: A New Paradigm in AI Development via La]]></title>
            <link>https://medium.com/@advaitss11/understanding-flow-engineering-a-new-paradigm-in-ai-development-via-la-773feb6c6c97?source=rss-0ada2e05a420------2</link>
            <guid isPermaLink="false">https://medium.com/p/773feb6c6c97</guid>
            <category><![CDATA[langgraph]]></category>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[langchain]]></category>
            <category><![CDATA[flow-engineering]]></category>
            <dc:creator><![CDATA[Advait Shinde]]></dc:creator>
            <pubDate>Tue, 05 Nov 2024 09:51:42 GMT</pubDate>
            <atom:updated>2024-11-05T09:51:42.996Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding Flow Engineering: A New Paradigm in AI Development</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*yhEyu8IYZZVJs0tTLKW9Ow.png" /></figure><p>In the ever-evolving landscape of artificial intelligence, a new concept has emerged that promises to reshape how we approach software development: flow engineering.</p><p>This term, which has recently gained traction within the generative AI community, represents a systematic and strategic method for integrating AI-driven decision-making processes into software systems.</p><p>At its core, flow engineering aims to optimize the way AI systems, particularly those powered by large language models (LLMs), handle tasks. It goes beyond simple linear processes, introducing complex decision-making nodes where the AI can generate multiple outputs. This iterative cycle of assessment and refinement is crucial for enhancing the quality of AI-generated solutions.</p><p>One of the key challenges faced by autonomous AI agents, such as AutoGPT and Baby AGI, lies in long-term planning. These systems are designed to receive a goal, break it down into tasks, and execute those tasks. However, this approach can lead to unpredictability, as the AI may create imaginary tasks that deviate from the intended objectives. Flow engineering addresses this issue by allowing developers to define clear instructions and boundaries for the AI. Instead of letting the AI operate freely, we guide it through a structured flow, ensuring that it remains focused on the tasks we’ve outlined.</p><p>This structured approach can be likened to a state machine, where developers create the states and define the necessary steps. While the LLM can still make decisions — such as determining whether an output is ready for release or which step to take next — developers maintain control over the overall flow. This balance between developer oversight and AI flexibility is where flow engineering shines.</p><p>A practical application of flow engineering can be seen in LangGraph, a framework that bridges the gap between fully autonomous agents and deterministic chains. With LangGraph, developers can create intricate graphs composed of nodes and edges, allowing for complex logic and cycles that enhance the AI system’s capabilities. For instance, a flow might involve generating a tweet, followed by a reflection and critique process that iterates until the perfect post is crafted.</p><p>As we look to the future of AI development, it’s anticipated that a significant portion of our efforts will shift towards flow engineering. Experts predict that around 60% of our time will be dedicated to designing flows and architectures, including state machines and decision-making processes. About 35% will focus on fine-tuning models for specific tasks, while only 5% will be allocated to prompt engineering.</p><p>While flow engineering may seem abstract at first glance, its importance cannot be overstated. By adopting this new paradigm, we can build more reliable and functional AI systems that leverage the strengths of LLMs while maintaining human oversight.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*KcR4A1tdnD-6HECKoXRmWg.png" /></figure><h3>LangGraph: Motivation and Creation</h3><h4>Bridging the Gap in AI Development</h4><p>In the rapidly evolving field of artificial intelligence, the introduction of LangGraph represents a significant advancement in how we design and implement AI systems. LangGraph was created to address the challenges and limitations of existing frameworks, particularly when it comes to balancing flexibility and control in AI applications.</p><h4>The Spectrum of AI Autonomy</h4><p>To understand the motivation behind LangGraph, it’s essential to recognize the spectrum of AI autonomy. On one end, we have deterministic code — systems where developers have complete control over every aspect of the application. These systems are reliable and predictable but lack flexibility, as they are hard-coded to specific functions and flows.</p><p>On the opposite end of the spectrum are autonomous agents, which can dynamically generate tasks and execute them with minimal human intervention. While these agents offer remarkable flexibility and creativity, they often lack reliability in production environments. Projects like AutoGPT and Baby AGI illustrate this point; despite their innovative capabilities, they struggle with control and consistency, leading to unpredictable outcomes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*yRmaDjB_xTThNNsVSP2RWQ.png" /></figure><h4>The Need for a Middle Ground</h4><p>LangGraph was developed to fill the gap between deterministic systems and fully autonomous agents. It offers a structured approach that integrates large language models (LLMs) into a controlled framework. By allowing developers to define the flow while still leveraging the creative capabilities of LLMs, LangGraph enhances both flexibility and reliability.</p><p>The framework introduces concepts such as chaining, where outputs from one LLM can serve as inputs for another, and LLM routers that help determine the path an application should take. This enables the creation of complex systems that can adapt and respond intelligently while maintaining developer oversight.</p><h4>Key Features of LangGraph</h4><ol><li><strong>Controlled Flexibility</strong>: LangGraph allows developers to design flows as state machines with nodes and edges, ensuring that while LLMs can make decisions within those flows, the overall structure remains under human control. This approach mitigates the risks associated with fully autonomous systems.</li><li><strong>Enhanced Reliability</strong>: By scoping the LLM’s freedom, LangGraph increases the reliability of AI applications. Developers can implement checks and balances that prevent the system from going off-track, making it suitable for production environments.</li><li><strong>Human-in-the-Loop Capabilities</strong>: The framework supports human feedback integration, enabling continuous improvement of the AI’s performance. Developers can implement features like time-traveling to replay past actions for debugging or refinement.</li><li><strong>Readability and Maintainability</strong>: Representing AI systems as graphs makes them easier to understand, test, and monitor. This visual approach aligns with how many AI concepts are articulated in research literature, facilitating collaboration among developers.</li><li><strong>Versatility</strong>: LangGraph is designed to be flexible, allowing developers to incorporate various types of code, not just those specific to the LangChain ecosystem. This versatility ensures that developers can build the most effective solutions for their specific needs.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=773feb6c6c97" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>