Energy-Based Models for Enterprise Decision-Making: Architecture and PyTorch Implementation

Enterprise AI has become quite good at prediction. Given a food-delivery order, a machine-learning model can estimate the delivery time. A retailer can forecast demand for the next week. Large Language Models (LLMs) added another capability. They can understand unstructured information, generate content, summarize documents, interact with users and perform reasoning tasks.
But many enterprise problems do not end with prediction or reasoning. Eventually, the system has to decide:
What should we do next?
This is where decision systems become important. Recently, System One models have been proposed for fast, structured decision-making. TypeSafe AI, for example, positions Jev as a System One model that accepts state and typed questions and returns structured probabilistic answers.
Another approach worth examining is the Energy-Based Model (EBM). EBMs are not new. The concept has been studied for several decades. What makes them relevant to enterprise architecture today is their ability to score possible outcomes or actions instead of simply producing one prediction.
This article looks at where Energy-Based Models can fit alongside traditional machine learning, LLMs and emerging System One models.
Prediction Is Not the Same as Decision Making
Consider a simplified DoorDash-like food-delivery system. The platform wants to estimate how long an order will take to reach the customer.
A conventional machine-learning model might use:
- number of items,
- restaurant category,
- time of day,
- estimated driving duration,
- number of Dashers online,
- number of busy Dashers,
- outstanding orders, and
- current marketplace demand.
A regression model learns f(x)=y, where x represents the current marketplace state and y represents delivery duration.
The model might return f(x)=43.7 minutes that is useful. But it is not necessarily the final business decision. Should the application tell the customer "Your order will arrive in 44 minutes"?. Not necessarily. Being five minutes late may damage the customer experience more than providing a slightly conservative estimate. The platform therefore has to answer a different question:
What delivery time should we promise the customer?
And the real operational problem is even broader. The delivery platform may also need to determine:
- Which Dasher should take the order?
- Should the order be batched with another delivery?
- Which pickup sequence should be followed?
- Which route should be selected?
- What ETA should be shown to the customer?
These are related questions, but they are not the same as predicting one number.
Prediction asks:
What is likely to happen?
Decision making asks:
Which possible state, outcome or action best fits the situation and our objectives?
Consider the following probability distribution of delivery time for one-order (the 60-minute slot covers deliveries of 60 minutes or more):

The most preferred selection is around 45 minutes (higher probability - 27%). But suppose being late is much more damaging to customer experience than giving a conservative estimate. The best customer promise might be 50 minutes (though only 24% likely). The prediction remains 45 minutes. The decision might be 50 minutes. Hence “Models estimate reality. Decision systems choose actions.” Traditional machine learning primarily helps with the first problem. Decision systems must solve the second.
What Is an Energy-Based Model?
The below scenario illustrates the use of EBM:

An Energy-Based Model learns an energy function:

It is the energy assigned to candidate y given context x. The symbol theta (θ) represents the model parameters such as neural-network weights and biases - the model learned from historical data. Hence, if Energy function returns 0.5, that can be read as:
"Using the parameters learned during training, the model assigns energy 0.5 to the combination of this marketplace state and a 45-minute delivery."
Lower energy indicates that the candidate is more compatible with the current context. Higher energy means it fits poorly. Hence, Inference can therefore be expressed as:

This is different from asking a model to directly predict one value. Instead, we can evaluate several possible values or actions and ask: Which candidate fits this situation best?
Think of an Energy Landscape
Imagine placing a ball on an uneven surface. The ball naturally tends toward a valley.

An EBM creates something conceptually similar: a landscape over possible solutions. The EBM is learning the shape of the solution landscape. Instead of knowing only where the valley bottom is, we also know something about the terrain around it. For the delivery example, the model might assign:
Candidate duration Energy ------------------ ------ 30 minutes 2.70 35 minutes 1.85 40 minutes 1.09 45 minutes 0.50 ← lowest energy 50 minutes 0.62 55 minutes 1.09 60 minutes 1.85 65 minutes 3.10 A normal regression model might simply say:
ETA = 45 minutes The EBM instead says something closer to:
45 minutes fits this situation very well. 50 minutes is also plausible. 30 minutes is inconsistent with the current marketplace state. This is a subtle but important difference. The model is learning the shape of the solution space, not merely returning one scalar value.
From Energy to a Distribution
For a finite set of candidate delivery durations, we can convert energies into normalized probabilities:

In simple terms:
- x = current situation, e.g. order + traffic + driver availability.
- y = one possible outcome, e.g. 45-minute delivery.
- E_theta(x,y) = energy score for that outcome.
- Lower energy → higher probability.
- The denominator adds the scores of all possible outcomes, so the final probabilities add up to 100%.
Applying this formula to the eight energies from the previous section gives the distribution below (probabilities rounded to the nearest percent). For example, for 45 minutes: e^(-0.50) = 0.607, the eight terms sum to 2.244, and 0.607 / 2.244 = 27%. This is the same distribution as the opening chart, with its 60-minute slot (9%) split into 60 minutes (7%) and 65 minutes (2%).
| Delivery Duration | Energy | Probability | Cumulative Probability |
|---|---|---|---|
| 30 min | 2.70 | 3% | 3% |
| 35 min | 1.85 | 7% | 10% |
| 40 min | 1.09 | 15% | 25% |
| 45 min | 0.50 | 27% | 52% |
| 50 min | 0.62 | 24% | 76% |
| 55 min | 1.09 | 15% | 91% |
| 60 min | 1.85 | 7% | 98% |
| 65 min | 3.10 | 2% | 100% |
From this distribution: Mode=45 minutes; the median (P50) is also 45 minutes because cumulative probability crosses 50% at 45 minutes. Similarly: P90=55 minutes. We now have more information than a single ETA. But there is an important point here.
An EBM Is Not Required Just to Get P50 or P90
Traditional machine learning already provides strong techniques for uncertainty estimation. Quantile regression can directly estimate P50, P80 and P90. Probabilistic regression can estimate a complete probability distribution. LightGBM, XGBoost and neural-network-based approaches can all be used for this purpose. Hence, generating a probability distribution around an ETA is not sufficient justification for introducing an EBM.
An EBM becomes more interesting when the candidate being evaluated is richer than a single number. Before getting there, however, let us look at how prediction becomes a decision.
From ETA Prediction to Customer Promise
Suppose the business decides that being late is four time more costly than providing a conservative ETA.
Let (a) = actual delivery duration, (p) = promised delivery duration. Define the business cost as:

Now the system should not simply select the most likely ETA. It should choose the promise that minimises expected business cost. In our example:
50 minutes → cumulative probability 76% 55 minutes → cumulative probability 91% Evaluating the expected cost of each candidate promise against the distribution above gives E[C(a,50)] = 11.5 for a 50-minute promise and E[C(a,55)] = 10.5 for a 55-minute promise. Every other candidate costs more (45 minutes: 18.5; 60 minutes: 13.25). Among these discrete candidates, the optimal customer promise is therefore 55 minutes. This agrees with the classic critical-ratio result: when being late costs four times as much as being early, the best promise is the 4 / (4 + 1) = 80th percentile, and 55 minutes is the first candidate whose cumulative probability (91%) reaches 80%.
The result is:
Most likely ETA 45 minutes Expected ETA 47.25 minutes Median / P50 45 minutes P90 ETA 55 minutes Cost-optimal promise 55 minutes (P80) However, quantile regression could also solve this particular problem by directly estimating P80. So we need to go one step further to understand where an EBM can provide a more distinct capability.
The More Interesting EBM Use Case: Evaluate an Entire Delivery Plan
Until now, y represented only delivery duration. What happens if y represents an entire operational plan?
For example:
DeliveryPlan { dasher, batching_strategy, pickup_sequence, route, customer_promise } The platform may have several possible plans:
| Candidate | Dasher | Strategy | Promise | Energy |
|---|---|---|---|---|
| A | D17 | Direct | 38 min | 2.4 |
| B | D42 | Batch | 46 min | 0.8 |
| C | D99 | Direct | 41 min | 1.3 |
The energy function now becomes: E_theta({marketplace state}, {delivery plan}). Conceptually:

This is a stronger EBM use case. The model is no longer estimating uncertainty around one scalar value. It is scoring possible operational states and actions as illustrated below.

A Quick PyTorch Walkthrough
Take the three candidate plans from the previous section, now with their estimated route durations:
| Action | Dasher | Strategy | Route | Promise |
|---|---|---|---|---|
| A | D17 | Direct | 31 min | 38 min |
| B | D42 | Batch | 37 min | 46 min |
| C | D99 | Direct | 34 min | 41 min |
The EBM's job is to score these actions and identify the one that best fits the current marketplace state.
Step 1: Represent Context and Action
The context describes the current situation. For example:
Order items Restaurant load Busy Dashers Available Dashers Outstanding orders Traffic level Distance Time of day The action describes what we could do. For this simplified example, assume that each candidate action has numerical features such as:
Dasher current load Batching: yes/no Estimated route duration Customer promise Step 2: Define the Energy Model
A simple PyTorch model can concatenate the context with each candidate action and return one scalar energy per candidate. It scores a whole batch of decisions at once, which is how it is trained and served:
import torch from torch import nn class DeliveryActionEnergyModel(nn.Module): def __init__(self, context_dim: int, action_dim: int, hidden: int = 128): super().__init__() self.energy = nn.Sequential( nn.Linear(context_dim + action_dim, hidden), nn.SiLU(), nn.Linear(hidden, hidden // 2), nn.SiLU(), nn.Linear(hidden // 2, 1), ) def forward(self, context, actions): # context: [batch, context_dim] # actions: [batch, num_candidates, action_dim] context = context.unsqueeze(1).expand(-1, actions.shape[1], -1) features = torch.cat([context, actions], dim=-1) return self.energy(features).squeeze(-1) # [batch, num_candidates] Unlike regression, the energy model does this:
context + candidate duration → Energy Model → energy
Step 3: Generate Feasible Candidate Actions
Assume the operational system generates three feasible plans for one marketplace state. Route and promise minutes are divided by 60 so that every feature sits on a similar 0–1 scale; the same scaling must be applied during training:
# items, restaurant load, busy Dashers, available Dashers, # outstanding orders, traffic, distance, time of day (scaled 0-1) context = torch.tensor([[0.30, 0.70, 0.80, 0.25, 0.60, 0.50, 0.45, 0.80]]) ACTION_SCALE = torch.tensor([1.0, 1.0, 60.0, 60.0]) candidate_actions = torch.tensor([ # load, batch, route_min, promise_min [0.20, 0.0, 31.0, 38.0], # Action A [0.45, 1.0, 37.0, 46.0], # Action B [0.10, 0.0, 34.0, 41.0], # Action C ]) / ACTION_SCALE Step 4: Score Every Action
Now evaluate each candidate against the same marketplace context. Plans that break a hard constraint are masked out so they can never be selected:
model = DeliveryActionEnergyModel(context_dim=8, action_dim=4) @torch.no_grad() def choose_action(model, context, actions, feasible=None): model.eval() energies = model(context, actions) if feasible is not None: energies = energies.masked_fill(~feasible, float("inf")) return energies, energies.argmin(dim=-1) The result might look like:
Action A → Energy 2.4 Action B → Energy 0.8 Action C → Energy 1.3 Hence:
Action B → Energy 0.8 → Selected In PyTorch:
energies, best_action_index = choose_action( model, context, candidate_actions.unsqueeze(0) # a batch of one decision ) best_action = candidate_actions[best_action_index.item()] This is the basic EBM decision loop.
Step 5: Train Good Actions to Have Lower Energy
The model still has to learn what constitutes a good action. Suppose historical data, an operational simulator, or another trusted decision process tells us that Action B produced the best outcome for a particular marketplace state.
We want: E_theta(x,A_B) < E_theta(x,A_A) and E_theta(x,A_B) < E_theta(x,A_C)
One convenient implementation is to treat negative energy as the candidate logit and apply a cross-entropy loss across the candidates of each decision, the same contrastive objective used to train energy-based policies in Implicit Behavioral Cloning. In practice the model learns from many logged decisions, each with its own context, its own set of feasible candidates and the index of the best one:
optimizer = torch.optim.AdamW(model.parameters(), lr=1e-3) # Each batch holds many past decisions: # contexts [batch, 8] # actions [batch, max_candidates, 4] (padded, scaled) # feasible [batch, max_candidates] (False = padding or infeasible) # best_actions [batch] (index of the best plan) model.train() for contexts, actions, feasible, best_actions in loader: energies = model(contexts, actions) # Negative energy is the logit; masked plans get zero probability logits = (-energies).masked_fill(~feasible, float("-inf")) loss = nn.functional.cross_entropy(logits, best_actions) optimizer.zero_grad() loss.backward() optimizer.step() The training process adjusts (theta) so that preferred actions receive lower energy.
Conceptually:

There is an important practical consideration here. The historical action is not automatically the best action. If a historical dispatcher selected Dasher D42, that does not prove D42 was optimal. Training labels should therefore come from a suitable source such as:
- high-quality historical decisions and outcomes,
- an optimisation engine,
- a simulator,
- expert demonstrations, or
- a business utility function that evaluates the resulting outcome.
Otherwise, the EBM may simply learn to reproduce historical decision-making mistakes.
Step 6: Convert Energy Into Action Probabilities
If we are comparing a finite set of candidate actions, we can convert their energies into probabilities:
probabilities = torch.softmax( -energies, dim=-1 ) Suppose the result is:
Action A Energy 2.4 Probability 11.2% Action B Energy 0.8 Probability 55.3% <--- Action C Energy 1.3 Probability 33.5% Action B receives the highest probability because it has the lowest energy. These are normalized model scores over these three candidates, not necessarily calibrated probabilities of real-world success.
Where Does System One Fit?
System One Models and Energy-Based Models should not automatically be treated as competing technologies. TypeSafe describes Jev, its first System One Model, as taking state and typed questions and returning typed probabilistic decisions. Unlike an autoregressive LLM, which generates strings token by token, Jev is designed around structured outputs and parallel sampling.
TypeSafe reports approximately 70–500 ms end-to-end response times and 40×–200× speed improvements for comparable System-One-shaped queries in some of its demonstrations. In our delivery example, a System One model might rapidly classify the marketplace state:
NORMAL HIGH_DEMAND DRIVER_SHORTAGE RESTAURANT_DELAY SEVERE_CONGESTION This judgment can influence which actions should even be considered. The Energy-Based Model then compares possible responses within that context. This can be interpreted as “System One narrows the interpretation of the world. Energy-based scoring compares possible responses to that world”.
And Where Does the LLM Fit?
LLMs remain extremely useful because enterprise information is often messy and unstructured. Suppose a restaurant manager writes:
"Heavy rain around the store. Two riders cancelled, kitchen is running about 15 minutes behind and we suddenly have 23 open orders."
An LLM can transform this into structured state:
Weather = HEAVY_RAIN Driver shortage = TRUE Kitchen delay = 15 minutes Outstanding = 23 That state can feed predictive and decision models. The LLM can also explain the final decision:
"The delivery promise was extended because the restaurant is currently delayed, driver availability is low and heavy rain is increasing expected travel time."
This leads to an architecture in which each model does what it is good at.
You can also build an EBM on top of a small LLM such as gemma-3-270m or Qwen3-0.6B. The idea is simple: use the LLM only to read, not to write. Describe the context and one candidate as a short piece of text, pass it through the model, and add a small layer on top (the “energy head”) that turns the model’s internal representation into a single energy score. The model’s text generation ability is not used at all.
This approach is useful when the candidates or the context contain free text: dispatcher notes, restaurant messages, or constraints written in plain language. A small LLM already understands such text, so you do not have to convert it into numeric features by hand. Gemma 3 270M is the lighter and faster option; Qwen3 0.6B is about twice the size and gives somewhat richer representations at a higher cost.
For purely numeric inputs, like the food delivery example in this article, a plain MLP (multilayer perceptron) is the better choice. It is faster and usually more accurate, because LLMs of any family handle numbers poorly when they are written as text. Switching from Gemma to Qwen does not change this.
A practical middle path is a hybrid: let the LLM read only the text part of the context, and feed the numeric features straight into the energy head.
Decision Intelligence Architecture
Refer to the diagram below:

The roles are different:
- Traditional ML estimates variables.
- System One models can provide fast structured judgments.
- Energy-Based Models can score candidate configurations.
- Optimization searches for good feasible actions.
- Policy and deterministic code enforce hard constraints.
- LLMs interpret, generate and explain.
None of these components has to replace all the others. The interesting architecture is often a composition of them.
Closing Notes
An EBM can be a small neural network like the PyTorch example above. It does not require GPT, Claude, Llama or another LLM. For a structured enterprise problem such as pricing, scheduling, delivery planning or inventory allocation, I would often prefer a separate, domain-specific energy model. However, energy functions can also be built around large language models (References #7).
Unlike LLMs provided via closed APIs (OpenAI's GPT or Anthropic's Claude), Energy-Based Models are rarely offered as turnkey cloud APIs. This is due to the inherent computational difficulty of inference-time optimization (finding low-energy states typically requires iterative sampling or gradient descent loops at runtime). Instead, they are actively researched, custom-built, and integrated into specialized domain software such as autonomous vehicle trajectory planners, robotics policy optimizers, and advanced self-supervised world model architectures.
References
- Yann LeCun, Sumit Chopra, Raia Hadsell, Marc'Aurelio Ranzato and Fu Jie Huang, A Tutorial on Energy-Based Learning, 2006.
- Yilun Du, Toru Lin and Igor Mordatch, Model-Based Planning with Energy-Based Models, Conference on Robot Learning.
- Pete Florence et al., Implicit Behavioral Cloning, Conference on Robot Learning.
- TypeSafe AI, Introducing System One Models & Jev, 2026. Performance figures cited in this article are vendor-reported and should not be interpreted as independent benchmark results.
- Mastering TypeSafe Jev book by Sheik Uduman Ali
- Yann LeCun, A Path Towards Autonomous Machine Intelligence, 2022.
- Alexi Gladstone et al., Energy-Based Transformers are Scalable Learners and Thinkers, 2025.
- Yifei Xu et al., Energy-Based Continuous Inverse Optimal Control, 2019.
- LightGBM documentation, Parameters (quantile objective).
- Quantile Regression.
- Wikipedia, Newsvendor model (critical fractile formula).