Skip to main content

Official pytorch library for Tversky Neural Networks

Links

Tests Publish to PyPI PyPI - Version

Installation

Note: tversky requires PyTorch ≥ 2.0. Install it first following the instructions at https://pytorch.org/get-started. Then run:

pip install tversky

Notes

  • The code used to reproduce the experiments presented in our ICLR 2026 paper is located in the tversky-networks-iclr2026 repository. This library was forked that repository. That repository does not use this library.

Component: Tversky Similarity Layer

from tversky import nn as tnn

sim_layer = tnn.TverskySimilarity(
    embedding_dim=64,
    fbank_size=128,
    similarity_model='contrast',
    normalize=False
)

Component: Tversky Projection Layer

from tversky import nn as tnn

proj_layer = tnn.TverskyProjection(
    embedding_dim=64,
    class_count=10,
    fbank_size=128,
    similarity_model='contrast',
    normalize=False
)

MNIST Example

Example of neural network that employs Tversky projection to model MNIST.

import torch
import torch.nn as nn
import torch.nn.functional as F

from tversky import nn as tnn

class MnistNet(nn.Module):
    def __init__(self, fbank_size: int):
        super().__init__()

        self.conv1 = nn.Conv2d(1, 12, 3, padding="same")
        self.conv2 = nn.Conv2d(12, 12, 3, padding="same")
        self.pool2 = nn.MaxPool2d(2)

        self.conv3 = nn.Conv2d(12, 12, 3, padding="same")
        self.conv4 = nn.Conv2d(12, 12, 3, padding="same")
        self.pool4 = nn.MaxPool2d(2)

        self.conv5 = nn.Conv2d(12, 12, 3, padding="same")
        self.conv6 = nn.Conv2d(12, 36, 3, padding="same")

        self.tproj  = tnn.TverskyProjection(
            embedding_dim=36,
            class_count=10,
            fbank_size=fbank_size,
            similarity_model="contrast",
            intersection_reduction="product", 
            difference_reduction="ignorematch",
            normalize=False,
        )

    def forward_conv(self, x):
        x = self.conv2(F.relu(self.conv1(x)))
        x = self.pool2(x)

        x = self.conv4(F.relu(self.conv3(x)))
        x = self.pool4(x)

        x = self.conv6(F.relu(self.conv5(x)))
        x = x.mean((-2, -1))

        return x

    def forward(self, x):
        x = self.forward_conv(x)
        return self.tproj(x)
    
    def compute_salience(self, x):
        x = self.forward_conv(x)
        feature_measures = x @ self.tproj.feature_bank.weight.T
        salience_measures = F.relu(feature_measures).sum(-1)
        return salience_measures

Notes:

License

LICENSE.txt

Citation

If you use this work, please cite the following paper:

@inproceedings{doumbouya2026tversky,
    title={Tversky Neural Networks: Psychologically Plausible Deep Learning with Differentiable Tversky Similarity},
    author={Moussa Koulako Bala Doumbouya and Dan Jurafsky and Christopher D Manning},
    booktitle={The Fourteenth International Conference on Learning Representations},
    year={2026},
    url={https://openreview.net/forum?id=koKWoKaMrE}
}

Metadata

Release files for tversky 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tversky 0.2.1
File Size Uploaded
tversky-0.2.1.tar.gz 510.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tversky 0.2.1
File Interpreter ABI Platform
tversky-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 522.3 kB

Release files / tversky-0.2.1.tar.gz

Download URL tversky-0.2.1.tar.gz
Size 510.5 kB
Tags Source
SHA-256 checksum
How to use checksums
917e3f2c2739853d8c20b838644a85475f364adb1e0e9fd2cca7f33b7b7bb6d0
BLAKE2b-256 checksum
How to use checksums
71eba0751e740a3b6c53f7f21b6cc73fa70b51ee727b64198fc47e6cac5eb80e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 14, 2026.

Transparency log

Release files / tversky-0.2.1-py3-none-any.whl

Download URL tversky-0.2.1-py3-none-any.whl
Size 11.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
685de7f2c17e0d0eab5dc90a30e49a96691200091b8709a60a7901fb1787ce6f
BLAKE2b-256 checksum
How to use checksums
11cd620e838dbd1fb3b7e15dfa10ea0debf9235ac5eb1034cf965e8f119f9b0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 14, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page