Remember your first conversation with ChatGPT? That feeling of talking to something... alive. You ask a question — get a thoughtful answer. Write something vague — it still gets what you mean.
Magic? Nope. Math.
Behind those few seconds of "thinking" is a process you can break down piece by piece. From the first character of your prompt to the last word of the response — everything is logical, calculated, predictable. And understanding how artificial intelligence works is easier than you think — even without a technical background.
This article is your guide to neural networks for beginners. Let's figure out how a computer that only understands zeros and ones learned to understand human language.
What Do Neural Networks Actually Do When You Write a Prompt?

Any language model's task boils down to one simple principle: take an input sequence (your prompt) and transform it into an output (the response). In academic circles, this is called sequence transduction — transforming one sequence into another.
But first, let's break down what language models actually are. They're neural networks trained on massive amounts of text — billions or trillions of words from the internet, books, code. They've learned to find patterns in language: how words combine, which phrases make sense, which don't.
But how they do this — that's a whole science.
Early AI models read text like we read a book: word by word, left to right. Modern neural networks learned to do better — they see the entire text at once, like glancing at a page and instantly grasping the essence.
The response? The model always generates it the old-fashioned way: word by word. Writes one, "thinks," writes the next. Ever notice how text appears gradually in ChatGPT? That's not animation for effect. The model actually works that way — predicting each next word on the fly.
Why not the whole response at once? Because it's simpler this way. You can monitor the process, adjust on the fly, and most importantly — you don't need to hold the entire text in memory. Calculated the next word, added it, moved on.
The AI's main goal through all this: preserve the meaning of your prompt and output something coherent. Sounds simple, but decades of research stand behind it.
Now let's break down how it all works. From the earliest attempts to modern systems that seem like magic.
Chapter One: How Neural Networks Learned to Read Text — From RNN to Transformers

Remember reading a long poem in school? You'd get to the middle and the beginning would already slip from your memory. You'd have to go back and reread. The first neural networks for text processing worked pretty much the same way.
They're called recurrent neural networks, or RNN. Sounds like a spaceship name, but really it's just a way to read text one word at a time. Imagine a for loop in programming — you go through the text left to right, process each word, move forward.
Here's a simple sentence: "Yesterday I saw a cat that was sitting on a fence meowing at the moon."
RNN reads it like this:
- "Yesterday" — okay, remembered
- "I" — yep, got it
- "saw" — noted
- "a" — check
- "cat" — stored
- "that" — wait, what does "that" refer to?
By this point, the network is already starting to forget what was at the beginning. The connection between words gets lost. Especially if the sentence is long. Now imagine a whole paragraph or article!
The Long-Term Dependency Problem
Here's a classic example that broke all RNNs of that era:
"I grew up in Paris. I spent my entire childhood there. Went to the local school, played with friends in the courtyard, learned the language. That's why I speak fluent..."
What language do I speak? Right, French. But to understand that, you need to remember Paris from the very beginning. And by the end of the sentence, RNN has completely forgotten about it.
It's like watching a detective story and forgetting clues along the way. By the finale, you don't know who the killer is because you forgot who was even in the mansion that evening.
LSTM — Memory with Selective Access
In the mid-90s, they came up with an improvement: Long Short-Term Memory. The name's contradictory — "long short-term memory." Sounds like an oxymoron, but it works.
The idea is simple: let's teach the network to decide what's important to remember and what can be forgotten. Imagine reading a textbook with a highlighter. You highlight important parts, skip the rest. Then you only return to what's highlighted.
LSTM does the same thing. It has a system of "gates" that decide: is this word important (pass it to long-term memory) or not (forget it). The model learned to determine what matters on its own.
It got better. But not by much. The network still read sequentially, word by word. Slowly. And still made mistakes on long texts.
Convolutional Networks — Reading Multiple Words at Once
Then they tried convolutional neural networks (CNN). These are the same networks that learned to recognize cats in photos. They tried applying them to text.
CNN's trick: they look not at one word but at a group at once. Kind of like how you read not letter by letter, but whole words. Or even phrases, if your reading skill is good.
CNNs read text in "windows": three words together, then the next three, then the next. On the next layer, these triplets merged into groups of nine words. And so on, until they captured the whole sentence.
But the downsides still outweighed the upsides. They worked slowly. Got stuck on long texts. And most importantly — they still didn't see the whole picture at once.
A revolution was needed.
Chapter Two: Attention Mechanism and Transformers — How Modern AI Works

In 2017, a paper came out with a simple title: "Attention Is All You Need." Sounded bold. But they were right.
This was the breakthrough. Imagine that instead of reading text one word at a time, you could see ALL words at once. And not just see them, but instantly understand how each word relates to every other one.
Everything changed.
Tokens — The Language of Neural Networks
First, let's understand what a token is. It's not a word. And not a letter. Something in between.
When you write a prompt to ChatGPT, it doesn't see your words. It sees tokens. The model breaks text into chunks and turns them into numbers. Computers only know how to work with numbers.
Here's a simple example:
"Hello, world!"
For the model, it's roughly like this:
[Hello] [,] [world] [!]
Four tokens. Not three words, not thirteen characters. Four tokens.
But here's where it gets interesting. Different languages use different numbers of tokens for the same meaning. English is actually one of the most "efficient" languages for tokenization. In languages with complex morphology — like German, Polish, Arabic, or Chinese — the same sentence often requires 2-4 times more tokens.
Why? Because English has relatively simple grammar and shorter words. Languages with lots of cases, genders, or character-based writing systems need more tokens to express the same thing.
Example: "Hello, how are you?" in English = ~5 tokens. The same phrase in German ("Hallo, wie geht es dir?") = ~8-9 tokens. In Chinese = ~7-8 tokens.
Got a limit of 100,000 tokens? In English, that's miles of text. In many other languages — 2-3 times less.
Pro tip: If you have a strict token limit and you're working in a non-English language, consider translating your prompt to English first. You'll save significantly on token usage.
Vectors — How Numbers Get Meaning
Okay, text turned into tokens. Tokens into numbers. But how can numbers convey meaning?
This is where the beauty of mathematics begins.
Each token gets assigned not one number, but a whole set of numbers. A vector. Imagine coordinates in multidimensional space. Only not in two or three dimensions, but in hundreds or thousands.
The word "cat" — that's a vector of 768 numbers.
The word "kitten" — also a vector of 768 numbers.
And you know what? These vectors will be close to each other. Because the words are close in meaning.
And the word "asphalt" will be far from them.
Here's a simpler example. Take the phrase: "In the evening at home watching a movie."
In the model's mind, it looks roughly like this (simplified):
- evening: [0.8, 0.3, 0.1, 0.9]
- home: [0.7, 0.4, 0.2, 0.8]
- watching: [0.2, 0.9, 0.8, 0.3]
- movie: [0.3, 0.9, 0.7, 0.2]
See? "Evening" and "home" are close (both about setting). "Watching" and "movie" are also close (action and object).
The model sees this closeness and understands connections in the text.
Attention Mechanism — The Main Breakthrough
Now the most important part. Attention mechanism.
Imagine you're reading a mystery novel. At the beginning, they mention the butler was in the garden. In the middle, they talk about poisoned tea. At the end, they find the dead owner.
Your brain automatically connects these three facts. Butler → garden → tea → death. Hmm, suspicious.
The attention mechanism does the same thing. It looks at each word and asks: "Which other words in the text is this connected to?"
Take the phrase: "The river bank was steep."
The word "bank" could mean:
- A financial institution
- The edge of a river
The attention mechanism looks at the word "river" and understands: okay, here "bank" means the edge. Connected two words, eliminated ambiguity.
Now the phrase: "The bank raised interest rates."
Here "bank" is connected with "interest rates." So it's a financial institution.
The model checks all connections simultaneously. Not sequentially. In parallel.
This is the key difference from RNN.
Self-Attention — When Text Looks at Itself
There's a special kind of attention: self-attention.
The model takes one token and checks its connection with all other tokens in the text. Then takes the next token — and again with all. And so in a circle.
Imagine a matrix of connections. Each word is checked against each. You get a map of interactions.
Take the phrase: "The cat chased the mouse, but it escaped."
Self-attention finds:
- "it" is connected to "mouse" (not "cat")
- "chased" is connected to "cat" (the cat did the chasing)
- "escaped" is connected to "mouse" (the mouse escaped)
All automatically. No grammar rules. The model saw patterns in the data itself.
Multi-Head Attention — Multiple Views at Once
But that's not all. Turns out one attention mechanism isn't enough.
They invented multi-head attention — multiple attention.
The essence: run several attention mechanisms in parallel. Each looks at the text from its own angle.
One "head" searches for grammatical connections.
Another — semantic (meaning-based).
A third — syntactic.
Then all results are combined.
It's like looking at a painting from different angles. Each view gives a new insight. Together you get the complete picture.
GPT-3 uses 96 attention heads. Claude 3.5 — even more. Each head searches for its own patterns.
Positional Encoding — How the Model Remembers Word Order
There's a problem with parallel processing: the model loses understanding of word order.
"The cat ate the mouse" and "The mouse ate the cat" — different in meaning, but if you remove the order, for the model they're the same.
Solution: positional encoding.
A special number is added to each token that says: "You're first," "You're second," "You're tenth."
These numbers are encoded in a special way (through sinusoids) so the model understands not only absolute position ("you're third"), but also relative ("you're two words from the beginning").
Now the model knows: "cat" comes before "ate," and "mouse" — after. Order restored.
Chapter Three: Transformer Architecture — Layers That Build Understanding

A transformer isn't one neural network. It's a stack of many layers, each doing its own work.
Imagine a factory conveyor belt. Raw material enters from one side, passes through dozens of stations, comes out as a finished product.
Same with text.
Encoder — Reads Text
The first part of the transformer is the encoder. Its task: read the input text and understand it.
The encoder consists of several layers. Typical structure:
- Self-attention layer (we look at connections between words)
- Feed-forward layer (we process each word independently)
- Normalization (we stabilize the numbers)
- Residual connections (we preserve information from previous layers)
Each layer adds a new level of understanding.
The first layer sees simple connections: noun connected to adjective.
The second layer sees phrases: "red car."
The third layer sees sentences: "The red car stopped."
The fourth layer sees paragraphs: the logic of the text, transitions between thoughts.
GPT-3 has 96 such layers. Each digs deeper.
Decoder — Writes the Response
The second part is the decoder. Its task: generate text.
The decoder is similar to the encoder, but with one difference: it works sequentially. Wrote one token, added it to the context, wrote the next.
Decoder layer structure:
- Masked self-attention (we only look at already written tokens)
- Cross-attention (we connect with the encoder's output)
- Feed-forward layer
- Normalization and residual connections
Masked attention is an important detail. The decoder doesn't see the future. When it writes the fifth word, it doesn't know what the sixth will be.
This isn't a bug, it's a feature. This way the model learns to predict the next token based only on previous ones.
Training the Transformer — How AI Learns to Write
The training process is simple in essence but complex in implementation.
The model gets huge text. Trillions of words. The entire internet, basically.
Task: predict the next word.
The model sees: "The cat sat on the..."
Tries to guess: "fence."
Checks the answer in the text.
Wrong? Adjusts its weights.
Repeats millions of times.
Gradually the model learns:
- Grammar (after "on the" usually comes a noun)
- Meaning (a cat can sit on a fence, but not on a cloud)
- Style (formal text differs from conversational)
- Facts (the capital of France is Paris)
All this — from statistics. The model sees: in 90% of cases after "capital of France" comes the word "Paris." So that's the right answer.
Training GPT-3 cost $4.6 million in electricity. GPT-4 — tens of millions. That's weeks of supercomputer work.
Fine-Tuning — Making the Model Useful
After basic training, the model can predict words but doesn't know how to be a helper.
Need fine-tuning — additional training.
The model is shown examples of dialogues:
- Good responses (helpful, polite, accurate)
- Bad responses (rude, false, dangerous)
The model learns to distinguish: what's good, what's bad.
The method used is RLHF (Reinforcement Learning from Human Feedback) — learning with reinforcement based on human evaluations.
Process:
- Model generates several responses to one question
- People evaluate: which answer is better
- Model learns to generate responses similar to those people rated highly
This is how ChatGPT became polite and helpful. The base GPT model would just continue the text, not answer questions.
Chapter Four: Prompt Engineering — How to Talk to AI Correctly

You already understand how the model works. Now let's learn to interact with it properly.
A prompt isn't just a request. It's an instruction for AI. And the quality of the answer depends on how you write it.
Basic Principles of a Good Prompt
1. Be Specific
Bad: "Write an article"
Good: "Write a 1000-word article about prompt engineering for beginner programmers, conversational style, with practical examples"
2. Provide Context
Bad: "Explain recursion"
Good: "I'm a beginner Python programmer. Explain recursion in simple terms, with a code example and a real-life analogy"
3. Give Examples
Bad: "Translate to English"
Good: "Translate to English in informal style. Example: 'Привет, как дела?' → 'Hey, what's up?'"
4. Structure Your Request
Bad: long mess of requirements
Good: numbered list of tasks
Few-Shot Prompting — Teaching with Examples
One of the most powerful techniques: give the model examples of what you want.
Task: classify the sentiment of reviews.
Review: "Great product, fast delivery!"
Sentiment: Positive
Review: "Packaging was damaged, product arrived broken"
Sentiment: Negative
Review: "Average product, nothing special"
Sentiment: Neutral
Review: "Exceeded all expectations, will order again!"
Sentiment:The model sees the pattern and continues: "Positive."
This works for translations, formatting, analysis — anything.
Chain-of-Thought — Teaching to Think Step by Step
Sometimes the task is complex. The model makes mistakes if it tries to answer immediately.
Solution: ask it to think step by step.
Bad prompt: "Solve the problem: If apples in the store cost $2 per pound, I bought 3.5 pounds and gave the cashier $20. How much change will I get?"
The model might make arithmetic errors.
Good prompt: "Solve the problem step by step:
1. Calculate the purchase cost
2. Subtract from the amount given
3. Give the final answer
Problem: If apples in the store cost $2 per pound, I bought 3.5 pounds and gave the cashier $20. How much change will I get?"
The model thinks:
- Step 1: 2 × 3.5 = $7
- Step 2: 20 - 7 = $13
- Step 3: You'll get $13 in change
Accuracy increases dramatically.
Role Prompting — Assigning a Role to the Model
Want an expert answer? Tell the model who it is.
"You're an experienced Python developer with 10 years of experience. Explain why list comprehensions in Python are more efficient than for loops."
The model will take on the role and answer like an expert.
"You're a math teacher for 5th graders. Explain the Pythagorean theorem in simple terms."
The answer will be adapted for the audience.
Negative Prompting — Saying What NOT to Do
Sometimes it's easier to say what you DON'T want.
"Write a brief product description. Don't use words 'innovative,' 'revolutionary,' 'unique.' No marketing fluff, just facts."
The model will account for the limitations.
Chapter Five: How Models Can Make Mistakes — Hallucinations and Limits

AI isn't perfect. It's important to understand its limitations.
Hallucinations — When the Model Lies Confidently
The most famous problem with language models: they sometimes make up facts.
You ask: "Who invented the quantum computer?"
The model answers confidently: "The quantum computer was invented by David Deutsch in 1985."
Sounds convincing. But it's a lie. Deutsch is a real scientist, but the date and formulation are inaccurate.
Why does this happen?
The model doesn't "know" facts in the usual sense. It predicts probable words. If David Deutsch was often mentioned near quantum computers in the training data, the model will connect them.
But details might be wrong.
How to protect yourself:
- Verify facts in reliable sources
- Ask the model to cite sources
- Use commands like "If unsure, say 'I don't know'"
Context Window — Memory Limit
The model can't remember forever. It has a limit.
GPT-4: 128,000 tokens (about 300 pages of text)
Claude 3.5: 200,000 tokens
Gemini 1.5 Pro: 1 million tokens
If the dialogue gets longer, the model starts "forgetting" the beginning.
The first messages fall out of context. The model no longer sees them.
Solution: periodically summarize the dialogue and start a new session with a brief summary of the previous one.
Bias and Toxicity
Models are trained on data from the internet. And the internet... well, it's not perfect.
Training data includes:
- Gender stereotypes
- Racial bias
- Toxic expressions
- Political engagement
The model can absorb these patterns.
Developers fight this through:
- Data filtering
- RLHF to eliminate toxicity
- Special limitations in prompts
But the problem isn't completely solved.
Computing Costs
Running GPT-4 on one request costs about $0.03. Seems like little?
If you have a million users, each making 10 requests a day — that's $300,000 a day. $9 million a month.
That's why many services limit the number of requests or charge a subscription.
Computing power is a bottleneck. Until models get lighter, costs will remain high.
Chapter Six: Model Evolution — From GPT-3 to Modern Systems

In the three years since GPT-3 came out (2020), there's been a revolution.
GPT-4 — A Step Into Multimodality
GPT-4 doesn't just read text. It sees images.
Upload a photo of an interface, ask it to write code for it — you get working HTML/CSS.
Show a drawing, ask for an explanation — you get a detailed description.
This is the first step toward models that understand the world like we do: through a combination of words and images.
Claude from Anthropic — Focus on Safety
Claude was created by a company founded by former OpenAI employees. Their focus: safety and honesty.
Claude hallucinates less often. It admits when unsure. Refuses toxic requests more consistently.
And Claude has a huge context window. 200,000 tokens. You can upload an entire book and work with it.
Gemini from Google — Speed and Multitasking
Gemini 1.5 Pro can process 1 million tokens. That's about 1,500 pages of text.
Upload an entire project codebase, ask to find bugs — it finds them.
Give it several hours of video, ask for a summary — it summarizes.
Google is betting on speed and volume.
Multimodal Models — Everything in One
GPT-4o:
- Sees images
- Hears audio
- Reads text
- Responds with text, voice, or image
One model understands everything. This is the future.
You can upload a photo, ask by voice "What is this?" — and get an answer also by voice.
Chapter Seven: The Future Is Already Here (But Unevenly Distributed)

February 2025. GitHub announces Agent Mode for Copilot.
Now AI doesn't just complete code. It executes tasks itself.
You set a task: "Add OAuth authentication to the project." It:
- Analyzes current code
- Finds necessary libraries
- Writes code
- Tests
- Creates pull request
You only check the result.
May 2025. Announcement of Coding Agent — an even more autonomous version. It works in a cloud development environment, commits itself, pushes changes itself.
This isn't science fiction. This already works.
Specialized Models
Universal models are good, but narrow ones are better at their tasks.
Med-PaLM (Google):
Trained on medical data
Advises doctors
More accurate than GPT on medical questions
LawGPT:
Legal consultations
Contract analysis
Precedent search
BioGPT:
Biology, chemistry, pharmacology
Protein structure prediction
New drug development
These models are fine-tuned on specialized datasets. Their tokenization is also adapted: legal terms and medical abbreviations are separate tokens.
Ethical Questions
All this is cool, but there are problems.
Copyright:
Models are trained on public data. But much of this data is copyrighted. Legal proceedings are ongoing. GitHub Copilot already faced a lawsuit for generating code similar to others'.
Hallucinations in Critical Areas:
An AI doctor can make mistakes. An AI lawyer too. The consequences are serious.
Code Vulnerabilities:
Remember: 40% of code from Copilot can be insecure. Developers must check.
Job Replacement:
Copywriters, artists, programmers — everyone feels the pressure. But new professions are emerging: prompt engineers, AI trainers, AI ethics specialists.
What's Next?
Models will get smarter.
GPT-5 is already in development. Will understand even better, make fewer mistakes.
Context will get bigger.
Millions of tokens of context — that's a matter of a couple years. You'll be able to upload an entire documentation library and work with it.
Agents will become the norm.
AI won't just answer. It will act. Book tickets, write code, create content. Autonomously.
Personalization will intensify.
Your personal AI assistant that knows your preferences, work style, goals. Works only for you.
But one thing won't change: AI remains a tool. Powerful, but requiring understanding.
Frequently Asked Questions About How Neural Networks Work
What is a token in neural networks?
A token is the minimum unit of text that a language model works with. Not a whole word and not a single letter, but a fragment. In English, one token on average equals four characters; in Russian — one character. The model breaks all text into tokens, turns them into numbers, and only then starts processing.
Why does ChatGPT sometimes give wrong answers?
Language models don't "know" information in the usual sense. They predict the next token based on statistical patterns they saw in training data. The model can create a plausible but false answer — this is called a hallucination. This happens especially often with rare facts, dates after the model's training, or very specific questions.
What is the attention mechanism?
The attention mechanism allows the model to see connections between all words in text simultaneously, rather than processing them sequentially. When you write "The river bank was steep," the model sees the word "river" and understands that "bank" here is an edge, not a financial institution. It checks connections between all tokens in parallel.
How does a transformer differ from a regular neural network?
A transformer uses an attention mechanism for parallel text processing. Old architectures (RNN, LSTM) read text sequentially, like a person reads a book — word by word. A transformer sees all text at once, as if looking at a whole page. This is faster and more accurate.
How do you write a good prompt for AI?
A good prompt should be specific: indicate target audience, style, volume, response structure. Bad: "Write an article." Good: "Write a 1000-word article about prompt engineering for beginner programmers, conversational style, with practical examples." Use techniques like few-shot prompting (give examples) or chain-of-thought (ask to think step by step).
Why are some languages "more expensive" for neural networks?
Because tokenization efficiency varies by language. Languages with complex morphology (lots of endings, prefixes, suffixes) or character-based writing systems require more tokens to express the same meaning. English is relatively efficient — one token averages about four characters. In German, Polish, Arabic, or Chinese, tokenizers often need 2-4 times more tokens for equivalent content. Result: the same text costs significantly more tokens in morphologically complex languages than in English.
Can you fool an AI text detector?
AI text detectors look at statistical patterns: repetitive constructions, next-word predictability, absence of errors. If you add unevenness to the text — different sentence lengths, unexpected turns, live examples — the detector will be less certain. But there's no 100% guarantee of fooling it. The best way — write with AI but rework the text in your own way.
What is a context window?
A context window is the maximum number of tokens the model can process at once. For GPT-4, it's 128,000 tokens (about 300 pages of text); for Claude 3.5 — 200,000; for Gemini 1.5 Pro — 1 million. If the dialogue gets longer, the model starts "forgetting" the beginning — the first messages fall out of context.
Conclusion: Now You See What's Under the Hood
Now when you write a prompt to ChatGPT, you understand what's happening inside.
Tokenization — text is broken into chunks
Embeddings — chunks get meaning through vectors
Attention mechanism — model sees connections between words
Transformer — layers of analysis from simple to complex
Generation — response is created token by token
Not magic. Mathematics, architecture, engineering. Billions of numbers that add up to meaningful text.
And this knowledge is useful.
You can write better prompts. Understand limitations. Not fall for hallucinations. Work with AI more effectively.
Ten years ago, all this seemed like science fiction. Now — ordinary. And in ten years? It'll be even cooler.
But the foundation will remain the same. Tokens, vectors, attention, transformers.
Understanding the language of machines is becoming as basic a skill as knowing how to search for information on the internet.
And remember the old CodeGym principle: the best way to learn is to practice. Experiment with prompts. Try different models. See how they react.
That's the only way to truly understand AI.
Good luck! 🚀
P.S. Want to dive deeper into the technologies changing the world? We don't just teach programming — we show you how the tools of the future work, from basic algorithms to working with AI assistants.
Learn more:
- CodeGym Programming Courses — learning through practice with modern tools
- Java Course — from basics to advanced level
- Python Course — the language for AI and machine learning
Join thousands of developers building the future with us.
GO TO FULL VERSION