<?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 Aman Anurag on Medium]]></title>
        <description><![CDATA[Stories by Aman Anurag on Medium]]></description>
        <link>https://medium.com/@amananurag?source=rss-bed51e247430------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*WMZ9aPqyUl-fmE1N.</url>
            <title>Stories by Aman Anurag on Medium</title>
            <link>https://medium.com/@amananurag?source=rss-bed51e247430------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 11:16:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amananurag/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[Harness, Graph, and Loop Engineering -How to Evolve From Prompts and Context]]></title>
            <link>https://medium.com/@amananurag/harness-graph-and-loop-engineering-how-to-evolve-from-prompts-and-context-b985f6af2a45?source=rss-bed51e247430------2</link>
            <guid isPermaLink="false">https://medium.com/p/b985f6af2a45</guid>
            <dc:creator><![CDATA[Aman Anurag]]></dc:creator>
            <pubDate>Tue, 27 Oct 2026 16:12:38 GMT</pubDate>
            <atom:updated>2026-10-28T11:51:53.170Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UgmZPWKzWgYILesMsv8thA.png" /></figure><p>The conversation around AI agents is evolving.</p><p>We started with prompt engineering: how do we get better outputs from an LLM?</p><p>But building production-grade AI agents requires much more than writing a good system prompt. We need to engineer the context the model sees, the runtime around it, the loops that drive execution, and the graphs that orchestrate complex workflows.</p><p>I think about this through five interconnected disciplines.</p><p><strong>1. Prompt Engineering — Define the behavior</strong></p><p>System prompts establish the model’s role, instructions, constraints, and expected output. Few-shot examples and structured output schemas can make responses more consistent.</p><p>But a better prompt alone cannot solve missing context, unreliable tools, or uncontrolled execution.</p><p><strong>2. Context Engineering — Control what the model knows</strong></p><p>Context is a finite resource. Every tool definition, conversation message, retrieved document, and previous observation competes for space and attention.</p><p>Context engineering determines what enters the context window, what gets retrieved or reranked, what should be summarized, and what should be discarded.</p><p>The objective isn’t to provide the most context. It’s to provide the most relevant context at the right time.</p><p><strong>3. Harness Engineering — Build the runtime around the model</strong></p><p>The model is only one component of an agent system.</p><p>The harness connects the model to tools, file systems, sandboxes, memory, verification mechanisms, guardrails, and observability.</p><p>It manages tool execution, state, errors, retries, permissions, and feedback. It helps make a probabilistic model more useful within a controlled and verifiable system.</p><p><strong>4. Loop Engineering — Make execution goal-directed</strong></p><p>An agent often needs to do more than respond once. It must act, observe the result, evaluate progress, and decide what to do next.</p><p>Plan → Act → Observe → Evaluate → Repeat.</p><p>The engineering challenge is deciding when to continue, when to retry, when to stop, and when to involve a human. Budgets, timeouts, stopping conditions, and failure detection are essential to reliable autonomy.</p><p><strong>5. Graph Engineering — Orchestrate complex workflows</strong></p><p>When a task involves multiple agents, tools, deterministic functions, and human approvals, we need to model how work flows between them.</p><p>A graph makes nodes and transitions explicit. An orchestrator might route work to research, code, or data-processing agents, handle conditional branches, and pause for human approval.</p><p>A graph is not necessarily multi-agent, and an agent loop does not necessarily require a graph framework. A graph can represent a single agent’s workflow, while a simple loop can be sufficient for many tasks.</p><p>LangGraph and similar frameworks are implementations of these broader orchestration concepts, not the concepts themselves.</p><h3>The bigger picture</h3><p>These five disciplines are not sequential maturity stages or mutually exclusive alternatives. They address different parts of the same system:</p><ul><li>Prompt engineering defines intended behavior.</li><li>Context engineering selects relevant information.</li><li>Harness engineering provides controlled execution.</li><li>Loop engineering drives repeated action toward a goal.</li><li>Graph engineering structures workflows and transitions.</li></ul><p>The real shift is from <strong>engineering individual model interactions to engineering the complete system around the model.</strong></p><p>That is where the difficult — and interesting — work of building production-grade AI agents begins.</p><p>#AI #AgenticAI #LLM #AIEngineering #SoftwareArchitecture</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b985f6af2a45" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Attention Really Works in a Transformer]]></title>
            <link>https://medium.com/@amananurag/how-attention-really-works-in-a-transformer-ed45f7cc34f3?source=rss-bed51e247430------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed45f7cc34f3</guid>
            <dc:creator><![CDATA[Aman Anurag]]></dc:creator>
            <pubDate>Fri, 12 Sep 2025 10:46:50 GMT</pubDate>
            <atom:updated>2025-09-12T10:46:50.733Z</atom:updated>
            <content:encoded><![CDATA[<p>Transformers power today’s large language models (LLMs), from GPT to BERT. Their magic lies in a simple but powerful mechanism: <strong>attention</strong>. In this article, let’s break down step by step how attention works inside a Transformer, and why it makes tokens “talk to each other” so effectively.</p><h3>Step 1: Embeddings and Positional Encodings</h3><p>Every input token (a word or sub-word) is first mapped into a <strong>vector embedding</strong>. For example, the word <em>“tower”</em> might be mapped into a 768-dimensional vector.</p><p>But embeddings alone don’t know anything about <strong>order</strong> — “tower stands tall” and “tall stands tower” would look the same. To fix this, Transformers add <strong>positional embeddings</strong>, which inject information about a token’s position in the sequence.</p><p>So the model’s first input is:</p><pre>Input = Word Embedding + Positional Embedding</pre><h3>Step 2: Embeddings Have No Context</h3><p>At this stage, embeddings only capture a token’s “dictionary meaning.” They don’t know the context.</p><p>For instance, in</p><blockquote><em>“The miniature tower looked fragile.”<br> the meaning of </em>“tower”<em> is very different from in<br> “The Eiffel Tower is iconic.”</em></blockquote><p>To make embeddings context-aware, Transformers use <strong>self-attention</strong>.</p><h3>Step 3: Self-Attention — Tokens Talk to Each Other</h3><p>Self-attention lets each token decide <strong>how much to pay attention</strong> to every other token in the sequence.</p><p>Here’s how it works mathematically:</p><ol><li>Each input embedding is projected into three different vectors: <strong>Query (Q)</strong>, <strong>Key (K)</strong>, and <strong>Value (V)</strong>.</li><li>If the embedding size is 768 and the model has 12 heads, each head works on 64 dimensions. So Q, K, V have shape: <strong>768 × 64</strong></li><li>These projection matrices are learned weights, just like any other weights in a neural network.</li><li>We compute a <strong>score</strong> between tokens by multiplying Q × Kᵀ. This tells us how much one token should attend to another.</li><li>The scores are normalized with <strong>softmax</strong>, so they sum to 1.</li><li>These attention weights are applied to the <strong>V vectors</strong>, creating a weighted mix of contextual information.</li></ol><p>This is how <em>“tower”</em> can shift its meaning depending on whether the words around it are <em>“Eiffel”</em> or <em>“miniature.”</em></p><h3>Step 4: Multi-Head Attention</h3><p>Why not just one attention mechanism? Because different relationships matter: syntax, long-distance dependencies, word sense disambiguation, etc.</p><p>So instead of a single head, we have <strong>multiple heads</strong> (e.g., 12). Each head looks at the sequence in a different way. Their outputs are then concatenated and linearly combined.</p><p>This is what gives Transformers such rich contextual understanding.</p><h3>Step 5: MLP and Normalization</h3><p>After attention, the output goes through two more essential blocks:</p><ul><li><strong>Feed-Forward Network (MLP)</strong><br> Each token’s vector is passed through a small neural network (usually two linear layers with a non-linear activation like GELU). This helps the model capture more complex patterns beyond pairwise attention.</li><li><strong>Layer Normalization (Norm)</strong><br> Normalization ensures stable training and smooth flow of gradients. It rescales activations so no dimension dominates, improving convergence.</li></ul><p>Together, the flow looks like this:</p><pre>Embedding + Position → Self-Attention → Multi-Head → Add &amp; Norm → MLP → Add &amp; Norm</pre><h3>Step 6: Final Prediction</h3><p>At the top of the Transformer stack, the final vector for each token is taken. For language modeling tasks, the model applies a <strong>softmax over the vocabulary</strong> to predict the next token.</p><p>So in a sentence like:</p><blockquote><em>“The Eiffel …”</em></blockquote><p>the model uses the contextualized representation of <em>“Eiffel”</em> to predict <em>“Tower”</em> with high probability.</p><h3>Why This Works</h3><p>The brilliance of self-attention is that <strong>tokens can talk to each other across the entire sequence</strong>. Unlike RNNs, which move step by step, Transformers allow any word to attend to any other word — whether it’s right next to it or 100 tokens away.</p><p>This is why modern LLMs can generate coherent essays, answer questions, or even write code.</p><p>✅ That’s the flow:</p><ul><li>Embedding + Position</li><li>Self-Attention (Q, K, V, Softmax, V-mixing)</li><li>Multi-Head</li><li>MLP + Normalization</li><li>Final Softmax</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed45f7cc34f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Really Matters When Building a Transformer-Based LLM]]></title>
            <link>https://medium.com/@amananurag/what-really-matters-when-building-a-transformer-based-llm-2c34561ce18a?source=rss-bed51e247430------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c34561ce18a</guid>
            <dc:creator><![CDATA[Aman Anurag]]></dc:creator>
            <pubDate>Thu, 07 Aug 2025 15:39:11 GMT</pubDate>
            <atom:updated>2025-08-07T15:46:35.191Z</atom:updated>
            <content:encoded><![CDATA[<p>The rise of Large Language Models (LLMs) like GPT-4, Gemini, Claude, and others has reshaped AI development, but beneath the hype lies a carefully engineered system where architecture, data, training techniques, and evaluation play critical roles. Whether you’re building your own model or studying how these systems work, here’s a comprehensive breakdown of the essential components involved in training an LLM based on the Transformer architecture.</p><h3>🌐 Language Modeling: Predicting the Next Token</h3><p>At the heart of an LLM lies a simple idea: <strong>language modeling</strong> — estimating the probability distribution over a sequence of tokens. This allows us to sample the most likely next token and generate coherent text step by step.</p><p>Autoregressive models like GPT implement this via the <strong>chain rule of probability</strong>, where each token is predicted given all previous ones. During training, this typically involves a <strong>for-loop structure</strong> over the sequence.</p><h3>🔤 Tokenization: Preparing Text for the Model</h3><p>Before anything hits the neural net, text must be converted to tokens. But not just any tokens:</p><h3>Why Subword Tokenization?</h3><ul><li>Natural languages like <strong>Thai</strong> don’t use spaces reliably.</li><li>Misspellings, rare words, or code require flexible tokenization.</li></ul><h3>Tokenization Process</h3><ul><li><strong>Pretokenizer</strong>: separates punctuation, whitespace, etc., into standalone tokens.</li><li><strong>Subword Tokenization</strong> (usually via 3–4 character units).</li><li><strong>Byte Pair Encoding (BPE)</strong>: starts with characters as tokens and repeatedly merges the most frequent adjacent pairs.</li></ul><p>This results in a manageable vocabulary size and helps the model handle diverse inputs — from typos to code snippets to math expressions.</p><h3>🔁 From Tokens to Predictions: The Forward Pass</h3><p>Once tokenized, inputs go through:</p><ul><li><strong>Word embeddings</strong> (dense vectors).</li><li><strong>Positional embeddings</strong> (capture order/context).</li><li><strong>Transformer blocks</strong> (self-attention layers, feed-forward networks).</li></ul><p>The output is a <strong>probability distribution</strong> over the vocabulary for the next token. During training, we calculate <strong>cross-entropy loss</strong> between predicted and actual tokens to guide optimization.</p><p>At inference time:</p><ul><li>We <strong>sample</strong> from this probability distribution (or use techniques like greedy decoding or beam search).</li><li>We <strong>detokenize</strong> the outputs to form human-readable text.</li></ul><h3>📉 Loss and Evaluation</h3><h3>Training Loss</h3><ul><li><strong>Cross-entropy loss</strong> pushes the model to assign higher probability to the correct token and penalize others.</li></ul><h3>Evaluation Metrics</h3><ul><li><strong>Validation loss</strong> gives a sense of generalization.</li><li><strong>Perplexity</strong> = exp(cross-entropy loss); lower is better.</li><li>But beware: <strong>perplexity depends on tokenizer size</strong></li></ul><h3>Benchmarks</h3><ul><li><strong>HELM</strong> (Holistic Evaluation of Language Models)</li><li><strong>MMLU</strong> (Massive Multitask Language Understanding)</li><li><strong>Hugging Face Open LLM Leaderboard</strong></li></ul><h3>Pitfall: Data Contamination</h3><p>Using benchmark test data in training can cause <strong>train-test contamination</strong>, reducing the reliability of benchmark scores.</p><h3>📦 Data: The Foundation of LLM Quality</h3><p>High-quality models begin with high-quality datasets. Here’s how large-scale corpora are typically created:</p><h3>Data Pipeline:</h3><ol><li><strong>Crawl</strong> the web (e.g., Common Crawl).</li><li><strong>Parse</strong> HTML and extract clean text.</li><li><strong>Filter</strong> for unwanted content:</li></ol><ul><li>PII (Personally Identifiable Information)</li><li>Blacklisted domains</li><li>Spam, porn, hate speech</li></ul><p>4. <strong>Deduplication</strong>:</p><ul><li>Remove boilerplate content (e.g., headers/footers).</li><li>Identify duplicate documents.</li></ul><p>5. <strong>Filtering</strong>:</p><ul><li><strong>Heuristic-based</strong> (too small/big sites).</li><li><strong>Model-based</strong> (e.g., “Would Wikipedia cite this page?”).</li></ul><h3>Data Mixing:</h3><ul><li>Domains like <strong>code</strong>, <strong>math</strong>, <strong>dialogue</strong>, and <strong>science</strong> are often upweighted.</li><li>Training on <strong>code</strong>, for example, improves <strong>reasoning and logic</strong> performance.</li></ul><h3>🧠 Architecture: The Transformer Backbone</h3><p>The Transformer architecture remains dominant for LLMs. Variations in model design can include:</p><ul><li>Decoder-only (e.g., GPT)</li><li>Encoder-decoder (e.g., T5, FLAN-T5)</li><li>Multi-modal (e.g., Gemini, GPT-4o)</li></ul><p>Most training involves stacking <strong>self-attention layers</strong> and <strong>MLPs</strong>, with <strong>residual connections</strong> and <strong>layer normalization</strong> throughout.</p><h3>📊 Scaling Laws: Size Matters, But So Does Data</h3><h3>The Chinchilla Insight:</h3><ul><li>For a given compute budget (FLOPs), <strong>smaller models trained on more data</strong> outperform <strong>larger models trained on less</strong>.</li></ul><p>Scaling laws help determine:</p><ul><li>Ideal model size vs. dataset size.</li><li>Expected performance based on current loss curves.</li><li>Tradeoffs between compute, model size, and dataset quality.</li></ul><h3>🧮 Systems &amp; Hardware: The Real Cost</h3><p>LLMs require:</p><ul><li><strong>Massive compute</strong> (TPUs, GPUs, custom accelerators).</li><li><strong>Memory optimization</strong> (activation checkpointing, mixed precision).</li><li><strong>Efficient data pipelines</strong> (streaming from petabyte-scale storage).</li></ul><p>Hardware directly affects training speed, batch size, and ultimately how large a model you can afford to train.</p><p>LLM training is not just about throwing more data and compute at the problem. It’s about making smart choices across architecture, data quality, evaluation methods, and system design. With careful engineering and informed tradeoffs, we can continue pushing the boundaries of what language models can do.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c34561ce18a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[✨ Seq2Seq & Attention — A Mental Model You Shouldn’t Miss ]]></title>
            <link>https://medium.com/@amananurag/seq2seq-attention-a-mental-model-you-shouldnt-miss-3fe44bee6b35?source=rss-bed51e247430------2</link>
            <guid isPermaLink="false">https://medium.com/p/3fe44bee6b35</guid>
            <dc:creator><![CDATA[Aman Anurag]]></dc:creator>
            <pubDate>Thu, 31 Jul 2025 09:21:20 GMT</pubDate>
            <atom:updated>2025-07-31T10:02:54.163Z</atom:updated>
            <content:encoded><![CDATA[<h3>✨ Seq2Seq &amp; Attention — A Mental Model You Shouldn’t Miss 🧠</h3><p>Translation. Summarization. Chatbots.<br> All these tasks share one powerful idea: <strong>converting one sequence into another</strong>.<br> That’s the idea behind <strong>Seq2Seq</strong> — and with <strong>attention</strong>, it becomes even more powerful.<br> In this article, let’s build a strong mental model for how these architectures work — and what happens <strong>under the hood</strong>.</p><h3>🔁 Seq2Seq — The Classic Architecture</h3><p>A <strong>Sequence-to-Sequence</strong> (Seq2Seq) model takes an input sequence (like an English sentence) and transforms it into an output sequence (like the French translation).<br> At its core, it’s made of two main components:</p><p>🧱 <strong>Encoder</strong> → 🧠 <strong>Context Vector</strong> → 🧱 <strong>Decoder</strong></p><h3>🧠 Step-by-Step Mental Model (No Attention Yet)</h3><h3>1. 🔤 Input is Tokenized</h3><p>A sentence like:</p><blockquote><em>“How are you?”</em></blockquote><p>gets broken into token:</p><pre>[&quot;how&quot;, &quot;are&quot;, &quot;you&quot;, &quot;?&quot;]]</pre><p>These are mapped to vector representations (via an embedding layer).</p><h3>2. 🧱 The Encoder (RNN/LSTM)</h3><p>The encoder reads tokens one by one using a <strong>Recurrent Neural Network</strong></p><pre>hₜ = tanh(Wₓ·xₜ + Wₕ·hₜ₋₁ + b)</pre><p>Here:</p><ul><li>xₜ is the input embedding at time t</li><li>hₜ₋₁ is the hidden state from the previous step</li><li>tanh is the activation function, squashing output between -1 and +1</li></ul><p>✅ <strong>This update happens at every step in the encoder</strong>, transforming each</p><p><strong>Last hidden state </strong>(say, h_final) is saved as the <strong>context vector</strong>.</p><p>🧠 <strong>This vector is a compressed memory of the entire input.</strong></p><h3>3. 🧠 The Context Vector</h3><ul><li>The encoder passes this <strong>single vector</strong> to the decoder</li><li>Acts like the “summary” of the sentence</li><li>Limitation: It’s <strong>fixed size</strong> even if input is long</li></ul><h3>4. 🧾 Decoder — Predicting Words</h3><p>Takes the context vector + a special start token &lt;sos&gt; to begin. At each step, it:</p><ol><li>Predicts the next word (via softmax over vocab)</li><li>Feeds that word as input for the next time step</li></ol><p>It also uses:</p><pre>hₜ = tanh(Wₓ·xₜ + Wₕ·hₜ₋₁ + b)</pre><ul><li>✅ <strong>Yes, the decoder also uses this RNN-style hidden state update</strong> — <br> but here, xₜ is the <strong>embedding of the previously generated word</strong> (e.g., &lt;sos&gt;, then “Je”, then “t’aime”…).<br> The hidden state allows it to <strong>build fluency</strong> and remember past outputs.</li><li>Decoder also has it’s hidden state which is context vector (hₜ₋₁)</li><li>⏳ One token at a time — until it hits an &lt;eos&gt; (end of sentence).</li></ul><h3>🛑 Limitation of Classic Seq2Seq</h3><ul><li><strong>Bottleneck</strong>: One vector (context) must represent entire input</li><li>For long/complex inputs — much is forgotten</li><li>Decoder cannot look back at specific input tokens</li></ul><h3>✨ 5. Enter Attention Mechanism</h3><p>Attention fixes this by allowing the decoder to <strong>look at all encoder hidden states</strong> at every decoding step — not just the final one.</p><p>Instead of compressing everything into one vector, the model now dynamically decides <strong>which parts of the input to focus on</strong> when generating each output token.</p><h3>✅ Key Points:</h3><ul><li>✅ <strong>Encoder produces a sequence of hidden states</strong>: h1,h2,…,hn</li><li>✅ <strong>Decoder receives:</strong></li><li>The full set of encoder hidden states H — these are the <strong>Keys (K)</strong> and <strong>Values (V)</strong></li><li>The <strong>initial hidden state of the decoder s0</strong> is set to the <strong>final hidden state of the encoder hn</strong> — this becomes the <strong>Query (Q)</strong> at the first step</li><li>✅ At each decoding step, attention computes a <strong>context vector ctc​</strong> using Q,K,V</li><li>✅ This ctc is then used to update the decoder hidden state and generate the output token</li></ul><h3>✴️ Step 2: Attention Score Calculation</h3><p>We compute a <strong>score</strong> between the decoder’s current query and each key:</p><p>score =Q⋅K</p><p>This gives us a raw alignment score for each input token.</p><p>This score vector is passed through softmax function to generate attention scores for each token which is then multiplied with V vector to generate the context which is passed into decoder along with output token , hidden state to generate next token in seq.</p><p>The power of attention lies in letting the model learn <strong>where to look</strong> instead of forcing it to squeeze the entire input into a single thought.</p><p>🧭 Decoder doesn’t guess blindly — it <strong>scans the full input</strong> with each word it generates.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3fe44bee6b35" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TF-IDF Demystified: A Mental Model You Shouldn’t Miss]]></title>
            <link>https://medium.com/@amananurag/tf-idf-demystified-a-mental-model-you-shouldnt-miss-80411340e67e?source=rss-bed51e247430------2</link>
            <guid isPermaLink="false">https://medium.com/p/80411340e67e</guid>
            <dc:creator><![CDATA[Aman Anurag]]></dc:creator>
            <pubDate>Wed, 30 Jul 2025 11:10:00 GMT</pubDate>
            <atom:updated>2025-07-30T11:10:00.946Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve come to realize that simple, reliable algorithms are often the unsung heroes behind systems we use every day. TF-IDF — short for <strong>Term Frequency–Inverse Document Frequency</strong> — is one of them.</p><p>TF-IDF continues to silently power parts of systems like search engines, document stores, and even recommendation engines at scale.</p><h3>Imagine This: You’re Building a Cricket Recommendation Engine</h3><p>Say you’re Netflix, but instead of movies, you recommend cricket articles, podcasts, or video clips.</p><p>You’ve got:</p><ul><li>Thousands of cricket-related documents (articles, transcripts, subtitles)</li><li>A user searching: <em>“Rahul Dravid centuries in Australia”</em></li></ul><p>How do you find and rank the most relevant content for this query? TF-IDF is one of the earliest — and surprisingly effective — techniques used for this.</p><h3>Step 1: Tokenization — But Not the NLP Kind You Think</h3><p>In TF-IDF, tokenization is about <strong>splitting text into individual units (words)</strong> to analyze frequency.</p><p>🧱 For example:<br> <em>“Rahul Dravid hit a century in Adelaide”</em> →<br> Tokens: [&quot;Rahul&quot;, &quot;Dravid&quot;, &quot;hit&quot;, &quot;a&quot;, &quot;century&quot;, &quot;in&quot;, &quot;Adelaide&quot;]</p><p>TF-IDF just wants bag-of-words simplicity: it doesn’t care about grammar or context — only counts.</p><h3>Step 2: Term Frequency (TF)</h3><p>TF measures <strong>how important a word is within a single document</strong>.</p><p>If “century” appears 3 times in a 100-word document, its TF is 3/100 = 0.03.</p><p>But TF alone can be misleading. “The” or “in” also appear a lot. So we need a way to <strong>penalize common words across all documents</strong>.</p><h3>Step 3: Inverse Document Frequency (IDF)</h3><p>This part kicks in to answer:<br> <em>“How rare or unique is this word across the entire document collection?”</em></p><p>We take the total number of documents N and divide it by the number of documents that contain the word n. Then take the log:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*8civJFx7OMnHYdc6djj9DA.png" /></figure><p>The 1+ is a smoothing term — to avoid division by zero for super rare terms.</p><p>So:</p><ul><li>Words like “century” or “Adelaide” get <strong>high IDF</strong> (less common, more signal)</li><li>Words like “the”, “in”, “was” get <strong>low IDF</strong> (ubiquitous, low signal)</li></ul><h3>Step 4: TF × IDF = Final Score</h3><p>Multiply the two:</p><p>TF-IDF=TF×IDF</p><p>Now each word in each document has a score that captures <strong>its importance within the document</strong>, and <strong>its uniqueness across the corpus</strong>.</p><h3>Visualizing the TF-IDF Matrix</h3><p>Let’s say you have:</p><ul><li>3 documents: Match report, Interview, Stats page</li><li>10,000 unique words across all</li></ul><p>This gives you a <strong>Document-Term Matrix</strong> of size:</p><p>Documents×Vocabulary=3×10,000</p><p>Each cell stores the TF-IDF score of a word in that document.</p><p>Here’s the catch: most words don’t appear in most documents. So this matrix is mostly zeros — i.e., <strong>sparse</strong>.</p><p>That’s why TF-IDF vectors are <strong>sparse vectors</strong>. They only store positions where the word actually appears, saving memory and computation.</p><h3>How is this Used in Recommendation?</h3><p>Back to our cricket engine. When a user types a query like:</p><blockquote>“Rohit Sharma’s best innings”</blockquote><ol><li>The query is treated like a <strong>tiny document</strong>.</li><li>Its TF-IDF vector is computed.</li><li>You compare this vector with all document vectors using <strong>cosine similarity</strong>.</li><li>Rank the results — closer the angle, higher the relevance.</li></ol><p>No training, no neural nets — just smart math and vector space intuition.</p><h3>Final Thought</h3><p>As an engineer, once you internalize this mental model — that every document is just a sparse vector of word significance — you’ll start seeing text through the lens of math. TF-IDF might be old-school, but it’s fast, interpretable, and still surprisingly powerful for building search or recommendation systems.</p><p>And if someone throws “cosine similarity” at you, just smile — you already get the angle.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80411340e67e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Neural Networks = Computational Graphs: A Mental Model You Shouldn’t Miss]]></title>
            <link>https://medium.com/@amananurag/neural-networks-computational-graphs-a-mental-model-you-shouldnt-miss-07a32b7b3a14?source=rss-bed51e247430------2</link>
            <guid isPermaLink="false">https://medium.com/p/07a32b7b3a14</guid>
            <dc:creator><![CDATA[Aman Anurag]]></dc:creator>
            <pubDate>Thu, 24 Jul 2025 05:29:52 GMT</pubDate>
            <atom:updated>2025-07-24T05:42:23.357Z</atom:updated>
            <cc:license>https://creativecommons.org/publicdomain/mark/1.0/</cc:license>
            <content:encoded><![CDATA[<p>🚀 <strong>Neural Networks = Computational Graphs: A Mental Model You Shouldn’t Miss</strong></p><p>Have you ever visualized a <strong>neural network as a computational graph</strong>? 🤖<br>Let me break this down from a first-principles perspective, the way it truly clicks.</p><h3>🧠 What is a Computational Graph?</h3><p>A <strong>computational graph</strong> is a <em>directed graph</em> that depicts the <strong>sequence of operations</strong> inside a neural network. Think of it as a blueprint where:</p><ul><li><strong>Nodes = operations or variables (like tensors, activations)</strong></li><li><strong>Edges = flow of data (values passed between operations)</strong></li></ul><p>This graph helps you <em>track the flow of computation</em>, both for inference (forward pass) and learning (back propagation).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1jb57CMJUh4v8IsqY51aQg.png" /></figure><h3>🔢 Tensors &amp; Activation Functions: The Two Core Entities</h3><p><strong>Tensors</strong> are the backbone of data in deep learning.</p><ul><li>They’re generalised forms of vectors and matrices.</li><li>Enable batch processing on GPUs.</li><li>Can represent a wide variety of inputs — images, audio, text, video.</li></ul><p><strong>Activation Functions</strong> introduce <strong>non-linearity</strong> to help networks learn complex patterns.<br> Examples: ReLU, Sigmoid, Tanh, Softmax.</p><h3>⚙️ What Happens During Forward Pass?</h3><p>Let’s say your input is a <strong>128-dimensional embedding</strong> (common in NLP tasks after tokenisation):</p><ul><li>You need <strong>128 input nodes</strong> — each receives one scalar from the embedding vector.</li><li>These inputs are <strong>multiplied by weights</strong> (which sit on the edges).</li><li>A <strong>bias</strong> term is added (we’ll discuss why below).</li><li>The result is passed through an <strong>activation function</strong>, and forwarded to the next layer.</li></ul><p>This continues until we get the final prediction at the output layer.</p><h3>📉 Back propagation = Learning from Mistakes</h3><p>The network compares its prediction to the ground truth → computes <strong>error</strong> using a loss function.</p><p>Then comes the <strong>backward pass</strong>, where:</p><ul><li><strong>Gradients</strong> of the loss w.r.t. each weight are calculated via <strong>chain rule</strong> on the computational graph.</li><li>These gradients are used to <strong>update weights</strong> using optimisation algorithms like SGD, Adam, etc.</li><li>This helps the model <em>reduce error</em> over time and generalise better.</li></ul><h3>❓Why Do We Use Bias?</h3><p>A common misconception: “Bias prevents overfitting.”</p><p>🔍 In reality:</p><ul><li><strong>Bias allows shifting the activation curve</strong> (like moving a sigmoid left/right), giving the neuron more flexibility. It is able to identify patterns in the data and works well with unseen data, else it will momorize training data and would be great on it, but not so good at unseen data.</li><li>It helps <strong>fit the data better</strong>, especially when input is zero or constant.</li><li>Overfitting is more about model capacity and regularisation, not bias directly.</li></ul><h3>💡 NLP Example: Tokens, Embeddings &amp; Input Nodes</h3><p>In NLP:</p><ul><li>Input text is tokenised → converted into tokens or subwords.</li><li>Each token gets converted into an <strong>embedding vector</strong> (say, 128-dim).</li><li>The model’s input layer must accept inputs of shape (128,).</li></ul><p>If your model expects 128 features and you pass 256, it will <strong>throw a shape mismatch error</strong>. Always match your tensor dimensions with model architecture.</p><h3>🏁 Final Thoughts</h3><p>👉 <strong>Neural networks are not magic.</strong></p><p>They’re structured mathematical functions represented as <strong>graphs</strong>, composed of simple building blocks: <strong>tensors, weights, activations</strong>.</p><p>Understanding them as computational graphs helps demystify deep learning and gives you the foundation to go from beginner to pro.</p><p>#MachineLearning #NeuralNetworks #DeepLearning #NLP #ComputationalGraph #AI #TensorFlow #PyTorch #LinkedInLearning #LearningOutLoud</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=07a32b7b3a14" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An intro for the ‘Docker Container’]]></title>
            <link>https://medium.com/@amananurag/an-intro-for-the-docker-container-78ea09932b09?source=rss-bed51e247430------2</link>
            <guid isPermaLink="false">https://medium.com/p/78ea09932b09</guid>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Aman Anurag]]></dc:creator>
            <pubDate>Fri, 08 Nov 2019 04:37:37 GMT</pubDate>
            <atom:updated>2019-11-08T04:37:37.429Z</atom:updated>
            <content:encoded><![CDATA[<p>phrase: “It works on my machine!”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZNZjIdW0K0E_998B.jpeg" /><figcaption>Docker Container</figcaption></figure><p>A container to the host is just a process and to itself is a super power machine. Docker is one of the most popular form of containerization method used in Industry. A container runs on bare metal or on Host OS .</p><p>A container has much faster performance than a VM. A container can be spinned up within seconds while it takes VM to much time to boot up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aWEWoJJZzmlzsQxI.png" /></figure><p>As the above image shows, we not only ship an application but we also ship application dependency with the container.</p><p>Container is made from an image, which lists the dependency that has to be shipped with the application. A single image can be used my multiple containers, each having a writable layer at the top which is deleted when the container is deleted. An image should be lightweight. Image is made up from docker-file.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78ea09932b09" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Container Component in Angular & why should we use one]]></title>
            <link>https://medium.com/@amananurag/container-component-in-angular-why-should-we-use-one-addc0bd9caf2?source=rss-bed51e247430------2</link>
            <guid isPermaLink="false">https://medium.com/p/addc0bd9caf2</guid>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Aman Anurag]]></dc:creator>
            <pubDate>Tue, 11 Jun 2019 16:26:20 GMT</pubDate>
            <atom:updated>2019-06-11T16:26:20.199Z</atom:updated>
            <content:encoded><![CDATA[<p>Container Component in Angular &amp; why should we use one</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-96b9LHxLYjS-Iuefx6V5Q.jpeg" /><figcaption>Angular Container</figcaption></figure><p>The container component contains the state of the component and has only child template and bindings. They themselves should have zero presentational content.</p><p>It’s important to separate the application state from presentation layer.<br>Container components sit at the boundary of the presentational layer and integrate our UI with the application state.</p><p>Container components address the issue of bucket brigading events and properties through several layers of the component tree — a phenomenon known as <a href="https://blog.kentcdodds.com/prop-drilling-bb62e02cb691"><em>prop drilling</em> in the React community</a>.</p><p><strong>Data flows down from a container component:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*UaAvdHs1OqgTl3yiyF2f1A.gif" /></figure><p><strong>Events flow up to the container component:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*Tbkk6AS1RapTZkOZ6WFYpw.gif" /></figure><h3>Related Articles</h3><p>Read the introductory article “<a href="https://blog.angularindepth.com/model-view-presenter-with-angular-3a4dbffe49bb">Model-View-Presenter with Angular</a>”:</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=addc0bd9caf2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular Library]]></title>
            <link>https://medium.com/@amananurag/angular-library-bf54b634422a?source=rss-bed51e247430------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf54b634422a</guid>
            <category><![CDATA[angular-cli]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[backbase]]></category>
            <dc:creator><![CDATA[Aman Anurag]]></dc:creator>
            <pubDate>Tue, 23 Apr 2019 03:49:43 GMT</pubDate>
            <atom:updated>2019-04-23T03:49:43.735Z</atom:updated>
            <content:encoded><![CDATA[<p>Get started with Angular Library and Application</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1iy27EzUwkvWBEyarUy-YQ.jpeg" /></figure><p>Working on multiple projects at the same time, with very similar functionality has often resulted in copy-paste of the feature from one project to another.However with the concept of Angular library we can have these functionality added and published to npm package and used across the projects via npm dependency in root package.json file.</p><p>In this article I will create a library that will be used in other projects as npm dependency</p><pre><strong>npm install -g @angular/cli<br>ng new</strong> ng-library</pre><pre><strong><br>cd </strong>ng-library<br>ng g lib shared-lib</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*n_k3udS6UvIN7Fj6PHlCnw.png" /></figure><p>public-api.ts file is created where we can export the contents of the library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*ACu81KKGepHanbQ0wU7dbw.png" /></figure><pre><strong><br>ng build</strong> shared-lib</pre><p>This will create a dist folder inside the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P6u2DN7Gz5vWbZ4PCQGFIQ.png" /></figure><pre>shared-lib&gt; npm pack</pre><p>This command will pack library to tarball named shared-lib-0.0.1.tgz</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*wzykz-aG22sv1Dez2XMTGw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*tC1J8tC71EhHGz0bzG4y1Q.png" /></figure><p>Using the library in other project is very easy , we can add it into package.json file</p><pre>&quot;lib-shared&quot; : &quot;../libraries/dist/lib/shared/shared-lib-0.0.1.tgz&quot;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf54b634422a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Love letter to Vuejs]]></title>
            <link>https://medium.com/@amananurag/love-letter-to-vuejs-2c689519fd36?source=rss-bed51e247430------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c689519fd36</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Aman Anurag]]></dc:creator>
            <pubDate>Wed, 20 Feb 2019 04:09:26 GMT</pubDate>
            <atom:updated>2019-02-20T04:37:05.742Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*qx-JkTg3APQv75-XEVmzHA.png" /></figure><p>Web application development has changed drastically in last half of the decade with all the new frameworks like Angular, React and many others. Primary objectives of these framework was to make development easier , faster and maintainable. Which has been achieved. However complicated concept involved in Angular or a React framework is making it steep learning curve for the developers community.</p><p>Vuejs with it’s simplistic approach just stands out.</p><p>It’s lean, it’s elegant, it’s fast, it’s extensible, it’s lightweight, it’s made for progressive web app development which means it is incrementally adoptable.And on top of that it has a very less learning curve.</p><p>Vuejs has taken best out of Angular and React world and given developers community reason to love it.</p><p>Vuejs works on the principle of collation; single file component file known as *.vue. This file will have aggregated content for template, styles and scripts which is parsed, process and rendered over the browser using vue internal engines and methodology.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*CXFi5itnM1w-zFAInbOkTA.jpeg" /></figure><p>Single file component is one of the key take away of Vuejs features.</p><p>Vue compiler undertakes following process to run vue based components on the browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*LrWPpoyRwQOFtpxqmbQSgg.png" /></figure><p><strong><em>Parsing stage:</em></strong></p><p>Vuejs uses vue-loader to load the parsed and codegen template over the browser.</p><p>Internally it pipes &lt;template&gt; to a template-loader-compiler which converts the template into Abstract syntax tree</p><p><a href="https://en.wikipedia.org/wiki/Abstract_syntax_tree">Abstract Syntax Tree</a></p><p>Vue-template-compiler is used to convert this Abstract Syntax tree into a Render function.</p><p>We can use following website to check how HTML template is parsed and changed into a render function.</p><p><a href="https://template-explorer.vuejs.org/"><em>https://template-explorer.vuejs.org</em></a></p><p>This bootstraps main component template in main.ts file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*i3NiOe8hp0h5Yz-6017xyQ.png" /></figure><p>The render function is responsible for creating a virtual DOM.</p><blockquote>The virtual DOM is an in-memory representation of the real DOM elements generated by vue components before any changes are made to the page.</blockquote><p>Each component will have their own compiler and a render function. If changes are made to any of the component it will re-create a render function which in turn will generate a virtual DOM. Vue will compare the previously generated virtual DOM from the memory to this new one and only the changed view will be re-render again using Vnode.</p><p>Vue is compiling templates before rendering it over the browser and this has made it very performant. It has separated the rendering logic from the browser.</p><p>Similar to &lt;template&gt; , tags &lt;style&gt; and &lt;script&gt; also are piped to respective compiler ( pre/post css processor/ babel) and a javascript function/object is generated which is injected.</p><p>Vue uses webpack plugin to merge all &lt;style&gt; together from all the component . However we can also ask vue to inject it separately using different design approach.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c689519fd36" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>