The Tsetlin Machine (TM) has no explicit notion of a loss function. Its learning signal is fixed to an implicit, margin-based update rule (MBUR), with no way to choose an objective function suited to a specific task. This paper introduces Loss-Guided TM, which replaces MBUR with an explicit and swappable loss function. In our proposed method, clause feedback and weight updates are driven by the loss, while keeping the Tsetlin Automaton and clause logic unchanged. The approach incorporates cross entropy (CE), symmetric cross entropy (SCE), and asymmetric loss (ASL). We evaluate Loss-Guided TM across six datasets that span multiclass, multilabel, and binary classification tasks. With a suitable loss, Loss-Guided TM matches or improves accuracy and F1 over MBUR on five of the six datasets. The gains are greatest for the imbalanced multilabel datasets, where ASL improves macro F1 by up to 9 percentage points. With CE, Loss-Guided TM is also significantly better calibrated than MBUR on all six datasets, reducing calibration error by a factor of 3 to 11. A qualitative inspection shows that the clause-based global interpretability, examined at the per-class level on image and text data, is preserved when using the Loss-Guided mechanism. These results show that our explicit TM learning objective allows direct targeting of uncertainty calibration, data imbalance, and task structure, opening the TM to the broader literature on loss functions.
Figures & tables
Dataset
C
s
T
q
p×p
ℓ
η
λ
MNIST
1000
10.0
2000
1.0
10×10
CE
1.0
1.0
FashionMNIST
16000
10.0
20000
1.0
3×3
CE
0.5
3.0
IMDB
10000
1.1
10000
1.0
-
CE
0.01
1.0
AG News
8000
2.0
40000
1.0
-
CE
0.01
1.0
SCE ( α=1.0 , β=1.0 )
0.005
1.0
GoEmotions
22400
2.0
25000
1.5
-
CE
0.5
4.0
Table 1: Hyperparameters used for each dataset and condition. T and q are used by MBUR, while η (learning rate) and λ (feedback rate) are used by Loss-Guided TM.
Dataset
Condition
Accuracy (%)
F1 (%)
ROC-AUC (%)
PR-AUC (%)
ECE
MNIST
MBUR
98.75 ± 0.11
98.74 ± 0.11
99.92 ± 0.01
99.46 ± 0.06
0.0056 ± 0.0002
CE
98.55 ± 0.13
98.54 ± 0.13
99.98 ± 0.00 †
99.87 ± 0.02 †
0.0016 ± 0.0001 †
FashionMNIST
MBUR
90.32 ± 0.13
90.28 ± 0.15
98.85 ± 0.04
92.49 ± 0.07
0.0263 ± 0.0009
CE
90.49 ± 0.18 †
90.46 ± 0.16 †
99.31 ± 0.01 †
95.37 ± 0.08 †
0.0047 ± 0.0003 †
IMDB
MBUR
85.52 ± 0.12
85.52 ± 0.12
90.20 ± 0.10
87.37 ± 0.23
0.0934 ± 0.0011
CE
88.61 ± 0.08 †
88.61 ± 0.08 †
95.14 ± 0.04 †
94.96 ± 0.04 †
0.0142 ± 0.0012 †
Table 2: Multiclass classification test metrics (mean ± std over 10 seeds).
Dataset
Condition
F1 (macro, %)
F1 (weighted, %)
PR-AUC (%)
ROC-AUC (%)
ECE
GoEmotions
MBUR
28.09 ± 1.08
38.03 ± 0.63
28.51 ± 0.60
80.55 ± 0.28
0.1601 ± 0.0076
CE
26.38 ± 0.37
40.42 ± 0.25 †
30.69 ± 0.22 †
81.60 ± 0.16 †
0.0142 ± 0.0005 †
ASL
37.06 ± 0.28 †
50.44 ± 0.18 †
34.46 ± 0.15 †
82.45 ± 0.08 †
0.2396 ± 0.0008
CelebA
MBUR
55.21 ± 0.67
67.99 ± 0.51
57.82 ± 0.16
86.08 ± 0.18
0.1457 ± 0.0150
CE
58.47 ± 0.50 †
71.12 ± 0.25 †
67.04 ± 0.10 †
89.60 ± 0.04 †
0.0299 ± 0.0021 †
ASL
63.86 ± 0.11 †
73.75 ± 0.09 †
66.73 ± 0.08 †
89.44 ± 0.05 †
0.1802 ± 0.0009
Table 3: Multilabel classification results on the test set (mean ± std over 10 seeds).
Figure 1: Training and test curves over 100 epochs for all six datasets. Plots show accuracy for MNIST, FashionMNIST, IMDB, and AG News, and macro F1 for CelebA and GoEmotions. Solid curves denote test performance and dashed curves denote training performance for MBUR and Loss-Guided variants.
Figure 2: Per-class global interpretations for all 40 CelebA facial attributes, comparing MBUR, Loss-Guided CE, and Loss-Guided ASL averaged over 10 seeds.
Figure 3: Per-class global interpretation for the IMDB dataset under MBUR and Loss-Guided CE. Words in red indicate positive word importance, while blue indicates negative importance. The relative magnitude of the importance is shown using the size of the word and the intensity of the color.
Appendix figures & tables12 assets
Supplementary material from the paper’s appendix.
Appendix
Figure 4: The local and global interpretation for the MNIST dataset. Red indicates positive feature importance, while blue indicates negative importance. The color intensity indicates the relative magnitude of the importance. The white region ( ≈ zero importance) indicates don’t care features, which do not affect the predictions of the model.
Figure 5: The local and global interpretation for the FashionMNIST dataset. Red indicates positive feature importance, while blue indicates negative importance. The color intensity indicates the relative magnitude of the importance.
Test Accuracy
Config
Clauses
s
T
η
Features
MBUR
Loss-Guided CE
v1
2000
2.0
5000
0.1
5000
0.813
0.837
v2
1000
2.0
5000
0.01
15000
0.849
0.861
v3
500
2.0
5000
0.01
2000
0.828
0.859
v4
500
1.1
5000
0.01
2000
0.822
0.868
v5
10000
1.1
50000
0.01
10000
0.857
0.875
Appendix
Table 4: Hyperparameters for the twelve IMDB sweep configurations (v1–v12). The Final row is the configuration reported in the main text (Table 1 ), using the MBUR runs of v12.
Figure 6: Training and test accuracy curves for all twelve IMDB sweep configurations (Table 4 ), using MBUR (left) and Loss-Guided CE (right). Solid curves denote test accuracy, dashed curves denote train accuracy.
Figure 7: Global interpretation for AG News across MBUR, CE, and SCE. The red color indicates positive word importance, while the blue color indicates negative importance. The relative magnitude of the importance is shown using the size of the word and the intensity of the color.
Figure 8: GoEmotions label distribution and performance sorted by class rarity from rarest to most common. The top panel shows training set frequency per label. The bottom panel displays test F1 scores (mean ± std over 10 seeds) for MBUR, CE, and ASL.
Figure 9: Global interpretations for the five rarest GoEmotions classes.
Figure 10: Global interpretations for the five most common GoEmotions classes.
Figure 11: (Top) per-label frequency in the CelebA training set. (Bottom) per-class test F1 for MBUR, CE, and ASL, mean ± std over 10 seeds. Both sorted by class rarity (rarest first).
Dataset
MBUR
Loss-Guided
MNIST
5 min
9 min (CE)
FashionMNIST
11 min
14 min (CE)
IMDB
35 min
54 min (CE)
AG News
77 min
55 min (CE), 54 min (SCE)
GoEmotions
7.4 h
2.5 h (CE), 2.3 h (ASL)
CelebA
8.4 h
4.5 h (CE), 5.2 h (ASL)
Appendix
Table 5: Mean runtime per seed for 100 training epochs on a single NVIDIA H100 GPU.
ECE
NLL
Brier
Dataset
Model
Uncalibrated
Post-hoc
Uncalibrated
Post-hoc
Uncalibrated
Post-hoc
MNIST
MBUR
0.0056 ± 0.0002
0.0016 ± 0.0001
0.0827 ± 0.0027
0.0397 ± 0.0017
0.0337 ± 0.0008
0.0193 ± 0.0011
CE
0.0015 ± 0.0001
0.0017 ± 0.0001
0.0466 ± 0.0026
0.0467 ± 0.0023
0.0230 ± 0.0011
0.0230 ± 0.0010
FashionMNIST
MBUR
0.0255 ± 0.0015
0.0055 ± 0.0003
0.4166 ± 0.0076
0.2854 ± 0.0030
0.1767 ± 0.0030
0.1438 ± 0.0017
CE
0.0045 ± 0.0004
0.0045 ± 0.0004
0.2727 ± 0.0030
0.2724 ± 0.0030
0.1409 ± 0.0020
0.1409 ± 0.0020
IMDB
MBUR
0.0902 ± 0.0009
0.0179 ± 0.0031
1.2310 ± 0.0136
0.3488 ± 0.0018
0.1189 ± 0.0006
0.1068 ± 0.0006
Appendix
Table 6: ECE, NLL, and Brier score on the test set without (Uncalibrated) and with (Post-hoc) post-hoc calibration, mean ± std over 10 seeds. The best value per column and dataset is in bold.
Dataset
Model
Accuracy (%)
ECE
MNIST
MBUR
98.66 ± 0.08
0.0057 ± 0.0002
Loss-Guided (CE)
98.42 ± 0.12
0.0015 ± 0.0001
Ablation A
97.50 ± 0.21
0.0047 ± 0.0004
Ablation B
85.55 ± 0.72
0.3204 ± 0.0023
FashionMNIST
MBUR
90.39 ± 0.11
0.0261 ± 0.0010
Loss-Guided (CE)
90.50 ± 0.27
0.0046 ± 0.0003
Appendix
Table 7: Test accuracy and ECE of the two ablations, compared with MBUR and Loss-Guided TM (CE), mean ± std over 5 seeds. Ablation A uses loss-guided feedback with integer weight updates, and Ablation B uses MBUR feedback with gradient-trained weights. ( A.8 )
The Tsetlin machine learns propositional rules with teams of Tsetlin automata that are driven by reward and penalty rather than gradients, so its models are interpretable by construction and cheap to evaluate. Its software, however, consists of C and CUDA kernels behind scikit-learn-style wrappers that sit outside the deep learning ecosystem. torchtsetlin implements the Tsetlin machine family as ordinary PyTorch modules: vanilla and weighted, coalesced, regression, convolutional over sequences, images and volumes, and dense per-pixel segmentation. The automata are a tensor buffer, so a model moves with .to(device), is saved with state_dict() and learns from a mini-batch with one update(x,y) call. Its core technique is a batched formulation of Type I and Type II feedback, in which automaton transitions become event counts realised as binomial draws, with one commit per mini-batch. On ten benchmarks taken from the existing libraries, it matches their accuracy, and on all but the two smallest it trains 2.4-10.9X faster than PyTsetlinMachineCUDA and 10.3-81.2X faster than tmu on the same GPU. The package is pure Python, MIT-licensed and on PyPI; every number in this paper is reproduced by one script. Code: https://github.com/vlbthambawita/torchtsetlin; package: https://pypi.org/project/torchtsetlin/.
In real-world applications of multiclass classification models, misclassification in an important class (e.g., stop sign) can be significantly more harmful than in other classes (e.g., no parking). Thus, it is crucial to improve the recall of an important class while maintaining overall accuracy. For this problem, we found that improving the separation of important classes relative to other classes in the feature space is effective. Existing methods that give a class-sensitive penalty for cross-entropy loss do not improve the separation. Moreover, the methods designed to improve separations between all classes are unsuitable for our purpose because they do not consider the important classes. To achieve the separation, we propose a loss function that explicitly gives loss for the feature space, called class-sensitive additive angular margin (CAMRI) loss. CAMRI loss is expected to reduce the variance of an important class due to the addition of a penalty to the angle between the important class features and the corresponding weight vectors in the feature space. In addition, concentrating the penalty on only the important class hardly sacrifices separating the other classes. Experiments on CIFAR-10, GTSRB, and AwA2 showed that CAMRI loss could improve the recall of a specific class without sacrificing accuracy. In particular, compared with GTSRB's second-worst class recall when trained with cross-entropy loss, CAMRI loss improved recall by 9%.
Cross-entropy (CE) is the default training loss for supervised classification, but its sample efficiency is limited when labels are scarce. Existing remedies primarily act on the data side, via augmentation, synthesis, or transfer from pretrained models; the training objective itself is rarely revisited. We revisit it here. Drawing on the classical observation that generative classifiers reach their asymptotic error with fewer samples than discriminative ones, we propose Generative Cross-Entropy (GenCE), a drop-in replacement for CE that introduces a generative learning principle into a standard discriminative network without altering the architecture or fitting a separate density model. GenCE follows from a Bayesian rewrite of the class-conditional likelihood and, in the mini-batch approximation, reduces to normalizing each sample's softmax score against the model's predictions on the batch, coupling the training signal across examples sharing a class. We extend the proper-scoring-rule framework to such non-local losses and prove that GenCE is strictly proper under a mild completeness condition: its population risk is uniquely minimized at the true posterior. Across three datasets, on two architectures and in both balanced small-data and class-imbalanced regimes, GenCE outperforms CE and other widely used losses, while also producing better-calibrated probabilities and stronger out-of-distribution detection.