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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dualing-2.0.3.tar.gz.
File metadata
- Download URL: dualing-2.0.3.tar.gz
- Upload date:
- Size: 33.2 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b970e43a558919d5fb18d1dfc5c8a773b58aab08f643e2082535bba4b8163bdb
|
|
| MD5 |
d4cc635782451ace7b1ac7af1246d4be
|
|
| BLAKE2b-256 |
17f56783a7985fc37ed095f1891baa3683a4fc17574c6e8a742b65d60d90d80c
|
File details
Details for the file dualing-2.0.3-py3-none-any.whl.
File metadata
- Download URL: dualing-2.0.3-py3-none-any.whl
- Upload date:
- Size: 37.2 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85e621aa9cd85954c5249a4a6a476c6dfc9db3b99d40d88cca9cbbfd5bf00ea4
|
|
| MD5 |
e36cb65f7c74e9a4df6a2b07741bdfb5
|
|
| BLAKE2b-256 |
683f7a845d374b62978424cff3e55e68b3d7070efd3ee30cf7b8feadf55bb07a
|