Dualing
Dualing provides small TensorFlow building blocks for contrastive, cross-entropy, and triplet Siamese networks.
Install
pip install dualing
Dualing requires Python 3.11 or newer. In a uv-managed project, use
uv add dualing instead.
Quick start
import numpy as np
from dualing import MLP, ContrastiveSiamese, balanced_pair_dataset
samples = np.random.default_rng(0).normal(size=(100, 16))
labels = np.repeat([0, 1], 50)
dataset = balanced_pair_dataset(samples, labels, n_pairs=100, batch_size=16)
model = ContrastiveSiamese(MLP((32, 8)))
model.compile(optimizer="adam")
model.fit(dataset, epochs=5)
Dataset helpers return native tf.data.Dataset objects and all models use
standard Keras compile, fit, and evaluate behavior. The original
dualing.core, dualing.datasets, dualing.models.base, and dualing.utils
APIs remain available.
The examples directory contains dataset/model construction examples and MNIST training scripts for all three Siamese variants.
Native pair datasets yield ((left, right), labels) or
((left, right), labels, sample_weights). The original pair dataset classes
yield (left, right, labels) through their .batches attribute. Both forms
work with pair-model fit, evaluate, and fit(validation_data=...).
Default pair losses retain one value per pair so Keras can apply sample weights.
Native and original dataset APIs share preprocessing: normalization maps
constant data to the lower bound instead of producing NaNs. Use normalize=None
to leave values unscaled.
Save and restore models
Dualing models support native Keras cloning and .keras persistence:
import dualing # Registers Dualing models and losses with Keras.
import tensorflow as tf
model.save("siamese.keras")
restored = tf.keras.models.load_model("siamese.keras")
restored.fit(dataset, epochs=1)
Saved trained models retain their weights, loss configuration, and optimizer
state. Constructor aliases remain accepted but serialize to one canonical
configuration. Custom embedders and activations follow Keras's own registration
or custom_objects mechanism.
See the usage guide for tensor shapes, triplet distance semantics, and extension conventions.
Development
From a cloned checkout, use the existing development tools:
uv sync
uv run pytest
uv run ruff check .
uv run ruff format --check .
uv run --group docs sphinx-build -W -b html docs docs/_build/html
uv build
For an editable runtime-only installation, pip install -e . remains supported.
Code style and compatibility rules are documented in CONVENTIONS.md.
API documentation is available at dualing.readthedocs.io.
Metadata
Release files for dualing 2.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| dualing-2.0.3.tar.gz | 33.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dualing-2.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 70.4 kB
Release files / dualing-2.0.3.tar.gz
| Download URL | dualing-2.0.3.tar.gz |
|---|---|
| Size | 33.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b970e43a558919d5fb18d1dfc5c8a773b58aab08f643e2082535bba4b8163bdb
|
|
BLAKE2b-256 checksum How to use checksums |
17f56783a7985fc37ed095f1891baa3683a4fc17574c6e8a742b65d60d90d80c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / dualing-2.0.3-py3-none-any.whl
| Download URL | dualing-2.0.3-py3-none-any.whl |
|---|---|
| Size | 37.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
85e621aa9cd85954c5249a4a6a476c6dfc9db3b99d40d88cca9cbbfd5bf00ea4
|
|
BLAKE2b-256 checksum How to use checksums |
683f7a845d374b62978424cff3e55e68b3d7070efd3ee30cf7b8feadf55bb07a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for dualing 2.0.3
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.