Generative AI: The Magic Behind the Curtain

Shubham BhattShubham Bhatt
4 min read

Ever been amazed by something that seems too good to be true? Like when you type a few words and AI comes up with a perfect story, code, or even makes a drawing? It’s easy to think it’s magic, but trust me—there’s no magic wand involved. It’s just AI learning to make guesses and predictions based on patterns it’s seen. Let’s take a quick, fun journey to understand how this works.


What Is Generative AI?

Imagine you’re at a party, and you need to tell a joke. But you can’t remember one. So, you start guessing the punchline based on what you remember about other jokes. Generative AI works similarly—it guesses new content (like text, images, or music) based on patterns it has learned, but it’s never truly understanding the content like a human. It’s more like an expert guesser.🤓


Breaking It Down: How Does It Work?

Tokenization: Breaking Down the Puzzle🧩

Okay, so let's say you’re at home, and you need to solve a math problem in front of your parents (we've all been there). You write something like 5 × 2 = 15. Big mistake. What happens next? Chataak!👋 (Yeah, a slap, right?). So, you rethink the answer—should it be bigger or smaller? You try again, write 8, and boom, another chataak! That’s fine-tuning.

Now, when Generative AI handles a sentence, it doesn’t deal with the whole thing at once. It breaks the sentence into pieces. Every word or punctuation mark is like a “token.” Think of each token as a little puzzle piece—like each answer to your math question. And just like your parents slap the wrong answer out of you, the AI’s "training" adjusts these tokens to make sure it gets the right answer (no slaps needed though).🙅‍♂️

Check out how your sentence breaks down into tokens in real time — pretty cool, right?

Here’s the Transformer model — the magical engine behind GPT and many other AI marvels!

GPT - Generative Pre-trained Transformer


Vectors and Embeddings: Turning Tokens into Numbers🔢

After breaking the sentence into tokens, AI needs to understand these pieces. But, since AI doesn’t speak human languages, it turns tokens into numbers. Each word becomes a vector—a kind of numeric "DNA"🧬 that shows what the word means in relation to others.

Example: If you type “dog,” AI assigns a number to it. If you type “cat,” that number is close to “dog,” because both are animals. But if you say “car,” that number is very different. It’s like how you’d distinguish between your school bestie and a random person in the crowd. The AI knows which words are similar, and which are far apart.


Positional Encoding: Understanding Order (Not Just Timing)

If you were hanging out on the Delhi streets with your friends, you’d know who’s walking first, who’s second, and who’s trailing behind, right? AI works the same way—understanding the order of words is key. Without positional encoding, it would be like mixing up the sequence of your favorite Bollywood song.🎶 Imagine if “Dilwale Dulhania Le Jayenge” was called “Le Jayenge Dilwale Dulhania”—confusing, right?

Positional encoding helps AI know the order of words. So, if it sees “Iron Man defeats Thanos,” it knows who’s doing what. It doesn’t get confused with word order like some of us (cough, me, during exams) do!😅


Attention Mechanisms: The Art of Focus (Not Just on a Cute Girl)

Let’s say you’re chilling at a beach🏖️, and you notice this cute girl. Now, what do you notice first? Her hair color? Her age? Or maybe how the waves are crashing? If you’re like me, you’re focusing on all these things at once 😎. This is called multi-head attention.

AI works similarly. When analyzing a sentence, it doesn’t treat every word the same. Some words get more “attention.” Like when you’re reading a romantic movie script, you don’t focus on the word "and" but on words like “kiss,” “love,” or “moment.” That’s AI’s way of figuring out what’s important in a sentence—giving extra attention to the parts that matter most.


Two Big Things Behind GPT’s Power (And No, Not What You’re Thinking… Or Are You?😏)

You know when you’re at the beach, and you can’t help but notice two big things—yeah, those two big things that catch your eye immediately? Well, GPT has two big things too that make it work:

  1. Training🎓
    This is where the model learns by making guesses and fixing mistakes—kind of like when you try to impress that girl but fumble a line and have to adjust your game.

  2. Inferencing
    This is when the model uses what it learned to actually respond or create something new—like finally nailing that pick-up line perfectly on the second try.

Basically, GPT spends a lot of time practicing before it performs for you, just like you (hopefully) practice before a big moment.


Wrap-Up: No Magic, Just Data and Math📊🧠

Generative AI may feel like a magic trick, but it's all about data, math, and learning. The more it practices (just like you with dance steps or solving problems in front of your parents), the better it gets. So, next time you use it, remember: there’s no magic, just pure tech wizardry.✨

11
Subscribe to my newsletter

Read articles from Shubham Bhatt directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shubham Bhatt
Shubham Bhatt