​
AapkaEngineer
TRENDING
​

How ChatGPT and Other AI Chatbots Actually Work, Explained by an Engineer

​

AI chatbots can draft an email, explain a physics problem and write working code. It feels like magic, but underneath it is an engineering idea you can understand without any maths: predicting the next word, very well, at enormous scale.

Thebeamcrackedbecauseit...Attention picks what mattersAapkaEngineerHow LLMs work
How LLMs work: AapkaEngineer illustration

Step 1: text becomes numbers

Computers work with numbers, so the first job is to break text into small pieces called tokens. A token might be a whole word, part of a word or a punctuation mark. "Engineering" might become two or three tokens. Each token is then turned into a long list of numbers that captures its meaning. Words used in similar ways, like "cement" and "concrete", end up with similar lists.

Step 2: the model predicts the next token

At its core, a large language model does one thing. Given all the tokens so far, it estimates the probability of every possible next token, picks one, adds it to the text and repeats. Writing a paragraph means running that loop hundreds of times.

That sounds too simple to produce intelligent answers. The surprise of the last decade is that when you train a big enough model on enough text, predicting the next word well forces it to learn grammar, facts, reasoning patterns and even some common sense, because all of those help prediction.

Step 3: attention, the key invention

Modern chatbots are built on an architecture called the transformer, introduced by Google researchers in 2017. Its central idea is attention. When the model processes a word, it looks back at every other word in the text and decides which ones matter most for understanding it.

In the sentence "The beam cracked because it was overloaded", attention helps the model connect "it" to "beam" rather than to anything else. Stack dozens of these attention layers and the model builds up a rich understanding of how every part of the text relates to every other part.

Step 4: training in three stages

  • Pre-training. The model reads a huge collection of text from books, websites and code, and repeatedly guesses the next token. Every wrong guess slightly adjusts billions of internal numbers called parameters. This stage takes weeks on thousands of specialised chips.
  • Fine-tuning. The raw model can continue any text, but it is not yet a helpful assistant. It is then trained on examples of good conversations: clear questions followed by helpful, accurate answers.
  • Learning from feedback. People compare different answers and mark which is better. The model is trained to prefer the kinds of answers people rate highly, which makes it more helpful and less likely to produce harmful content.

Why chatbots sometimes make things up

Because the model generates the most plausible continuation, it can produce text that sounds right but is wrong. This is called hallucination. It is especially likely with specific numbers, quotes, citations and recent events. Newer systems reduce it by searching the web or reading documents before answering, but the rule for any engineer stands: verify anything that matters.

What this means for engineers and students

  • Use AI to explain concepts, draft reports, summarise standards and check your reasoning. It is an excellent tutor that never gets tired of questions.
  • Do not use it as the final authority on design values, code clauses or safety calculations. Check the actual code or standard.
  • Give it context. A question with your assumptions, units and constraints gets a far better answer than a one-line query.
A simple way to remember it: a chatbot is a brilliant, fast-reading assistant who has read an enormous amount but was not on your site. You bring the ground truth.

Frequently asked questions

Does an AI chatbot understand what it says?

That is debated. It clearly models meaning well enough to reason through many problems, but it has no direct experience of the world and can be confidently wrong.

Does the model look things up on the internet?

The base model answers from patterns learned during training. Some chatbots add a web search step, and then they can cite current sources.

Will AI replace engineers?

It is automating routine drafting, calculation checks and documentation. Judgment, site knowledge, accountability and design responsibility remain human, and engineers who use AI well are becoming more productive.

DP
Dr. Deepak N. Paithankar

PhD in Civil Engineering and head of a civil engineering department. Writes about the engineering behind everyday life and builds the calculators on this site.