Skip to main content

Library that contains implementations of machine learning components in the hyperbolic space

Project description

HyperLib: Deep learning in the Hyperbolic space

PyPI version

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 references[^1] [^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 [^6].

If your data has a natural metric you can also use TreeRep[^5]. 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

[^1]: Chami, I., Ying, R., Ré, C. and Leskovec, J. Hyperbolic Graph Convolutional Neural Networks. NIPS 2019.

[^2]: Nickel, M. and Kiela, D. Poincaré embeddings for learning hierarchical representations. NIPS 2017.

[^3]: Khrulkov, Mirvakhabova, Ustinova, Oseledets, Lempitsky. Hyperbolic Image Embeddings.

[^4]: Wei Peng, Varanka, Mostafa, Shi, Zhao. Hyperbolic Deep Neural Networks: A Survey.

[^5]: Rishi Sonthalia and Anna Gilbert. Tree! I am no Tree! I am a Low Dimensional Hyperbolic Embedding
[^6]: De Sa et. al. Representation Tradeoffs for Hyperbolic Embeddings

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

hyperlib-0.0.6.tar.gz (24.0 kB view details)

Uploaded Source

Built Distributions

hyperlib-0.0.6-cp39-cp39-win_amd64.whl (100.8 kB view details)

Uploaded CPython 3.9 Windows x86-64

hyperlib-0.0.6-cp39-cp39-win32.whl (90.9 kB view details)

Uploaded CPython 3.9 Windows x86

hyperlib-0.0.6-cp39-cp39-musllinux_1_1_x86_64.whl (666.1 kB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

hyperlib-0.0.6-cp39-cp39-musllinux_1_1_i686.whl (725.3 kB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

hyperlib-0.0.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (148.4 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

hyperlib-0.0.6-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl (155.2 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686

hyperlib-0.0.6-cp39-cp39-macosx_10_9_x86_64.whl (111.9 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

hyperlib-0.0.6-cp38-cp38-win_amd64.whl (101.6 kB view details)

Uploaded CPython 3.8 Windows x86-64

hyperlib-0.0.6-cp38-cp38-win32.whl (90.8 kB view details)

Uploaded CPython 3.8 Windows x86

hyperlib-0.0.6-cp38-cp38-musllinux_1_1_x86_64.whl (665.8 kB view details)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

hyperlib-0.0.6-cp38-cp38-musllinux_1_1_i686.whl (724.8 kB view details)

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

hyperlib-0.0.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (148.3 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

hyperlib-0.0.6-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl (154.8 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686

hyperlib-0.0.6-cp38-cp38-macosx_10_9_x86_64.whl (111.6 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

hyperlib-0.0.6-cp37-cp37m-win_amd64.whl (102.6 kB view details)

Uploaded CPython 3.7m Windows x86-64

hyperlib-0.0.6-cp37-cp37m-win32.whl (91.8 kB view details)

Uploaded CPython 3.7m Windows x86

hyperlib-0.0.6-cp37-cp37m-musllinux_1_1_x86_64.whl (669.0 kB view details)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

hyperlib-0.0.6-cp37-cp37m-musllinux_1_1_i686.whl (727.2 kB view details)

Uploaded CPython 3.7m musllinux: musl 1.1+ i686

hyperlib-0.0.6-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (150.5 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

hyperlib-0.0.6-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl (157.3 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686

hyperlib-0.0.6-cp37-cp37m-macosx_10_9_x86_64.whl (110.8 kB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

File details

Details for the file hyperlib-0.0.6.tar.gz.

File metadata

  • Download URL: hyperlib-0.0.6.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for hyperlib-0.0.6.tar.gz
Algorithm Hash digest
SHA256 6b9dc939287bbd6a0a18ceb0a1f3763acf26f3bbfd147ea488dc2db250ad8a5e
MD5 3e33ddad8edf2fd27e2845f0637156ab
BLAKE2b-256 34ec4621c610ca31b7534dba4c1e076706b697a841afdb7d9ea7180e07996afc

See more details on using hashes here.

File details

Details for the file hyperlib-0.0.6-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: hyperlib-0.0.6-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 100.8 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for hyperlib-0.0.6-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 3eaf393a2d3567a15647dfef78124b0a41c5e04e09d398a4318fa913f7fb1a56
MD5 48092e66e7dac6d54caf753b78074df8
BLAKE2b-256 ea9003cad712e43b8ef77a826eda68ebe8b450f9dbcdb633a6bd305a7f07ac48

See more details on using hashes here.

File details

Details for the file hyperlib-0.0.6-cp39-cp39-win32.whl.

File metadata

  • Download URL: hyperlib-0.0.6-cp39-cp39-win32.whl
  • Upload date:
  • Size: 90.9 kB
  • Tags: CPython 3.9, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for hyperlib-0.0.6-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 0feca7865f0869f0e034444d74f9ca81eb50bee5b825e17fcc692273fed9c29c
MD5 35978b05d67cafa268c62db51de15292
BLAKE2b-256 a96aae1f6ff7b000be5bff826586df2f4cc83e716275c70930d84bba78d792ef

See more details on using hashes here.

File details

Details for the file hyperlib-0.0.6-cp39-cp39-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for hyperlib-0.0.6-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 8c0b96d59b7cc14b1e9e45e483c7a8429964355e076c01da469a0add81890a9a
MD5 8599d4dd15e6caf237276564caeec54e
BLAKE2b-256 bc34cf3139a70669bcee5ff0adb7fafe7bdd4136537936039561392a9949ed30

See more details on using hashes here.

File details

Details for the file hyperlib-0.0.6-cp39-cp39-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for hyperlib-0.0.6-cp39-cp39-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 e3c69544731d9b244ce6b99a0cb45a3dc2ac7381ea7543c6179263bef412a330
MD5 198d5737a11c5d741a30e8db2d9e728e
BLAKE2b-256 6fd5a45b72950cb8c08184e36b3de9c558a32b9fb2b7cf07262288f04f2a6c38

See more details on using hashes here.

File details

Details for the file hyperlib-0.0.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hyperlib-0.0.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 81b2b6021bc63dccc102a722d21518c83951827a82ade06785c636d407d1b4a8
MD5 df7e511e12dfd9e4d6868793e4d13fea
BLAKE2b-256 28dfe59bcff47aca53579fb590ab389bd02c6a45168b752fdc26faf756bec6b5

See more details on using hashes here.

File details

Details for the file hyperlib-0.0.6-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for hyperlib-0.0.6-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 6c22b206cd952ff3bffc10223a239da59e00a1cd464af770ad6ad3b590245205
MD5 fb7cde5e8139137233a348898b697262
BLAKE2b-256 672db0a31234c613b9b0c9726cc72c79c31794fb636ad0a381080c9e984dbcd1

See more details on using hashes here.

File details

Details for the file hyperlib-0.0.6-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for hyperlib-0.0.6-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5c311d3381e360a6833a31b5d5914baa9e004032f656fce910b260a705d5b730
MD5 9b720a73c5201b2c3e2655096620d77c
BLAKE2b-256 933766f75a9a5d55294ee8a0a91a290539dd2bd72af0f4ac6b73d8d77a6f4c6e

See more details on using hashes here.

File details

Details for the file hyperlib-0.0.6-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: hyperlib-0.0.6-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 101.6 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for hyperlib-0.0.6-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 001b217f594233fcd1e5bcec4881ec4b68d8e3260e7782428ca7d12dd936afe4
MD5 3d505abd676f876e80c69ecf99d52774
BLAKE2b-256 2408d4a81a23f42b204f4231634a34da5bf9a047f661906fa8f10bd5728e1ad6

See more details on using hashes here.

File details

Details for the file hyperlib-0.0.6-cp38-cp38-win32.whl.

File metadata

  • Download URL: hyperlib-0.0.6-cp38-cp38-win32.whl
  • Upload date:
  • Size: 90.8 kB
  • Tags: CPython 3.8, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for hyperlib-0.0.6-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 559758fc32e59432159aaaba436516bfccda15798157a279fd15b7c05d38583f
MD5 82a680c9599e5d080a26f8d0ef932432
BLAKE2b-256 d501d8e231f34c2b54039d2cb4248420a24b0609639f99ca42aba94955ba4f5d

See more details on using hashes here.

File details

Details for the file hyperlib-0.0.6-cp38-cp38-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for hyperlib-0.0.6-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 d1f2f767cd268c6597cf117c9d3cb862ab8044b6ccb491b29123f31138ab7df4
MD5 9f5eede8dc8d5a0c0c84bdbae83467b8
BLAKE2b-256 45dc2b292167fb0131a1283fcd8f8fd6c0033a95c63f875b8fdfd80b27884923

See more details on using hashes here.

File details

Details for the file hyperlib-0.0.6-cp38-cp38-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for hyperlib-0.0.6-cp38-cp38-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 3729fb36582123aefbcdb7b01c277c2f5593174583dbf774aa5435dfb0b87d19
MD5 e59b2b2aee34627f7127b813765d9c48
BLAKE2b-256 77299a47ae5d766f3479a4adefa940c06347e2dfc1de1bb1779157049abb9c6a

See more details on using hashes here.

File details

Details for the file hyperlib-0.0.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hyperlib-0.0.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b6ce96f662f5c89e963c50a1284387ac785d57260d1bee9f4f09f106db9ad157
MD5 d6652362f8c29ebc2c1e588e61657ebc
BLAKE2b-256 6e74eda0c5b0aaac551d8f62e5abc89ecf7fe33585a102053b6f31f4f1c7ded3

See more details on using hashes here.

File details

Details for the file hyperlib-0.0.6-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for hyperlib-0.0.6-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 143315eca34f06f15a29d94f9a595394869a02b71874fcec82c6b29e468a4f7b
MD5 900bbc7dffd0110ec5d0bf97853c3c39
BLAKE2b-256 9b907d57787a0696e762331ca5496dffb745d1be9ae26b9ee06e837235e8ca2a

See more details on using hashes here.

File details

Details for the file hyperlib-0.0.6-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for hyperlib-0.0.6-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7b003b6022ec2a5f1726eba17eb054874130390c8e46430410a8201ea2bbe4dd
MD5 ac1d097e512832ffab353164569a702e
BLAKE2b-256 e2bc09838f80ad5eba3d8b4bac51fa24a90492b6147a1f254b679655cb2b2ef9

See more details on using hashes here.

File details

Details for the file hyperlib-0.0.6-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: hyperlib-0.0.6-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 102.6 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for hyperlib-0.0.6-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 29badbc4b7d73835cb25ba40d782a4be07f8c9f398cd9d1fbac45f528866d126
MD5 89802c93ae99120f782f957d7548bab9
BLAKE2b-256 7e258dd9e00623e4f49c6a82220eede21d035aee01bb4b34cc1836f02ee2a3bb

See more details on using hashes here.

File details

Details for the file hyperlib-0.0.6-cp37-cp37m-win32.whl.

File metadata

  • Download URL: hyperlib-0.0.6-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 91.8 kB
  • Tags: CPython 3.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for hyperlib-0.0.6-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 e38f3f6c95e52846ad1b5ad4910cf2040f07e67c56a3cffd13fbda6303b526b5
MD5 3132a6a74042f8c0facbf18675becd61
BLAKE2b-256 4081527d6b2f8445b9e9786856b404fa85e0aa343216e55906bc64b9a2bbb29b

See more details on using hashes here.

File details

Details for the file hyperlib-0.0.6-cp37-cp37m-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for hyperlib-0.0.6-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 06f9f3908d627525e605c284bd156ec41550103516637e728e584d640dba9b13
MD5 32e9e192e3901f837bf48b5b96c6aa0f
BLAKE2b-256 0dc16b9242f49c5a14d87921b71ebe2b760d2c23042e6de93b56415e40441490

See more details on using hashes here.

File details

Details for the file hyperlib-0.0.6-cp37-cp37m-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for hyperlib-0.0.6-cp37-cp37m-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 39941b7a890b28496c0caaf9bc73a27a2e6b7378aa01f4c45636e64e0f612161
MD5 0b2c9fdd7b91ac5ba16cbdaad0ffae32
BLAKE2b-256 234ab636f30bef520145020eae6625aae9676687f786f4b074c309035a789b36

See more details on using hashes here.

File details

Details for the file hyperlib-0.0.6-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hyperlib-0.0.6-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 adf31918d25d29696cf8bf71bb2f98f2edc80ba90c787ed8d3f9ee2b88d124ef
MD5 a48881371004885d48c9f9f3c9347783
BLAKE2b-256 1dfff58bf11bc5f350a4ba4710adb0e3c9ae4502203c122fd56482855d12583a

See more details on using hashes here.

File details

Details for the file hyperlib-0.0.6-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for hyperlib-0.0.6-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 132314299309c4df15cbefd1f83ed766ff2d893b6fdb93ce2b519731459cf67a
MD5 a069f4e1982167d12d43923d9b2d4896
BLAKE2b-256 8e7acb5804fc0769eb6e1d28a240d89d203ef6b445eeadae0a2fc3711947380e

See more details on using hashes here.

File details

Details for the file hyperlib-0.0.6-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for hyperlib-0.0.6-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6e1a04143de6a70b385a6ad48c2e14db13cf81c45b7448c2979f90168c7cc851
MD5 0e755855503f73cb6b33d1619945391c
BLAKE2b-256 473fb81f04ebedecf8f52e2be6ad267010b32157a3f792a1fc88e106054e2c1a

See more details on using hashes here.

Supported by

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