<?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 Rashijaiswal on Medium]]></title>
        <description><![CDATA[Stories by Rashijaiswal on Medium]]></description>
        <link>https://medium.com/@rashijaiswal2026?source=rss-1e7d11788745------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*5C8y1KCmhNe6prJ_</url>
            <title>Stories by Rashijaiswal on Medium</title>
            <link>https://medium.com/@rashijaiswal2026?source=rss-1e7d11788745------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 22:50:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rashijaiswal2026/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[MinHash, Memory Leaks, and Surviving Text Cleaning: A Pragmatic Guide to Text Preprocessing]]></title>
            <link>https://medium.com/@rashijaiswal2026/minhash-memory-leaks-and-surviving-text-cleaning-a-pragmatic-guide-to-text-preprocessing-bbe703a10d28?source=rss-1e7d11788745------2</link>
            <guid isPermaLink="false">https://medium.com/p/bbe703a10d28</guid>
            <category><![CDATA[text-mining]]></category>
            <category><![CDATA[data-cleaning]]></category>
            <category><![CDATA[data-preprocessing]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[Rashijaiswal]]></dc:creator>
            <pubDate>Mon, 08 Jun 2026 16:17:39 GMT</pubDate>
            <atom:updated>2026-06-08T16:17:39.038Z</atom:updated>
            <content:encoded><![CDATA[<p>My journey into the world of text data cleaning</p><p>When you first dive into Natural Language Processing, the tutorials paint a beautiful picture. You run import nltk, call a magic .clean(), or use spacyfunction on a perfectly manicured CSV, and suddenly you’re training state-of-the-art models. What they don’t tell you is the real story, real challenges and where the real cleaning holds. Many of them give you a standard steps, remove this or that but seldom will they tell you the type of issues you may encounter and unique handling it requires.</p><p>Recently, I met a real dataset, yeah real one, the one with lots of historical issues, not the mommy daddy issues, but the ones that gets added by creepy algorigthms, scraped news from internet and shared on various platforms to be used but they inherit issues from bad algos that can’t identify what its pasting into the dataset.</p><p>So one day you get a nice link , that say oh this is a dataset that you need to clean, its looks good , the columns are well defined, it looks good but beneath that is lot of Botox that was not required, hence it looks good but seldom required. So the task is to remove the botox so that natural beauty appears, you know people say old is gold but trust me when I say, anything clean is gold. Goes for everything no? Skin, dataset, cupboards etc., enough of jokes.</p><p>Recently, I set out to prepare the cc_news dataset for advanced concept modeling. The goal was simple: turn ~800,000 rows of raw, web-scraped news articles into a pristine, English-only corpus. Why is this so crucial? Because downstream tasks like Concept Bottleneck Models (CBMs) are highly sensitive to noise. If you feed your model cookie consent banners and stock market tickers, it will learn to concept-map cookie consent banners and stock market tickers.</p><p>Here is the story of how I survived the cc_news dataset, the spectacular failure of standard data cleaning methods and why we should be careful of those, and the practical &quot;Do&#39;s and Don&#39;ts&quot; I learned along the way that nobody taught me, oh sorry, I should credit to Google search, Literature articles that I stumbled upon, and AI, of course, how can I forget who was there when nobody was there, few tears rolled down just now. lol.</p><h3><strong>Phase 1: The Discovery (Looking the Beast in the Eye, on a funny note these are your small beasts)</strong></h3><p>Scraped news datasets are notorious for hiding structural web noise inside the “article” columns. Before writing a single line of cleanup code, you have to read the raw data.</p><p>By digging into the ~800,000 rows, I discovered that “news” often included:</p><ul><li><strong>Sticky Scraper Issues:</strong> The exact same text duplicated across dozens of different headlines.</li><li><strong>Structural Noise:</strong> Endless footers, paywall demands, and privacy policies.</li><li><strong>Ad-Tech Blobs:</strong> Raw, flat JSON script fragments and ad-tracking objects hiding in plain sight.</li><li>Its a good mix of small and capital letters, weird symbols, non-English (be it any language) text and symbols.</li><li>Identify or may be jot down waht you see. Lots of eyeballing required. Make notes always good to do that.</li></ul><h3>Phase 2: The Spectacular Failure (N-grams vs. RAM)</h3><p>My first instinct was to use a standard NLP technique to find the repetitive junk: an n-gram document frequency audit. The plan was to count the most frequently occurring 20-word phrases across the entire dataset and slice them out.</p><p><strong>It was a spectacular failure. But this was also the first time I cleaned a text dataset so I did not know that RAM issue can happen.</strong></p><p>If you attempt to store and count massive arrays of 20-word n-grams across 800,000 documents, the strings grow exponentially. My Python environment confidently chewed through the data until it hit exactly 51% — and then the RAM violently crashed. Standard tutorials don’t prepare you for memory leaks. I needed a method that was fast, scalable, and memory-efficient.</p><p>So like anyone learning something new for the first time, I googled. I found that in some big companies there is this method which is used, when I found out about it , I thanked whosoever came up with it.</p><h3>Phase 3: The MinHash LSH Pivot</h3><p>To solve the memory crisis, I abandoned the exhaustive n-gram count and pivoted to <strong>Locality Sensitive Hashing (LSH)</strong> using MinHash (via the datasketch library).</p><p>Instead of exhaustively comparing every string to every other string, MinHash creates a tiny, condensed mathematical “fingerprint” of the text. LSH then buckets these fingerprints so you only compare documents that are highly likely to be near-duplicates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*5L2JTiowIfzOqeUjCMS-Vg.png" /></figure><p>just a small snippet that you can use</p><p>By applying MinHash LSH over n-word shingles, I could efficiently group near-identical articles without destroying my hardware. I set a high similarity threshold (0.95) to safely capture exact matches and relied on a human-in-the-loop audit to confirm I was dropping boilerplate, not journalism. <strong><em>And let me tell you something, if you want stellar job done validate everything, do not leave it to the code to do it, they can be lazy too, but you can’t afford to be lazy.</em></strong></p><h3>Phase 4: Surgical Noise Removal (Massive Beasts)</h3><p>With the massive duplicates gone, I deployed a targeted series of regular expressions (regex) to strip the hyper-specific structural noise that LSH ignores. Real-world datasets require highly specific scalpels.</p><p>Once the massive structural blocks (like endless fragments of Non-English words or phrases and annoyingly repeating spam) were gone, I was left with the massive structural-noise:</p><ul><li><strong>Glued Words:</strong> Web scrapers are notoriously clumsy and love to smash words together (e.g., turning <em>report says</em> into <em>reportSays</em>).</li></ul><blockquote><strong>You get different types, sizes, forms, and structure of SLIDING HEADLINES. <em>Keep this in mind, most of the crap coming from internet especially in news data is filled with this, I was amazed to see the types, size, forms of the sliding headline issue.</em></strong></blockquote><ul><li><strong>Sliding Headlines:</strong> Scrapers also blindly grab scrolling news carousels and stitch them together into endless repetitive strings separated by weird pause seams.</li><li><strong>Inline Cruft:</strong> Datelines, bylines, “Share on Twitter” buttons, and image captions that interrupt the actual prose.</li></ul><h3>The Pragmatic Preprocessing Playbook: Do’s and Don’ts</h3><p>Based on this pipeline, here are the core rules I established for handling massive text corpora:</p><ul><li><strong>DO swap your deduplication and cleaning order.</strong> Initially, I deduplicated the data <em>before</em> cleaning the text. Do this but validate what you are removing, I threw a lot of junk before I applied operations and even did language detection and symbols and waht not, once you dedup you will see a lot of shit gets cleared away and you can run your code onto a comparatively smaller dataset.</li><li>Even after applying operations like say n-gram, Min HASH, you will need to dedup again. Clean the text first (standardizing whitespace, lowercasing, etc.), and <em>then</em> run your deduplication. Also save this step for careful elimination of whatever shit gets behind after you are done with last of the many operations.</li><li><strong>DON’T rely on naive language filters.</strong> Datasets contain a mix of languages. I flagged non-English rows but deliberately deferred removing them. Many articles start with a foreign phrase or quote but continue entirely in English. A naive “drop if foreign” rule will destroy valid content.</li><li><strong>DON’T over-aggressively normalize accents.</strong> When normalizing text, be careful with forcing ASCII encodings. It removes accents, but it also silently destroys smart quotes, em-dashes, and foreign scripts that might be contextually important.</li></ul><h3>Phase 5: The “Tag the decision” Philosophy</h3><p>Here is the most important pipeline design principle I established: Tag the decision<strong>. If you completely rely on the code to do your validation, and not the amazing human- in the loop, then make it tag the decision for transparency and if you do anything wrong you can always go back and see if there is anything to not be dropped. Unlike life where you can’t go back, and re-do stuff, it is easier to tag decisions here. But you know waht even if you make a wrong move in life, look ahead.</strong></p><p>Throughout the cleaning stages, I simply tagged problematic rows with the reason they failed (stage:reason). Rows were only permanently dropped at the very end of the pipeline if they crossed a specific tech-token ratio, had a bizarre symbol density, or simply cleaned down to an empty string.</p><h3>The Final Tally</h3><p>Preprocessing is never truly finished; it is done and dusted, properly dusted. But by prioritizing memory-efficient algorithms like LSH, deploying surgical regex, and maintaining strict pipeline principles, the results were incredibly satisfying.</p><p>The next time you load a massive open-source dataset, remember: the real modeling starts in the messy, unglamorous trenches of data cleaning. <strong><em>Grab a mop</em>. <em>And no, its not enough to grab a mop inside your home, you know what let me share a secret, text data cleaning is just like house cleaning.</em> <em>Once you start doing it, you will know why I wrote this. Until then, happy cleaning!</em></strong></p><p>Next, I will talk about reproducible pipelines…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bbe703a10d28" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Evolution Of Topic Modeling]]></title>
            <link>https://medium.com/@rashijaiswal2026/evolution-of-topic-modeling-92bc57c93970?source=rss-1e7d11788745------2</link>
            <guid isPermaLink="false">https://medium.com/p/92bc57c93970</guid>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[language]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[topic-modeling]]></category>
            <dc:creator><![CDATA[Rashijaiswal]]></dc:creator>
            <pubDate>Mon, 16 Mar 2026 18:27:46 GMT</pubDate>
            <atom:updated>2026-03-16T18:27:46.503Z</atom:updated>
            <content:encoded><![CDATA[<p>Digging deep — why is it there and why do we need it?</p><p>We talked about how data is converted to topic or themes in millions and millions of texts in my post (From Data To Topic). But let’s sit back and see how it actually evolved, why people around the world advanced the concept of Topic Modeling. There must be something special about this process, isn’t it? Maybe its telling us something that we can’t uncover on our own? So what is it that led to evolution of Topic Modeling? Well I think we can uncover this on our own. I will try my best to keep it simple.</p><p>The word simple reminds me that some of the things that we think are complex are actually simple, but like any process, it takes time, effort and energy and many a times money, to uncover the simplicity of that complex thing. I believe everything that seems complex is simple until we discover it. Well, you know I can go on and on about this, but I won’t waste your time and get right to the point.</p><p>Well, Topic modeling, started from again a very simple concept, few individuals came up with <strong>Singular Value Decomposition (SVD)</strong> on the term document (text, abstract, summary, could be anything text related) to uncover semantic structure in the texts. What was simple about this? They used <strong>linear algebra</strong>. This process was called <strong>Latent Semantic Analysis</strong> (LSA). They used a mathematical method called SVD. I know you will ask me what the heck is this SVD?</p><p>SVD is a method to reduce noise, it is a method that breaks down a matrix into even simpler constituents. Let me give you an example. Now, mathematically, any matrix can be factored into the form below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/157/1*PayworOsvV6Zcv1fd246Bg.png" /></figure><p>Now what is this U, V and T.</p><p><strong>The Three Components</strong></p><p>To understand what SVD is actually doing, you have to look at what these three specific matrices represent:</p><ul><li>U<strong> (Left Singular Vectors):</strong> These represent the “rows” or the <strong>objects</strong> in your data (e.g., the documents in a text dataset). They describe how much each object relates to the underlying concepts.</li><li><strong>Σ (Singular Values):</strong> This is a diagonal matrix of numbers sorted from largest to smallest. These values tell you the <strong>strength</strong> or importance of each hidden concept. The bigger the number, the more important that “topic” is to the overall data.</li><li>V^T<strong> (Right Singular Vectors):</strong> These represent the “columns” or the <strong>features</strong> (e.g., the words). They describe how much each word contributes to those same hidden concepts.</li></ul><p>SVD allows dimensionality reduction, fancy of way of saying we are reducing redundant information.</p><p>If you need to understand it more, then here’s a link for learning:<a href="https://www.youtube.com/watch?v=vSczTbgc8Rc"> SVD</a></p><p>It can get very math-y if you are into it. We can get it touch. I can teach you these concepts.</p><p>But how did it help in latent semantic analysis? It clumps words together, say if words, cancer and chemotherapy appear constantly appear in documents, then it will club it together. It sort of creates a concept bubble, where the space between cancer and chemotherapy becomes small, even if the two words never appear together but because they appear near words like patient, fatigue, hospital.</p><p>It sounds great, dimensionality reduction, finding concepts hidden in words, but each word was a fixed point in a space. When a word has multiple meanings, let’s say, there is a word ‘orange’, it will try find one point somewhere halfway between color and fruit, so if you look for word orange, you may end up seeing citrusy and bright side by side, just an example. The model will think oh ‘bright citrusy’ makes sense, but does it? No, so what do we need here? We need something that allows orange to sit in color as well as in fruit bubble. But there’s more to why LSA wasn’t addressing some other issues that existed with this method.</p><blockquote><strong>This led to entry of probabilistic models. One that said you know what, there is 50% chance that Orange belongs to fruit bubble and 50% chance that it belongs to Color as well.</strong></blockquote><h3><strong>Probabilistic Latent Semantic Analysis (pLSA)</strong></h3><p>pLSA models the probability of a <strong>word</strong> (w) appearing in a <strong>document</strong> (d) as a mixture of <strong>topics</strong> (z). The formula for this looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*bXmhmR0CbBhMRLEhe7akkQ.png" /></figure><p>Does this equation look heavy to you, I guess no.</p><p>This equation expresses the <strong>joint probability</strong> of a document <strong>d</strong> and a word <strong>w</strong>.</p><ul><li>P(d, w): the probability that we observe document d and word w together.</li><li>P(d): the marginal probability of selecting document d.</li><li>z: a latent (unobserved) categorical variable which is ‘the topic’.</li><li>P(z ∣ d): the conditional probability that topic z is chosen given document d.</li><li>P(w ∣ z): the conditional probability of word w given topic z.</li></ul><p>Before we get pulled into the world of probabilities, let me give you a toy example.</p><h3>Two Topics Example:</h3><p>We start with the equation:<br> P(d, w) = P(d) * sum_z P(w | z) P(z | d)</p><p><strong>Setup: Two Topics</strong></p><p>Suppose we model documents using two topics:</p><p>z1 = Sports</p><p>z2 = Politics</p><p>We want to compute P(d, w).</p><p><strong>Step 1</strong>: Topic → Word Distributions</p><p>Let the word be: w = “goal”</p><p>P(“goal” | z1) = 0.30</p><p>P(“goal” | z2) = 0.02</p><p>Interpretation:<br> — In Sports, ‘goal’ is common.<br> — In Politics, ‘goal’ is rare.</p><p><strong>Step 2: </strong>Document → Topic Distribution</p><p>Suppose the document d is mostly sports:</p><p>P(z1 | d) = 0.8</p><p>P(z2 | d) = 0.2</p><p>So the document is 80% Sports and 20% Politics.</p><p><strong>Step 3: </strong>Compute P(w | d)</p><p>Using the mixture formula:</p><p>P(w | d) = P(w | z1)P(z1 | d) + P(w | z2)P(z2 | d)</p><p>Substitute values:</p><p>P(“goal” | d) = (0.30)(0.8) + (0.02)(0.2)</p><p>= 0.24 + 0.004</p><p>= 0.244</p><p>Therefore, P(“goal” | d) = 0.244</p><p><strong>Step 4: </strong>Compute the Joint Probability</p><p>Suppose: P(d) = 0.01</p><p>Then:</p><p>P(d, w) = P(d)P(w | d)</p><p>= 0.01 * 0.244</p><p>= 0.00244</p><h3>Mathematical Interpretation</h3><blockquote>We computed:<br> P(d, w) = P(d)[P(w|z1)P(z1|d) + P(w|z2)P(z2|d)]<br> <br> <strong>This shows that P(w | d) is a weighted average of topic-specific word probabilities, where the weights are given by the document’s topic distribution.<br> </strong><br> In expectation form:<br> P(w | d) = E_{Z ~ P(z|d)} [P(w | Z)]</blockquote><p>If you want to learn more about this algorithm, here’s a cool link: <a href="https://www.youtube.com/watch?v=4Muj9ba83Ks">PLSA</a>.</p><p>Good thing about this method is that each document can be explained as combination of topics, we also have distribution of these topics per document, and it allows for co-occurrence patterns where as LSA didn’t. But like every thing, there is a scope for improvement here as well. Why? I thought it was perfect but it isn’t perfect.</p><p>Imagine you have say ten documents, couple of topics, we know the word distribution for topics in these documents, but if we introduce say 1000 more documents, then, pSLA falls short as P(z ∣ d) is a parameter for every document in the training set. There will be a need for new parameters. So we need a method that generates those new parameters as new documents are introduced.</p><blockquote>If you recall, in the toy example, I had shared the probabilities (0.30, 0.20, 0.8,0.2) these were given but usually these have to estimated in real life, for that we use <strong>Maximum Likelihood Estimation </strong>method.</blockquote><p>Now, how does Maximum Likelihood Estimation method helps us here?</p><p>First step: For each word occurrence in a document, compute the <em>posterior probability</em> that it came from topic z.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/351/1*qk5J4QCwqZfNbRtndCDs_g.png" /></figure><p>Second step: Update the parameters using the expected assignments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/1*826nClcD5PTonIgMGM6Ppg.png" /></figure><p>where n(d, w) is the count of word w in document d. We keep alternating first step and second step until convergence happens.</p><p>In pLSA, each document has its own parameter vector P(z∣d), that means the number of parameters grows with document. Also, the document specific parameter has to be calculated for each document, and if there are thousands of documents then parameters grow as the document size grows. Also, since each document has their own parameter vector P(z | d), P then there is no distributional assumption for how these vectors are created , and it also assign extreme probabilities for rare words or for a rare topic. Additionally, it has fixed distribution learned for each document, if there is a brand new document with other words not present in previous document, it will So, there is re-training required for a new document as there is no prior distribution for guidance.</p><blockquote>So what is needed?</blockquote><p>What is needed is a prior distribution, and for extreme values we need something that will smooth things out. It is just like how we all need a balm for those days when things are new to us and sometimes too extreme? For some it could be a video game to distract themselves, for some a corner with a window where they can read a book, and look beyond the window, for some it could be philosophy to sooth the rough days.</p><p>But here we need something flexible enough.</p><h4>Latent Dirichlet Allocation (LDA) became the answer to this problem.</h4><p>Remember pLSA assumes fixed numbers for each document? LDA assumes that these numbers are drawn from Dirichlet Distribution, it is a probability distribution whose outcome is a probability distribution, it generates vectors of positive numbers that sum to one.</p><p>Let’s say we have some clippings from a newspaper, now we can assume right that clippings will follow a certain pattern especially if its coming from the same source?</p><p>For example, maybe most of the clippings are primarily about one topic and only lightly touch others. The Dirichlet distribution can encode this general tendency. Some settings of its parameters imply that documents are usually concentrated on a single topic; other settings imply that documents are more evenly mixed. In this way, the Dirichlet acts as a way of expressing prior beliefs about how topic mixtures typically look.</p><p>This is where Bayesian inference enters. Bayesian reasoning combines two things: what we know about data (prior belief) and what we are actually observe. The Dirichlet represents the prior belief about what document mixtures usually look like. The actual words in a document are the data. When LDA analyzes a document, it updates the prior belief using the observed words to produce a posterior estimate of the topic mixture . This updating process balances general expectations with document-specific evidence. If a document contains two sports words and one politics word, the model does not blindly conclude it is exactly 66% sports and 33% politics. Instead, it adjusts this estimate in light of the broader belief about how documents are typically structured. This prevents extreme conclusions when data are sparse.</p><p>So in simple words, because of this additional layer, LDA forms a complete generative story of how documents are produced. First, <em>a document’s topic proportions are randomly drawn from a Dirichlet distribution</em>. Then, for each <em>word in the document, a topic is chosen according to those proportions</em>, and <em>finally a word is chosen from that topic’s word distribution</em>. <strong>Every step is probabilistically defined.</strong></p><p>It controls overfitting because the prior prevents extreme parameter estimates unless strongly supported by data. It also generalizes naturally to new documents, since new topic mixtures can simply be viewed as additional draws from the same Dirichlet distribution. So there are several reasons why LDA was a superior method over pLSA to me but then it had its own shortcomings.</p><p>Slowly and gradually we moved from probabilistic topic models to deep neural architectures. But before we moved to deep neural architectures, we had models which were evolved forms of topic models.</p><p>In the next post, I will talk about one of the concept modeling methods.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92bc57c93970" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Data To Topic]]></title>
            <link>https://medium.com/@rashijaiswal2026/from-data-to-topic-67be184bab34?source=rss-1e7d11788745------2</link>
            <guid isPermaLink="false">https://medium.com/p/67be184bab34</guid>
            <category><![CDATA[topic-modeling]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[information-science]]></category>
            <category><![CDATA[large-language-models]]></category>
            <dc:creator><![CDATA[Rashijaiswal]]></dc:creator>
            <pubDate>Thu, 26 Feb 2026 11:03:05 GMT</pubDate>
            <atom:updated>2026-02-26T11:03:05.113Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*zjc5UUG0WuKNYCreNkjYkA.png" /></figure><p>Delving into world of language, vectors, and meaning.</p><p>I don’t remember the first time I said any word, my first word, well, my mom can tell you that, she has many stories to share about me. But I want to tell you a story of how I look at language and words these days.</p><p>Recently I read a paper which mentioned Topic Modeling techniques (I will tell you more about this in detail, wait for sometime), well for me it was a first. That got me wondering, we humans started using some early form of language about 2 million years ago to communicate with each other. We have been using words, languages, texts since so long that we consider it a regular thing. A common thing. I will not delve into how language evolved and how we converted language into words, but it is some medium using which we communicate. It doesn’t matter which language it is but we use it to to talk, to fight, to express love, to shout out decisions, to tell the world what’s happening and to basically communicate. Saying I love you changes something in a person, it evokes emotions, happiness, tears of joy sometimes, it changes relationships, so does, I don’t give a damn about you! Language makes expressing anything effortless. Its like we have taken it for granted, it is one of the easiest ways we use to communicate with each other and to add meaning to our every day lives. We use language. We use words. But hello, we have reached here after almost 2 million years.</p><p>This paper that I was reading about topic modeling got me thinking what happens when a Large Language Models (LLMs) processes language or say how does it processes words.</p><p>When an LLM has to process it, it breaks it into smaller chunks, but these chunks looks very different to them.</p><blockquote>They break it into something called ‘<strong>Tokens</strong>’, so for example:</blockquote><h4><em>Playing basketball </em>→ tokens: {‘play’, ‘ing’, ‘basketball’}.</h4><p>Mathematically, a <strong>document</strong> <strong>D</strong> is represented as a sequence of tokens:</p><h4>D={t1,t2,t3,…,tn}</h4><blockquote>But no, they don’t stop there. They convert these <strong>Tokens</strong> into <strong>Numerical indices , then </strong>in a <strong>Vector</strong>.</blockquote><p>So <strong>{‘play’, ‘ing’, ‘basketball’}</strong> becomes <strong>{‘play’: 1, ‘ing’: 2, ‘basketball’: 3}.</strong></p><p>Now these vectors could be a really long list of numbers, for example, sparse representation for basketball may look like this [0,1,0,0,1,0…]. Tokenization varies by model and tokenizer.</p><p>But there can be scenario where we have different words and they have different vectors but then how do we know if some words arranged in a phrase are similar to each other? But wait why ? Why do we need to look for similarity? Does it mean we are looking to attribute some meaning to the sentence or those groups of words? I think so. But how do LLMs attribute meaning to those words? So, we wanted to know if we can represent words can be represented in a certain way to that it captures similarity or a relationship between words. Because assigning a relationship to the words makes it easy for the models to understand structure.</p><p>So how was this achieved? We remember that a vector for a word could be a really long number, so we squeeze it, compress it into dense forms.</p><p>But hey, we have been just talking about words to express, but these days we also use images to express something or tell something (I will talk about this later on in some other post). When it comes to semantically similar it may look like this.</p><p>Let’s say, we have four words</p><p><strong>pen: [0.5, 1.15, 0.98], paper: [0.4, 1.13, 0.89], soup: [2.5, 0.5, 2.025], crackers: [2.6, 0.5, 2.024]</strong></p><p>Now we can see that pen and paper, soup and crackers , their forms look alike. Isn’t it? Can we say pen and paper, soup and crackers they are related ? This list that we used as an example is Embedding Vector.</p><p>But isn’t it almost miraculous? When vectors related to pen and paper, and soup and crackers sit close to each other or look similar, the models start learning small relationships between words. Inferring similarity between vectors allows a model to detect association, context and we humans rely on patterns. Don’t we look for similarities as well when we meet people? We also seek similarities sometimes isn’t it? When we find similarities in people who seem more like us , we say we are similar and that means something to each one of us.</p><p>So, now we understand that there is some relationship between words when its learned in a different format by models. Models start to understand a structure.</p><p>Now, like any moment when we meet someone, we try to predict, what will happen next?</p><p>Models also try to <strong>predict the next word</strong>, they learn the embedding vectors through <strong>Training objectives</strong> that lowers the loss of making the wrong prediction.</p><p>During training words that appear in similar environments are nudged closer, and unrelated words drift apart, very much how life is like right?</p><p>This learned information enables the models to recognize related themes, detect patterns across documents. This is the foundational capability behind tasks like search, recommendation, clustering and ultimately topic modeling.</p><p>When models see similar vectors like pen and paper, soup and crackers, it starts inferring usage. The guiding intuition here is that words that have similar contexts tend to have similar meanings. Models predict. They predict nearby words. Let’s say they see a sentence like ‘I like having tomato soup with salty crackers’. The model sees the word <strong>Soup</strong>, it attempts to predict nearby words such as <strong>salty </strong>or <strong>crackers</strong>. If it assigns a high probability to the correct context word, the prediction is considered good. If the probability is low, the model knows it needs to improve. <strong>Mathematically, they try to maximize the probability.</strong></p><p><strong>P(context word ∣ target word)</strong></p><p>The closer two vectors are, the higher this probability becomes. Training minimizes prediction error using a <strong>loss function </strong>. Now what is this <strong>Loss Function</strong>?</p><p>Suppose the model predicts:</p><ul><li>P(crackers | soup) = 0.15 → poor prediction (First case)</li><li>P(crackers | soup) = 0.82 → strong prediction (Second case)</li></ul><p>In the first case, loss is high. In the second, loss is low. Training becomes a repeated effort to <strong>reduce this loss</strong>.</p><p>Each time loss is computed, backpropagation calculates gradients, these are tiny corrective signals that indicate how the vectors should move to improve the prediction. If <strong>soup</strong> failed to predict <strong>crackers</strong>, their vectors are nudged closer. If <strong>soup</strong> wrongly predicts something unrelated like <strong>airplane</strong>, those vectors are pushed apart.</p><p>Here is an example of a simple gradient update:</p><p>Imagine this:</p><p>soup = [1.0, 0.5]<br>crackers = [0.2, 0.1]</p><p>Their similarity (dot product) is:</p><p>(1.0×0.2)+(0.5×0.1)=0.25</p><p>Now suppose the model has learned that <strong>soup</strong> frequently appears near <strong>crackers</strong>, but the similarity score is still too low.</p><p>So it makes a small adjustment.</p><p>soup ← soup + 0.1 × crackers</p><p>New soup vector:</p><p>[1.0,0.5]+0.1×[0.2,0.1]=[1.0,0.5]+[0.02,0.01]=[1.02,0.51]</p><p>That’s it.</p><p>A tiny move. Barely noticeable. But now the similarity increases slightly.</p><p>If this happens thousands, then millions of times, of times across different contexts, different documents, <strong>soup</strong> drifts closer to <strong>crackers</strong>, and also toward words like <strong>bowl</strong>, <strong>warm, lunch</strong>.</p><p>Meanwhile, if <strong>soup</strong> accidentally predicts something unrelated like <strong>airplane</strong>, the gradient update would push those vectors slightly apart.</p><p>Enough of vectors now, let’s take a bird’s eye view of things.</p><p>Now, think of this, when words becomes closer to those they frequently accompany, then clusters begin to form.</p><p>Words like soup, crackers, bowl, warm, winter begin to occupy a nearby region. Elsewhere, pen, paper, stapler, notebook will begin to gather into their own neighborhood. These clusters emerge from usage.</p><blockquote><strong>These clusters begin to resemble themes.</strong></blockquote><p>That means model is learning patterns in the data.</p><p>Once words organize into meaningful clusters/regions, documents can be represented as combination of these regions. Documents start leaning towards certain semantic regions. Now, many people have tried to uncover such regions, and the <strong>methods designed to uncover such hidden themes in large text collections is Topic Modeling.</strong></p><p>If we go back to how words are tokenized first into vectors, and imagine billions of text around the world, everything is transformed into Mathematical representations.</p><p><strong><em>Language once carried love, tenderness, grief, sadness, excitement, nervousness, disappointment, in the models, now words related to these concepts, they exist as representations.</em></strong> Can we actually reduce these concepts to representations? Is mathematics a universal language we have for communication? This is a naive question and an incomplete one in today’s world. This is not just a modeling language, isn’t it?</p><p>In the next post, I will discuss something that helps us understand how researchers uncover hidden themes from massive dataset having millions and millions of texts. I will discuss Topic Modeling.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67be184bab34" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>