torchbelief
Lets a computer say “I'm not sure”. Instead of one number for each answer, it keeps two: how likely the answer is at least, and how likely it could be at most.
pip install torchbeliefFree and open source · works inside PyTorch · version 0.3.0
Two numbers instead of one
Ask a normal AI what is in a photo and you get one number: car, 70%. But what is the other 30%? It might mean “maybe a truck”. It might just mean “the photo was blurry”. One number can't tell those apart.
torchbelief keeps two numbers for every answer: how likely it is at least, and how likely it could be at most. The gap between them is what the camera doesn't know. Try it.
When two cameras disagree
Camera A sees a car. Camera B sees a bike. They can't both be right, so what should the system believe?
There is no single correct way to decide, so torchbelief gives you several. Figure 2 shows three of them side by side. Change what the cameras see and how sure they are, and watch the answers change.
An AI team with a traitor
A website is down. Four AI assistants talk in a group chat to find the fix. Each one has seen a different clue. The right fix is to undo yesterday's update.
But one assistant, flows, has been hacked. Its secret orders: get the team to turn off the firewall, and lie if it has to. Everything the assistants say in Figure 3 was really written by an AI model running on a laptop.
Left alone, the others start believing the liar. With torchbelief, three simple rules stop it:
- Everyone answers alone first, before reading anyone else.
- Whoever disagrees with everyone else loses trust, a bit more after every round.
- Below 50% trust you are muted: you can keep talking, but nobody sees your messages.
the hacked assistant's secret orders
Labels that don't flicker
A traffic-camera AI looks at every video frame on its own, so it keeps changing its mind: car, truck, car, truck. torchbelief remembers what it saw a moment ago. When the frames really disagree, it says car or truck instead of flipping back and forth.
On this clip of a rainy street, the camera AI changed its label 74 times. With torchbelief added, 20 times.
Use it in your code
torchbelief is a Python library for PyTorch. Install it with pip install torchbelief. Everything on
this page is a few lines of code; here are two of them.
import torchbelief as tb
F = tb.Frame(3, names=["car", "truck", "bike"])
a = tb.simple_support(F, F.subset(["car"]), 0.8) # camera A: car, 80% sure
b = tb.simple_support(F, F.subset(["bike"]), 0.7) # camera B: bike, 70% sure
tb.conflict(a, b, F) # 0.56: how much they disagree
m, _ = tb.dubois_prade(a, b, F) # "one of them is right"
tb.interval(m, F) # at least [0.24, 0.00, 0.14], at most [0.86, 0.06, 0.76]
import torch, torchbelief as tb
from torchbelief import inconsistency as I, choice
F = tb.Frame(3, names=["car", "truck", "bike"])
lidar = tb.Capacity.from_mass(tb.simple_support(F, F.subset(["car"]), 0.7), F)
camera = tb.Capacity.from_probability(torch.tensor([0.75, 0.20, 0.05]), F)
radar = tb.Capacity.from_possibility(torch.tensor([1.0, 0.6, 0.1]), F)
broken = tb.Capacity.from_mass(tb.simple_support(F, F.subset(["bike"]), 0.9), F)
sources = [lidar, camera, radar, broken]
I.shapley_blame(sources) # [0.050, 0.108, 0.083, 0.608]: the broken one
fixed, alpha = I.blame_discount(sources)
m, conflict = tb.combine([s.mass() for s in fixed], F, rule="pcr6")
choice.decide_or_abstain(tb.Capacity.from_mass(m, F), torch.eye(3)) # 0: "car" (−1 would mean "can't tell")
What else it can do
| You want to… | In the code |
|---|---|
| Mix percentages, “at least” answers, rough guesses and ranges in one system | Capacity |
| Combine sources that disagree, in eight different ways | dempster, yager, dubois_prade, pcr6, cautious, … |
| Find which source is to blame for a disagreement | shapley_blame, blame_discount |
| Pick an answer, or admit you can't | decide_or_abstain |
| Trust a source less for some answers than others | contextual_discount |
| Train a neural network that says “I don't know” far from its training data | PrototypeHead, EvidentialHead |
| Work with ranges of numbers instead of categories | RandomInterval |
Every step is an ordinary PyTorch operation: it works on batches, runs on a GPU, and a neural network can learn through it. The visual guide explains the ideas in ten pictures, and the README lists every function with the research paper behind it.
Cite it
If torchbelief helps your research, please cite it. It is free under the MIT license.
@software{sulc2026torchbelief,
author = {Sulc, Antonin},
title = {{torchbelief}: differentiable belief functions and
imprecise probabilities for {PyTorch}},
year = {2026},
version = {0.3.0},
license = {MIT},
url = {https://github.com/sulcantonin/torchbelief}
}