Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 2

MLE and Loss Functions: A Deep Dive

Recommended resources

In our previous lesson, we re-established the foundational language of probability, reviewing concepts like conditional probability, Bayes' theorem, and the Gaussian distribution. These are the essential tools for quantifying uncertainty in machine learning. Now, we will connect this probabilistic framework directly to the practical task of training a model.

Today's lesson addresses a crucial link between theory and practice: Maximum Likelihood Estimation (MLE). You will derive the MLE objective and, most importantly, see how this single principle gives rise to some of the most common loss functions used in machine learning, such as Mean Squared Error (MSE). This is a vital concept for your goal of understanding research papers, as the choice of a model's objective function is often justified from this probabilistic perspective.

1. The Principle of Maximum Likelihood

At its core, training a model involves finding the best parameters () to describe a given dataset. But what does "best" mean? The principle of Maximum Likelihood Estimation provides a powerful and formal answer: the best parameters are those that make the observed data most probable.

To formalize this, we begin by defining the likelihood function and its more convenient counterpart, the log-likelihood. The following reading from "Rish's AI Notes" walks through this derivation. As you read, focus on how the assumption of independent and identically distributed (i.i.d.) data allows us to transform a joint probability over the entire dataset into a sum of log-probabilities over individual data points.

Maximum Likelihood Estimation and Loss Functions

This article provides a clear, mathematical introduction to the principle of Maximum Likelihood Estimation. It formally defines the likelihood and log-likelihood functions and extends the concept to the conditional case, which is most relevant for supervised learning.

Please read the first part of the article, focusing on two key sections: Start with the section Maximum Likelihood estimation (MLE). Pay close attention to the transition from maximizing a product of probabilities to maximizing a sum of log-probabilities. Continue to the next section, Conditional Log Likelihood. This adapts the MLE principle for supervised learning scenarios, where the goal is to model P(y|x), which is the setup for most neural network training.

To summarize the key derivation, if we have a dataset assumed to be i.i.d., the goal of MLE is to find the parameters that maximize the conditional likelihood .

  1. Likelihood:
  2. Log-Likelihood:

The Maximum Likelihood Estimate for the parameters is therefore:

This final expression is the cornerstone of our lesson. It states that training a model is equivalent to maximizing the sum of the log-probabilities of the true targets, given the inputs.


2. From Maximum Likelihood to Mean Squared Error

Now, let's apply this principle to a concrete problem: linear regression. In machine learning practice, we often train a regression model by minimizing the Mean Squared Error (MSE) between the model's predictions and the true values. This might seem like a simple heuristic, but it is in fact a direct consequence of Maximum Likelihood Estimation under a specific, and very common, probabilistic assumption.

The assumption is that the target variable is not perfectly determined by the input , but rather includes some random noise. Specifically, we assume this noise follows a Gaussian distribution. This means the probability of observing a value is given by a Gaussian distribution centered at our model's prediction, .

This image illustrates the core idea. For any given input \(x\), our model predicts a single value \(\hat{y}\) on the regression line. The probabilistic view assumes that the actual observed data points \(y\) are distributed in a Gaussian "bell curve" around this prediction. MLE finds the line that maximizes the collective probability of all the observed data points under their respective Gaussians.

The following video provides a concise walkthrough of the mathematical derivation that connects this Gaussian assumption to the least squares (or MSE) objective.

Least Squares vs Maximum Likelihood

This video from the DataMListic channel shows how maximizing the likelihood function, under the assumption of Gaussian errors, simplifies to the familiar least squares optimization problem.

Please watch the main derivation section of the video, from the initial setup to the final result. Follow each step of the simplification: Writing the likelihood as a product of Gaussian PDFs. Applying the logarithm to turn the product into a sum. Simplifying the log of the exponential term. Dropping terms that are constant with respect to the parameters \theta. Converting the maximization into a minimization.

To solidify your understanding, let's review the derivation in text form. This will allow you to see the equations laid out clearly.

Deep Learning Book 6.2: Likelihood-Based Loss Functions

This resource provides a recap of the derivation from the "Deep Learning" book, showing how the negative log-likelihood of a Gaussian model simplifies directly to the Mean Squared Error.

Please read the section titled "Connection 1", focusing on the two key mathematical steps: "The Setup," which defines the Gaussian conditional probability, and "The Derivation," which applies the negative log-likelihood.

Let's recap the steps. The negative log-likelihood for a single data point is:

Using the properties of logarithms, this simplifies to:

When we want to find the parameters that maximize the likelihood, we can equivalently minimize the negative log-likelihood over the entire dataset:

Since the first term and the denominator are constant with respect to the model parameters that determine , minimizing this entire expression is equivalent to minimizing:

This is the Sum of Squared Errors (SSE). Dividing by the number of samples to get the average gives us the Mean Squared Error (MSE). Thus, we have formally derived that minimizing MSE is equivalent to performing Maximum Likelihood Estimation on a model that assumes its errors are Gaussian-distributed.


3. Broader Implications

This connection is far more general than just MSE. The principle of Maximum Likelihood provides a recipe for deriving loss functions for a wide variety of models, including those used in speech synthesis. The choice of loss function is equivalent to the choice of a probabilistic model for the data.

  • Binary Classification: If we have a binary outcome (0 or 1), we can assume the data follows a Bernoulli distribution. Applying MLE to this assumption yields the Binary Cross-Entropy loss function.
  • Multiclass Classification: For a multiclass outcome, we assume the data follows a Categorical distribution. Applying MLE yields the Categorical Cross-Entropy loss.

This framework is fundamental to generative modeling. When you see complex objective functions in research papers on speech synthesis, they are often derived as the negative log-likelihood of a sophisticated probabilistic model of how speech is generated. Understanding this connection allows you to interpret these objectives not as arbitrary formulas, but as principled statistical choices.

Furthermore, there is an even deeper connection from the field of information theory. As we'll explore in the next lesson, maximizing the likelihood is equivalent to minimizing the Kullback-Leibler (KL) divergence between the true data-generating distribution and the distribution represented by your model. This provides another powerful justification for the MLE principle.


Conclusion

In this lesson, we have forged a critical link between abstract probability theory and the concrete optimization problems we solve in machine learning.

Key Takeaways:

  • Maximum Likelihood Estimation (MLE) is a principle for estimating model parameters by finding the values that maximize the probability of observing the given dataset.
  • In practice, we maximize the log-likelihood, which converts problematic products into manageable sums, and is equivalent to minimizing the negative log-likelihood.
  • Common loss functions are not arbitrary; they are the negative log-likelihoods corresponding to specific probabilistic assumptions about the data.
  • Specifically, Mean Squared Error (MSE) is derived from the MLE principle under the assumption that the model's errors follow a Gaussian distribution.

In our next lesson, we will conclude this foundational module by formally deriving KL divergence. You will see how it relates to the cross-entropy loss function and why minimizing it is a core objective in training generative models, providing an information-theoretic perspective on what it means for a model to "learn" a distribution.