Sitemap
Mohammad Atif

Mohammad Atif

AI Developer passionate about problem-solving with expertise in AI, its subfields, and Power BI for data analysis & visualization

TensorFlow Explained: A Complete Guide From Basics to Transformers and LLMs

21 min readOct 21, 2026

--

Press enter or click to view image in full size

Introduction

Have you ever wondered how your phone recognizes your face, how YouTube suggests videos you like, or how Google Translate changes one language into another? Behind many of these tools, a powerful library works quietly in the background. One of the most famous is TensorFlow.

When you start learning Artificial Intelligence, Machine Learning, or Deep Learning, you will hear the name TensorFlow again and again. In this article, we will learn what TensorFlow is, how it works, which tools come with it, and how it connects with Transformers and Large Language Models (LLMs), the technology behind modern AI chatbots. We will also build a tiny Transformer step by step, so you can see exactly what happens inside.

Let’s start from the very beginning.

What is TensorFlow?

TensorFlow is a free and open-source library for building and training machine learning models.

It was created by the Google Brain team and released to the public in 2015. Today, students, researchers, startups, and big companies around the world use it.

Think of TensorFlow as a big toolbox. Inside it, you get everything you need to:

  • Prepare your data
  • Build a neural network
  • Train the model
  • Test the model
  • Deploy it on a website, a mobile app, or a server

TensorFlow mainly works with the Python language, but it also supports JavaScript, C++, and Java.

Why is it Called “TensorFlow”?

The name has two parts.

1. Tensor: A tensor is a container for numbers. It is like a table of numbers that can have many dimensions.

  • A single number is called a scalar (example: 5)
  • A list of numbers is called a vector (example: 1, 2, 3)
  • A table of numbers with rows and columns is called a matrix
  • A bigger table with more dimensions is called a tensor

For example, a black and white picture is a 2D table of pixel numbers. A color picture is a 3D tensor (height, width, and color channels).

2. Flow: In TensorFlow, numbers (tensors) “flow” through a series of mathematical operations. This chain of operations is called a computation graph.

So the name simply means: numbers flowing through a network of calculations.

Why Do We Need TensorFlow?

You can write machine learning code from scratch, but it is slow and difficult. Deep learning needs a lot of math, such as matrix multiplication and derivatives. TensorFlow does this hard work for you.

1. It saves time. You can build a neural network in just a few lines of code.

2. Automatic differentiation. Training a model needs gradients (a kind of derivative). TensorFlow calculates them automatically, so you do not need to do the hard math by hand.

3. GPU and TPU support. Deep learning is slow on a normal CPU. TensorFlow can use a GPU (Graphics Processing Unit) or a TPU (Tensor Processing Unit, made by Google) to train models much faster.

4. It works everywhere. The same model can run on a laptop, a server, a website, or even a low-cost Android phone.

5. Big community. There are many tutorials, free courses, and forums, so help is easy to find.

Key Features of TensorFlow

1. Keras: The Easy API

Keras is the high-level interface of TensorFlow. It is simple and readable. Most beginners start with Keras because building a model feels like stacking Lego blocks.

2. Eager Execution

In TensorFlow 2.x, code runs line by line, just like normal Python. This makes it easy to test and fix mistakes.

3. tf.data

This is a tool to load, clean, and prepare large datasets efficiently. It is very useful when your data is too big to fit in memory.

4. tf.function and Graph Mode

When you add the tf.function decorator to a function, TensorFlow converts it into an optimized graph. This makes your code run faster.

5. Distributed Training

You can train a big model on many GPUs or many machines at the same time using tf.distribute.

6. Cross-Platform Deployment

You can deploy models almost anywhere, as you will see in the next section.

The TensorFlow Ecosystem

TensorFlow is not just one library. It is a full family of tools:

  • TensorFlow Core: The main library for building and training models.
  • Keras: An easy, high-level API for building neural networks.
  • TensorBoard: A dashboard to see graphs of loss, accuracy, and model structure.
  • TensorFlow Lite (now called LiteRT): Runs models on mobile phones and small devices.
  • TensorFlow.js: Runs models inside the web browser using JavaScript.
  • TensorFlow Serving: Serves models to many users in production.
  • TFX (TensorFlow Extended): A full pipeline for production machine learning.
  • Kaggle Models (earlier TensorFlow Hub): A place to download pre-trained models.

For example, you can train a plant disease detection model for farmers, convert it to TensorFlow Lite, and run it on a basic Android phone without needing internet. This is a very practical use of AI.

Installing TensorFlow

Open your terminal or command prompt and run this command:

pip install -q tensorflow

To check that it works, run this in Python:

import tensorflow as tf
print(tf.__version__)

If you see a version number, everything is ready.

Tip: If you do not have a powerful laptop or GPU, do not worry. You can use Google Colab or Kaggle Notebooks. Both give you free GPU access in the browser, and both are great for learning and projects.

Your First Steps with TensorFlow

Working with Tensors

import tensorflow as tf

a = tf.constant([1, 2, 3])
b = tf.constant([4, 5, 6])
print(a + b)

The output is [5 7 9]. TensorFlow adds the two tensors element by element.

Building a Simple Neural Network

Let’s build a small model that recognizes handwritten digits. It uses the famous MNIST dataset, which is like the “Hello World” of deep learning.

import tensorflow as tf
from tensorflow import keras
df = keras.datasets.mnist.load_data()
import matplotlib.pyplot as plt

# Unpack the dataset tuple we loaded earlier into df
(x_train, y_train), (x_test, y_test) = df

# Let's inspect the shapes of our arrays
print(f"Training images shape: {x_train.shape}")
print(f"Training labels shape: {y_train.shape}")
print(f"Test images shape: {x_test.shape}")
print(f"Test labels shape: {y_test.shape}")
# Plot the first 10 images in the training set
fig, axes = plt.subplots(2, 5, figsize=(10, 5))
axes = axes.ravel()

for i in range(10):
axes[i].imshow(x_train[i], cmap='gray')
axes[i].set_title(f"Label: {y_train[i]}")
axes[i].axis('off')

plt.tight_layout()
plt.show()
Press enter or click to view image in full size
x_train, x_test = x_train / 255.0, x_test / 255.0

model = keras.Sequential([
keras.layers.Flatten(input_shape=(28, 28)),
keras.layers.Dense(128, activation="relu"),
keras.layers.Dense(10, activation="softmax")
])

model.compile(
optimizer="adam",
loss="sparse_categorical_crossentropy",
metrics=["accuracy"]
)

model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test, y_test)

What did we just do?

  1. Loaded the data: images of handwritten numbers.
  2. Normalized it: divided by 255 so pixel values become small numbers between 0 and 1.
  3. Compiled it: chose an optimizer (how the model learns), a loss (how wrong the model is), and a metric (how we measure success).

compile sets up how the model will learn. Nothing is trained yet. Training starts later with model.fit(...).

optimizer="adam"
This decides how the model fixes its weights after each mistake. Adam is a smart, popular choice that adjusts the size of each step by itself. In PyTorch this was the line torch.optim.Adam(...).

loss="sparse_categorical_crossentropy"
This measures how wrong the model is. Let’s break the name into three parts:

categorical: there are many classes (digits 0 to 9).

crossentropy: the loss is small when the model is confident and right, and very big when it is confident and wrong.

sparse: the correct answers are plain numbers like 7, not long lists like [0,0,0,0,0,0,0,1,0,0].

For example, if the image is a “7” and the model gives 7 a 90% score, the loss is small. If it gives 7 only 5%, the loss is big. In PyTorch this was loss_fn = ....

metrics=["accuracy"]
This shows how many answers were correct, for example 92 out of 100. It is only for you to read. The model does not learn from it, only from the loss.

  1. Trained it: the model looked at the data 5 times (epochs {If you have 60,000 images, one epoch = the model looked at all 60,000 images once. epochs=5 means it repeats this 5 times, so it sees every image 5 times.} ) and improved.
  2. Evaluated it: checked how well it works on new images.
  3. Built the model: a Flatten layer, one hidden Dense layer, and an output layer with 10 neurons (one for each digit from 0 to 9).

Layer 1: Flatten(input_shape=(28, 28))

Your image is a grid of 28 × 28 pixels, like a small square photo. This layer opens the grid into one long line of 784 numbers (28 × 28 = 784). It does no learning. It only changes the shape.

Why do we change the shape?
The next layer, Dense, can only read a single line of numbers, not a grid. Think of each Dense worker as having 784 buttons in a row, and every button has its own weight (importance). A grid has rows and columns, so there is no single row of buttons to attach the weights to.

Flatten joins the rows end to end:

Row 1: [a b c]
Row 2: [d e f] → [a b c d e f g h i]
Row 3: [g h i]

Same numbers, same order. Nothing is lost, only the shape is different.

Layer 2: Dense(128, activation="relu")
This layer has 128 small “workers” (neurons). Each worker looks at all 784 numbers and finds a pattern, like a curve or a straight line. relu is a simple rule: if a worker’s answer is negative, make it 0, and keep it if it is positive.

Layer 3: Dense(10, activation="softmax")
This layer has 10 workers, one for each answer (for example, digits 0 to 9). Each worker gives a score for its digit. softmax changes the scores into percentages that add up to 100%, and the highest one is the model’s answer.

This is the basic workflow of almost every deep learning project:

Data → Model → Compile → Train → Evaluate → Deploy

import numpy as np

# Take one image from the test set (pretend it is a new image)
img = x_test[0] # shape (28, 28)

# The model expects a batch, so add one extra dimension
img_batch = np.expand_dims(img, axis=0) # shape (1, 28, 28)

prediction = model.predict(img_batch) # 10 scores
print(prediction)

digit = np.argmax(prediction) # position of the highest score
print("Model says:", digit)
print("Real answer:", y_test[0])

plt.imshow(img, cmap="gray")
plt.title(f"Predicted: {digit}")
plt.show()
predictions = model.predict(x_test[:10])
print(np.argmax(predictions, axis=1)) # 10 answers
print(y_test[:10]) # real answers
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 125ms/step
[7 2 1 0 4 1 4 9 6 9]
[7 2 1 0 4 1 4 9 5 9]
from PIL import Image

img = Image.open("/content/ten05.png").convert("L") # "L" = gray
img = img.resize((28, 28)) # same size as MNIST
img = np.array(img) / 255.0 # same scaling as training

# MNIST digits are white on a black background.
# If your digit is black on white, flip it:
img = 1 - img

pred = model.predict(np.expand_dims(img, axis=0))
print("Model says:", np.argmax(pred))
model.save("mnist_model.keras")
from tensorflow import keras
import numpy as np

model = keras.models.load_model("mnist_model.keras")

# Now use it directly, no training needed
pred = model.predict(np.expand_dims(x_test[0], axis=0))
print(np.argmax(pred))
from google.colab import files
files.download("mnist_model.keras")

How TensorFlow Works Inside

When you train a model, three main things happen again and again:

  1. Forward pass: Input data goes through the layers and the model makes a prediction.
  2. Loss calculation: The model compares its prediction with the real answer and finds the error.
  3. Backward pass (backpropagation): TensorFlow calculates gradients using a tool called GradientTape. Then the optimizer updates the weights to reduce the error.

This cycle repeats thousands of times until the model becomes good.

TensorFlow and Transformers

Now comes the exciting part.

What is a Transformer?

A Transformer is a type of neural network architecture introduced in 2017 in a famous research paper called “Attention Is All You Need” by Google researchers.

Before Transformers, models like RNN and LSTM read text word by word, one after another. This was slow, and they often forgot earlier words in long sentences.

Transformers solved this with an idea called Self-Attention. It lets the model look at all the words in a sentence at the same time and decide which words are important for understanding each other.

For example, read this sentence:

“Ali gave the book to Ahmed because he was his friend.”

The model must understand who “he” refers to. Self-attention helps the model connect “he” with the correct person by paying more attention to the relevant words.

Main Parts of a Transformer

  • Embeddings: Turn words into numbers (vectors).
  • Positional Encoding: Tell the model the order of words, since it reads all words together.
  • Multi-Head Attention: Look at the sentence from many angles at once.
  • Feed-Forward Layers: Process the information further.
  • Layer Normalization and Residual Connections: Keep training stable.
  • Encoder and Decoder: The encoder understands the input, and the decoder generates the output.

How a Transformer Works Inside: A Step-by-Step Example

Reading the list of parts is not enough. Let’s follow one tiny sentence through a Transformer and see what happens at every step. Our sentence is:

“I love eating biryani”

We want the model to predict the next word. A good answer would be something like “every” or “daily”.

Step 1: Tokenization (Words to Numbers)

A computer cannot read words. It only understands numbers. So the first step is to break the text into small pieces called tokens, and give each token an ID number from a dictionary called the vocabulary.

Imagine our tiny vocabulary is:

  • I = 0
  • love = 1
  • eating = 2
  • biryani = 3

Now our sentence becomes: [0, 1, 2, 3]

In real LLMs, tokens are often parts of words, not full words. For example, the word “unhappiness” may become “un”, “happi”, and “ness”. The vocabulary has around 30,000 to 200,000 tokens.

Step 2: Embeddings (Numbers to Meaning)

An ID like 3 does not tell the model anything about meaning. So each ID is converted into a list of numbers called an embedding vector. This vector is learned during training. Words with similar meanings end up with similar vectors. For example, “biryani” and “pulao” will be close to each other, and far from “airplane”.

In our tiny example, each word gets a vector of 8 numbers. So our 4 words become a table of 4 rows and 8 columns. Real models use vectors with thousands of numbers.

Here is how this looks in TensorFlow:

import tensorflow as tf

ids = tf.constant([[0, 1, 2, 3]])

embedding = tf.keras.layers.Embedding(input_dim=4, output_dim=8)

x = embedding(ids)

print(x.shape)

The output is (1, 4, 8). It means: 1 sentence, 4 tokens, 8 numbers per token. This shape (batch, tokens, features) is the most important shape to remember in Transformers.

Step 3: Positional Encoding (Adding the Word Order)

A Transformer looks at all words at the same time, so it does not know which word came first. But order matters a lot. “Ali beat Ahmed” and “Ahmed beat Ali” have different meanings.

To fix this, we add a position vector to each word vector. Position 0 gets one vector, position 1 gets another, and so on. After adding, each token vector carries two things: what the word is, and where it is in the sentence.

Step 4: Self-Attention (The Heart of the Transformer)

This is the most important step. Self-attention lets every word look at every other word and decide how much attention to give to each one.

For each word, the model creates three vectors using three learned weight matrices:

  • Query (Q): “What am I looking for?”
  • Key (K): “What do I contain?”
  • Value (V): “What information will I give if you choose me?”

Think of it like a library. You have a question (Query). Every book has a title on its cover (Key). You compare your question with every title. The books that match best get more of your attention, and you read their content (Value).

Get Mohammad Atif’s stories in your inbox

Join Medium for free to get updates from this writer.

The steps are:

  1. Compare the Query of one word with the Keys of all words. This gives a score for each word.
  2. Divide the scores by the square root of the vector size, to keep numbers stable.
  3. Apply softmax. This turns scores into percentages that add up to 100%.
  4. Use these percentages to take a weighted mix of the Value vectors.

Let’s say the word “biryani” is looking at the other words. After softmax, the attention weights might look like this:

  • I: 5%
  • love: 15%
  • eating: 60%
  • biryani: 20%

This means the word “biryani” pays most attention to “eating”. The new vector for “biryani” is now a mix: 60% of the information from “eating”, 20% from itself, 15% from “love”, and 5% from “I”. So “biryani” now understands that it is something being eaten, and that someone loves it.

Here is the same idea in TensorFlow code:

import tensorflow as tf

d = 8

Wq = tf.keras.layers.Dense(d, use_bias=False)
Wk = tf.keras.layers.Dense(d, use_bias=False)
Wv = tf.keras.layers.Dense(d, use_bias=False)

Q = Wq(x)
K = Wk(x)
V = Wv(x)

scores = tf.matmul(Q, K, transpose_b=True) / tf.math.sqrt(float(d))
weights = tf.nn.softmax(scores, axis=-1)
output = tf.matmul(weights, V)
print(weights.shape)
print(output.shape)

The weights have shape (1, 4, 4). This is a table where each row shows how much one word pays attention to all four words. The output has shape (1, 4, 8), the same as the input, but now each word vector is enriched with information from the other words.

Step 5: The Causal Mask (Why LLMs Cannot See the Future)

When an LLM is learning to predict the next word, it must not be allowed to peek at the answer. So when the model reads “I love”, it should not see “eating” or “biryani”.

To do this, we use a causal mask. It blocks every word from looking at the words that come after it. So:

  • “I” can see only “I”
  • “love” can see “I” and “love”
  • “eating” can see “I”, “love”, and “eating”
  • “biryani” can see all four words

In code, it looks like this:

mask = tf.linalg.band_part(tf.ones((4, 4)), -1, 0)
scores = scores + (1.0 - mask) * -1e9
weights = tf.nn.softmax(scores, axis=-1)

The blocked positions get a very big negative number, so softmax turns them into almost zero. This one idea is what makes models like GPT able to write text one word at a time.

Step 6: Multi-Head Attention (Many Viewpoints)

One attention calculation looks at the sentence in only one way. But a sentence has many kinds of relationships: grammar, meaning, who did what, and so on. So the Transformer runs several attentions at the same time. Each one is called a head.

One head may learn to connect verbs with their subjects. Another may connect adjectives with nouns. Another may track names. The results of all heads are joined together. Keras gives you this ready-made as MultiHeadAttention, so you do not need to write the steps above every time.

Step 7: Feed-Forward Network (Thinking Time)

After attention collects information from other words, each word goes through a small neural network on its own. This is usually two Dense layers. You can think of attention as “gathering information” and the feed-forward network as “thinking about it”. Many researchers believe a lot of the facts that a model remembers are stored in these layers.

Step 8: Residual Connections and Layer Normalization

After attention and after the feed-forward network, the model does two small but important things:

  • Residual connection: It adds the original input back to the output. This is like keeping a copy of the original notes while you add new notes on top. It helps very deep models train without losing information.
  • Layer normalization: It keeps the numbers in a healthy range, so training stays stable.

Steps 4 to 8 together form one Transformer block. A small model may stack 6 blocks. A big LLM may stack 80 or more blocks. Each block makes the understanding of the sentence a little deeper.

Step 9: Output and Prediction

After the last block, we take the final vector of the last word (“biryani”) and pass it through one Dense layer. This layer has one neuron for each word in the vocabulary. The result is a score for every possible next word. We apply softmax to turn the scores into probabilities. For example:

  • every: 30%
  • daily: 25%
  • with: 15%
  • because: 5%
  • airplane: 0.0001%

The model picks the next word from these probabilities. This is how an LLM chooses its answer.

Putting It All Together: A Tiny Transformer in TensorFlow

Now let’s put all the steps into one small working model using Keras. First, we create a layer that does token embedding and position embedding together:

import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers

class TokenAndPosition(layers.Layer):
def __init__(self, seq_len, vocab_size, d_model):
super().__init__()
self.tok = layers.Embedding(vocab_size, d_model)
self.pos = layers.Embedding(seq_len, d_model)

def call(self, x):
positions = tf.range(tf.shape(x)[-1])
return self.tok(x) + self.pos(positions)

Now we build the full model:


# 1. Define hyperparameters
vocab_size = 1000
seq_len = 16
d_model = 64

# 2. Instantiate the layer
pos_embedding_layer = TokenAndPosition(seq_len, vocab_size, d_model)

# 3. Create dummy input tensor: batch size of 1 with 4 token IDs (values must be < vocab_size)
dummy_input = tf.constant([[1, 5, 2, 8]], dtype=tf.int32)

# 4. Pass the input through the layer to get the output embeddings
output_embeddings = pos_embedding_layer(dummy_input)

# 5. Display shape and the tensor values
print("Input shape:", dummy_input.shape)
print("Output shape (batch_size, seq_len, d_model):", output_embeddings.shape)
print("\nOutput Tensor Values:\n", output_embeddings.numpy())

inputs = keras.Input(shape=(seq_len,), dtype="int32")

x = TokenAndPosition(seq_len, vocab_size, d_model)(inputs)

attn = layers.MultiHeadAttention(num_heads=4, key_dim=16)(x, x, use_causal_mask=True)

x = layers.LayerNormalization()(x + attn)

ffn = layers.Dense(128, activation="relu")(x)

ffn = layers.Dense(d_model)(ffn)

x = layers.LayerNormalization()(x + ffn)

outputs = layers.Dense(vocab_size)(x)

model = keras.Model(inputs, outputs)

model.compile(
optimizer="adam",
loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True)
)

model.summary()

This is a real, working mini version of the same design used in GPT-style models. It has token and position embeddings, causal multi-head attention, a feed-forward network, residual connections, layer normalization, and an output layer over the vocabulary. The only difference between this and a big LLM is the size: more blocks, bigger vectors, a bigger vocabulary, and a huge amount of training data.

TensorFlow and Large Language Models (LLMs)

What is an LLM?

A Large Language Model (LLM) is a very big Transformer model trained on a huge amount of text from books, websites, and articles. It learns the patterns of language, so it can answer questions, write essays, translate, summarize, and even write code.

Examples include GPT-style models, Gemini, Claude, and Llama. The word “large” means these models can have billions of parameters (the numbers that the model learns).

How an LLM Learns: Next-Word Prediction

The training idea of an LLM is surprisingly simple: predict the next token.

Take the sentence “I love eating biryani every day”. We create training pairs by shifting the sentence by one position:

  • Input: “I” → Target: “love”
  • Input: “I love” → Target: “eating”
  • Input: “I love eating” → Target: “biryani”
  • Input: “I love eating biryani” → Target: “every”
  • Input: “I love eating biryani every” → Target: “day”

Because of the causal mask, the model can learn all of these pairs from one sentence in one pass. In code, the input is the token list without the last token, and the target is the token list without the first token:

import numpy as np

tokens = [0, 1, 2, 3, 4, 5]

# The model expects a sequence length of 4 (seq_len = 4)
# We'll slice the tokens to create sequences of length 4
input_tokens = np.array([tokens[:4]]) # Shape (1, 4)
target_tokens = np.array([tokens[1:5]]) # Shape (1, 4)

# Fit the model using the NumPy arrays
model.fit(input_tokens, target_tokens, epochs=10)

At the start, the model’s guesses are random and the loss is high. After seeing billions of sentences, the loss goes down, and the model becomes very good at predicting what comes next. To predict well, the model is forced to learn grammar, facts, reasoning patterns, and even coding styles. That is why such a simple task creates such a powerful system.

How an LLM Writes an Answer: The Generation Loop

When you ask a chatbot a question, it writes the answer one token at a time, using a loop:

  1. Convert your prompt into tokens.
  2. Pass the tokens through the Transformer.
  3. Get the probabilities for the next token.
  4. Pick one token. This can be the most likely token, or a random pick based on the probabilities. A setting called temperature controls how creative or safe the pick is.
  5. Add this token to the end of the text.
  6. Repeat from step 2 until the answer is finished.

Here is the loop in simple code:

text = [0, 1, 2, 3]

for _ in range(5):
# Only take the last seq_len (4) tokens to match the model's required input shape
input_sequence = text[-4:]
logits = model(tf.constant([input_sequence]))
next_token = int(tf.argmax(logits[0, -1]))
text.append(next_token)
print(text)

Every word you see from a chatbot is made by this same loop running again and again. The model does not write the whole answer at once.

What Do Fine-Tuning and Transfer Learning Mean?

Training a big LLM from zero costs millions of dollars. So most people start from a pre-trained model, which already knows language, and then train it a little more on their own data. This is called fine-tuning. For example, you can fine-tune a model on medical questions, legal documents, or customer support chats. It needs much less data, time, and money.

Where Does TensorFlow Fit In?

Let’s be honest and clear here, because you should know the real picture.

TensorFlow’s role in LLMs:

  • History: The Transformer idea and early models like BERT and T5 came from Google and were first built with TensorFlow. This helped start the whole LLM era.
  • Training at scale: TensorFlow supports distributed training across GPUs and TPUs, which large models need.
  • Fine-tuning: You can take a pre-trained language model and fine-tune it on your own data.
  • Text processing: Tools like the TextVectorization layer and TensorFlow Text help with tokenization.
  • Deployment: Smaller language models can be optimized using quantization and deployed with TensorFlow Lite or TensorFlow Serving.
  • Keras 3: Keras is now multi-backend. This means you can write your model in Keras and run it on TensorFlow, JAX, or PyTorch.

The honest picture today:

In recent years, PyTorch has become the most popular framework for LLM research and open-source models. Many new papers and libraries, including Hugging Face Transformers, focus mainly on PyTorch, and Hugging Face has been reducing its TensorFlow support. JAX is also popular for very large-scale training at Google.

But this does not mean TensorFlow is useless. It is still widely used in:

  • Production systems in many companies
  • Mobile and edge AI (TensorFlow Lite)
  • Browser-based AI (TensorFlow.js)
  • Education and real-world projects
  • Many existing industry pipelines (TFX)

Good advice: Learn the concepts first, such as tensors, embeddings, attention, and training. These ideas are the same in every framework. If you understand the tiny Transformer above, you already understand the core of every LLM.

How TensorFlow Helps with Transformers: Summary

1. Ready-made building blocks. Keras gives you Embedding, MultiHeadAttention, LayerNormalization, and Dense layers, so you can build a Transformer in a few lines.

2. Fast math on GPUs and TPUs. Transformers need huge matrix multiplications. TensorFlow is built to run them fast on GPUs and TPUs.

3. Automatic gradients. GradientTape calculates all the gradients for training, even for models with billions of parameters.

4. Distributed training. Big models cannot train on one device. TensorFlow’s distribution strategies split the work across many accelerators.

5. Pre-trained models. You can use models like BERT from Kaggle Models, KerasHub (the successor of KerasNLP), and Hugging Face.

6. Deployment tools. After training, use TensorFlow Serving for servers, TensorFlow Lite (LiteRT) for mobile devices, and TensorFlow.js for browsers.

Real-Life Uses of TensorFlow

  • Healthcare: Detecting diseases from X-rays and medical images
  • Agriculture: Finding crop diseases from leaf photos
  • Finance: Fraud detection in banking and mobile payments
  • E-commerce: Product recommendations
  • Language: Translation, chatbots, and sentiment analysis
  • Vision: Face detection, object detection, and number plate recognition
  • Speech: Voice assistants and speech-to-text
  • Mobile apps: Offline AI features on Android phones

Advantages and Limitations

Advantages

  • Free and open-source
  • Strong production and deployment tools
  • Runs on CPU, GPU, TPU, mobile, and browser
  • Excellent documentation and learning material
  • Keras makes it beginner-friendly

Limitations

  • Older TensorFlow 1.x code looks very different, which can confuse beginners
  • Less popular than PyTorch in new research
  • Some errors can be hard to understand for beginners
  • Many cutting-edge open-source LLM projects start with PyTorch first

TensorFlow vs PyTorch

  • Created by: TensorFlow was made by Google. PyTorch was made by Meta (Facebook).
  • Ease of learning: TensorFlow is easy with Keras. PyTorch is easy and feels very natural to Python users.
  • Research popularity: TensorFlow is moderate. PyTorch is very high.
  • Deployment tools: TensorFlow is very strong (Lite, JS, Serving). PyTorch is improving.
  • Mobile and browser: TensorFlow is excellent. PyTorch is more limited.
  • Community for LLMs: TensorFlow is smaller today. PyTorch is larger today.

Neither is “bad.” The best choice depends on your goal. If you want to deploy on mobile or the web, TensorFlow is great. If you want to follow the latest research and open-source LLMs, PyTorch is very useful. Learning both is the best option.

A Simple Learning Roadmap

  1. Learn Python basics (lists, functions, classes)
  2. Learn NumPy and Pandas for data handling
  3. Understand basic math: vectors, matrices, and a little calculus and probability
  4. Learn machine learning basics with scikit-learn
  5. Start TensorFlow and Keras and build simple models
  6. Try CNNs for images and RNNs for sequences
  7. Learn Transformers: understand embeddings, attention, and the causal mask
  8. Fine-tune a pre-trained model on a small dataset
  9. Build a small project and deploy it, for example as a web app or an Android app
  10. Share your work on GitHub, Kaggle, and Medium

Practice on Google Colab and Kaggle, since both are free.

Project Ideas

  • Sentiment analysis of reviews or social media posts
  • Fake news detection
  • Crop leaf disease detection
  • Currency note recognition for visually impaired people
  • Number plate recognition
  • Handwritten digit or character recognition
  • A tiny next-word predictor built with the Transformer from this article
  • A simple question-answering chatbot using a pre-trained Transformer
  • House price prediction for your city

Projects like these make your CV strong and show real skills to employers and universities.

Conclusion

TensorFlow is one of the most important tools in the history of modern AI. It makes deep learning easier by giving you ready-made tools for building, training, and deploying models. With Keras, even a beginner can create a working neural network in minutes.

Inside every Transformer and LLM, the same simple story repeats: text becomes tokens, tokens become embeddings, attention lets words share information, feed-forward layers process it, and the final layer predicts the next token. Big LLMs do exactly this, just with more layers, more data, and more computing power.

TensorFlow played a big role in the beginning of this story, and it still offers strong tools for training, fine-tuning, and deployment, especially on mobile, browsers, and production systems. At the same time, PyTorch and JAX are now very popular for LLM research, so a smart learner should understand the core ideas and stay flexible.

The most important thing is to start learning and keep building. You do not need an expensive computer. A laptop, internet, and curiosity are enough.

I hope this article helped you understand TensorFlow, Transformers, and LLMs clearly. If you liked it, please clap, share it with your friends, and follow for more AI and technology articles.

Happy learning!

--

--