AnyLearn
All lessons
AIadvanced

Energy Landscapes: The EBM View

Energy-based models replace input-to-output functions with a scalar energy that scores how compatible a configuration is. This lesson covers the energy function, inference as finding the lowest-energy answer, the energy landscape picture, the link from energy to probability via the partition function, and why this framing handles problems with many valid answers.

Updated · AI-authored, review-gated · how lessons are made

Not signed in: your progress and quiz score won't be saved.
Progress1 / 8

A different way to model

Most neural networks are functions: feed an input in one end, get an output the other. An energy-based model (EBM) reframes the whole setup. Instead of a function from input to output, it learns a single scalar energy that scores how well things fit together: low energy for configurations that are correct or compatible, high energy for those that are wrong.

This sounds abstract, but it is a powerful shift, and it is the framing Yann LeCun has advocated for decades, laid out in his 2006 "A Tutorial on Energy-Based Learning." Rather than committing the model to produce one answer, you give it a way to judge any proposed answer. Asking for the best answer then becomes a search for the lowest-energy one. This lesson builds that picture: what energy is, how you use it to make predictions, and why measuring compatibility, rather than computing an output directly, buys real flexibility.

Full lesson text

All 8 steps on one page, for reading, reference, and search.

Show

1. A different way to model

Most neural networks are functions: feed an input in one end, get an output the other. An energy-based model (EBM) reframes the whole setup. Instead of a function from input to output, it learns a single scalar energy that scores how well things fit together: low energy for configurations that are correct or compatible, high energy for those that are wrong.

This sounds abstract, but it is a powerful shift, and it is the framing Yann LeCun has advocated for decades, laid out in his 2006 "A Tutorial on Energy-Based Learning." Rather than committing the model to produce one answer, you give it a way to judge any proposed answer. Asking for the best answer then becomes a search for the lowest-energy one. This lesson builds that picture: what energy is, how you use it to make predictions, and why measuring compatibility, rather than computing an output directly, buys real flexibility.

2. The energy function

Formally, an EBM defines an energy function that takes a configuration and returns a single number. In the simplest case it scores one variable, written E(x)E(x): how plausible is this data point xx? More often it scores a pair, E(x,y)E(x, y): how compatible is output yy with input xx?

The convention is that lower energy means better. A real photograph gets low E(x)E(x); random noise gets high E(x)E(x). A correct caption yy for an image xx gets low E(x,y)E(x, y); a nonsense caption gets high energy. The energy function is typically a neural network, and it can be arbitrarily expressive. Note what is different from a classifier: the energy function does not output a class or a value. It outputs a score for a configuration you hand it. Getting an actual answer out of the model is a separate step, and that step is inference.

3. Inference is optimization

If the model only scores configurations, how do you get an answer? By searching for the configuration with the lowest energy. This is the defining move of EBMs: inference is optimization.

Suppose you have a trained E(x,y)E(x, y) and a specific input xx. To predict, you fix xx and search over possible outputs yy for the one that minimizes the energy: the most compatible answer. For a small discrete set of yy (say, class labels) you can just evaluate them all and pick the minimum. For a large or continuous yy you run an optimization, for example gradient descent on yy while holding xx fixed.

The power of this is flexibility. The same trained energy function answers many kinds of question depending on what you hold fixed and what you search over: fill in a missing part, rank candidates, check plausibility, or generate. One model, many query types, because inference is just "minimize energy over the unknowns."

4. The energy landscape

The most useful mental image is a landscape. Picture the space of all possible configurations spread out on a plain, with the energy as height. Correct, plausible data sits in the valleys (low energy); implausible configurations rise up the hills (high energy).

Training an EBM is sculpting this landscape: carving deep valleys exactly where the real data lives and raising everything else. Inference is then rolling downhill: from wherever you start, descend to the nearest valley, the most compatible answer. This picture makes the key ideas intuitive. A well-trained model has valleys precisely at the data and high ground everywhere else. A broken model has a flat landscape, no valleys, so every answer looks equally good and the model is useless. Keeping the landscape from flattening out is, as the next lesson shows, the entire difficulty of training, and it is the same collapse problem seen in self-supervised learning.

5. Sculpting and descending the landscape

Two operations on the same surface. Training pushes the energy down at real data points and up elsewhere, carving valleys at the data. Inference starts from an initial guess and descends the surface to the nearest valley, returning the lowest-energy, most compatible configuration. A flat landscape (no valleys) is the failure mode both later lessons work to prevent.

flowchart LR
  T["Training: push energy DOWN at data, UP elsewhere"] --> L["Energy landscape with valleys at real data"]
  L --> I["Inference: start from a guess"]
  I --> D["Descend to nearest valley (lowest energy)"]
  D --> A["Answer: most compatible configuration"]
  L -.->|"failure: no valleys"| F["Flat landscape: model useless"]

6. From energy to probability

Energies are unnormalized scores, but you can turn them into a probability distribution. The standard recipe (the Boltzmann or Gibbs form) is:

p(x)=eE(x)Z,Z=xeE(x)p(x) = \frac{e^{-E(x)}}{Z}, \qquad Z = \sum_{x'} e^{-E(x')}

Low energy gives high probability, and the exponential makes everything positive. The catch is ZZ, the partition function: the sum (or integral) of eEe^{-E} over every possible configuration, needed to make the probabilities add to one. For any interesting model, that sum is astronomically large or infinite, and therefore intractable to compute.

This single quantity, ZZ, is the source of nearly all the difficulty in energy-based modeling, and the reason the next lesson exists. But notice a liberating point: many uses of an EBM, ranking candidates, finding the most compatible answer, only need to compare energies, and for comparisons the constant ZZ cancels out. You often need the landscape's shape, not its absolute normalization.

7. Why energy handles many valid answers

A concrete payoff of the energy view is how naturally it handles problems with more than one correct answer. A standard regression network outputs a single value, so when several answers are valid it averages them, often landing on something wrong (the multimodality problem seen in the robot-learning cursus, where averaging "left" and "right" drives straight into an obstacle).

An EBM has no such trouble. Multiple valid answers are simply multiple valleys in the energy landscape, each a distinct low-energy region. Inference descends into one of them, returning a coherent answer rather than an incoherent average of all of them. This is why LeCun stresses energy-based models for perception and prediction: the real world is full of situations with many plausible continuations, and a model that scores compatibility can represent all of them at once, where a model forced to emit a single output cannot. The remaining question is purely practical: how do you train the energy function so those valleys land in the right places?

8. Where this cursus goes

You now have the core of the energy-based view. An EBM learns a scalar energy that scores compatibility; inference means searching for the lowest-energy configuration; the landscape picture makes training (sculpt valleys) and inference (roll downhill) intuitive; energies convert to probabilities through the intractable partition function ZZ; and multiple valid answers are just multiple valleys.

The next lesson tackles the hard part head-on: how to train an EBM when ZZ cannot be computed. The answer splits into two strategies, pushing energy up on wrong configurations (contrastive) versus constraining the landscape so it cannot flatten (regularized), and those two strategies are exactly the contrastive and non-contrastive families from the self-supervised-learning cursus. The final lesson then shows how this one framework unifies classification, generation, self-supervised learning, and JEPA under a single idea, which is why energy-based models sit at the center of LeCun's program.

Check your understanding

The lesson ends with a 5-question quiz. Take it in the player above to see your score.

  1. What does an energy-based model learn, instead of a direct input-to-output function?
    • A scalar energy that scores how compatible a configuration is, with low energy meaning better
    • A fixed lookup table of answers
    • A classifier that always outputs one label
    • The exact partition function Z
  2. In an EBM, how is a prediction (inference) made?
    • By reading the output layer directly
    • By searching for the configuration that minimizes the energy, holding the known inputs fixed
    • By computing the partition function Z
    • By averaging all possible outputs
  3. In the energy-landscape picture, where does real data sit and what is training?
    • Data sits on the hills; training flattens the surface
    • Data sits in the valleys (low energy); training sculpts deep valleys at the data and raises everything else
    • Data sits at infinity; training deletes it
    • There is no landscape in EBMs
  4. Why is the partition function Z problematic?
    • It is always exactly zero
    • It is the sum of exp(-E) over every possible configuration, which is intractable to compute for real models
    • It only appears in supervised learning
    • It makes energies negative
  5. Why does the energy view naturally handle problems with several valid answers?
    • It forces a single averaged output
    • Multiple valid answers are multiple valleys in the landscape, so inference descends into one coherent answer instead of averaging them
    • It ignores all but one answer during training
    • It requires the answers to be identical

Related lessons

AI
intermediate

Streams, Actions, Rewards, and Thinking That Is Not Ours

The paper is concrete about what an experiential agent would differ on, and names four: it lives in a continuous stream rather than episodes, acts in the world rather than emitting text, takes rewards from grounded signals rather than human judgement, and plans in terms it worked out rather than imitating human chain of thought. This lesson works through each.

8 steps·~12 min
AI
intermediate

The Argument: Why Learning From Us Runs Out

David Silver and Richard Sutton argue that the current approach has a ceiling built into it, because a system trained to predict what humans wrote is aiming at human performance by construction. This lesson works through their three eras, the claim about data exhaustion, why they think superhuman performance needs a different learning signal, and the honest counter-arguments.

8 steps·~12 min
AI
advanced

Grammars, Stacks, and Making It Free

Recursive formats need a machine with a stack, and a stack breaks the precomputed index because the mask now depends on context. This lesson covers context-free grammars and pushdown automata, XGrammar's split between context-independent and context-dependent tokens, why overlapping grammar work with the GPU makes overhead near zero, and how this interacts with batching and speculative decoding.

10 steps·~15 min
AI
advanced

From Schema to Mask: The Automaton Index

The naive mask costs 64 million validity checks per response. The trick that made constrained decoding practical is to notice that the answer depends only on the automaton's current state, so it can be computed once per state and looked up thereafter. This lesson builds that idea: regex to DFA, why the state is a sufficient summary, how JSON Schema compiles down, and what the index costs.

10 steps·~15 min