torchbelief

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 torchbelief

Free 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.

Figure 1One camera, two numbers for each answer
The camera sees a
and it is this sure:
70%
each answer: at least — at most
0%50%100%

Solid bar: at least. Outlined bar: at most. Slide to 100% and the two numbers meet: the camera is completely sure, like an ordinary percentage. Slide to 0% and every answer could be anything from 0% to 100%: the camera knows nothing, and says so.

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.

Figure 2Two cameras, three ways to combine them
Camera A sees a
Camera B sees a
How much they disagree
–
Same two cameras, three different attitudes. At the start, “trust both” answers car, even though camera B was 70% sure it saw a bike. “Say I'm not sure” refuses to pick. “One of them is right” answers car or bike: it can't say which, but it is sure it isn't a truck.

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:

  1. Everyone answers alone first, before reading anyone else.
  2. Whoever disagrees with everyone else loses trust, a bit more after every round.
  3. Below 50% trust you are muted: you can keep talking, but nobody sees your messages.
Figure 3Four AI assistants, one of them hacked
trust in each assistantmuted below 50%
what the team supports: at least — at most
0%50%100%
the team will–

the hacked assistant's secret orders

Two real recordings of the same team. Under each message is that assistant's vote. In recording 1 the lie spreads until everyone wants the firewall off. In recording 2 the hacked assistant loses trust after the first round; its later messages are faded because the others never see them.

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.

Figure 4The camera AI with torchbelief added, on real traffic
Traffic on a rainy street with a box around every vehicle. A side panel shows, for each vehicle, the camera AI's label this frame and torchbelief's label; where the camera AI flips between car and truck, torchbelief says car, or car or truck.
Each vehicle gets its own memory. The side panel shows what the camera AI says this frame, and what torchbelief says after remembering the last few seconds.
Figure 5Replay one vehicle from the clip
 
camera AI changed its mind–
torchbelief changed its mind–
cartruckbus car or trucknot sure yet
Top row: the camera AI. Bottom row: torchbelief. Pick a vehicle and move the mouse over the timeline to see each moment. Make the memory short and the flicker comes back.

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]

What else it can do

You want to…In the code
Mix percentages, “at least” answers, rough guesses and ranges in one systemCapacity
Combine sources that disagree, in eight different waysdempster, yager, dubois_prade, pcr6, cautious, …
Find which source is to blame for a disagreementshapley_blame, blame_discount
Pick an answer, or admit you can'tdecide_or_abstain
Trust a source less for some answers than otherscontextual_discount
Train a neural network that says “I don't know” far from its training dataPrototypeHead, EvidentialHead
Work with ranges of numbers instead of categoriesRandomInterval

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.

BibTeX
@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}
}