Machine Learning

Machine learning is a way to build software by fitting models to examples instead of writing every rule by hand. A model sees data, optimizes an objective, and generalizes the learned pattern to new inputs.

What is a Transformer?

A Transformer is a neural network architecture designed to process sequences by using attention rather than relying on recurrence. Core idea For each token, the model creates three learned representations: query (Q) , key (K) , and value (V) . Self attention compares queries with keys to determine how strongly tokens should attend to one another, then combines the corresponding values. A common form is: This lets the model connect information across a sequence directly. For example, in the sentence “The animal didn't cross the street because it was tired,” attention can help the representation of “it” incorporate information from “animal.” Main building blocks A Transformer typically combines: Token embeddings to represent input tokens as vectors. Positional information so token order is represented. Multi head self attention so different attention heads can learn different relationships. Feed forward networks that transform each token representation. Residual connections and normalization that help train deep networks. Encoder and decoder variants The original Transformer contains both an encoder and a decoder . Modern models often use only part of that design: Encoder only models are commonly used for understanding or representation tasks. Decoder only models generate tokens autoregressively and are widely used for LLMs. Encoder decoder models are useful when transforming one sequence into another, such as translation. Why Transformers matter Unlike recurrent neural networks, Transformers can process many sequence positions in parallel during training. Self attention also provides a direct mechanism for modeling relationships between distant tokens. The tradeoff is that standard self attention requires computing interactions between pairs of sequence positions, giving it roughly quadratic attention cost with sequence length . This becomes important when designing systems for long contexts. In short, a Transformer repeatedly uses attention and feed forward computation to build context aware token representations. This architecture became the foundation for many modern language models and has also been adapted to vision, audio, and multimodal systems.

What is embedding?

Embeddings are numerical vector representations of data—such as words, sentences, images, users, or products—designed so that items with similar meaning or characteristics are located closer together in a vector space. For example, a text embedding model might represent: The real vectors usually contain hundreds or thousands of dimensions. The important property is not an individual number; it is the relative position of vectors . How embeddings are created An embedding model learns a function: During training, the model learns representations that capture useful patterns in its training objective. In language models, token embeddings are learned parameters that map token IDs to vectors. Separate embedding models can also convert complete sentences or documents into vectors intended for semantic comparison. How similarity is measured A common metric is cosine similarity , which compares the direction of two vectors: A higher cosine similarity generally indicates that two vectors are more similar according to the embedding model. A simple Python example: In a production system, an embedding model generates these vectors rather than developers manually defining them. Why embeddings are useful Embeddings make unstructured information searchable and comparable mathematically. Common applications include: Semantic search: retrieve documents based on meaning rather than exact keyword matches. RAG: embed documents and queries, retrieve relevant chunks, then provide them to an LLM. Recommendation systems: represent users and items so similar preferences can be matched. Clustering: group semantically related documents or products. Classification: use embeddings as features for downstream models. Duplicate detection: identify text or other content with very similar representations. Embeddings in RAG A typical retrieval workflow is: The query and stored documents should normally be embedded using compatible representations from the same embedding model or model family intended for that retrieval task. Embeddings vs. tokens Tokens and embeddings are related but different. A token is a discrete unit produced by tokenization. An embedding is a continuous numerical vector representing a token or larger piece of information. For example: In short, embeddings turn information into vectors that machine learning systems can compare and process mathematically while preserving useful learned relationships.

What is attention ?

Attention is a mechanism that lets a model assign different importance to different parts of its input when producing an output. Instead of treating every input element equally, attention asks: which pieces of information are most relevant right now? For example, in a sentence, when the model processes one word, it can give higher attention to other words that provide useful context, even if they are far away in the sequence. How attention works A common form of attention uses three representations: Query (Q): what the current position is looking for Key (K): what each input position can be matched against Value (V): the information carried by each position The model first measures how well each query matches the keys. Those scores are converted into attention weights, and the values are combined using those weights. For scaled dot product attention: Here, dₖ is the dimension of the key vectors. Dividing by √dₖ keeps the scores from becoming too large before the softmax operation. Simple intuition Suppose a model is processing: When interpreting “it” , the model may assign a larger attention weight to “cat” than to less relevant words such as “mat” . This allows the representation of “it” to incorporate information from the more relevant part of the sentence. Why attention is useful Attention helps models: capture relationships between distant parts of an input focus dynamically on relevant information build context aware representations process sequence elements more flexibly than relying only on nearby information When queries, keys, and values all come from the same sequence, the mechanism is called self attention . Self attention is a core building block of Transformers. See “What is a Transformer?” for the broader architecture. In short, attention lets a model decide what information matters most for the current computation and combine that information using learned relevance weights.

What is machine learning?

Machine learning is a branch of artificial intelligence in which computers learn patterns from data and use those patterns to make predictions, classifications, recommendations, or decisions without being explicitly programmed with every rule. Instead of telling the computer exactly how to solve a problem step by step, we provide data and a learning algorithm. The algorithm adjusts a model so that it can map inputs to useful outputs. Simple example Suppose we want to predict whether an email is spam. A machine learning system can be trained using many example emails along with information about whether each email is spam or not. From those examples, the model learns patterns such as: words or phrases commonly found in spam unusual sender behavior suspicious links or formatting After training, the model can use the learned patterns to classify a new email it has never seen before. The basic idea A typical machine learning process looks like this: The important part is that the useful behavior is learned from data rather than being fully specified through hand written rules. Machine learning includes several learning approaches, such as supervised learning, unsupervised learning, and reinforcement learning. Each approach learns from data in a different way and is covered separately. In short, machine learning allows computers to learn useful patterns from data and apply what they learned to new examples.

Why is machine learning used?

Machine learning is used when a problem can be solved more effectively by learning patterns from data than by writing every rule manually. This is especially useful when the relationships in the data are too complex, too numerous, or too changeable to express as fixed instructions. Why machine learning is useful Machine learning can help systems: Make predictions from historical data Recognize patterns that are difficult to define with hand written rules Handle large amounts of data efficiently Adapt as new data becomes available Automate repeated decisions at scale Improve performance as better data and training become available Simple example Consider email spam detection. A rule based system might require developers to manually define rules such as: But spammers continually change their wording and behavior. A machine learning model can instead learn patterns from many examples of spam and legitimate emails and use those patterns to classify new messages. When machine learning is valuable Machine learning is most useful when there is enough relevant data and when the desired behavior can be learned from examples or feedback. It is not automatically the best choice for every problem. If a task can be solved reliably with a few clear and stable rules, traditional programming may be simpler. In short, machine learning is used to build systems that can learn useful patterns from data and apply them to predictions or decisions that would be difficult to program explicitly.

What kinds of problems can machine learning solve?

Machine learning can solve problems where useful patterns can be learned from data and then applied to new cases. Different machine learning problems usually fall into a few common categories. Common types of problems Classification: assign an input to a category. Example: classify an email as spam or not spam. Regression: predict a numerical value. Example: predict the price of a house. Forecasting: predict future values from historical data. Example: forecast next month's product demand. Clustering: group similar items when predefined labels are not available. Example: group customers with similar behavior. Anomaly detection: identify unusual or rare observations. Example: detect suspicious financial transactions. Recommendation and ranking: decide which items are most relevant to a user. Example: rank products or recommend movies. Pattern recognition: identify useful structures in complex data such as text, images, audio, or sensor readings. Sequential decision making: learn which actions produce better long term outcomes. Example: choosing actions for a robot or an automated control system. A simple way to think about it Machine learning is a good candidate when the task can be expressed as learning a relationship such as: For example: or: Machine learning is less useful when a problem can already be solved reliably with a small set of clear, fixed rules or when there is not enough relevant data to learn from. In short, machine learning is commonly used for prediction, classification, forecasting, grouping, anomaly detection, ranking, recommendation, pattern recognition, and data driven decision making.

How does machine learning differ from traditional rule-based programming?

Traditional rule based programming and machine learning differ mainly in where the decision logic comes from . In traditional programming, a developer writes explicit rules that map inputs to outputs. In machine learning, the system learns that mapping from data. Traditional rule based programming A programmer defines the logic directly: For example, a simple loan rule might be: The program behaves exactly according to the rules that were written. Machine learning Instead of manually specifying every rule, we provide examples or historical data: For a loan application, the model may learn how income, credit history, debt, repayment behavior, and other features relate to previous approval or repayment outcomes. Key differences Decision logic: Rule based programming uses rules written by developers, while machine learning learns patterns from data. Best suited for: Rule based programming works well for clear and stable logic, while machine learning is useful when relationships are complex or difficult to express manually. How behavior changes: A rule based system changes when its rules are edited, while a machine learning system changes when its model is retrained or updated. Interpretability: Rule based logic is usually easier to trace exactly, while learned relationships in machine learning can be more difficult to interpret. Training data: Rule based programming does not require training data, while machine learning usually depends on relevant training data. Machine learning is not automatically better. If a problem can be solved reliably with a small number of clear rules, traditional programming is often simpler and easier to maintain. In short, traditional programming tells the computer exactly how to make a decision, while machine learning lets the computer learn decision patterns from data.

What are the main types of machine learning?

Machine learning is commonly divided into four main types based on what kind of feedback or training signal the model receives . 1. Supervised learning The model learns from examples where the correct output is already known. Example: predicting whether an email is spam using emails already labeled as spam or not spam. 2. Unsupervised learning The model works with data that does not have predefined labels and tries to discover useful structure or patterns. Example: grouping customers with similar purchasing behavior. 3. Semi supervised learning The model learns from a combination of a small amount of labeled data and a larger amount of unlabeled data. Example: training an image classifier when only some images have been manually labeled. 4. Reinforcement learning An agent learns by interacting with an environment and receiving rewards or penalties for its actions. Example: teaching a game playing agent which actions lead to better long term results. Quick comparison Supervised learning: Uses labeled examples and is commonly used to predict an output. Unsupervised learning: Uses unlabeled data and is commonly used to discover structure or patterns. Semi supervised learning: Uses both labeled and unlabeled data and is useful when labeled examples are limited. Reinforcement learning: Uses rewards and penalties and is used to learn actions or strategies. These categories describe different ways a system can learn from data or feedback. Each type is covered separately in the following articles. In short, the main types of machine learning are supervised learning, unsupervised learning, semi supervised learning, and reinforcement learning.

What is supervised learning?

Supervised learning is a type of machine learning in which a model learns from examples that include both the input data and the correct output. Each training example contains: Features: the input information given to the model Label or target: the correct answer the model should learn to predict The model learns the relationship between the features and the target so it can make predictions for new, unseen data. Simple example Suppose we want to predict whether an email is spam. A training dataset might contain: Because the correct result is already known for each training example, the learning process is supervised. After training, the model receives a new email and predicts whether it is spam based on the patterns it learned. Common supervised learning problems Supervised learning is commonly used for: Classification: predict a category, such as spam or not spam Regression: predict a numerical value, such as a house price During training, the model's predictions are compared with the known targets. The learning algorithm adjusts the model to reduce the difference between its predictions and the correct answers. In short, supervised learning trains a model using labeled examples so it can learn how to predict the correct output for new inputs.

What is unsupervised learning?

Unsupervised learning is a type of machine learning in which a model learns patterns or structure from data that does not have predefined labels or target values. Instead of being shown the correct answer for each example, the model tries to discover how the data is organized. Simple example Suppose a company has customer data containing information such as: purchase frequency average order value products viewed time spent on the website If the customers are not already labeled into groups, an unsupervised learning algorithm can analyze their similarities and form groups such as customers with similar buying behavior. Common unsupervised learning tasks Unsupervised learning is commonly used for: Clustering: group similar data points together Dimensionality reduction: represent complex data using fewer variables while preserving important structure Pattern discovery: identify relationships or structures that were not explicitly labeled How it differs from supervised learning In supervised learning, the training data includes known targets: In unsupervised learning, only the input data is provided: Because there is no single correct label supplied during training, evaluating unsupervised learning often depends on the task and whether the discovered structure is useful. In short, unsupervised learning finds useful patterns, groups, or representations in unlabeled data without being given the correct answers in advance.

Page 1 of 27