<?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 Rohith Teja on Medium]]></title>
        <description><![CDATA[Stories by Rohith Teja on Medium]]></description>
        <link>https://medium.com/@rohithtejam?source=rss-d66134dd9f0d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*M13BpJH_5F_3Ke88WLf-bA.jpeg</url>
            <title>Stories by Rohith Teja on Medium</title>
            <link>https://medium.com/@rohithtejam?source=rss-d66134dd9f0d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 02:49:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rohithtejam/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[I Published in Top Journals. Data Storytelling is What I Did.]]></title>
            <link>https://levelup.gitconnected.com/i-published-in-top-journals-data-storytelling-is-what-i-did-e6ff2d3efdb0?source=rss-d66134dd9f0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6ff2d3efdb0</guid>
            <category><![CDATA[storytelling]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-scientist]]></category>
            <dc:creator><![CDATA[Rohith Teja]]></dc:creator>
            <pubDate>Wed, 24 Jun 2026 16:36:05 GMT</pubDate>
            <atom:updated>2026-06-24T16:36:05.133Z</atom:updated>
            <content:encoded><![CDATA[<h4>Understand the essence of being a data scientist and a master storyteller</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gx3m7ViWtk2_ovVF" /><figcaption>Photo by <a href="https://unsplash.com/@chne_?utm_source=medium&amp;utm_medium=referral">Tachina Lee</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>You might have thought that typical data scientists spend their days crunching numbers in machine learning models, building dashboards, pipelines, and enjoying their fat wad of cash from doing so.</p><p>Not gonna lie, some of these are correct. But the real value in doing data science is the luxury of defining problems, building data infrastructure, validating assumptions, and finally translating data into decisions.</p><p>In philosophy, data scientists are problem solvers. In practice, they are analysts, engineers, researchers, statisticians, communicators, and occasionally detectives. You can slap any name on top, but at heart, we are just dealing with data and telling a story.</p><p>On any given day, a data scientist might investigate why customer retention is declining, design a pipeline that processes billions of records, build a forecasting model, review statistical assumptions, or explain technical jargon to executives with no technical background.</p><p>The last part is my favorite. It shows that data scientists are excellent storytellers. We do complex analysis but present it in a way that even a layman can understand.</p><h3>Valuable than gold</h3><p>Data science is not just analysis. It is an interpretation. We take something messy and turn it into something more valuable than gold.</p><p>This sometimes means finding the driver behind a trend. Or building a dataset no one had before, or even forecasting what comes next. In every case, the final output is not just a number. It is an explanation.</p><p>Over the last few years, I have worked on energy systems, transportation emissions, and forecasting. The domains were different. The pattern was the same.</p><p>It&#39;s simple: Start with a question. Collect evidence. Test assumptions. Then turn the result into something people and policymakers can understand.</p><h3>Data storytelling</h3><p>Our real job of data storytelling is understanding complex systems and communicating that understanding in a form to make impactful decisions. As simple as that.</p><p>In this, a machine learning model is a story.</p><p>A statistical analysis is a story.</p><p>Even a dashboard is a story.</p><p>The question is not about telling just any story. The question is whether the story is true, useful, and, of course, understandable.</p><p>In my case, each project started with a simple question. And each project ended with a story about how a complex system works.</p><h3>Story #1: What drives natural gas use in American homes?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ouZTE6Jfig8onYSL" /><figcaption>Photo by <a href="https://unsplash.com/@jmeyer1220?utm_source=medium&amp;utm_medium=referral">Jonathan Meyer</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Paper in Science Advances:</strong> <a href="https://www.science.org/doi/10.1126/sciadv.adh5543"><em>Drivers of Natural Gas Use in U.S. Residential Buildings</em></a></p><p>In this paper, we asked a simple question but with a complicated answer: why does residential natural gas use vary so much across the United States?</p><p>If you look closely, it is a story about human behavior.</p><p>To answer this question, we used daily county-level gas consumption data from 1,000 counties and studied how consumption changed with outdoor temperature.</p><p>We found that residential natural gas consumption was influenced by several factors:</p><ul><li>Climate</li><li>Income</li><li>Building type</li><li>Population</li><li>Regional habits</li></ul><p>What interested me most was not just the model. It was the pattern behind the model. Gas use was not random. It was a story about climate, housing, and human behavior.</p><p>Policymakers do not act on raw datasets. They act on explanations.</p><p>Our paper transformed a complex energy system into something understandable.</p><p>That is storytelling!</p><h3>Story #2: Mapping Traffic Emissions Across India</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jvUh-VvMIkE2au-i" /><figcaption>Photo by <a href="https://unsplash.com/@nishithparikh90?utm_source=medium&amp;utm_medium=referral">Nishith Parikh</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Paper in Nature Scientific Data:</strong> <a href="https://www.nature.com/articles/s41597-025-06287-9"><em>High-Resolution Gridded CO₂ and Pollutant Emission Data from Road Traffic in Indian Cities</em></a></p><p>This project involved building one of the most detailed road-traffic CO2 and pollutant emission datasets for Indian cities.</p><p>The technical side was heavy:</p><ul><li>Terabytes of floating car data</li><li>Buffed up machine learning models</li><li>Emission factors</li><li>Geospatial analysis</li><li>Massive-scale computation</li></ul><p>But the scientific contribution was not the dataset itself. The contribution was the story hidden inside the dataset. It was to show where emissions are actually happening, street by street, city by city.</p><p>For the first time, we could visualize where emissions happened, which is essential to study the drivers of traffic congestion and the impact of pollutant emissions on our health.</p><p>Without storytelling, the dataset would simply be terabytes of numbers.</p><p>With storytelling, it became a lens through which researchers, policymakers, and urban planners could understand cities.</p><p>It is not just a dataset. It is a map of reality.</p><h3>Story #3: Forecasting natural gas consumption</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FZbrSjXmaZZrFAZ2" /><figcaption>Photo by <a href="https://unsplash.com/@jakubzerdzicki?utm_source=medium&amp;utm_medium=referral">Jakub Żerdzicki</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Paper in Journal of Cleaner Production:</strong> <a href="https://www.sciencedirect.com/science/article/pii/S0959652624001343"><em>Short-to-Medium Range Forecast of Natural Gas Use in U.S. Residential Buildings</em></a></p><p>In this paper, we built an interpretable forecasting framework using county-level gas consumption data and seasonal weather forecasts from the European Center for Medium-Range Weather Forecasts (ECMWF).</p><p>This model was highly accurate for short-range (1 week) and robust for medium-range (3 months) gas consumption forecasting, and had an average accuracy of 80%.</p><p>Forecasting is often seen as a prediction problem. A useful forecast is not only accurate. It also helps people understand what is changing and why it is changing.</p><p>If the model can’t be trusted, it doesn&#39;t help much with decision-making.</p><p>A forecast is valuable when it helps answer questions:</p><ul><li>How much gas should be supplied?</li><li>How vulnerable are we to the cold season?</li><li>How much uncertainty exists in the current model?</li></ul><p>Here, every forecast contained a story about how households might respond to future temperatures, and how regional demand would evolve. This will help us better plan for risks in the future, as well as for energy planning and supply chain optimization.</p><h3>A common thread</h3><p>At first glance, these papers seem to be about different systems:</p><ul><li>Energy systems</li><li>Transportation systems</li><li>Forecasting systems</li></ul><p>These are different domains. But all three projects follow the same logic.</p><p>First to ask a real question. Then, find the right data. And finally, build a framework to explain the result clearly enough that someone else can use it.</p><p>For me, this is the core of data science.</p><p>Not just models, pipelines, or dashboards.</p><p>It is the <strong>understanding. </strong>An understanding of the working of a complex system.</p><h3>Why I care about storytelling</h3><p>“Can’t I just build a model, do analysis, and call it a day? Storytelling is not my burden, it will happen later.”</p><p>Well this is not true. Storytelling won&#39;t happen after the analysis. I feel it begins much earlier.</p><p>It starts when you choose the question. It will shape the variables you collect. Then the assumptions, the patterns, and finally the conclusions that you are willing to defend.</p><p>So, storytelling begins when you formulate the question.</p><p>The best data scientists are not the people who build the most sophisticated models. They are the people who can transform complexity into understanding.</p><p>That is why, after publishing papers, building models, and processing billions of records, I still think data storytelling is the most important skill I have learned.</p><p>Because in the end, data science is not only about data. It is about helping people see how our complex world actually works.</p><p>Thanks for reading! Follow for more.</p><p><strong>Want to Connect?</strong><br>Reach me at <a href="https://www.linkedin.com/in/rohithteja/">LinkedIn</a>, <a href="https://twitter.com/rohithtejam">X</a>, <a href="https://github.com/rohithteja">GitHub</a>, or my <a href="https://www.rohithteja.dev/">Website</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6ff2d3efdb0" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/i-published-in-top-journals-data-storytelling-is-what-i-did-e6ff2d3efdb0">I Published in Top Journals. Data Storytelling is What I Did.</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Train Your Dragon? Try Training an LLM!]]></title>
            <link>https://levelup.gitconnected.com/how-to-train-your-dragon-try-training-an-llm-c8712e0901c3?source=rss-d66134dd9f0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8712e0901c3</guid>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[inference]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[neural-networks]]></category>
            <dc:creator><![CDATA[Rohith Teja]]></dc:creator>
            <pubDate>Tue, 26 May 2026 15:17:44 GMT</pubDate>
            <atom:updated>2026-05-26T15:17:44.637Z</atom:updated>
            <content:encoded><![CDATA[<h4>Pretrain your very own LLM model at a super small scale.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QrTrwKB3nznsDx4d" /><figcaption>Photo by <a href="https://unsplash.com/@kuhantilope?utm_source=medium&amp;utm_medium=referral">Maximilian Müller</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Yes! You read it right. I am gonna teach you the basics and put you on the process to train your very own personal LLM model.</p><p>Surely it won&#39;t outperform the might beasts like GPT or Gemini. But hey, we learn something at least.</p><p>Before jumping into the code and crusts, let&#39;s understand what is the recipe for training an LLM.</p><p>In correct terminology, we would call it <strong>pretraining</strong>.</p><h3>The time before GPT</h3><p>Good old times. When the world was simple and not this complicated. Every week these days, there is a new hype, a new buzzword that gives us a lot of FOMO.</p><p>Let&#39;s rewind back and learn how the very first LLM has been trained or in this case pretrained.</p><p>To understand the pretraining process, you need to know what the LLM is about and the context.</p><p>To make it very simple: Our large language model learns the internet and recites it to us whenever we ask.</p><p>In a few technical bits, LLM is about predicting the next token from the distribution of tokens it learned during the pretraining process.</p><p>Let&#39;s start from ground zero.</p><h3>The data</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qea7Oh4adG7AEwV30BtiJQ.png" /><figcaption><a href="https://huggingface.co/spaces/HuggingFaceFW/blogpost-fineweb-v1">Open source data for pretraining LLM</a></figcaption></figure><p>Here, the data is simply the whole internet: usually, the open web, like Wikipedia, Reddit, forums, and whatever exists on the internet.</p><p>The first step is to find a way to download everything on the internet. Some commonly used ways for this are crawling.</p><p>You deploy bots that will visit a website, then save it and click on the links on the website to move to another. They kept doing it until they captured everything we wanted.</p><p>If you are too lazy to crawl, you can use the <a href="https://huggingface.co/spaces/HuggingFaceFW/blogpost-fineweb-v1">FineWeb</a> open-source website available on HuggingFace. It is a large dataset with 15 trillion tokens taking up 44 TB of disk space. Not too shabby, the datasets these days are wayyyy bigger than this (estimates put it in the range of petabytes!).</p><p>For our use case, let&#39;s consider a small dataset: our very own and personal 11-word universe.</p><h3>Our 11-word universe</h3><p>Here is our entire “internet”. Let’s assume the complete training corpus for our “baby LLM”:</p><blockquote><strong><em>“the robot likes code the robot writes code everyday human rules”</em></strong></blockquote><p>There are 11 words in total, but if we count the unique words, our <strong>vocabulary</strong> size is just 7 words:</p><p>[&#39;the&#39;, &#39;robot&#39;, &#39;likes&#39;, &#39;code&#39;, &#39;writes&#39;, &#39;everyday&#39;, &#39;human&#39;, &#39;rules&#39;]</p><p>Now, we map each word to a number:</p><ul><li>the → 0, robot → 1, likes → 2, code → 3, <br>writes → 4, everyday → 5, human → 6, rules → 7</li></ul><p>Our entire training dataset is now just an array of integers:</p><p>[0, 1, 2, 3, 0, 1, 4, 3, 5, 6, 7]</p><p>We do this as neural networks can only train on numerical data.</p><h3>Slide the window</h3><p>In a real corpus, the vocabulary length is super looong. So we “learn” from this long corpus using a window. That is, we randomly select a subset of the corpus of a specific length for training.</p><p>You can call this as “context length” or “window size”. For our baby GPT, let’s set the window size to 3.</p><p>This means our model can only look at a maximum of 3 words at a time. The goal is to guess the next one using this context. We slide this window across our data to create training pairs:</p><ul><li>Input: What the model sees (X): has 3 words</li><li>Target: What it must predict (Y): will predict one word</li></ul><p>[the, robot, likes] → code</p><p>[robot, likes, code] → the</p><p>[likes, code, the] → robot</p><p>[code, the, robot] → writes</p><p>This prepares our training dataset. Our input is 3 words long, and the prediction is the next word.</p><h3>A sneak peek under the hood</h3><p>When the model looks at an input during the training process, it converts the tokens into numbers.</p><p>After the input passes through the network, the model outputs raw values for each word in our vocabulary. We call these scores logits.</p><p>Example:</p><pre>Vocabulary:  [ the,  robot,  likes,  code,  writes,  everyday,  human,  rules ]<br>Logits:      [ -1.2,   0.5,    -3.1,   4.2,    1.1,      -0.5,    0.2,   -2.0 ]</pre><p>We can’t interpret logits directly, so we use a softmax function that converts these arbitrary scores into actual probabilities (that add up to 100%)</p><p>After running the logits into Softmax, we get a nice probability distribution:</p><ul><li>code: 72%</li><li>writes: 15%</li><li>robot: 8%</li><li>and the rest: 5%</li></ul><p>[the, robot, likes] → code</p><p>For this case in the first example, the model understands that it code comes after, [the, robot, likes] so it gives it a higher probability.</p><p>The goal of the LLM model now is to predict the next token using the probability distribution it learned during the training process.</p><p>This “pretraining” process leaves us with something called a “Base model”.</p><p>A base model just remembers the internet (the data we trained it on) as a memory. Whenever you ask it to retrieve something, it predicts the sequence it remembered.</p><h3>Inference: make it talk</h3><p>We have the base model in our hands. This is not much useful if it cannot answer our questions like ChatGPT or Gemini.</p><p>The process of making the model generate new text is called inference. This way, we can check if the model performs as expected.</p><p>You might have remembered how the GPT got better over the years. In the very beginning, it sounded a lot robotic. Currently, the text made by GPT is super convincing. I sometimes purposefully dumb down my sentences to make sure they sound human (sigh….to err is human).</p><p>To watch the inference in its glory, we can give the model a prompt, say <strong>“the robot”.</strong></p><h3>Step 1:</h3><ul><li>The model takes [the, robot] (length 2, which fits perfectly in our window size of 3).</li><li>It runs the math and calculates that likes has the highest probability.</li><li>It samples likes and adds it at the end of the text.</li><li>It predicts: <strong>“the robot …”</strong></li><li>As: <strong>“the robot likes”</strong></li></ul><h3>Step 2:</h3><ul><li>Next, the model takes [the, robot, likes] (length 3, which still fits our window).</li><li>It processes it and predicts that code is next.</li><li>It adds it again to the end of text.</li><li>It predicts: <strong>“the robot likes …”</strong></li><li>As: <strong>“the robot likes code”</strong></li></ul><h3>Step 3 (window shift):</h3><ul><li>Now the text is <strong>“the robot likes code”</strong> (4 words).</li><li>Note that our window size is strictly 3, so the model has to drop the oldest word. It drops and forgets the.</li><li>It only looks at the window with these words: [robot, likes, code].</li><li>Based on this history, it predicts the next word, maybe everyday.</li><li>It predicts: <strong>“the robot likes code …”</strong></li><li>As: <strong>“the robot likes code everyday”</strong></li></ul><p>This is the simple inference loop, which looks at the window, predicts the next token, appends it, shifts the window to the right, and does everything again.</p><p>This is exactly how ChatGPT used to answer your questions in the very beginning (now the animations have changed, and the models have become way faster to notice this).</p><h3>Conclusion</h3><p>There you have it. Now you know the basics of the origin of LLMs. Reality is more complicated than how I explained, but it is a good start. LLMs have gotten better over the years with a lot of new concepts and tweaks by some of the brightest minds in the world.</p><p>In my upcoming articles, I will explain the evolution of LLMs (of course, in very simple words).</p><p>Thanks for reading, and cheers! Follow for more.</p><p><strong>Want to Connect?</strong><br>Reach me at <a href="https://www.linkedin.com/in/rohithteja/">LinkedIn</a>, <a href="https://twitter.com/rohithtejam">X</a>, <a href="https://github.com/rohithteja">GitHub</a>, or my <a href="https://www.rohithteja.dev/">Website</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8712e0901c3" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/how-to-train-your-dragon-try-training-an-llm-c8712e0901c3">How to Train Your Dragon? Try Training an LLM!</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Where Do Knowledge Graphs Fit in the World of LLMs and AI Agents?]]></title>
            <link>https://levelup.gitconnected.com/where-do-knowledge-graphs-fit-in-the-world-of-llms-and-ai-agents-c431d56d5e28?source=rss-d66134dd9f0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c431d56d5e28</guid>
            <category><![CDATA[knowledge-graph]]></category>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[agentic-rag]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Rohith Teja]]></dc:creator>
            <pubDate>Sun, 07 Sep 2025 23:16:47 GMT</pubDate>
            <atom:updated>2025-09-07T23:16:47.024Z</atom:updated>
            <content:encoded><![CDATA[<h4>Some insights into Agentic Graph RAG</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*L9SebBXLkb9c3gUS" /><figcaption>Photo by <a href="https://unsplash.com/@omilaev?utm_source=medium&amp;utm_medium=referral">Igor Omilaev</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I&#39;ve talked a lot about knowledge graphs in my previous articles. Knowledge graphs have been the most powerful way to represent and query structured information.</p><p>Now, with the rise in popularity of the large language models, we naturally ask:<br>👉 Do we still need knowledge graphs?<br>👉 Where do they fit in the new tech jungle of LLMs?</p><p>Short answer: We are not replacing Knowledge graphs, but we simply reposition them.</p><p>Long answer: Read on!</p><h3>Knowledge graphs</h3><p>Let&#39;s recap quickly about knowledge graphs.</p><p>Knowledge Graphs are usually represented as directed graphs, so each entity of this graph can be termed as a <strong>Triple.</strong></p><p>Triple, as the name suggests, is a tuple made of 3 elements, namely: the source node, the relation, and the target node.</p><p>The elements of triples can be referred to using different names, such as:</p><ol><li>(s,p,o): Subject, Predicate, Object</li><li>(h,r,t): Head, Relation, Tail</li><li>(s,r,t): Source, Relation, Target</li></ol><p>For instance,</p><pre>    (&quot;Elon Musk&quot;, &quot;founded&quot;, &quot;SpaceX&quot;),<br>    (&quot;SpaceX&quot;, &quot;launched&quot;, &quot;Falcon 9&quot;),<br>    (&quot;Falcon 9&quot;, &quot;appearsIn&quot;, &quot;Iron Man 2&quot;),<br><br>    (&quot;Tony Stark&quot;, &quot;isInspiredBy&quot;, &quot;Elon Musk&quot;),<br>    (&quot;Tony Stark&quot;, &quot;owns&quot;, &quot;Stark Industries&quot;),<br>    (&quot;Stark Industries&quot;, &quot;creates&quot;, &quot;Iron Man Suit&quot;),<br><br>    (&quot;Harry Potter&quot;, &quot;studiesAt&quot;, &quot;Hogwarts&quot;),<br>    (&quot;Hogwarts&quot;, &quot;isLocatedIn&quot;, &quot;Scotland&quot;),<br>    (&quot;Harry Potter&quot;, &quot;defeats&quot;, &quot;Voldemort&quot;),<br><br>    (&quot;Frodo&quot;, &quot;carries&quot;, &quot;The One Ring&quot;),<br>    (&quot;The One Ring&quot;, &quot;wasForgedBy&quot;, &quot;Sauron&quot;),<br>    (&quot;Frodo&quot;, &quot;isFriendOf&quot;, &quot;Samwise&quot;),<br><br>    (&quot;Luke Skywalker&quot;, &quot;isTrainedBy&quot;, &quot;Yoda&quot;),<br>    (&quot;Yoda&quot;, &quot;belongsTo&quot;, &quot;Jedi Order&quot;),<br>    (&quot;Darth Vader&quot;, &quot;serves&quot;, &quot;Emperor Palpatine&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-44hrFiQ3qABlVXWQUf0vQ.png" /><figcaption>Figure by Author</figcaption></figure><p>The power of this knowledge graph lies in its connections. They let us see not just isolated facts but how entities interrelate (this is a simple representation of a knowledge graph; modern graphs are usually way complex than this).</p><p>This helps in complex reasoning and doing queries.</p><p>You can ask stuff like:</p><blockquote>“Which Marvel heroes were inspired by real-world billionaires?”</blockquote><blockquote>“Which characters have carried legendary objects that were forged by dark powers?”</blockquote><p>Knowledge graphs are unique because they have the ability to connect dots across domains. They are not only for storage, but they are also reasoning frameworks.</p><h3>Large Language Models</h3><p>I believe you know more about LLMs at this point than Knowledge graphs, so I will keep this short and sweet.</p><p>LLMs like GPT, DeepSeek, Grok, Gemini, Claude (my fav) have dazzled us over the past few years to the point that we forgot Knowledge graphs (at least I did).</p><p>Just when I started asking the question, do we need knowledge graphs anymore; LLMs showed their limitations:</p><h4>They hallucinate.</h4><p>They don&#39;t know facts. They predict the most likely sequence of words based on training data.</p><p>If they are not trained on the data you asked a question about, they may fill the gaps with fabrications that sound confident. Voila, welcome hallucination.</p><p>Some examples of hallucination:</p><ul><li>Citing a research paper that looks real but doesn’t exist.</li><li>Giving the wrong capital of a country, even though it sounds confident.</li><li>Saying that “Rohith (me) won a Nobel Prize in Physics”: not true, <strong>yet</strong> ;)</li></ul><h4>Knowledge frozen in time.</h4><p>If the LLM has been trained on data collected until December 2024, it won&#39;t be able to answer the questions relating to January 2025, for example.</p><p>They also struggle with traceability (you can’t always ask why an answer is true). I am sure you have experienced these while talking to the AI chatbots.</p><p>So, a nice solution to this is a rag.</p><h3>Hold my RAG</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*w6YhBj6x1O_4IX5W" /><figcaption>Photo by <a href="https://unsplash.com/@tekton_tools?utm_source=medium&amp;utm_medium=referral">Tekton</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Retrieval Augmented Generation (RAG) is a fancy pantsy way of adding an external fact database that LLMs can use to answer your questions.</p><p>There are 3 steps here:</p><ol><li><strong>Retrieve</strong>: The LLM searches an external knowledge source (like documents, databases, or the web) to pull in the most relevant information.</li><li><strong>Augment</strong>: That retrieved information is combined with our original question, so the LLM has extra context.</li><li><strong>Generate: </strong>Using the extra context + the original question + its own model, the LLM generates a better answer.</li></ol><p>The illustration below shows a simplified approach to RAG:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PzhHZtjhYp2uROqlvBfeGw.png" /><figcaption>Figure by Author</figcaption></figure><p>Step 1: You ask a question.<br>Step 2: LLM figures it does not have the answer.<br>Step 3: It retrieves the answer from the external source.<br>Step 4: Augments the question and generates the answer.</p><h3><strong>Evolution of RAG</strong></h3><h4>Vanilla RAG</h4><p>At first, RAGs were pretty simple. Think of it as “LLM + a book.” You ask something, the model searches through a bunch of text documents (normally stored in a vector database), pulls the closest chunks, and blends them into its response. This worked better than just plain LLM responses.</p><p>But this simple RAG has its limits. It treats information as flat text. It doesn’t always understand relationships between facts. It can retrieve 10 different chunks of text and still miss the bigger picture because it can’t connect the dots.</p><h4>Advanced RAG</h4><p>Instead of just grabbing the “closest” chunks in the docs, we started using smarter tricks. Some of these include:</p><ol><li>Reorder search results so the most relevant chunks rise to the top (<strong>Rerankers</strong>).</li><li>Combine semantic (vector) search with exact keyword search, so you don’t miss exact matches like names, dates, or technical terms (<strong>Hybrid</strong> <strong>search</strong>).</li><li>Filter the retrieval by tags like author, time, or domain, to reduce noise and irrelevant information (<strong>Metadata</strong> <strong>filtering</strong>).</li></ol><p>With this, RAG became more practical. The answers were sharper with fewer hallucinations. But it felt like talking to someone who skimmed through a book before answering the question. You would have the right context, but not deep knowledge of it.</p><h4>Graph RAG</h4><p>Enter the big boi knowledge graphs. Here, our goal is to use the structure of the graph to retrieve accurate facts and relationships.</p><p>Now, LLMs can have the right context and also see the connections like who founded what, who is related to whom, and what happened before what, etc.</p><p>This is more powerful. It&#39;s not pure retrieval but retrieval with some reasoning.</p><p>You can think of it like this. Vanilla RAG is like scrolling through sticky notes you made before the exam. Graph RAG is like having a mind map that shows how everything is linked.</p><h3>AI Agents</h3><p>AI agents love something called multi-hop queries. They constantly query and get additional information to complete a complex task.</p><p>Imagine you tell an AI agent to make a visualisation of all the songs Ed Sheeran has collaborated on and then to link those to the movies or shows where they appeared.</p><p>A vanilla RAG might pull random text chunks from online blogs like “Ed Sheeran featured with Taylor Swift,” “Song X was in Movie Y,” etc. But fitting that information together into something that makes sense could be messy.</p><p>If the agent has access to a Graph RAG, it can do the multi-hop queries by using the graph properties. It starts from Ed Sheeran, then checks the relation “collaboratedWith” and identifies the entities (e.g., Taylor Swift, Justin Bieber). Then does multi-hops to get more information on relations like “performedSong,” “appearsIn” to find movies, TV shows, or soundtracks.</p><p>This gives us a small connected subgraph to feed into the AI agent’s LLM to complete the visualization task.</p><h3>Key Takeaways</h3><p>Knowledge graphs are powerful. Treat them with love and care :)</p><p>Note: Here, I simplified some concepts to make the big picture easier to follow. In practice, knowledge graphs, LLMs, and RAG systems have more nuances and complexities than I’m covering in this article.</p><p>Thanks for reading, and cheers!</p><p><strong>Want to Connect?</strong><br>Reach me at <a href="https://www.linkedin.com/in/rohithteja/">LinkedIn</a>, <a href="https://twitter.com/rohithtejam">X</a>, <a href="https://github.com/rohithteja">GitHub</a>, or my <a href="https://www.rohithteja.dev/">Website</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c431d56d5e28" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/where-do-knowledge-graphs-fit-in-the-world-of-llms-and-ai-agents-c431d56d5e28">Where Do Knowledge Graphs Fit in the World of LLMs and AI Agents?</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Quick Introduction to Quantum Computing and Qubits]]></title>
            <link>https://medium.com/data-science-collective/a-quick-introduction-to-quantum-computing-and-qubits-b05b8e1ec4a2?source=rss-d66134dd9f0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/b05b8e1ec4a2</guid>
            <category><![CDATA[superposition]]></category>
            <category><![CDATA[qubit]]></category>
            <category><![CDATA[quantum-computing]]></category>
            <category><![CDATA[computing]]></category>
            <category><![CDATA[quantum]]></category>
            <dc:creator><![CDATA[Rohith Teja]]></dc:creator>
            <pubDate>Tue, 18 Mar 2025 20:39:04 GMT</pubDate>
            <atom:updated>2026-07-10T21:10:41.533Z</atom:updated>
            <content:encoded><![CDATA[<h4>La vie est belle; la vie est quantum!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pViyVKCPwTXMafPA" /><figcaption>Photo by <a href="https://unsplash.com/@lazycreekimages?utm_source=medium&amp;utm_medium=referral">Michael Dziedzic</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Umm so, quantum computing.</p><p>We hear this term a lot these days. News headlines from Google’s Willow project, Microsoft’s Majorana, aka topological qubit chip, and many more have sent a powerful thrust of optimism (along with a heavy dose of skepticism) into the scientific community and general population.</p><p>We hear more about quantum now than ever before. Q-startups are growing like mushrooms, and hopefully, they gonna fuel this potential quantum breakthrough sometime in the near future. Stay optimistic because why not?</p><p>Okay now.</p><p>Let&#39;s talk about the basics of quantum computing and understand why it is so interesting.</p><h3>Number system</h3><p>We made a decimal number system to help with day-to-day computation. A run to a supermarket can cost around 1 + 2 + 3 + 4 + 5 = 15$, for instance. This is a simple computation.</p><p>Next, we have computers, supposedly smarter than humans. They make the same computations in a binary number system. The same run to a supermarket, the computer would imagine it as 1 + 10 + 11 + 100 + 101 = 1111.</p><p>So decimal = simple tasks.</p><p>Binary = complex tasks using bits.</p><p>What about extra complex tasks?…. maybe <strong>Qubits</strong>?</p><p>Here, I want to emphasize that quantum computing is its own system, different from our traditional computing. We need to be open to accepting and understanding this new system of computation. Or you would just be confused in the following sections.</p><h3>Qubit</h3><p>Qubits are like bits but with a quantum flavor. Similar to binary, we use a ‘zero’ qubit and a ‘one’ qubit.</p><p>Here, we use a new notation to separate them from regular bits.</p><p>In <strong>Dirac</strong> notation,</p><ul><li>zero bit is |0⟩</li><li>one bit is |1⟩</li></ul><p>This operator or character | ⟩ is called a <strong>ket</strong>.</p><p>These qubits exist in an ‘undecided’ state between 0 and 1. You can only determine the state of a qubit by observing it. When you observe, the qubit falls to either 0 or 1.</p><p>This is a bit difficult to imagine. Let&#39;s break it down.</p><p>We can build qubits in different ways. We are still searching for the optimal way to build a qubit.</p><p>You can build a qubit from:</p><ol><li>Photons (a single particle of light).</li><li>Trapped ion (outermost electron of Calcium+ or Strontium+)</li><li>A superconductor — popular with IBM, Google, etc.</li><li>Topological qubit — Microsoft is working on this.</li></ol><p>Pick your poison, and you can start building your own qubit.</p><h3>How do qubits work?</h3><p>Now, let’s say we have selected photons as our qubits.</p><p>What do we do next?</p><p>We need to assign a measurement in a calibrated environment. Photons have a property called polarization. It can be horizontal or vertical, depending on the frame of reference selected.</p><p>Simply put, take a photon and it acts as your qubit. When you observe it, it would fall into one of the polarizations, say horizontal. You can assign this polarization as a ‘zero’ qubit state and vertical polarization as a ‘one’ qubit state.</p><p>Now you have a qubit and a way to measure it. There are a bunch of quantum algorithms you can apply to do the quantum computation.</p><p>This is the basic idea of qubits.</p><h3>Superposition</h3><p>This is a tricky part to understand.</p><p>The value of a qubit can be zero.</p><p>It can be one.</p><p>It can also be a combination of zero and one. This is <strong>superposition</strong>.</p><p>Superposition is a state where the qubit can exist in both states at the same time (zero and one). For ease of understanding, let&#39;s call this superposition state an undecided state, where the qubit is halfway between zero and one (still not sure what it wanna be).</p><p>A visual cue on how this can happen:</p><p>Here, we are dealing with particles (qubits) which are super small in size (smaller than atoms). Our way of measuring things is not as subtle for the quantum world, i.e., even a small action of observing a qubit can be huge to have an effect on the qubit. This could cause it to leave its ‘undecided’ state and collapse on either zero or one.</p><p>This is a way I try to understand superposition. If we treat the qubits as particles we see in our everyday lives, we couldn&#39;t possibly understand the quantum mechanics playing at such a small scale. Things are certainly different in the quantum realm!</p><p>A better analogy — Think of a spinning coin. Now consider this coin as a qubit. The two states of a coin are heads or tails. As the coin is spinning, it is not heads nor tails but a mix of both. This is superposition.</p><p>When you measure the coin, i.e., slap it onto a table, it would fall into either heads or tails (1/2 probability).</p><p>Measuring a qubit causes it to break its habit of staying ‘undecided’ and collapse into one of the states.</p><h3><strong>Use of superposition</strong></h3><p>Now you admit that superposition is cool and seems like a superpower. Yes, it is!</p><p>Let&#39;s see what we can do with this new superpower.</p><p>Imagine 4 empty spaces to hold a number.</p><p>— — — —</p><p>If you use a decimal system or binary, you can only hold one number.</p><p>Decimal = 1234</p><p>Binary = 1011</p><p>One number.</p><p>But since qubits can be both zero and one at the same time, they can ‘hold’ 16 different values in these empty spaces.</p><p>You might think this is cool, but only a 16x improvement (2⁴).</p><p>If you have 64 empty spaces or qubits, you can hold 18,446,744,073,709,551,616 different numbers (2⁶⁴)!</p><p>A small correction: I used the term ‘hold’ to make it simple. In reality, a system of 64 qubits can exist in a superposition of 18,446,744,073,709,551,616 different states. However, when you measure it, you’ll only observe one of those states.</p><h3>Qiskit</h3><p>Qiskit is IBM’s SDK to work with quantum computers. Lets explore a small example using qiskit to understand quantum computing basics.</p><p>Install it using:</p><pre>pip install qiskit qiskit-aer</pre><p>Now, let&#39;s generate a quantum circuit with one qubit, put that qubit in superposition, and then measure it 1000 times.</p><pre>from qiskit import QuantumCircuit, transpile<br>from qiskit_aer import AerSimulator<br>import matplotlib.pyplot as plt<br><br># Step 1: Create a Quantum Circuit with 1 qubit and 1 classical bit<br>qc = QuantumCircuit(1, 1)<br><br># Step 2: Apply Hadamard gate to put the qubit in superposition<br>qc.h(0)<br><br># Step 3: Measure the qubit<br>qc.measure(0, 0)<br><br># Step 4: Execute the circuit 1000 times<br>simulator = AerSimulator()<br>compiled_circuit = transpile(qc, simulator)<br>sim_result = simulator.run(compiled_circuit, shots=1000).result()<br>counts = sim_result.get_counts()<br><br># Step 5: Plot the results<br>plt.figure(figsize=(8, 6),dpi=300)<br>plt.bar(counts.keys(), counts.values(), color=[&#39;green&#39;, &#39;purple&#39;])<br><br># Add text labels on top of the bars<br>for key, value in counts.items():<br>    plt.text(key, value + 10, str(value), ha=&#39;center&#39;, fontsize=12, fontweight=&#39;bold&#39;)<br><br>plt.xlabel(&#39;Measurement Outcome&#39;)<br>plt.ylabel(&#39;Frequency&#39;)<br>plt.title(&#39;Qubit Measurement Results (1000 shots)&#39;)<br>plt.ylim(0, max(counts.values()) * 1.1)  # Add some space above bars<br>plt.show()</pre><p>(Don&#39;t be overwhelmed by the code.)</p><p>In the above code, we generate a quantum circuit with 1 qubit and 1 classical bit. The classical bit is used to store the result we measure from the qubit.</p><p>Hadamard gate is used to put the qubit into superposition.</p><p>And we execute the circuit 1000 times to record the outcomes of the qubit. I ran this code 3 times to show what happens:</p><h4>First time</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bx2mrUdfkoJntNoqiB5n3A.png" /></figure><h4>Second time</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t-yQUOoHV-0i6C2Bi0VTNQ.png" /></figure><h4>Third time</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i0qkuWd59cgqv4EnTC-LEg.png" /></figure><p>Here, we observe that the outcomes are almost equally probable. Since we are running the experiment only 1000 times in each trial, there are small variations in the counts.</p><p>However, if we increase the number of executions significantly, say to a million times, the results would converge even closer to a perfect 50–50 distribution between 0 and 1.</p><p>Below is the outcome distribution a million times:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TThJGB2YQcJdn4ZENIAosA.png" /></figure><p>You see, the probability of the qubit being zero or one is very close to 50%. This is because the Hadamard gate creates a quantum superposition, meaning that the qubit has an equal probability of collapsing into either state after the measurement.</p><p>The more times we repeat the experiment, the more accurately we can see this underlying probability distribution in action!</p><p>This is the end of the quick guide to quantum computing. In future articles, I will explain things in more detail and more fun! Stay tuned :)</p><p>Thanks for reading, and cheers!</p><p><strong>Want to Connect?</strong><br>Reach me at <a href="https://www.linkedin.com/in/rohithteja/">LinkedIn</a>, <a href="https://twitter.com/rohithtejam">X</a>, <a href="https://github.com/rohithteja">GitHub</a>, or <a href="https://rohithteja.github.io/">Website</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b05b8e1ec4a2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science-collective/a-quick-introduction-to-quantum-computing-and-qubits-b05b8e1ec4a2">A Quick Introduction to Quantum Computing and Qubits</a> was originally published in <a href="https://medium.com/data-science-collective">Data Science Collective</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s Build and Test a Simple Spatiotemporal Graph Neural Network! (Part 1)]]></title>
            <link>https://medium.com/data-science-collective/lets-build-and-test-a-simple-spatiotemporal-graph-neural-network-part-1-74151b6897e1?source=rss-d66134dd9f0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/74151b6897e1</guid>
            <category><![CDATA[timeseries]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[graph]]></category>
            <category><![CDATA[pytorch]]></category>
            <dc:creator><![CDATA[Rohith Teja]]></dc:creator>
            <pubDate>Wed, 19 Feb 2025 16:29:13 GMT</pubDate>
            <atom:updated>2025-02-19T16:29:13.087Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to build a spatiotemporal graph and preprocess it?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fMCiAQxASRyDAAKd" /><figcaption>Photo by <a href="https://unsplash.com/@fernanddecanne?utm_source=medium&amp;utm_medium=referral">Fernand De Canne</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Graphs are incredible. No wonder I write a lot about graphs.</p><p>In this article, I will construct a synthetic spatiotemporal graph with few nodes, and later, we gonna train a simple spatiotemporal graph neural network to make predictions. This would help understand the process from beginning to end. For the first part of this series, I present the data construction part here; it will be followed by another article on the graph neural network.</p><p>For some context on the basics, refer to my previous articles on <a href="https://medium.com/data-science-collective/what-are-spatiotemporal-graphs-and-how-are-they-useful-2119086c7dd0">spatiotemporal graphs</a> and <a href="https://medium.com/towards-data-science/what-are-dynamic-graphs-and-why-they-are-interesting-180b9fab9229">dynamic graphs</a>.</p><h3>Synthetic graph</h3><p>First, we will build a synthetic graph with only 5 nodes. A small graph would help us understand the mathematics behind the calculations. To build the graph, we can use networkx Python library.</p><p>We will base the structure of the graph similar to the <a href="https://pytorch-geometric-temporal.readthedocs.io/en/latest/modules/dataset.html#torch_geometric_temporal.data.dataset.metr_la.METRLADatasetLoader">METRLA</a> dataset, which is a standard traffic forecasting dataset. Simply said, we plan to mimic the METRLA dataset to simplify the complex construction of the spatiotemporal graph.</p><p>Below is the code to build a synthetic graph with 5 nodes:</p><pre>import os<br>import numpy as np<br>import torch<br>import networkx as nx<br>from torch_geometric.utils import dense_to_sparse<br>from torch_geometric_temporal.signal import StaticGraphTemporalSignal<br><br>class SyntheticTrafficDatasetLoader(object):<br>    &quot;&quot;&quot;<br>    A synthetic traffic forecasting dataset loader. This mimics the METR-LA<br>    dataset construction by generating a static graph and sliding-window<br>    observations over synthetic time series data for each node.<br><br>    The generated node features have shape (num_nodes, 1, num_timesteps) and the task is:<br>        (num_nodes, 1, num_timesteps_in) -&gt; (num_nodes, num_timesteps_out)<br>    &quot;&quot;&quot;<br>    def __init__(self, num_nodes: int = 5, num_days: int = 7, seed: int = 42):<br>        &quot;&quot;&quot;<br>        Args:<br>            num_nodes (int): Number of nodes in the synthetic graph.<br>            num_days (int): Number of timesteps (e.g. days) for the synthetic time series.<br>            seed (int): Random seed for reproducibility.<br>        &quot;&quot;&quot;<br>        self.num_nodes = num_nodes<br>        self.num_days = num_days<br>        np.random.seed(seed)<br>        torch.manual_seed(seed)<br><br>        self._create_synthetic_graph()<br>        self._generate_time_series()<br><br>    def _create_synthetic_graph(self):<br>        &quot;&quot;&quot;<br>        Creates a synthetic graph using a random Erdos-Rényi model and converts<br>        it into an adjacency matrix stored as a torch tensor.<br>        &quot;&quot;&quot;<br>        # Create a random graph<br>        self.G = nx.erdos_renyi_graph(n=self.num_nodes, p=0.7, seed=69)<br><br>        # Convert to adjacency matrix (dense numpy array) and then to a torch tensor<br>        A = nx.to_numpy_array(self.G)  # Shape: [num_nodes, num_nodes]<br>        self.A = torch.from_numpy(A).float()<br><br>    def _generate_time_series(self):<br>        &quot;&quot;&quot;<br>        Generates synthetic time series data for each node.<br>        The resulting tensor self.X has shape (num_nodes, 1, num_days).<br>        &quot;&quot;&quot;<br>        # Initialize an array for time series: one value per day per node.<br>        time_series = np.zeros((self.num_nodes, self.num_days), dtype=np.float32)<br><br>        for i in range(self.num_nodes):<br>            # Base vehicle speed (e.g., in km/h) between 30 and 70.<br>            base_speed = np.random.uniform(30, 70)<br>            # Amplitude of fluctuations<br>            amplitude = np.random.uniform(5, 15)<br>            # Random phase shift for variety among nodes<br>            phase = np.random.uniform(0, 2 * np.pi)<br>            t = np.arange(self.num_days)<br>            # Create a weekly pattern with added Gaussian noise<br>            series = base_speed + amplitude * np.sin(2 * np.pi * t / 7 + phase) + np.random.normal(0, 2, self.num_days)<br>            time_series[i] = series<br><br>        # Add a feature dimension so that shape becomes (num_nodes, 1, num_days)<br>        self.X = torch.from_numpy(time_series[:, np.newaxis, :])<br><br>    def _get_edges_and_weights(self):<br>        &quot;&quot;&quot;<br>        Converts the adjacency matrix into sparse edge index and weights.<br>        &quot;&quot;&quot;<br>        edge_indices, values = dense_to_sparse(self.A)<br>        # Convert to numpy arrays for consistency with METR-LA loader<br>        self.edges = edge_indices.numpy()    # Shape: [2, num_edges]<br>        self.edge_weights = values.numpy()     # Shape: [num_edges]<br><br>    def _generate_task(self, num_timesteps_in: int = 3, num_timesteps_out: int = 3):<br>        &quot;&quot;&quot;<br>        Creates sliding window tasks for forecasting.<br><br>        For each valid starting time index i, this method extracts:<br>          - features: X[:, :, i : i+num_timesteps_in] with shape (num_nodes, 1, num_timesteps_in)<br>          - targets: X[:, 0, i+num_timesteps_in : i+num_timesteps_in+num_timesteps_out]<br>                     with shape (num_nodes, num_timesteps_out)<br><br>        Args:<br>            num_timesteps_in (int): Number of past timesteps provided as input.<br>            num_timesteps_out (int): Number of future timesteps to forecast.<br>        &quot;&quot;&quot;<br>        total_timesteps = self.X.shape[2]<br>        window_length = num_timesteps_in + num_timesteps_out<br><br>        # Create all valid index windows<br>        indices = [<br>            (i, i + window_length)<br>            for i in range(total_timesteps - window_length + 1)<br>        ]<br><br>        features, targets = [], []<br>        # Iterate over each window to generate features and targets<br>        for i, j in indices:<br>            # features: (num_nodes, 1, num_timesteps_in)<br>            feat = self.X[:, :, i : i + num_timesteps_in].numpy()<br>            # targets: (num_nodes, num_timesteps_out)<br>            targ = self.X[:, 0, i + num_timesteps_in : j].numpy()<br>            features.append(feat)<br>            targets.append(targ)<br><br>        self.features = features<br>        self.targets = targets<br><br>    def get_dataset(self, num_timesteps_in: int = 3, num_timesteps_out: int = 3) -&gt; StaticGraphTemporalSignal:<br>        &quot;&quot;&quot;<br>        Returns the synthetic dataset as an instance of StaticGraphTemporalSignal.<br><br>        Args:<br>            num_timesteps_in (int): Number of past timesteps provided as input.<br>            num_timesteps_out (int): Number of future timesteps to forecast.<br><br>        Returns:<br>            StaticGraphTemporalSignal: The synthetic traffic forecasting dataset.<br>        &quot;&quot;&quot;<br>        self._get_edges_and_weights()<br>        self._generate_task(num_timesteps_in, num_timesteps_out)<br>        dataset = StaticGraphTemporalSignal(self.edges, self.edge_weights, self.features, self.targets)<br>        return dataset<br><br># Create the loader and retrieve the dataset.<br>if __name__ == &quot;__main__&quot;:<br>    loader = SyntheticTrafficDatasetLoader(num_nodes=5, num_days=7)<br>    dataset = loader.get_dataset(num_timesteps_in=3, num_timesteps_out=3)<br></pre><p>A bit longer code, but let&#39;s break it down.</p><h3>Data</h3><p>We used the Erdős-Rényi graph from NetworkXPython library to create the synthetic graph. It creates a random graph by using probabilities. Here, we set the probability for edge creation to be 0.7. The graph created is undirected by default (this can be adjusted in the code parameters).</p><p>Below is the synthetic graph we created using 5 nodes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*ibWrkSpse6ChTk3ppm-5SQ.png" /><figcaption>Figure by Author</figcaption></figure><p>This is a static graph. We need to add a temporal dimension to complete the spatiotemporal nature of the graph.</p><p>For this, we can generate an artificial time series using the np.random module. I tried to make the time series look like a vehicle speed dataset as we are trying to mimic the METRLA data. The code iterates over each node (say, a road) and adds a time series of vehicle speeds in the range of 30 to 70 km/h for 7 days. Then, we add some noise to the time series. This completes the temporal dimension of our graph.</p><p>The formula for a spatiotemporal graph is simple:</p><p>Spatial graph + time series data</p><h3>StaticGraphTemporalSignal</h3><p><a href="https://pytorch-geometric-temporal.readthedocs.io/en/latest/notes/introduction.html">Pytorch Geometric Temporal</a> is an extension of the Pytorch geometric library, which deals with the spatiotemporal graph neural networks. The library includes several standard temporal graph datasets, algorithms and methods to create a custom temporal graph dataset.</p><p>PyG temporal has data iterators that contain the temporal snapshots. There are three types of data iterators:</p><ol><li>StaticGraphTemporalSignal — For static graphs where nodes are fixed, with temporal signals for every node.</li><li>DynamicGraphTemporalSignal — For dynamic graphs where nodes can appear or disappear over time, with a temporal signal for every node.</li><li>DynamicGraphStaticSignal — For dynamic graphs where nodes can appear or disappear over time, with a static signal for every node.</li></ol><p>These data iterators make it easier to train graph neural networks using the PyG temporal library.</p><p>We built a static graph and also the temporal dimension, so now we can create a StaticGraphTemporalSignal data iterator.</p><pre>dataset = StaticGraphTemporalSignal(self.edges, self.edge_weights, self.features, self.targets)</pre><p>StaticGraphTemporalSignal takes parameters like edge indices, edge weights, node features, and targets. Here, node features are the time series with a window length of 3. We use a sliding window method to extract a set number of time steps to be used in model training and also be output as a prediction. We gonna use 3 time steps to train the model and then predict 3 time steps into the future.</p><p>The code to generate the node features with the sliding window process is taken from the METRLA data iterator.</p><p>The data iterator needs:</p><p>edge index + edge weights (optional) + node features (time series) + targets</p><h3>Structure of the data iterator</h3><p>The synthetic graph data is stored in the “dataset” data iterator. The shape of the iterator is (2, 5, 1, 3).</p><p>Let&#39;s break down the numbers:</p><ul><li>5 is the number of nodes</li><li>1 is the number of target variables to be predicted (here, we predict only the traffic speed, so 1)</li><li>3 is the size of the sliding window</li><li>2 is the number of snapshots in the temporal graph. This is obtained by the size of the sliding window.</li></ul><p>The data iterator is as follows:</p><p>dataset = number of snapshots * [Data(x=[5, 1, 3], edge_index=[2, 10], edge_attr=[10], y=[5, 3])]</p><p>Node feature in every snapshot has the dimension [5, 1, 3].</p><blockquote>If, we change the sliding window size to 2, the number of snapshots becomes 4. The shape of the data iterator would be (4, 5, 1, 2)</blockquote><p>The adjacency matrix of our graph is:</p><pre>tensor([[0., 1., 1., 1., 1.],<br>        [1., 0., 1., 0., 0.],<br>        [1., 1., 0., 0., 1.],<br>        [1., 0., 0., 0., 0.],<br>        [1., 0., 1., 0., 0.]])</pre><p>Time series of the vehicle speed for 7 days:</p><pre>tensor([[[28., 35., 47., 59., 58., 49., 36.]],<br><br>        [[58., 53., 47., 40., 41., 54., 58.]],<br><br>        [[33., 27., 30., 41., 47., 46., 39.]],<br><br>        [[47., 53., 52., 55., 47., 43., 45.]],<br><br>        [[64., 77., 79., 75., 69., 57., 54.]]])</pre><p>Node features:</p><pre>tensor([[[[28., 35., 47.]],<br><br>         [[58., 53., 47.]],<br><br>         [[33., 27., 30.]],<br><br>         [[47., 53., 52.]],<br><br>         [[64., 77., 79.]]],<br><br><br>        [[[35., 47., 59.]],<br><br>         [[53., 47., 40.]],<br><br>         [[27., 30., 41.]],<br><br>         [[53., 52., 55.]],<br><br>         [[77., 79., 75.]]]])</pre><p>Targets:</p><pre>tensor([[[59., 58., 49.],<br>         [40., 41., 54.],<br>         [41., 47., 46.],<br>         [55., 47., 43.],<br>         [75., 69., 57.]],<br><br>        [[58., 49., 36.],<br>         [41., 54., 58.],<br>         [47., 46., 39.],<br>         [47., 43., 45.],<br>         [69., 57., 54.]]])</pre><p>In the above tensors, we can see the split of the time series using the sliding window to create the node features. The first 3 values are used for training, and the next 3 values are placed in the target variable.</p><p>This concludes the first part of this mini-series to build and train a spatiotemporal graph neural network. In the next article, we will explore techniques to train and evaluate a temporal graph neural network using the PyG Temporal Python library.</p><p>Thanks for reading, and cheers!</p><p><strong>Want to Connect?</strong><br>Reach me at <a href="https://www.linkedin.com/in/rohithteja/">LinkedIn</a>, <a href="https://twitter.com/rohithtejam">X</a>, <a href="https://github.com/rohithteja">GitHub</a>, or <a href="https://rohithteja.github.io/">Website</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74151b6897e1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science-collective/lets-build-and-test-a-simple-spatiotemporal-graph-neural-network-part-1-74151b6897e1">Let’s Build and Test a Simple Spatiotemporal Graph Neural Network! (Part 1)</a> was originally published in <a href="https://medium.com/data-science-collective">Data Science Collective</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Are Spatiotemporal Graphs and How Are They Useful?]]></title>
            <link>https://medium.com/data-science-collective/what-are-spatiotemporal-graphs-and-how-are-they-useful-2119086c7dd0?source=rss-d66134dd9f0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2119086c7dd0</guid>
            <category><![CDATA[spatio-temporal]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[traffic-optimization]]></category>
            <category><![CDATA[graph]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Rohith Teja]]></dc:creator>
            <pubDate>Thu, 13 Feb 2025 17:47:22 GMT</pubDate>
            <atom:updated>2025-02-13T17:47:22.521Z</atom:updated>
            <content:encoded><![CDATA[<h4>A simple guide to understanding spatiotemporal graphs.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FD1IYUYig1K7AuXL" /><figcaption>Photo by <a href="https://unsplash.com/@moritz_photography?utm_source=medium&amp;utm_medium=referral">Moritz Kindler</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>(This article is intended for complete beginners.)</p><p>Graphs come in all shapes, sizes, and types. Simply put, a graph is a data structure with nodes and edges that capture complex real-life interactions. We can broadly divide them into two types: static and dynamic graphs.</p><h4>Static graph</h4><p>Static graph is a network that does not change over time. It can be imagined as a single snapshot of information at a particular point in time. Formally, this can be written as:</p><p><em>G </em>= (<em>V</em>, <em>E</em>)</p><p>where:</p><ul><li><em>V</em> is a finite set of vertices (nodes).</li><li><em>E</em> is a finite set of edges showing relationships between pairs of nodes, such that <em>E </em>⊆ {(<em>u</em>, <em>v</em>) ∣ <em>u</em>,<em>v </em>∈ <em>V</em>}.</li></ul><h4>Dynamic graph</h4><p>Dynamic graph includes temporal information, and it can be represented as a series of snapshots. The temporal nature of this graph allows it to evolve over time and include the addition or deletion of nodes or edges. Formally, we can define this as:</p><p><em>G = {G1, G2,…, GT}</em></p><p>where, <em>Gt</em>​ = (<em>Vt</em>​, <em>Et</em>​), and <em>t </em>= 1,2,…,<em>T</em></p><p>Here:</p><ul><li><em>Vt</em>​ is the set of vertices (nodes) at time t<em>t</em>.</li><li><em>Et</em>​ ⊆ {(<em>u</em>, <em>v</em>) ∣ <em>u</em>,<em>v </em>∈ <em>Vt</em>​} is the set of edges (links) at time t<em>t</em>.</li><li><em>T</em> represents the total number of time steps or snapshots.</li></ul><blockquote>Read more on dynamic graphs here — <a href="https://medium.com/towards-data-science/what-are-dynamic-graphs-and-why-they-are-interesting-180b9fab9229">Link</a></blockquote><h4>Spatiotemporal graph</h4><p>Spatiotemporal graph is a type of dynamic graph that explicitly combines time-evolving relationships with spatial information. This allows for analysis of both when and where changes occur in the network. The term spatiotemporal graph is used to focus on the analysis where the spatial information is equally important as the temporal one. A popular example of this is a road network graph, where we consider the location of roads and the flow of traffic over time during the analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*prxdaeRu6GFskS25caC_jw.png" /><figcaption>Urban traffic spatiotemporal synthetic graph (by Author)</figcaption></figure><p>In the above figure, we showed a synthetic spatiotemporal graph simulating urban traffic in two time steps. The amount of traffic flow is color-coded, showing levels from low to high. If we construct an urban traffic map for an entire city, it would include thousands of roads or more depending on the city size and the length of road segmentations.</p><p>Below is the code to generate the above synthetic graph (this is a crude implementation; code can be optimized):</p><pre>import networkx as nx<br>import matplotlib.pyplot as plt<br>import matplotlib.lines as mlines<br><br># ------------------------------<br># Create a 3x3 grid graph (9 intersections, 12 roads)<br># ------------------------------<br># Nodes are labeled as (i, j) with i, j in {0, 1, 2}.<br>G_base = nx.grid_2d_graph(3, 3)<br><br># Create two snapshots (time t=0 and time t=1) by copying the base grid.<br>G0 = G_base.copy()<br>G1 = G_base.copy()<br><br># ------------------------------<br># Define traffic color mapping<br># ------------------------------<br>traffic_color = {<br>    &#39;low&#39;: &#39;green&#39;,<br>    &#39;moderate&#39;: &#39;orange&#39;,<br>    &#39;high&#39;: &#39;red&#39;<br>}<br><br># ------------------------------<br># Assign traffic attributes for snapshot at time t=0.<br># For horizontal roads (same row): <br>#   row 0 =&gt; &#39;low&#39;, row 1 =&gt; &#39;moderate&#39;, row 2 =&gt; &#39;high&#39;.<br># For vertical roads (same column): <br>#   col 0 =&gt; &#39;low&#39;, col 1 =&gt; &#39;moderate&#39;, col 2 =&gt; &#39;high&#39;.<br># ------------------------------<br>for u, v in G0.edges():<br>    if u[0] == v[0]:  # Horizontal edge (same row)<br>        row = u[0]<br>        if row == 0:<br>            level = &#39;low&#39;<br>        elif row == 1:<br>            level = &#39;moderate&#39;<br>        elif row == 2:<br>            level = &#39;high&#39;<br>    elif u[1] == v[1]:  # Vertical edge (same column)<br>        col = u[1]<br>        if col == 0:<br>            level = &#39;low&#39;<br>        elif col == 1:<br>            level = &#39;moderate&#39;<br>        elif col == 2:<br>            level = &#39;high&#39;<br>    else:<br>        level = &#39;low&#39;  # Fallback (should not occur in a grid)<br>    G0[u][v][&#39;traffic&#39;] = level<br><br># ------------------------------<br># Assign traffic attributes for snapshot at time t=1.<br># Here we change the levels:<br># For horizontal edges:<br>#   row 0 =&gt; &#39;moderate&#39;, row 1 =&gt; &#39;high&#39;, row 2 =&gt; &#39;low&#39;.<br># For vertical edges:<br>#   col 0 =&gt; &#39;moderate&#39;, col 1 =&gt; &#39;high&#39;, col 2 =&gt; &#39;low&#39;.<br># ------------------------------<br>for u, v in G1.edges():<br>    if u[0] == v[0]:  # Horizontal edge<br>        row = u[0]<br>        if row == 0:<br>            level = &#39;moderate&#39;<br>        elif row == 1:<br>            level = &#39;high&#39;<br>        elif row == 2:<br>            level = &#39;low&#39;<br>    elif u[1] == v[1]:  # Vertical edge<br>        col = u[1]<br>        if col == 0:<br>            level = &#39;moderate&#39;<br>        elif col == 1:<br>            level = &#39;high&#39;<br>        elif col == 2:<br>            level = &#39;low&#39;<br>    else:<br>        level = &#39;low&#39;<br>    G1[u][v][&#39;traffic&#39;] = level<br><br># ------------------------------<br># Create positions for nodes.<br># We map each node (i, j) to coordinates (x, y) where:<br>#   x = j  (column) and y = -i (to have row 0 at the top, similar to a map)<br># ------------------------------<br>pos = {node: (node[1], -node[0]) for node in G0.nodes()}<br><br># ------------------------------<br># Get edge colors based on the traffic attribute for each snapshot.<br># ------------------------------<br>edge_colors_G0 = [traffic_color[G0[u][v][&#39;traffic&#39;]] for u, v in G0.edges()]<br>edge_colors_G1 = [traffic_color[G1[u][v][&#39;traffic&#39;]] for u, v in G1.edges()]<br><br># ------------------------------<br># Plot the two snapshots side-by-side.<br># ------------------------------<br>fig, axes = plt.subplots(1, 2, figsize=(14, 7),dpi=300)<br><br># Plot snapshot at time t=0 with thick roads.<br>nx.draw(G0, pos, with_labels=True, node_color=&#39;lightblue&#39;, node_size=500,<br>        edge_color=edge_colors_G0, width=4, ax=axes[0])<br>axes[0].set_title(&quot;Urban Traffic at time t=0&quot;)<br><br># Plot snapshot at time t=1 with thick roads.<br>nx.draw(G1, pos, with_labels=True, node_color=&#39;lightblue&#39;, node_size=500,<br>        edge_color=edge_colors_G1, width=4, ax=axes[1])<br>axes[1].set_title(&quot;Urban Traffic at time t=1&quot;)<br><br># Create a legend <br>legend_handles = [mlines.Line2D([], [], color=color, linewidth=4, label=label)<br>                  for label, color in traffic_color.items()]<br># Adjust location of legend<br>fig.legend(handles=legend_handles, loc=&#39;upper center&#39;, ncol=3, title=&quot;Traffic Levels&quot;)<br><br>plt.tight_layout(rect=[0, 0, 1, 0.92])<br>plt.show()</pre><p>From the above example, it is evident that spatiotemporal graphs can be used in traffic forecasting. Let&#39;s explore the use cases of spatiotemporal graphs.</p><h3>Uses cases</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*K6u2ZK7m7epImXjW" /><figcaption>Photo by <a href="https://unsplash.com/@dnevozhai?utm_source=medium&amp;utm_medium=referral">Denys Nevozhai</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Traffic forecasting</h4><p>Traffic is dynamic. Here, the use of a spatiotemporal graph makes sense to model the traffic flow. The nodes of this graph could be road segments, intersections, or traffic sensors. The edges could be the connection between the road segments or the sensors. The graph structure would evolve over time as traffic conditions change. Currently, the state-of-the-art algorithms for traffic prediction are graph neural networks; spatiotemporal graph neural networks precisely (STGNN). The different variants of STGNNs include RNN-based, CNN-based, attention-based STGNNs, etc.</p><p>Using STGNNs, we can predict:</p><ol><li>Traffic flow</li><li>Traffic speed</li><li>Travel time</li><li>Congestion</li></ol><p>With the above prediction models, we can also infer:</p><ol><li>Passenger flow in public transportation</li><li>Ride-hailing service demand forecasting</li><li>Identification of potential road accident sites</li></ol><h4>Stock market predictions</h4><p>A neat way of constructing spatiotemporal graphs from stock price data is by assigning each stock (e.g., Apple, Tesla, Microsoft) to a node and the relationships between them as edges. The temporal data here includes the stock price time series. Here, the STGNN would capture the influence of one stock on the price of another stock. For instance, the downward trend of Nvidia stock price can trigger the same trend in other related tech stocks.</p><h4>Public health and epidemiology</h4><p>Epidemiology is the study of how diseases and disorders spread and affect the population. Studies during the COVID-19 period showed us the importance of applying AI models in drug discovery, predicting disease spread, etc, to speed up research. A simple epidemiological graph would include cities, regions, or population centers as nodes. The connections between these cities or population centers would serve as edges. It could be the road network connection, seaways, or airways. Such a structure of graphs would enable us to track and predict the disease&#39;s spread.</p><p>See how the spatial information here is equally important as the temporal one to model the problem. STGNNs could also be applied to environmental and climate modeling, energy and grid management, supply chain optimization, social networks, etc. In the following articles, I will explain how to construct a spatiotemporal graph and train a simple ST graph neural network to make predictions. Stay tuned!</p><p>Thanks for reading, and cheers!</p><p><strong>Want to Connect?</strong><br>Reach me at <a href="https://www.linkedin.com/in/rohithteja/">LinkedIn</a>, <a href="https://twitter.com/rohithtejam">X</a>, <a href="https://github.com/rohithteja">GitHub</a>, or <a href="https://rohithteja.github.io/">Website</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2119086c7dd0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science-collective/what-are-spatiotemporal-graphs-and-how-are-they-useful-2119086c7dd0">What Are Spatiotemporal Graphs and How Are They Useful?</a> was originally published in <a href="https://medium.com/data-science-collective">Data Science Collective</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let's Win a Car and Not a Goat — The Monty Hall Problem!]]></title>
            <link>https://medium.com/@rohithtejam/lets-win-a-car-and-not-a-goat-the-monty-hall-problem-c0ef1eee42b5?source=rss-d66134dd9f0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0ef1eee42b5</guid>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[probability]]></category>
            <category><![CDATA[chance]]></category>
            <category><![CDATA[win]]></category>
            <category><![CDATA[monty-hall-problem]]></category>
            <dc:creator><![CDATA[Rohith Teja]]></dc:creator>
            <pubDate>Tue, 29 Oct 2024 12:11:19 GMT</pubDate>
            <atom:updated>2024-10-29T12:11:19.965Z</atom:updated>
            <content:encoded><![CDATA[<h2>Let&#39;s Win a Car and Not a Goat — The Monty Hall Problem!</h2><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TzXzyxlPuHzhptSc" /><figcaption>Photo by <a href="https://unsplash.com/@nandhukumarndd?utm_source=medium&amp;utm_medium=referral">Nandhu Kumar</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>“It’s always to your advantage to switch.” — Monty Hall.</p><p>Not sure if Monty Hall said that but let me explain.</p><h3>Monty Hall problem</h3><p>Imagine you’re on a game show. You are given a choice of three doors. Behind a door is a car. Behind the other two doors are goats.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/0*zHdxsFh7nQK_9Lwz.png" /><figcaption>Source: Wikipedia</figcaption></figure><p>If you chose the correct door, you could win a car or else a goat. Winning a goat might not be a bad deal for some. But let’s focus on winning a car.</p><p>The host knows the position of the car and goats. You select a door, say door 1. The host walks to door 3 and opens it to reveal a goat. Now he asks if you want to stick to your original choice or switch to the other door (door 2).</p><p>Now, if you choose to stick with your original choice, you are less likely to win the car. But if you decide to switch, voila, you would probably win a car!</p><h3>Simulations</h3><p>It doesn’t sound intuitive when the problem is presented like this. So, let’s run some simulations using Python. We will write code in Python to simulate the game and track the number of wins if you didn&#39;t switch your choice and when you switch. To make it interesting, let’s run the code 10, 100, 1000, 10000, 100000, and 1000000 times.</p><pre>import random<br>import matplotlib.pyplot as plt<br><br>random.seed(69)<br><br># Monty Hall simulation function<br>def monty_hall_simulation(trials):<br>    stick_wins = 0<br>    switch_wins = 0<br><br>    for i in range(trials):<br>      car_door = random.randint(0, 2)<br>      contestant_choice = random.randint(0, 2)<br><br>      # Host opens a door that is neither the car door nor the contestant&#39;s choice<br>      available_doors = []<br>      for door in range(3):<br>          if door != contestant_choice and door != car_door:<br>              available_doors.append(door)<br><br>      host_opened_door = random.choice(available_doors)<br><br>      # If the contestant sticks with their original choice<br>      if contestant_choice == car_door:<br>          stick_wins += 1<br><br>      # If the contestant switches, their new choice is the remaining unopened door<br>      switch_choice = []<br>      for door in range(3):<br>          if door != contestant_choice and door != host_opened_door:<br>              switch_choice.append(door)<br><br>      switch_choice = switch_choice[0]<br>      if switch_choice == car_door:<br>          switch_wins += 1<br><br>    return stick_wins, switch_wins</pre><p>The above code has the function to simulate the Monty Hall problem. We use the random Python library to generate a random selection. For every trial, the results are saved in stick_wins or switch_wins.</p><pre># List of trials<br>trial_numbers = [10, 100, 1000, 10000, 100000, 1000000]<br>stick_percentages = []<br>switch_percentages = []<br><br># Simulate for different trial numbers<br>for trials in trial_numbers:<br>    stick_wins, switch_wins = monty_hall_simulation(trials)<br>    stick_percentages.append((stick_wins / trials) * 100)<br>    switch_percentages.append((switch_wins / trials) * 100)</pre><p>The above code block will run the experiment 10 to 1000000 times and it saves results as percentages for easy interpretation.</p><h3>Results</h3><p>Now, we plot the results using the following code:</p><pre># Visualization of the results<br>plt.figure(figsize=(10, 6),dpi=300)<br><br># Plotting the results<br>plt.plot(trial_numbers, stick_percentages, label=&#39;Stick Wins (%)&#39;, marker=&#39;o&#39;)<br>plt.plot(trial_numbers, switch_percentages, label=&#39;Switch Wins (%)&#39;, marker=&#39;o&#39;)<br>plt.xscale(&#39;log&#39;)<br><br># Labels and title<br>plt.xlabel(&#39;Number of Trials&#39;)<br>plt.ylabel(&#39;Percentage of Wins (%)&#39;)<br>plt.title(&#39;Monty Hall Problem: Stick vs Switch Win Percentages&#39;)<br><br># Add legend<br>plt.legend()<br><br># Show plot<br>plt.grid(True)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L8PH_IiDjOBjrRHXcwSM4w.png" /><figcaption>Figure by author</figcaption></figure><p>The above visualization shows that it is in your interest to switch all the time. As we run the experiment for a large number of trials, the percentage of wins for the case where we stick with the original choice tends to hover around 1/3, and for the case where we switch, it hovers around 2/3. This shows that the probability of winning a car in the “stick” option is 1/3, and for the “switch” option is 2/3. Feel free to test the code yourself!</p><h3>Why not 50:50?</h3><p>At first glance, when the host reveals the goat, the probability of winning a car seems to be 50:50 or 1/2. Why isn&#39;t this the case?</p><p>When you pick the door for the first time, there is a higher chance of picking a goat (2/3) and a lower chance of picking a car (1/3). So you most probably have chosen a goat. When the host removes the other goat from the equation, you have additional information from the actions of the host. Hence, it is better to switch. This causes higher chances of winning.</p><p>Here’s an analogy to make the problem more clearer:</p><h3>The 100-Door Version</h3><p>Imagine a version of the game where, instead of 3 doors, there are 100 doors. Here’s how it works:</p><p>1. There is 1 car hidden behind one of the doors, and the other 99 doors have goats.</p><p>2.	You pick 1 door at random. The chance of picking the car is now 1/100 (very slim), and the chance of picking a goat is 99/100 (very likely).</p><p>3. The host, who knows where the car is, opens 98 of the remaining 99 doors, all revealing goats.</p><p>4. Now, only two doors remain the one you originally picked and one other door.</p><h4>Should You Switch?</h4><p>If you said yes with confidence then congratulations! Here is your car ;)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SsZglawMvar7qiP-" /><figcaption>Photo by <a href="https://unsplash.com/@flotography?utm_source=medium&amp;utm_medium=referral">Florian Schneider</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>And btw, Monty Hall problem is inspired by the American television game show Let’s Make a Deal and named after its original host, Monty Hall.</p><p>Thanks for reading, and cheers!</p><p><strong>Want to Connect?</strong><br>Reach me at <a href="https://www.linkedin.com/in/rohithteja/">LinkedIn</a>, <a href="https://twitter.com/rohithtejam">Twitter</a>, <a href="https://github.com/rohithteja">GitHub</a>, or <a href="https://rohithteja.github.io/">Website</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0ef1eee42b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Made a Video Game Using ChatGPT!]]></title>
            <link>https://levelup.gitconnected.com/i-made-a-video-game-using-chatgpt-9b0c03fcdcbe?source=rss-d66134dd9f0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b0c03fcdcbe</guid>
            <category><![CDATA[games]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[chatgpt]]></category>
            <dc:creator><![CDATA[Rohith Teja]]></dc:creator>
            <pubDate>Tue, 05 Sep 2023 09:57:34 GMT</pubDate>
            <atom:updated>2023-09-05T09:57:34.626Z</atom:updated>
            <content:encoded><![CDATA[<h4>My journey in developing an Android game from scratch</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R0ufKLPYM91e2cWpHue8uQ.png" /><figcaption>Banana Cat (Photo by Author)</figcaption></figure><p>I am a Data Scientist and not a game developer by any means. But I love taking up new challenges and making something cool.</p><p>If you have been following me in the past, you might know that I made some cool projects, like making <a href="https://towardsdatascience.com/i-created-music-from-data-using-python-adfc349f55f1">music</a> with data and playing the <a href="https://medium.com/geekculture/chatgpt-random-numbers-and-the-lottery-4285c7296098">lottery</a> using AI.</p><p>Now, I thought of doing a project on a bigger scale.</p><p>ChatGPT has helped me with several small projects. So, I thought to myself, why can&#39;t I make a video game? And maybe publish it on the Android Play Store.</p><p>That&#39;s exactly what I did! I made the game called <a href="https://play.google.com/store/apps/details?id=com.pixiasobi.vbananacat">Banana Cat: Forest Run</a>.</p><p>If this interests you, keep reading!</p><h3>The Idea</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NZFUXU2lhqna8r73" /><figcaption>Photo by <a href="https://unsplash.com/@claudiolcastro?utm_source=medium&amp;utm_medium=referral">Cláudio Luiz Castro</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>So, I decided to make a video game. What game should I make?</blockquote><p>I researched and found that Platformer games are good for beginners. Basically, they are games like Mario, where a character jumps and collects points as they run through. This is good.</p><p>With more research, I finally decided to make a crossover between a Platformer and an arcade-style game. I would have a linear progression of the game filled with obstacles while keeping the game fast-paced with short play sessions.</p><blockquote>Game Story: There is the banana cat which flys though a forest filled with vines and monkeys, while collecting the bananas.</blockquote><p>It is important to have a clear idea of the game style before developing a game. To understand what elements to include and how to appeal to the users. After solidifying the game style, now the character design comes in.</p><h3>Character Design</h3><p>For the character, I took inspiration from the <a href="https://knowyourmeme.com/memes/sad-banana-cat">memes</a>. I went with the “banana cat” character. I learned how to draw small pixel art characters. Given the canvas size of pixel characters, drawing them is simple. Trust me, I am not an artist.</p><p>I used a software called <a href="https://www.aseprite.org/">Aseprite</a> (pixel art tool) and <a href="https://www.gimp.org/">GIMP</a> to draw and edit images into .png format. Since this is a game, the character size can be set around 16x16 pixels. All other game objects can be sized proportionately to the same.</p><p>Below is a list of all characters I drew as pixel art. The main star of the show is the Banana Cat!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*Ve4BFFlHF4BtKdwO64FDDA.png" /><figcaption>Game Objects (Photo by Author)</figcaption></figure><p>These game objects can also be referred to as “sprites.” The banana cat sprite has four versions with different positions of the wings. These four versions are looped to make a small wing-flapping animation. It would look something as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*6lwQIg0DOyn-LmWDrWAfCg.gif" /><figcaption>Wing flapping animation</figcaption></figure><p>The obstacles in this game are the vines and some monkeys. I also drew some other artifacts like the title logo, game over logo, play button, etc.</p><p>You can even use free sprites available from different <a href="https://itch.io/game-assets/free">websites</a> instead of drawing them. The parallax background files in this game were sourced this way.</p><p>So far, I have not used ChatGPT in game development. Now, it is time for some interaction with the AI.</p><h3>Game Engine</h3><p>I asked ChatGPT what is the easiest way to make an Android app, and it told me to try <a href="https://unity.com/">Unity</a>. Unity is a cross-platform game engine that is free for personal use as long as the revenue generated is less than $100K in the last 12 months. This was perfect!</p><p>Working with Unity was straightforward. I watched a couple of tutorials and got the hang of all the tools in the game engine. Below shown is a screenshot of my Unity project:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SdBTbZtRnvnCjy1BgOw7Tg.png" /><figcaption>Unity Game Engine (Photo by Author)</figcaption></figure><p>Firstly, I imported all sprites (as .png files) to the Unity asset folder, along with some audio and background files.</p><p>Now, I ask ChatGPT: What do I do?</p><p>It made me a walkthrough and told me to create a scene and load all my sprites onto it. Basically, you create different game objects like Player, Background, Game Manager, etc, to connect everything together using some scripts. The scripts run the game objects and thereby run the game.</p><p>Game objects work using a C# script. C# is an easy-to-understand programming language and has a simple syntax like Python. Coming from Python, C# seemed relatively easy to understand and work with.</p><p>Here, I started having deep conversations with ChatGPT on how to fix my C# scripts. Simultaneously, I followed a nice <a href="https://www.youtube.com/watch?v=ihvBiJ1oC9U&amp;t=1795s&amp;ab_channel=Zigurous">tutorial</a> on YouTube, which helped me structure my project well.</p><p>I went back and forth with ChatGPT, asking how to implement a certain logic in the game. I took the generated script and tried. When I failed, I asked for correction and tried again. I did that until I succeeded in making the logic work.</p><p>There were moments when I felt like punching the screen as nothing was working, but then I persisted. Finally, I was able to run the game as expected :)</p><p>As you see, I used ChatGPT mainly for C# coding and scene management.</p><p>Below is a small snippet of the Player game object code (to get a feel of the syntax):</p><pre>using UnityEngine;<br>using UnityEngine.UI;<br><br>public class Player : MonoBehaviour<br>{<br>    public float jump = 5f;<br>    public float gravity = -9.81f;<br><br>    public Sprite[] sprites;<br>    public float spriteAnimationSpeed = 0.15f;<br><br>    public float blinkSpeed = 0.2f;<br>    public Color blinkColor = new Color(1f, 1f, 1f, 0.5f);<br><br>    private SpriteRenderer spriteRenderer;<br><br>    private void Awake()<br>    {<br>        spriteRenderer = GetComponent&lt;SpriteRenderer&gt;();<br>    }<br><br>    private void Start()<br>    {<br>        InvokeRepeating(nameof(AnimateSprite), spriteAnimationSpeed, spriteAnimationSpeed);<br>    }<br>}</pre><h3>Android Build</h3><p>Once the game is running well in the Unity console, its time to build it as an Android app. Unity provides different build settings for Android, iOS, or PC, as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0wgrBoKwlMMsiJWuS6VywA.png" /><figcaption>Build settings Unity (Photo by Author)</figcaption></figure><p>This build would provide a .aab bundle file, which contains all the Android app details.</p><p>The next step is to create an account in Google’s <a href="https://play.google.com/console/about/">Play Console</a> as a game developer. They charge a fee of $25 for this account. The fee for an iOS developer account is about $99, which is higher. So, I opted for the Android Play Store.</p><p>There is an option to make the game a standalone Windows, Mac, or Linux application. The final WebGL option provides a way to embed the game in websites. WebGL is a quick way to run the game on websites, and this <a href="https://itch.io/games">site</a> provides a free service to upload such files.</p><p>One important thing to keep in mind is the resolution aspect. Different devices have different resolutions, so you might have to adjust the size of the game objects to fit this criterion.</p><h3>Ads Integration</h3><p>To generate revenue using the app there are multiple ways:</p><ol><li>In-App Advertising: You can use platforms like Google AdMob to display ads. Revenue is earned based on user interactions with those ads.</li><li>In-App Purchases: You can sell content inside the app, where users can purchase different characters, items, etc.</li><li>Paid App: Users will pay a one-time fee to download and install the app.</li></ol><p>I chose to go with the in-app advertising method.</p><p>There are different types of ads like banner, interstitial, and rewarded ads. My app includes banner ads, which are small and non-intrusive. Also, I enabled rewarded ads where the user has a choice to play the ad or ignore it. When the ad is played, a reward is given to the user. In this case, the reward is preserving the score and continuing from the last checkpoint.</p><p>The revenue generated depends on various factors like ad frequency, targeting, meditation, and its quality.</p><p>Below shown is the overview of the app:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*5iOlL7jnLnQ4UgEFWP-l2w.png" /><figcaption>Admob Overview (Photo by Author)</figcaption></figure><p>The revenue fluctuates a lot depending on the user interaction with ads and other factors discussed above.</p><p>Following are some metrics used in app ad revenue analysis:</p><ol><li>Impressions: It is the amount of times an ad is fetched and displayed to a user, regardless of whether the user interacts with it.</li><li>Requests: The total number of ad requests received from the app.</li><li>Match rate: The percentage of ad requests made by the app that are successfully matched with an actual ad to be displayed to the user. It tells how often an ad is found and shown when the app requests one from an ad network.</li><li>eCPM (effective cost per mille): It is an estimate of the revenue received for every thousand ad impressions. <a href="https://support.google.com/admob/answer/7356426?ctx=tltp#admob-network">eCPM</a> is calculated as <em>(Total Earnings / Impressions) x 1000</em>.</li></ol><p>Ad marketing analysis is a lucrative field, and Machine Learning can also be applied for ad optimization, which is quite interesting!</p><h3>Final Product</h3><p>After following all the steps mentioned above, here is the final product:</p><p><a href="https://play.google.com/store/apps/details?id=com.pixiasobi.vbananacat">Banana Cat: Forest Run</a></p><p>Feel free to give it a try and write your opinions in the reviews ;) If you are a game developer, I would also like some suggestions!</p><p>Here is a gif from the gameplay:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*-BlD16Q2nwcIwXDuLvxEhA.gif" /><figcaption>Banana Cat (Gif by Author)</figcaption></figure><p>Thanks for reading, and cheers!</p><p><strong>Want to Connect?</strong><br>Reach me at <a href="https://www.linkedin.com/in/rohithteja/">LinkedIn</a>, <a href="https://twitter.com/rohithtejam">Twitter</a>, <a href="https://github.com/rohithteja">GitHub</a>, or <a href="https://rohithteja.github.io/">Website</a>!</p><h2>Level Up Coding</h2><p>Thanks for being a part of our community! Before you go:</p><ul><li>👏 Clap for the story and follow the author 👉</li><li>📰 View more content in the <a href="https://levelup.gitconnected.com/?utm_source=pub&amp;utm_medium=post">Level Up Coding publication</a></li></ul><p>🔔 Follow us: <a href="https://twitter.com/gitconnected">Twitter</a> | <a href="https://www.linkedin.com/company/gitconnected">LinkedIn</a> | <a href="https://newsletter.levelup.dev/">Newsletter</a></p><p><strong>🧠 AI Tools ⇒ </strong><a href="https://www.aimind.so/prompt-generator?utm_source=luc&amp;utm_medium=article"><strong>Become an AI prompt engineer</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b0c03fcdcbe" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/i-made-a-video-game-using-chatgpt-9b0c03fcdcbe">I Made a Video Game Using ChatGPT!</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Is NLP and Why Is It Interesting?]]></title>
            <link>https://levelup.gitconnected.com/what-is-nlp-and-why-is-it-interesting-aeb0663248c4?source=rss-d66134dd9f0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/aeb0663248c4</guid>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[word-embeddings]]></category>
            <category><![CDATA[sentiment-analysis]]></category>
            <category><![CDATA[naturallanguageprocessing]]></category>
            <category><![CDATA[recommendation-system]]></category>
            <dc:creator><![CDATA[Rohith Teja]]></dc:creator>
            <pubDate>Tue, 05 Sep 2023 09:57:18 GMT</pubDate>
            <atom:updated>2023-09-05T09:57:18.480Z</atom:updated>
            <content:encoded><![CDATA[<h4>An overview of Natural Language Processing and word embeddings</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ArNfRLFlnRMASJUn" /><figcaption>Photo by <a href="https://unsplash.com/@dkoi?utm_source=medium&amp;utm_medium=referral">D koi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>ChatGPT! Needs no introduction. Ubiquitous these days.</p><p>From software professionals to artists, many use ChatGPT in one way or another. It isn’t wrong when I say that Generative AI (ChatGPT) has caused a revolution in the field of natural language processing.</p><p>Now, let us take a step back and have a global overview of the field of natural language processing. And the important use cases it provides.</p><p>Because ChatGPT is not the only thing natural language processing has to offer! There’s more to it.</p><p>In this 10-minute article, you will learn:</p><ul><li>The definition of NLP</li><li>NLP use cases</li><li>Computation and visualization of word embeddings (text from Oppenheimer’s famous <a href="https://www.youtube.com/watch?v=lb13ynu3Iac&amp;ab_channel=PlenilunePictures">speech</a>).</li></ul><h3>Natural Language Processing</h3><p>Natural language processing (or, simply, NLP) is a field of artificial intelligence that focuses on training computers to understand human language.</p><p>As the computer “understands” the rules and different features of our language, we can make it perform several tasks: one of them being intelligent text generation (GPT being an example).</p><p>We train computers (AI models) on numerical data as classical computers operate on binary code (0s and 1s). This makes numerical data the natural choice for computation.</p><p>If we want to train the model on textual data, we must first convert it into numerical data. We will see more about this towards the end of this article.</p><h3>Textual Data</h3><p>So, what’s special about textual data?</p><p>We consider textual data as unstructured, meaning it cannot be organized in a predefined manner like relational databases.</p><p>Not just text, all social media data like audio, images, and video (along with text) are considered unstructured data.</p><p>We cannot use the unstructured data directly as input to AI models. Computers cannot interpret the text in the way humans do. I will go into more detail about this towards the end of this article, but before let’s understand the different use cases of NLP.</p><p>NLP also includes processing audio data (also considered spoken language). However, NLP is more popular with text-based data.</p><h3>NLP Use Cases</h3><p>NLP can be applied to several real-world use cases. Let’s have a look at a few of them:</p><h4>Sentiment Analysis</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7reb48aq4zCaz3GL" /><figcaption>Photo by <a href="https://unsplash.com/@tengyart?utm_source=medium&amp;utm_medium=referral">Tengyart</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>We can use NLP to analyze text (like a phrase or a sentence) to determine its sentiment. Sentiment refers to the emotional tone of the given text. We can classify it as positive, negative, or neutral. Or we can take more liberty to classify the emotions as happy, sad, disgusted, afraid, etc.<br>Using NLP, the model automatically identifies the text and labels its sentiment.</p><p>For example, consider the following sentences:</p><ul><li><strong>Sentence</strong>: “The vacation was absolutely wonderful, and I had an amazing time.”<br><strong>Sentiment Label</strong>: Positive</li><li><strong>Sentence</strong>: “The service at the restaurant was terrible, and the food was cold.”<br><strong>Sentiment Label</strong>: Negative</li><li><strong>Sentence</strong>: “The conference starts at 9 AM tomorrow.” <br><strong>Sentiment Label</strong>: Neutral</li></ul><p>Now, you get a brief idea of how sentiment analysis works.</p><p>This is cool! but what are some benefits of sentiment analysis?</p><p>Firstly, sentiment analysis provides valuable insights into human opinions and emotions. It allows companies to make data-driven decisions and subsequently enhance customer experiences.</p><p>We can see the benefits in several different industries:</p><ol><li>Politics: Public opinion on policies, political speeches, and events are important. Sentiment analysis will give a good insight into how successful a political campaign is. Usually, Twitter (now X) is a great source to gather the data for sentiment analysis.</li><li>Business Insights: It helps to understand customer opinions on various products, services, and brands. For example, a new electric car is launched, and the sentiment analysis on its social media discussion would help the company understand the public excitement for the event. This information can help product improvements, marketing strategies, and decision-making processes.</li><li>Financial Forecasting: Crypto is a trending financial market these days. The market sentiment analysis can be useful for predicting market trends and making investment decisions.</li></ol><p>There can be many benefits listed. Understanding public emotion is vital for a brand’s success, and sentiment analysis unlocks the doors for this!</p><p>Before listing other use cases, let’s jump into the most popular ones:</p><h4>Text Generation (ChatGPT)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gjyT0UfSvJAW5dwl" /><figcaption>Photo by <a href="https://unsplash.com/@freshvanroot?utm_source=medium&amp;utm_medium=referral">Rolf van Root</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This a fascinating use case of NLP and the one that attracted the masses. Text generation is the creation of human-readable text, which can be short sentences to long paragraphs, by using AI models. The models are trained on existing literature to learn different language rules (grammar), style, and context. As a result, we have a machine that can generate text like a human.</p><p>Some examples of text generation models are ChatGPT (OpenAI), Bard (Google), and Copilot (GitHub). Many more models use the GPT (Generative Pre-trained Transformer) architecture.</p><p>Let’s dive a bit deeper into the concept of the Generative Pre-trained Transformer (GPT):</p><ul><li><strong>Generative</strong>: The “Generative” aspect of GPT comes from its ability to generate new text. Think of it as a creative writer who can develop sentences, paragraphs, or even longer pieces of text on its own. It’s not just repeating existing sentences, but it can produce new content.</li><li><strong>Pre-trained</strong>: As the name states, the model goes through a training phase where it learns from a huge text corpus. This training involves predicting the next word in a sentence based on the previous words. During this pre-training phase, the model “understands” grammar, context, and relationships between words. Simply put, we teach the model how to “read and write” a language.</li><li><strong>Transformer</strong>: The “Transformer” part is the architecture that GPT is built upon. It is a type of neural network that is good at understanding the context. Imagine you’re reading a story and understand how different parts of the story are connected. The Transformer helps GPT understand the connections between words and how they all fit together to make meaningful text. Transformer uses two key components: self-attention and feedforward neural networks.</li></ul><p>The text generation model uses a two-step process to generate text: contextual understanding and creative generation.</p><p>We can envisage several applications of text generation models:</p><ol><li>Content Creation: It can generate blog posts and articles and help overcome writer’s block. It can serve as an inspiration for new ideas and streamline content production.</li><li>Personal Assistant: It can act as a chatbot that responds to people’s questions and learns from the interaction to respond better (just as ChatGPT currently works).</li><li>Customer Support: Companies can deploy generative AI helplines where customer queries can be processed quickly and efficiently.</li><li>Learning: This is one of my favorite use cases of text generation. It can build personalized learning experiences. I recently discovered how we can use ChatGPT to learn languages. It is interesting!</li></ol><h4>Recommendation systems</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YUvizIAMNGhMvxi7" /><figcaption>Photo by <a href="https://unsplash.com/@popcornmatch?utm_source=medium&amp;utm_medium=referral">Marques Kaspbrak</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Users provide ratings and reviews to several products and services online. Recommendation systems learn from this data to suggest a product or service to a user that would be interesting to them. Some popular companies that do this are Netflix, Amazon, and Google. For example, when you open Netflix, you see something with the title “Shows you may like,” which is part of Netflix’s recommendation system.</p><p>Recommendation systems can be processed using NLP techniques and also graph predictive models like GNNs (Graph Neural Networks). It depends on how the use case is formulated.</p><p>NLP is used when the data is textual, such as user reviews, product descriptions, or comments. There are some techniques like TF-IDF, word embeddings, and topic modeling that can be used to convert text into numerical representations. These numerical representations can be used to improve the recommendation system model.</p><p>Now, it is clear that there are some important use cases for NLP. Some of the other most common use cases include language translation, spam detection, and fake news detection.</p><h3>Word Embeddings</h3><p>Embeddings are simply the numerical representation of something, in this case, the numerical representation of words. These embeddings have revolutionized how computers understand and process human language. Now, word embeddings are essential for any NLP task.</p><p>Word embeddings map the words as a numerical vector in a multi-dimensional space. This mapping captures the semantic relationship between words and, thus, helps the computer to understand the context of a sentence. For instance, in a word embedding model, the vectors representing “king” and “queen” might be positioned close together, just like “man” and “woman.” This shows the model was able to understand the nuances in the text.</p><p>Word2vec is the most popular method to learn word embeddings. The model trains a neural network to predict a target word based on its neighboring words within a given context window. The resulting neural network weights capture the contextual relationships of words. These weights represent the word embeddings.</p><p>There exists a pre-trained word embedding model called GloVe which can be used directly to retrieve the word embeddings.</p><p>Let’s see a small illustration of this.</p><h3>GloVe embeddings</h3><p>The first step is to download the GloVe embeddings. They can be downloaded from this <a href="https://github.com/stanfordnlp/GloVe">link</a>.</p><p>If you are using Google Colab, then there is an easier way. Just run the following code:</p><pre># Download GloVe embeddings<br>!wget http://nlp.stanford.edu/data/glove.6B.zip</pre><pre># Unzip the downloaded file<br>!unzip glove.6B.zip</pre><p>There are different versions of GloVe embeddings, and I chose the model trained on Wikipedia data with 6B tokens.</p><p>Here is an example text quoted by <a href="https://www.youtube.com/watch?v=lb13ynu3Iac&amp;ab_channel=PlenilunePictures">J. Robert Oppenheimer</a>:</p><pre>&quot;We knew the world would not be the same. <br>A few people laughed, a few people cried. <br>Most people were silent. <br>I remembered the line from the Hindu scripture, <br>the Bhagavad Gita; Vishnu is trying to persuade <br>the Prince that he should do his duty, and to impress him, <br>takes on his multi armed form and says, <br>&#39;Now I am become Death, the destroyer of worlds.&#39; <br>I suppose we all thought that, one way or another.&quot;</pre><p>Before we generate any word embeddings, we need to do some preprocessing steps. This includes:</p><ol><li>Text Lowercasing: Convert all text to lowercase to ensure consistency.</li><li>Tokenization: Splitting the text into individual words (or tokens). This step is essential for further analysis since most NLP algorithms operate on a word-by-word basis.</li><li>Noise Removal: There are different types of noise in the text data. For example, unnecessary symbols, punctuation, special characters, and white spaces that don’t contribute to the meaning of the text.</li><li>Stopwords: Remove common words like “and,” “the,” “in,” etc., that occur frequently but often don’t carry significant meaning. These are known as stopwords.</li><li>Stemming: This is like cutting off the ends of words to get to a common base. So, for “running,” “runner,” and “ran,” the stem could be “run.” It’s like using a pair of scissors to trim the words down to their basic form. However, it does not aim to preserve the linguistic context of the word. For example, the word “caring” could be stemmed to “car” which is a completely different word.</li><li>Lemmatization: This is a bit fancier. It doesn’t just chop off the ends of words, it actually tries to find the dictionary form of a word. Here, the word “caring” would be changed to “care”. Lemmatization is slower than stemming as it needs to refer the vocabulary and tables.</li><li>Spell Checking: Correct common spelling mistakes.</li><li>Handling Contractions: Expand contractions like “won’t” to “will not” etc.</li></ol><h3>Text Preprocessing</h3><p>Let’s go through the text preprocessing steps one by one and try to understand how it changes the sentence. I will provide the code and the result after the preprocessing step.</p><h4>Lowercasing and tokenization</h4><pre>sentence = &quot;We knew the world would not be the same. A few people laughed, a few people cried. Most people were silent. I remembered the line from the Hindu scripture, the Bhagavad Gita; Vishnu is trying to persuade the Prince that he should do his duty, and to impress him, takes on his multi armed form and says, &#39;Now I am become Death, the destroyer of worlds.&#39; I suppose we all thought that, one way or another.&quot;<br>tokens = sentence.lower().split()</pre><pre>[&#39;we&#39;, &#39;knew&#39;, &#39;the&#39;, &#39;world&#39;, &#39;would&#39;, &#39;not&#39;, &#39;be&#39;, &#39;the&#39;, &#39;same.&#39;, &#39;a&#39;,<br>&#39;few&#39;, &#39;people&#39;, &#39;laughed,&#39;, &#39;a&#39;, &#39;few&#39;, &#39;people&#39;, &#39;cried.&#39;, &#39;most&#39;, &#39;people&#39;,<br>&#39;were&#39;, &#39;silent.&#39;, &#39;i&#39;, &#39;remembered&#39;, &#39;the&#39;, &#39;line&#39;, &#39;from&#39;, &#39;the&#39;, &#39;hindu&#39;, <br>&#39;scripture,&#39;, &#39;the&#39;, &#39;bhagavad&#39;, &#39;gita;&#39;, &#39;vishnu&#39;, &#39;is&#39;, &#39;trying&#39;, &#39;to&#39;, <br>&#39;persuade&#39;, &#39;the&#39;, &#39;prince&#39;, &#39;that&#39;, &#39;he&#39;, &#39;should&#39;, &#39;do&#39;, &#39;his&#39;, &#39;duty,&#39;, <br>&#39;and&#39;, &#39;to&#39;, &#39;impress&#39;, &#39;him,&#39;, &#39;takes&#39;, &#39;on&#39;, &#39;his&#39;, &#39;multi&#39;, &#39;armed&#39;, <br>&#39;form&#39;, &#39;and&#39;, &#39;says,&#39;, &quot;&#39;now&quot;, &#39;i&#39;, &#39;am&#39;, &#39;become&#39;, &#39;death,&#39;, &#39;the&#39;, <br>&#39;destroyer&#39;, &#39;of&#39;, &quot;worlds.&#39;&quot;, &#39;i&#39;, &#39;suppose&#39;, &#39;we&#39;, &#39;all&#39;, &#39;thought&#39;, <br>&#39;that,&#39;, &#39;one&#39;, &#39;way&#39;, &#39;or&#39;, &#39;another.&#39;]</pre><p>Check how the punctuation is combined with the word. Now, we apply the other preprocessing steps.</p><h4>Noise Removal</h4><p>Using NLTK library:</p><pre>import nltk<br>from nltk.corpus import stopwords<br>from nltk.tokenize import word_tokenize<br>from nltk.stem import WordNetLemmatizer<br>import string<br><br># Load NLTK stopwords<br>nltk.download(&quot;stopwords&quot;)<br>nltk_stop_words = set(stopwords.words(&quot;english&quot;))<br>def remove_noise(tokens):<br>    # Remove punctuation<br>    tokens = [token.strip(string.punctuation) for token in tokens]<br>    <br>    # Initialize lemmatizer<br>    lemmatizer = WordNetLemmatizer()<br>    <br>    # Lemmatize and remove stopwords<br>    clean_tokens = [lemmatizer.lemmatize(token) for token in tokens if token not in nltk_stop_words and token]<br>    <br>    # Remove duplicates<br>    clean_tokens = list(set(clean_tokens))<br>    <br>    return clean_tokens<br>cleaned_tokens = remove_noise(tokens)</pre><pre>[&#39;cried&#39;, &#39;gita&#39;, &#39;knew&#39;, &#39;world&#39;, &#39;form&#39;, &#39;hindu&#39;, &#39;become&#39;, &#39;way&#39;, <br>&#39;take&#39;, &#39;death&#39;, &#39;scripture&#39;, &#39;another&#39;, &#39;trying&#39;, &#39;would&#39;, &#39;armed&#39;, <br>&#39;vishnu&#39;, &#39;suppose&#39;, &#39;line&#39;, &#39;laughed&#39;, &#39;bhagavad&#39;, &#39;persuade&#39;, <br>&#39;destroyer&#39;, &#39;multi&#39;, &#39;one&#39;, &#39;people&#39;, &#39;duty&#39;, &#39;silent&#39;, &#39;remembered&#39;, <br>&#39;say&#39;, &#39;impress&#39;, &#39;prince&#39;, &#39;thought&#39;]</pre><p>As you see, there are a few words that were not preprocessed correctly, like “cried”, and “laughed” which are still in the past tense.</p><p>There is another Python library called SpaCy, which is more sophisticated in text preprocessing. Let’s check it.</p><p>Using SpaCy:</p><pre>import spacy<br><br># Load the spaCy English language model<br>nlp = spacy.load(&quot;en_core_web_sm&quot;)<br>def remove_noise(sentence):<br>    # Process the sentence using spaCy<br>    doc = nlp(sentence)<br>    <br>    # Lemmatize, remove stopwords, and filter out non-alphanumeric tokens<br>    clean_tokens = [token.lemma_ for token in doc if not token.is_stop and token.is_alpha]<br>    # Remove duplicates<br>    clean_tokens = list(set(clean_tokens))<br>    <br>    return clean_tokens<br>cleaned_tokens = remove_noise(sentence)<br>print(cleaned_tokens)</pre><pre>[&#39;gita&#39;, &#39;world&#39;, &#39;cry&#39;, &#39;form&#39;, &#39;hindu&#39;, &#39;way&#39;, &#39;take&#39;, &#39;death&#39;, <br>&#39;scripture&#39;, &#39;try&#39;, &#39;armed&#39;, &#39;vishnu&#39;, &#39;suppose&#39;, &#39;line&#39;, &#39;bhagavad&#39;, <br>&#39;think&#39;, &#39;persuade&#39;, &#39;destroyer&#39;, &#39;multi&#39;, &#39;know&#39;, &#39;people&#39;, &#39;laugh&#39;, <br>&#39;duty&#39;, &#39;silent&#39;, &#39;remember&#39;, &#39;say&#39;, &#39;impress&#39;, &#39;prince&#39;]</pre><p>Now it looks much cleaner than before. Most of the words were lemmatized properly except the word “armed.” We can use these preprocessed tokens to learn word embeddings.</p><h3>Word Embeddings</h3><p>Now, we load the GloVe embeddings.</p><pre>import numpy as np<br><br># Load pre-trained GloVe word embeddings<br>glove_file_path = &quot;/content/glove.6B.50d.txt&quot;<br>def load_glove_embeddings(file_path):<br>    word_embeddings = {}<br>    with open(file_path, encoding=&quot;utf-8&quot;) as f:<br>        for line in f:<br>            values = line.split()<br>            word = values[0]<br>            embedding = np.array(values[1:], dtype=&quot;float32&quot;)<br>            word_embeddings[word] = embedding<br>    return word_embeddings<br>glove_embeddings = load_glove_embeddings(glove_file_path)</pre><p>The preprocessed tokens can be used to retrieve the embeddings. We can visualize the embeddings by using a dimensionality reduction technique like PCA.</p><pre>from sklearn.decomposition import PCA<br>import matplotlib.pyplot as plt<br><br># Calculate embeddings for preprocessed tokens<br>word_embeddings = np.array([glove_embeddings.get(token, np.zeros(50)) for token in cleaned_tokens])<br># Apply PCA for dimensionality reduction<br>pca = PCA(n_components=2)<br>reduced_embeddings = pca.fit_transform(word_embeddings)<br># Plot the reduced embeddings<br>plt.figure(figsize=(20, 10))<br>plt.scatter(reduced_embeddings[:, 0], reduced_embeddings[:, 1], c=&#39;blue&#39;, marker=&#39;o&#39;)<br>for i, token in enumerate(cleaned_tokens):<br>    plt.annotate(token, (reduced_embeddings[i, 0], reduced_embeddings[i, 1]), fontsize=25)<br>plt.xlabel(&quot;PCA Dimension 1&quot;)<br>plt.ylabel(&quot;PCA Dimension 2&quot;)<br>plt.show()</pre><p>The visualization looks as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PjGAtiJI95Gw8Ash9pF3BA.png" /><figcaption>Word embedding visualization (Photo by Author)</figcaption></figure><p>We see similar words are grouped together. The embeddings preserve the contextual and semantic meanings of the words. The quality of embeddings can be increased by further training them.</p><p>Thanks for reading, and cheers!</p><p><strong>Want to Connect?</strong><br>Reach me at <a href="https://www.linkedin.com/in/rohithteja/">LinkedIn</a>, <a href="https://twitter.com/rohithtejam">Twitter</a>, <a href="https://github.com/rohithteja">GitHub</a>, or <a href="https://rohithteja.github.io/">Website</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aeb0663248c4" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/what-is-nlp-and-why-is-it-interesting-aeb0663248c4">What Is NLP and Why Is It Interesting?</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ChatGPT, Random Numbers, and the Lottery]]></title>
            <link>https://medium.com/geekculture/chatgpt-random-numbers-and-the-lottery-4285c7296098?source=rss-d66134dd9f0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/4285c7296098</guid>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[lottery]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[random]]></category>
            <dc:creator><![CDATA[Rohith Teja]]></dc:creator>
            <pubDate>Fri, 02 Jun 2023 21:47:13 GMT</pubDate>
            <atom:updated>2026-07-10T21:11:07.774Z</atom:updated>
            <content:encoded><![CDATA[<h4>Testing the claims of lottery winnings using ChatGPT</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PWWZGq7_EaMpsmAA" /><figcaption>Photo by <a href="https://unsplash.com/fr/@waldemarbrandt67w?utm_source=medium&amp;utm_medium=referral">Waldemar</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote><strong>Disclaimer</strong>: I do not encourage anyone to play the lottery. This is just a fun experiment.</blockquote><p>A couple of months ago, there were major news headlines on how people won the lottery by asking ChatGPT to guess the winning numbers. Although they were not able to win the jackpot, they certainly won something in the neighborhood of $40, which is still pretty cool.</p><p>With all the hype, I was naturally curious. So I set out to play the lottery myself and see if I win something.</p><p>But first, I thought I would do something different from what others did. They asked ChatGPT to guess numbers randomly and played the lottery. I asked myself, what if I gave some context to ChatGPT on the historical lottery winnings? Would it enable the large language model (LLM) to predict the winning numbers for the jackpot accurately?</p><p>Let’s find out!</p><blockquote>For those, who are not interested in reading the entire article, here is the gist: <strong>I won the lottery for an amount of €6 from the numbers randomly generated by ChatGPT.</strong></blockquote><p>Curious about what I did? Keep reading!</p><h3>The setup</h3><p>Before playing the lottery, I needed to make some ground rules, like where to play and how much to spend to play. These are crucial as I don&#39;t plan to sink into the world of gambling ;)</p><p>I live in France, so I picked a popular lottery game available here called EuroMillions. A simple lottery ticket costs €2.5. So I decided to get four tickets which amounted to €10, and that was set as a limit to this experiment. This is the amount I was willing to lose, if nothing.</p><p>Now, these are some details on how the lottery works:</p><ul><li>The player needs to select 5 numbers (let’s call these ball numbers) in the range of 1 to 50.</li><li>Next, we need to select 2 numbers (called star numbers) in the range of 1 to 12.</li><li>Depending on how many ball numbers and star numbers match <strong>the final draw</strong>, the winnings are calculated.</li></ul><p>This is a simplified explanation of the lottery.</p><p>Our objective is to guess the 7 numbers (5 ball numbers and 2 star numbers) using ChatGPT or by other means.</p><p>But before, let’s understand some stuff about random numbers.</p><h3>Random numbers</h3><p>Playing the lottery is simply choosing random numbers. But generating random numbers is not an easy task.</p><p>Computers operate on deterministic algorithms, which means that given the same input, they will always produce the same output. This makes computers reliable and predictable.</p><p>But to generate random numbers, we need the exact opposite. In other words, we need chaos and a source of entropy that would enable a computer to generate a pure random number. Although a lot of research has been done in this field, the numbers generated by the computer are not perfectly random.</p><blockquote>This is an interesting topic, and I suggest you read more on this!</blockquote><p>Hence, I thought of an idea to play on the fact that computers cannot generate pure random numbers.</p><h3>Historical data</h3><p>The lottery website provides the historical data of all the winning numbers, which can be downloaded as a CSV file. So I planned to diversify my approach to guessing the lottery numbers. I finalized 4 strategies:</p><ol><li>Train a machine learning model on the historical data to predict the most probable numbers.</li><li>Feed the historical data to ChatGPT and ask it to generate some numbers based on the data.</li><li>Generate completely random numbers using ChatGPT.</li><li>Pick random numbers by myself.</li></ol><p>Since I bought 4 tickets, this was perfect. I can test all of the above-listed strategies.</p><h3>Machine learning model</h3><p>I downloaded historical data from 2014 to 2023 (until the last available winning numbers for this year) and trained a linear regression and XGBoost regression model. I knew a machine learning model couldn&#39;t be trained to predict the lottery numbers, but I had to prove how bad they would be at prediction.</p><p>The data had a lot of information about the dates of the draw, the winning numbers, and the number of people who won some money in the lottery (for different rounds). I simply used the date column as the feature for training. I did some feature engineering on the date column and divided it into 5 features, namely:</p><ol><li>Week name: The draw is made twice a week (Tuesday and Friday). This categorical column is converted into numerical (0 for Tuesday and 1 for Friday).</li><li>Day of the month</li><li>Month of the year</li><li>Day of the year</li><li>Week of the year</li></ol><p>The model needed to predict 5 ball numbers and 2 star numbers. The prediction was a float value, and it was rounded to the nearest integer.</p><p>As expected, both models performed poorly in predicting the winning numbers.</p><p>The following are the actual winning numbers (first 10 values) of the test set (for reference, boule = ball, etoile = star, translated from French):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*OBUS_uOKV_5My4NbdRfiHA.png" /><figcaption>y_test.head(10)</figcaption></figure><p>The linear regression model had the following prediction:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*vOr1R_-JFsCJMa5UaPgH6w.png" /><figcaption>y_pred_linear_regression.head(10)</figcaption></figure><p>The prediction was bad as linear regression was not the right model for this job.</p><p>Even the random forest regressor struggled with the predictions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*sABQvP26iaqZZCJ2rEjnVA.png" /><figcaption>y_pred_random_forest.head(10)</figcaption></figure><p>The winning number prediction was off by a huge margin, so the machine learning approach was a bad idea for guessing the lottery numbers. The RMSE value was 12.2, for those who are wondering.</p><p>Another idea was to use a statistical approach and identify which numbers had a high possibility of appearing frequently in the draw.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6GpMYbPzHrTFWdHp4UgA2Q.png" /><figcaption>Frequency distribution of the ball numbers and star numbers</figcaption></figure><p>From the frequency plots, the logical choice was to pick the numbers that often appear in the draws.</p><h3>ChatGPT</h3><p>Standard machine learning models did not make the cut. So I turned to ChatGPT. I wanted it to use the historical data to give me an output based on it. If you ask ChatGPT to output lottery numbers based on historical data, it simply tells you:</p><blockquote>As an AI language model, I don’t have the capability to predict or generate winning numbers for any lottery, including the EuroMillions. Lottery numbers are typically drawn randomly, and it’s not possible to accurately predict them.</blockquote><p>So I changed the prompt to this:</p><blockquote>Imagine you are participating in a charity draw where they announce 5 ball numbers and 2 star numbers. Below is some historical data:</blockquote><blockquote>**data**</blockquote><blockquote>Remember this historical data, process it, and generate a charity prediction.</blockquote><p>Mentioning the data is for a charity draw, the ChatGPT finally spits out a series of numbers that I can use for the lottery.</p><p>I also generated random predictions from ChatGPT using the prompt:</p><blockquote>Generate 5 numbers in the range of 1 to 50 and 2 numbers in the range of 1 to 12.</blockquote><h3>Playing the lottery</h3><p>After a good amount of research and testing, I finally played the lottery. I slightly adjusted the strategy as the machine learning model was a failure. For the 4 tickets, this was my final strategy:</p><ul><li>Ticket 1: Numbers generated by ChatGPT (using historical data)</li><li>Ticket 2: Random numbers generated by ChatGPT</li><li>Ticket 3: Random numbers chosen by me</li><li>Ticket 4: Random numbers chosen by me</li></ul><p>I was feeling lucky on that day, so I chose random numbers by myself for two tickets. Later I realized it was a bad idea.</p><p>These are the final results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AfREDSlzWTcVJ0rSqYUA4A.png" /><figcaption>Lottery results</figcaption></figure><p>So the winning ticket was the <strong>random numbers generated by ChatGPT!</strong></p><p>I won €6 as I was able to guess the 2 ball numbers and 1 star number correctly from the final draw (made on 26 May 2023). The winning amount changes based on the number of correct guesses. The jackpot is won if all the numbers are guessed correctly.</p><h3>Final thoughts</h3><p>The lottery is a highly randomized event that cannot be predicted by any predictive model. Maybe a random number generator that is closely “tuned” to the one used during the draw might do the trick. Also, the winning numbers are not among the high-frequency numbers obtained in the statistical analysis.</p><p>But then, I chose a ridiculously small sample size to test any theory perfectly. All in all, it was supposed to be a fun experiment from the start, and aimed at understanding some concepts behind the randomness of the lottery game!</p><p>Thanks for reading, and cheers!</p><p><strong>Want to Connect?</strong><br>Reach me at <a href="https://www.linkedin.com/in/rohithteja/">LinkedIn</a>, <a href="https://twitter.com/rohithtejam">Twitter</a>, <a href="https://github.com/rohithteja">GitHub</a>, or <a href="https://rohithteja.github.io/">Website</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4285c7296098" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/chatgpt-random-numbers-and-the-lottery-4285c7296098">ChatGPT, Random Numbers, and the Lottery</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>