Skip to main content

Tversky Neural Network

Project description

Tversky Neural Network - PyTorch

Implementation of Tversky Neural Networks in PyTorch.

Tversky (1977) argued that similarity judgments can be regarded as extensions of similarity statements. Such statements are directional, in the sense that "a is like b" may differ from "b is like a." However, most neural network architectures in deep learning model similarity through dot-product measures, which are symmetric and therefore have generally not incorporated asymmetry, given the challenges of representing it in differentiable form. Motivated by Tversky's insight, Doumbouya et al. (2025) has introduced architectures that incorporate asymmetric similarity.

From set form,

image

to differentiable vector form.

image image

Install

$ pip install tversky-neural-network-pytorch

Usage

Tversky Projection Layer

import torch
from tversky_neural_network import TverskyProjectionLayer

model = TverskyProjectionLayer(
    in_features = 32,
    out_features = 16,
    num_features = 8,
    alpha = 0.5,
    beta = 0.5,
    theta = 1.0,
    eps = 1e-8,
    psi = "softmin",
    softmin_tau = 0.8,
    match_type = "subtract",
)

x = torch.randn(10, 32)
out = model(x)

loss = out.sum()
loss.backward()

Develop in Docker

  1. Start the development environment:

    $ docker compose up -d 
    
  2. Access docker container terminal with:

    $ docker exec -it dev /bin/bash
    

    Exit terminal with CTRL + D.

  3. Stop docker container with:

    $ docker compose down
    
  4. In container terminal, execute scripts with:

    $ uv run python your_script.py
    # test
    $ uv run pytest -v
    

Citations

@article{doumbouya2025tversky,
  title={Tversky Neural Networks: Psychologically Plausible Deep Learning with Differentiable Tversky Similarity},
  author={Doumbouya, Moussa Koulako Bala and Jurafsky, Dan and Manning, Christopher D},
  journal={arXiv preprint arXiv:2506.11035},
  year={2025}
}
@article{tversky1977features,
  title={Features of similarity.},
  author={Tversky, Amos},
  journal={Psychological review},
  volume={84},
  number={4},
  pages={327},
  year={1977},
  publisher={American Psychological Association}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tversky_neural_network_pytorch-0.0.2.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file tversky_neural_network_pytorch-0.0.2.tar.gz.

File metadata

File hashes

Hashes for tversky_neural_network_pytorch-0.0.2.tar.gz
Algorithm Hash digest
SHA256 d8d41feda95d318f980a74aeb85945e20cb0a5c057146b2921a7bc340e0b9855
MD5 a8849afb7c7991c3a372f9d88dc824ac
BLAKE2b-256 9248c751bea4233fa4d8c83addb501fc217a4cced04ca29da76b7be75390cbd1

See more details on using hashes here.

File details

Details for the file tversky_neural_network_pytorch-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for tversky_neural_network_pytorch-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 00e9fc711ee9a4498fe27ba5d0e847633e0d87e0e22f9b199be639077e238dc8
MD5 31deebe75ff0d70c11c20daa023ae8c4
BLAKE2b-256 149329193818c7467379831f24f6caee73cfa66718099af3bb7d90eceddb5bca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page