Octonity
All articles
aigptmachine-learninggame-devmathematics

Understanding GPT from a Game Developer's Perspective

Build a mental model of GPT from the ground up using vectors, dot products, attention, and softmax — with interactive demos you can play with.

Mohammed Jawad Alsaedi
Product Developer
19 June 2026
4 min read
Understanding GPT from a Game Developer's Perspective

When developers first hear about GPT, Transformers, Attention, Embeddings, Neural Networks, and Large Language Models, it can sound complicated.

But if you already understand vectors from game development, GPT becomes much easier to understand.

At a simplified level, GPT is built from ideas like:

Vectors
Dot Products
Weighted Averages
Softmax
Probability

These are not completely foreign concepts. Game developers already use similar math for movement, direction, enemy vision, steering, and collision systems.


The Big Picture

GPT predicts the next token.

Example:

Ali likes ___

GPT may predict:

cats

The simplified flow is:

Text
 ↓
Tokens
 ↓
Vectors
 ↓
Attention
 ↓
Softmax
 ↓
Next Token Prediction

Step 1: Vectors in Game Development

A 2D vector is simply two numbers:

Vector2 position = new Vector2(3, 2);

This means:

x = 3
y = 2

In games, vectors can represent:

Position
Direction
Velocity
Acceleration

Example:

Vector2 direction = new Vector2(1, 0);

This means:

Move right

Step 2: Dot Product

The dot product measures how much two vectors point in the same direction.

Formula:

A · B = Ax * Bx + Ay * By

Example:

A = (1, 0)
B = (1, 0)

Calculation:

1 * 1 + 0 * 0 = 1

Meaning:

Same direction

Another example:

A = (1, 0)
B = (0, 1)

Calculation:

1 * 0 + 0 * 1 = 0

Meaning:

Perpendicular

Another example:

A = (1, 0)
B = (-1, 0)

Calculation:

1 * -1 + 0 * 0 = -1

Meaning:

Opposite direction

Try Dot Product Yourself

Vector dot product — interactive demo

Change the vectors and watch the dot product — the same operation GPT uses to compare meanings.

Vector A
Vector B
A · B = Ax·Bx + Ay·By
(1.0 × 1.0) + (0.0 × 0.0) = 1.00
Meaning: Similar direction · more related

Dot Product in C#

static double DotProduct(double ax, double ay, double bx, double by)
{
    return ax * bx + ay * by;
}

double result = DotProduct(1, 0, 1, 0);

Console.WriteLine(result); // 1

With arrays:

static double DotProduct(double[] a, double[] b)
{
    double sum = 0;

    for (int i = 0; i < a.Length; i++)
    {
        sum += a[i] * b[i];
    }

    return sum;
}

Step 3: From Game Vectors to Word Vectors

In games:

Vector = position or direction

In GPT:

Vector = meaning

Example:

likes = (0.6, 0.1)
cats  = (0.7, 0.2)
car   = (-0.5, 0.9)

Dot product:

likes · cats
=
0.6 * 0.7 + 0.1 * 0.2
=
0.44

Dot product:

likes · car
=
0.6 * -0.5 + 0.1 * 0.9
=
-0.21

So mathematically:

likes is more related to cats than car

This is the same dot product idea, but instead of comparing directions, GPT compares meanings.


Step 4: Attention

Suppose the sentence is:

Ali likes cats

And the current word is:

likes

GPT asks:

Which words should I pay attention to?

Use simple 2D vectors:

Ali   = (1, 0)
likes = (2, 1)
cats  = (2, 2)

Now compare likes with every word.

likes · Ali   = 2
likes · likes = 5
likes · cats  = 6

So we get scores:

Ali   = 2
likes = 5
cats  = 6

These scores are called attention scores.

But they are not probabilities yet.


Step 5: Softmax

Softmax converts raw scores into probabilities.

Formula:

Softmax(xᵢ) = eˣⁱ / Σ(eˣ)

Input:

[2, 5, 6]

Output:

Ali   = 1.33%
likes = 26.52%
cats  = 72.15%

Meaning:

When GPT processes "likes", it should mostly focus on "cats".

Try Softmax Yourself

Softmax — interactive demo

Add tokens, change their scores, and watch softmax turn raw scores into probabilities.

1.32%
Score: 2.0
26.54%
Score: 5.0
72.14%
Score: 6.0

Softmax in JavaScript

The interactive demo above uses this logic:

function softmax(values) {
  const max = Math.max(...values);

  const expValues = values.map(value =>
    Math.exp(value - max)
  );

  const sum = expValues.reduce(
    (total, value) => total + value,
    0
  );

  return expValues.map(value => value / sum);
}

The max part is used for numerical stability.

Instead of:

Math.exp(value)

we use:

Math.exp(value - max)

This prevents very large numbers from causing overflow.


Softmax in C#

using System;
using System.Linq;

class Program
{
    static void Main()
    {
        double[] scores = { 2, 5, 6 };
        string[] labels = { "Ali", "likes", "cats" };

        double[] probabilities = Softmax(scores);

        for (int i = 0; i < scores.Length; i++)
        {
            Console.WriteLine(
                $"{labels[i]}: {probabilities[i]:P2}");
        }
    }

    static double[] Softmax(double[] scores)
    {
        double max = scores.Max();

        double[] expValues = scores
            .Select(score => Math.Exp(score - max))
            .ToArray();

        double sum = expValues.Sum();

        return expValues
            .Select(value => value / sum)
            .ToArray();
    }
}

Output:

Ali: 1.33%
likes: 26.52%
cats: 72.15%

Step 6: Weighted Average

After Softmax, GPT has probabilities:

Ali   = 0.013
likes = 0.265
cats  = 0.722

Now it combines the word vectors:

0.013 * Ali
+
0.265 * likes
+
0.722 * cats

This creates a new vector.

The word likes now contains information from:

Ali
likes
cats

This new vector is called a contextual embedding.


Step 7: Final Prediction

At the end, GPT creates scores for possible next tokens.

Example:

dog = 2.1
cat = 5.8
car = 0.4

Softmax converts them:

dog = 2%
cat = 97%
car = 1%

GPT chooses the highest probability token:

cat

So the output becomes:

Ali likes cats

What Real GPT Adds

This article is simplified.

Real GPT also has:

Query vectors
Key vectors
Value vectors
Multi-head attention
Feed-forward neural networks
Layer normalization
Residual connections
Many transformer layers
Billions of learned parameters

But the foundation is still:

Vectors
Dot Products
Softmax
Weighted Averages
Probability

Does GPT Replace Classic Machine Learning?

No.

GPT is powerful, especially for text, reasoning, summarization, code, and language tasks.

But classic machine learning is still very useful for:

Fraud detection
Price prediction
Churn prediction
Risk scoring
Recommendation systems
Anomaly detection
Structured business data

For example, if you have transaction data:

Amount
Country
Device
Customer age
Transaction count

and you want to predict:

Fraud or not fraud

A classic ML model like:

Logistic Regression
Random Forest
XGBoost
LightGBM

may be faster, cheaper, and easier to explain than GPT.


Final Takeaway

For a game developer, GPT is not magic.

It is mostly:

Vector math
+
Probability
+
A lot of training

The same math used for:

Movement
Enemy vision
Steering
Direction checks

also appears inside modern AI systems.

The difference is what the vectors represent.

Game Development:
Vector = position or direction

GPT:
Vector = meaning

Once you understand vectors, dot products, and Softmax, the foundation of GPT becomes much easier to understand.

Mohammed Jawad Alsaedi
Product Developer at Octonity

Try Octonity for your team

Plan, create, and publish across every channel from one workspace. Free plan available — no credit card.