Linear Classifiers › Weights and Bias: What They Encode

Michael BrenndoerferApril 28, 20253 min read
Language AI HandbookAll chapters
Part 10 of 67Neural Network Foundations
Chapter 61Linear Classifiers › Weights and Bias: What They Encode
Reading section 4 of 16 · Weights and Bias: What They Encode · 3 minSection 4 of 16 · 3 min

Book contents

Section 4 of 16 · 3 min read

Linear Classifiers › Weights and Bias: What They EncodeOne section · Sections in this chapter4 / 16 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

The weight vector w\mathbf{w} has a direct interpretation. Each element wiw_i tells the classifier how much feature ii contributes to the positive class decision. A large positive wiw_i means feature ii strongly indicates the positive class. A large negative wiw_i means feature ii strongly indicates the negative class. A wiw_i near zero means feature ii is irrelevant for this decision.

For text classification with a bag-of-words representation (which you encountered in the Bag of Words chapter), the weights are word-level indicators. After training, you can inspect the top-weighted words to understand what the classifier has learned. For sentiment analysis, words like "excellent," "outstanding," and "recommend" will have large positive weights, while "awful," "disappointing," and "refund" will have large negative weights. This interpretability is one of the most practically valuable properties of linear classifiers. When a model makes an error, you can trace the error back to which features were responsible and understand whether the model's reasoning is coherent or whether the training data contains a misleading pattern.

The bias bb sets the base rate for the classifier. If you set bb to a large positive value, the classifier will predict the positive class for almost every input, regardless of features. This is appropriate when the positive class is very common in the training data and the prior probability is high. Conversely, a large negative bias makes the classifier predict the negative class by default unless features strongly push it positive. In a well-trained model, the bias adjusts to reflect class imbalance in the training set, effectively encoding a prior probability before any evidence is considered.

Sparse vs. Dense Features

The behavior of linear classifiers changes significantly depending on whether the feature space is sparse or dense. With bag-of-words representations in NLP, feature vectors are typically very sparse: a document might contain only a few hundred unique words out of a vocabulary of tens of thousands. Most entries in x\mathbf{x} are zero. The dot product w⋅x\mathbf{w} \cdot \mathbf{x} then only involves the non-zero entries, and the classifier effectively sums votes only from words present in the document.

Dense feature representations, such as averaged word embeddings or sentence vectors from a pretrained encoder, give every dimension a non-zero value. The classifier must consider the full vector, and every dimension can affect the decision. Logistic regression on top of dense embeddings is a common pattern in modern NLP, used as a lightweight classification head on top of a frozen pretrained model. The embeddings provide rich features; the linear classifier provides a trainable decision layer. This separation of feature extraction from classification is a recurring architectural pattern throughout this book.