Mechanical Engineering

How AI works

From a single artificial neuron to chat agents that use tools: the ideas behind modern AI, with demos you can try.

Artificial intelligence (AI) is software that learns patterns from data instead of following rules written by hand. Show it many examples and it adjusts millions of numbers, called weights, until its answers fit the examples.

Everything below runs in your browser. The demos are tiny versions of the real thing, so you can see the idea without a big computer.

Inside a language model

The transformer design lets every token look at the others to decide which words matter for what comes next.

1. Learning from examples: train a neuron

A neuron adds up its inputs multiplied by weights and squashes the result to a value between 0 and 1. Training nudges the weights to reduce the error. Here one neuron learns to separate two groups of points. Press Train and watch the shaded regions move. Click the plot to add your own points.

Add points as
Step 0   Loss -   Accuracy -

2. Predicting the next word: how a language model works

Large language models (LLMs), the engines behind chat assistants like ChatGPT and Claude, are trained to predict the next piece of text, called a token. This toy model has only read the short text below, but the idea is the same: look at the words so far, rank the likely next words, pick one. A real model does this with billions of weights and reads far more text.

Likely next words

Generated text

 

Low temperature picks the most likely word every time. High temperature takes more risks.

Training text

the robot moves the arm to the part. the robot picks the part and places the part on the conveyor. the conveyor moves the part to the machine. the machine cuts the part with a tool. the tool is controlled by a program. the program tells the machine where to move. the controller reads the sensor and moves the motor. the motor turns the gear and the gear moves the arm. a good controller keeps the motor at the right speed. the sensor sends a signal to the controller. the controller sends a signal to the motor. the engineer tests the machine and fixes the program. the engineer designs the part in the model and the machine cuts the part.

3. Chat agents: a model that can use tools

A chat agent is a language model running in a loop. It reads the conversation, decides whether to answer or to call a tool (a calculator, a search, code, a database), reads the result, and continues until it can give the answer. Choose a question and step through the loop. This is a simulation with fixed steps, but the calculator runs for real; in a real agent the model decides each step.

Inside a language model

Tokens

Text is split into small pieces (words or parts of words) and each piece becomes a number.

Embeddings

Each token becomes a long list of numbers that places it among other meanings: “motor” sits near “engine”.

Attention

The transformer design lets every token look at the others to decide which words matter for what comes next.

Training

The model reads huge amounts of text and adjusts billions of weights to predict the next token better. It needs a great deal of computing time.

Fine-tuning

Extra training on examples of good answers, and on human feedback, teaches the model to follow instructions and be helpful.

Inference

When you chat, the model predicts one token at a time, feeding each one back in, until the answer is finished.

What makes a chat agent

The model

The language model reads the conversation and decides what to do next.

Tools

Calculator, web search, code, files, databases: anything the program lets the model call.

Memory

The conversation so far, plus notes the system keeps, fits inside a limited context window.

Guardrails

The program checks every tool call and asks a person before anything risky happens.

Limits to know

  • It can be confidently wrong, called hallucination, so check important facts.
  • It only knows what was in its training data and what you give it.
  • It can only read a limited amount of text at once (the context window).
  • It can reflect biases in the data it learned from.
  • Safety-critical engineering still needs human review.

AI in engineering

Predictive maintenance

Spotting a failing bearing from vibration data before it breaks.

Machine vision

Inspecting parts on a production line for defects.

Generative design

Algorithms propose lighter shapes that still carry the load.

Control tuning

Learning controllers for robots and process plants.

Coding help

Assistants draft PLC, Python or MATLAB code for an engineer to review.

Let’s build something

Looking for an intern or have a project idea? Get in touch.

kenith [at] kenith.net