HyperLib: Deep learning in the Hyperbolic space
Background
This library implements common Neural Network components in the hyperbolic space (using the Poincare model). The implementation of this library uses Tensorflow as a backend and can easily be used with Keras and is meant to help Data Scientists, Machine Learning Engineers, Researchers and others to implement hyperbolic neural networks.
You can also use this library for uses other than neural networks by using the mathematical functions available in the Poincare class. In the future we may implement components that can be used in models other than neural networks. You can learn more about Hyperbolic networks here, and in the references1 2 3 4.
Install
The recommended way to install is with pip
pip install hyperlib
To build from source, you need to compile the pybind11 extensions.
For example to build on linux:
conda -n hyperlib python=3.8 gxx_linux-64 pybind11
python setup.py install
Hyperlib works with python>=3.8 and tensorflow>=2.0.
Example Usage
Creating a hyperbolic neural network using Keras:
import tensorflow as tf
from tensorflow import keras
from hyperlib.nn.layers.lin_hyp import LinearHyperbolic
from hyperlib.nn.optimizers.rsgd import RSGD
from hyperlib.manifold.poincare import Poincare
# Create layers
hyperbolic_layer_1 = LinearHyperbolic(32, Poincare(), 1)
hyperbolic_layer_2 = LinearHyperbolic(32, Poincare(), 1)
output_layer = LinearHyperbolic(10, Poincare(), 1)
# Create optimizer
optimizer = RSGD(learning_rate=0.1)
# Create model architecture
model = tf.keras.models.Sequential([
hyperbolic_layer_1,
hyperbolic_layer_2,
output_layer
])
# Compile the model with the Riemannian optimizer
model.compile(
optimizer=optimizer,
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics=[tf.keras.metrics.SparseCategoricalAccuracy()],
)
Using math functions on the Poincare ball:
import tensorflow as tf
from hyperlib.manifold.poincare import Poincare
p = Poincare()
# Create two matrices
a = tf.constant([[5.0,9.4,3.0],[2.0,5.2,8.9],[4.0,7.2,8.9]])
b = tf.constant([[4.8,1.0,2.3]])
# Matrix multiplication on the Poincare ball
curvature = 1
p.mobius_matvec(a, b, curvature)
Embeddings
A big advantage of hyperbolic space is its ability to represent hierarchical data. There are several techniques for embedding data in hyperbolic space; the most common is gradient methods 5.
If your data has a natural metric you can also use TreeRep6. Input a symmetric distance matrix, or a compressed distance matrix
import numpy as np
from hyperlib.embedding.treerep import treerep
from hyperlib.embedding.sarkar import sarkar_embedding
# Example: immunological distances between 8 mammals by Sarich
compressed_metric = np.array([
32., 48., 51., 50., 48., 98., 148.,
26., 34., 29., 33., 84., 136.,
42., 44., 44., 92., 152.,
44., 38., 86., 142.,
42., 89., 142.,
90., 142.,
148.
])
# outputs a weighted networkx Graph
tree = treerep(compressed_metric, return_networkx=True)
# embed the tree in 2D hyperbolic space
root = 0
embedding = sarkar_embedding(tree, root, tau=0.5)
Please see the examples directory for complete examples.
References
-
Chami, I., Ying, R., Ré, C. and Leskovec, J. Hyperbolic Graph Convolutional Neural Networks. NIPS 2019. ↩
-
Nickel, M. and Kiela, D. Poincaré embeddings for learning hierarchical representations. NIPS 2017. ↩
-
Khrulkov, Mirvakhabova, Ustinova, Oseledets, Lempitsky. Hyperbolic Image Embeddings. ↩
-
Wei Peng, Varanka, Mostafa, Shi, Zhao. Hyperbolic Deep Neural Networks: A Survey. ↩
-
De Sa et. al. Representation Tradeoffs for Hyperbolic Embeddings ↩
-
Rishi Sonthalia and Anna Gilbert. Tree! I am no Tree! I am a Low Dimensional Hyperbolic Embedding ↩
Metadata
Release files for hyperlib 0.0.6
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 | |
|---|---|---|---|---|
| hyperlib-0.0.6.tar.gz | 24.0 kB | Without provenance | Details |
Built distributions (wheels)
Total release size: 6.0 MB
Release files / hyperlib-0.0.6.tar.gz
| Download URL | hyperlib-0.0.6.tar.gz |
|---|---|
| Size | 24.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6b9dc939287bbd6a0a18ceb0a1f3763acf26f3bbfd147ea488dc2db250ad8a5e
|
|
BLAKE2b-256 checksum How to use checksums |
34ec4621c610ca31b7534dba4c1e076706b697a841afdb7d9ea7180e07996afc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / hyperlib-0.0.6-cp39-cp39-win_amd64.whl
| Download URL | hyperlib-0.0.6-cp39-cp39-win_amd64.whl |
|---|---|
| Size | 100.8 kB |
| Tags | CPython 3.9 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
3eaf393a2d3567a15647dfef78124b0a41c5e04e09d398a4318fa913f7fb1a56
|
|
BLAKE2b-256 checksum How to use checksums |
ea9003cad712e43b8ef77a826eda68ebe8b450f9dbcdb633a6bd305a7f07ac48
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / hyperlib-0.0.6-cp39-cp39-win32.whl
| Download URL | hyperlib-0.0.6-cp39-cp39-win32.whl |
|---|---|
| Size | 90.9 kB |
| Tags | CPython 3.9 Windows x86-32 |
|
SHA-256 checksum How to use checksums |
0feca7865f0869f0e034444d74f9ca81eb50bee5b825e17fcc692273fed9c29c
|
|
BLAKE2b-256 checksum How to use checksums |
a96aae1f6ff7b000be5bff826586df2f4cc83e716275c70930d84bba78d792ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / hyperlib-0.0.6-cp39-cp39-musllinux_1_1_x86_64.whl
| Download URL | hyperlib-0.0.6-cp39-cp39-musllinux_1_1_x86_64.whl |
|---|---|
| Size | 666.1 kB |
| Tags | CPython 3.9 Linux musl 1.1+ x86-64 |
|
SHA-256 checksum How to use checksums |
8c0b96d59b7cc14b1e9e45e483c7a8429964355e076c01da469a0add81890a9a
|
|
BLAKE2b-256 checksum How to use checksums |
bc34cf3139a70669bcee5ff0adb7fafe7bdd4136537936039561392a9949ed30
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / hyperlib-0.0.6-cp39-cp39-musllinux_1_1_i686.whl
| Download URL | hyperlib-0.0.6-cp39-cp39-musllinux_1_1_i686.whl |
|---|---|
| Size | 725.3 kB |
| Tags | CPython 3.9 Linux musl 1.1+ x86-32 |
|
SHA-256 checksum How to use checksums |
e3c69544731d9b244ce6b99a0cb45a3dc2ac7381ea7543c6179263bef412a330
|
|
BLAKE2b-256 checksum How to use checksums |
6fd5a45b72950cb8c08184e36b3de9c558a32b9fb2b7cf07262288f04f2a6c38
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / hyperlib-0.0.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | hyperlib-0.0.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 148.4 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
81b2b6021bc63dccc102a722d21518c83951827a82ade06785c636d407d1b4a8
|
|
BLAKE2b-256 checksum How to use checksums |
28dfe59bcff47aca53579fb590ab389bd02c6a45168b752fdc26faf756bec6b5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / hyperlib-0.0.6-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl
| Download URL | hyperlib-0.0.6-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl |
|---|---|
| Size | 155.2 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-32 |
|
SHA-256 checksum How to use checksums |
6c22b206cd952ff3bffc10223a239da59e00a1cd464af770ad6ad3b590245205
|
|
BLAKE2b-256 checksum How to use checksums |
672db0a31234c613b9b0c9726cc72c79c31794fb636ad0a381080c9e984dbcd1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / hyperlib-0.0.6-cp39-cp39-macosx_10_9_x86_64.whl
| Download URL | hyperlib-0.0.6-cp39-cp39-macosx_10_9_x86_64.whl |
|---|---|
| Size | 111.9 kB |
| Tags | CPython 3.9 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
5c311d3381e360a6833a31b5d5914baa9e004032f656fce910b260a705d5b730
|
|
BLAKE2b-256 checksum How to use checksums |
933766f75a9a5d55294ee8a0a91a290539dd2bd72af0f4ac6b73d8d77a6f4c6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / hyperlib-0.0.6-cp38-cp38-win_amd64.whl
| Download URL | hyperlib-0.0.6-cp38-cp38-win_amd64.whl |
|---|---|
| Size | 101.6 kB |
| Tags | CPython 3.8 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
001b217f594233fcd1e5bcec4881ec4b68d8e3260e7782428ca7d12dd936afe4
|
|
BLAKE2b-256 checksum How to use checksums |
2408d4a81a23f42b204f4231634a34da5bf9a047f661906fa8f10bd5728e1ad6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / hyperlib-0.0.6-cp38-cp38-win32.whl
| Download URL | hyperlib-0.0.6-cp38-cp38-win32.whl |
|---|---|
| Size | 90.8 kB |
| Tags | CPython 3.8 Windows x86-32 |
|
SHA-256 checksum How to use checksums |
559758fc32e59432159aaaba436516bfccda15798157a279fd15b7c05d38583f
|
|
BLAKE2b-256 checksum How to use checksums |
d501d8e231f34c2b54039d2cb4248420a24b0609639f99ca42aba94955ba4f5d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / hyperlib-0.0.6-cp38-cp38-musllinux_1_1_x86_64.whl
| Download URL | hyperlib-0.0.6-cp38-cp38-musllinux_1_1_x86_64.whl |
|---|---|
| Size | 665.8 kB |
| Tags | CPython 3.8 Linux musl 1.1+ x86-64 |
|
SHA-256 checksum How to use checksums |
d1f2f767cd268c6597cf117c9d3cb862ab8044b6ccb491b29123f31138ab7df4
|
|
BLAKE2b-256 checksum How to use checksums |
45dc2b292167fb0131a1283fcd8f8fd6c0033a95c63f875b8fdfd80b27884923
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / hyperlib-0.0.6-cp38-cp38-musllinux_1_1_i686.whl
| Download URL | hyperlib-0.0.6-cp38-cp38-musllinux_1_1_i686.whl |
|---|---|
| Size | 724.8 kB |
| Tags | CPython 3.8 Linux musl 1.1+ x86-32 |
|
SHA-256 checksum How to use checksums |
3729fb36582123aefbcdb7b01c277c2f5593174583dbf774aa5435dfb0b87d19
|
|
BLAKE2b-256 checksum How to use checksums |
77299a47ae5d766f3479a4adefa940c06347e2dfc1de1bb1779157049abb9c6a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / hyperlib-0.0.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | hyperlib-0.0.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 148.3 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
b6ce96f662f5c89e963c50a1284387ac785d57260d1bee9f4f09f106db9ad157
|
|
BLAKE2b-256 checksum How to use checksums |
6e74eda0c5b0aaac551d8f62e5abc89ecf7fe33585a102053b6f31f4f1c7ded3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / hyperlib-0.0.6-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl
| Download URL | hyperlib-0.0.6-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl |
|---|---|
| Size | 154.8 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-32 |
|
SHA-256 checksum How to use checksums |
143315eca34f06f15a29d94f9a595394869a02b71874fcec82c6b29e468a4f7b
|
|
BLAKE2b-256 checksum How to use checksums |
9b907d57787a0696e762331ca5496dffb745d1be9ae26b9ee06e837235e8ca2a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / hyperlib-0.0.6-cp38-cp38-macosx_10_9_x86_64.whl
| Download URL | hyperlib-0.0.6-cp38-cp38-macosx_10_9_x86_64.whl |
|---|---|
| Size | 111.6 kB |
| Tags | CPython 3.8 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
7b003b6022ec2a5f1726eba17eb054874130390c8e46430410a8201ea2bbe4dd
|
|
BLAKE2b-256 checksum How to use checksums |
e2bc09838f80ad5eba3d8b4bac51fa24a90492b6147a1f254b679655cb2b2ef9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / hyperlib-0.0.6-cp37-cp37m-win_amd64.whl
| Download URL | hyperlib-0.0.6-cp37-cp37m-win_amd64.whl |
|---|---|
| Size | 102.6 kB |
| Tags | CPython 3.7 CPython 3.7 pymalloc Windows x86-64 |
|
SHA-256 checksum How to use checksums |
29badbc4b7d73835cb25ba40d782a4be07f8c9f398cd9d1fbac45f528866d126
|
|
BLAKE2b-256 checksum How to use checksums |
7e258dd9e00623e4f49c6a82220eede21d035aee01bb4b34cc1836f02ee2a3bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / hyperlib-0.0.6-cp37-cp37m-win32.whl
| Download URL | hyperlib-0.0.6-cp37-cp37m-win32.whl |
|---|---|
| Size | 91.8 kB |
| Tags | CPython 3.7 CPython 3.7 pymalloc Windows x86-32 |
|
SHA-256 checksum How to use checksums |
e38f3f6c95e52846ad1b5ad4910cf2040f07e67c56a3cffd13fbda6303b526b5
|
|
BLAKE2b-256 checksum How to use checksums |
4081527d6b2f8445b9e9786856b404fa85e0aa343216e55906bc64b9a2bbb29b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / hyperlib-0.0.6-cp37-cp37m-musllinux_1_1_x86_64.whl
| Download URL | hyperlib-0.0.6-cp37-cp37m-musllinux_1_1_x86_64.whl |
|---|---|
| Size | 669.0 kB |
| Tags | CPython 3.7 CPython 3.7 pymalloc Linux musl 1.1+ x86-64 |
|
SHA-256 checksum How to use checksums |
06f9f3908d627525e605c284bd156ec41550103516637e728e584d640dba9b13
|
|
BLAKE2b-256 checksum How to use checksums |
0dc16b9242f49c5a14d87921b71ebe2b760d2c23042e6de93b56415e40441490
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / hyperlib-0.0.6-cp37-cp37m-musllinux_1_1_i686.whl
| Download URL | hyperlib-0.0.6-cp37-cp37m-musllinux_1_1_i686.whl |
|---|---|
| Size | 727.2 kB |
| Tags | CPython 3.7 CPython 3.7 pymalloc Linux musl 1.1+ x86-32 |
|
SHA-256 checksum How to use checksums |
39941b7a890b28496c0caaf9bc73a27a2e6b7378aa01f4c45636e64e0f612161
|
|
BLAKE2b-256 checksum How to use checksums |
234ab636f30bef520145020eae6625aae9676687f786f4b074c309035a789b36
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / hyperlib-0.0.6-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | hyperlib-0.0.6-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 150.5 kB |
| Tags | CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
adf31918d25d29696cf8bf71bb2f98f2edc80ba90c787ed8d3f9ee2b88d124ef
|
|
BLAKE2b-256 checksum How to use checksums |
1dfff58bf11bc5f350a4ba4710adb0e3c9ae4502203c122fd56482855d12583a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / hyperlib-0.0.6-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
| Download URL | hyperlib-0.0.6-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl |
|---|---|
| Size | 157.3 kB |
| Tags | CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-32 |
|
SHA-256 checksum How to use checksums |
132314299309c4df15cbefd1f83ed766ff2d893b6fdb93ce2b519731459cf67a
|
|
BLAKE2b-256 checksum How to use checksums |
8e7acb5804fc0769eb6e1d28a240d89d203ef6b445eeadae0a2fc3711947380e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / hyperlib-0.0.6-cp37-cp37m-macosx_10_9_x86_64.whl
| Download URL | hyperlib-0.0.6-cp37-cp37m-macosx_10_9_x86_64.whl |
|---|---|
| Size | 110.8 kB |
| Tags | CPython 3.7 CPython 3.7 pymalloc macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
6e1a04143de6a70b385a6ad48c2e14db13cf81c45b7448c2979f90168c7cc851
|
|
BLAKE2b-256 checksum How to use checksums |
473fb81f04ebedecf8f52e2be6ad267010b32157a3f792a1fc88e106054e2c1a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Security for hyperlib 0.0.6
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.