Listen: Class Imbalance

When one class in a training dataset vastly outnumbers another, causing a naive model to ignore the minority class — requires deliberate handling through weighted loss, resampling, or specialised loss functions.

Listen

Transcript

Class imbalance happens when a training dataset has far more examples of one category than another. For instance, a dataset might consist of ninety-five percent ordinary text and only five percent link text. If you train a model naively on this data, it will quickly learn that the easiest way to get a low average error is to simply predict the majority class every single time.

This creates a major problem. A model that always predicts "not a link" would technically achieve ninety-five percent accuracy, but it would completely fail to find any actual links. In these situations, standard accuracy is a misleading metric. Instead, developers have to focus on precision, recall, and F1 scores for the minority class.

To fix this, engineers use a few key strategies. One approach is class-weighted loss, which penalizes the model more heavily when it misclassifies the minority class. Another method is focal loss, which automatically down-weights easy examples during training, forcing the model to focus on the harder, rarer cases. Finally, there is resampling, which involves either undersampling the majority class or oversampling the minority class using synthetic data. These techniques ensure the model actually learns to detect what it was built to find, rather than just guessing the most common answer.