Skip to main content

Vector Symbolic Architecture(VSA) library that allows building VSA apps that use various flavours of VSA vectors.

Project description

vsapy - Vector Symbolic Architecture (VSA) library

⚠️ Version 0.10+ Update — Breaking Changes


Python Version Requirement (Breaking Change)

As of this release, vsapy now requires Python >=3.11 and <3.13.

python = ">=3.11,<3.13"

This restriction allows us to:

  • Standardise development across Poetry-managed environments
  • Leverage modern typing and performance improvements
  • Remove legacy compatibility layers
  • Align CI/CD and local development setups

If you are currently using Python 3.9 or 3.10, you will need to upgrade.

Recommended setup:

pyenv install 3.11.x
pyenv local 3.11.x
poetry env use 3.11
poetry install

NumberLine Refactor & Extensions

This release significantly refactors and extends the NumberLine implementations.

Linear NumberLine Improvements

  • Cleaner behaviour across extended ranges
  • Improved quantisation handling
  • More consistent HD similarity gradients
  • Clearer diagnostic plotting support
  • Better geometric interpretation of hyperdimensional distance

New Circular Variants

The following circular representations are now included:

  • CircularNumberLineFolded
  • CircularNumberLineRotational

These allow:

  • True rotational similarity (distance depends only on angular difference)
  • Periodic encodings
  • Geometry-aware embedding behaviour
  • Exploration of circular manifolds in hyperdimensional space

These representations are particularly useful for:

  • Periodic signals
  • Angular encodings
  • Cyclic variables (e.g., time-of-day, phase)
  • Spatial or geometric modelling
  • Investigating rotational invariance in VSA

Additional & Updated Demos

The demo suite has been expanded and cleaned up:

  • Improved hierarchical document demos
  • Expanded JSON bundling examples
  • NumberLine comparison and diagnostic plots
  • Clearer exploration of embedding geometry

Library Overview

This library implements the common methods used in hyperdimensional computing / Vector Symbolic Architectures. Namely:

  • bind
  • unbind
  • Bundling operations:
    • bag
    • ShiftedBag
    • NamedBag
  • Hierarchical bundling method:
    • CSPvec

The main objective of the library is to enable a single API to cater for various flavours of VSA, including:

  • Binary Spatter Codes
  • Ternary
  • TernaryZero
  • Laiho
  • LaihoX (a simplified Laiho that is faster and supports incremental bundling without catastrophic forgetting)
  • HRR

A set of demo test cases are supplied to demonstrate the use of the library calls.


Installation

Install from PyPI

poetry add vsapy

or

pip install vsapy

Installing from Source

Clone the repository:

git clone <repo-url>
cd vsapy

Installing Dependencies (Poetry Recommended)

poetry install
poetry shell

Installing with pip

Create and activate a virtual environment:

conda create -n vsapy python=3.11
conda activate vsapy
pip install -r requirements.txt

Usage

Valid values for VsaType are:

  • VsaType.BSC
  • VsaType.Laiho
  • VsaType.LaihoX (fastest)
  • VsaType.Tern
  • VsaType.TernZero
  • VsaType.HRR

Note: The demos listed below will not run with VsaType.HRR.

For examples of using the vsapy library, see the code examples in the ./tests directory.

There are currently no command-line arguments implemented for the tests.
To change the VSA type, edit the code and modify:

vsa_type = VsaType.BSC

All test cases can be run directly from the command line, for example:

python cspvec_sequence.py

Demo Files

cspvec_sequence.py

The most straightforward demo.
Demonstrates building a sentence as a VSA sequence and stepping forward & backwards.


build_docs.py

Combines large documents into a hierarchical VSA code book.

The top-level document vector is a high-level semantic representation of the entire document.


load_docs.py

Compares document vectors built using build_docs.py at various levels in the document hierarchy.

Modify:

levels_to_extract = [0, 1]

Where:

  • 0 = top-level document vectors
  • 1 = Act-level vectors
  • 2 = Scene-level vectors
  • etc.

You may set to any level (e.g., [2] to compare Scene-level only).

Understanding output names:

  • OE_ = Old English
  • NE_ = New English
  • nf_ = NoFear Shakespeare
  • tk_ = NLTK Shakespeare
  • og_ = Alternate Shakespeare
  • ham = Hamlet
  • mbeth = Macbeth

json2vsa.py

Demonstrates creation of a VSA vector from an input JSON file and comparison of multiple JSON structures using VSA.

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

vsapy-0.10.0.tar.gz (40.1 kB view details)

Uploaded Source

Built Distribution

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

vsapy-0.10.0-py3-none-any.whl (46.9 kB view details)

Uploaded Python 3

File details

Details for the file vsapy-0.10.0.tar.gz.

File metadata

  • Download URL: vsapy-0.10.0.tar.gz
  • Upload date:
  • Size: 40.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.9.10 Darwin/23.5.0

File hashes

Hashes for vsapy-0.10.0.tar.gz
Algorithm Hash digest
SHA256 86cda79ebcdb38c9626eaebe0a8ec2aa9993c182dfcfe89ef125d4adcca203fc
MD5 1b0ef133a9a99e3a265150ebf59a8fc7
BLAKE2b-256 b1a74c7ec533086736e6d32be484b023d1b5616b5e3d28a9727730e1a1a46210

See more details on using hashes here.

File details

Details for the file vsapy-0.10.0-py3-none-any.whl.

File metadata

  • Download URL: vsapy-0.10.0-py3-none-any.whl
  • Upload date:
  • Size: 46.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.9.10 Darwin/23.5.0

File hashes

Hashes for vsapy-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c4c145c2d745eb4090163261aa6615b26eb0510903ebea20e8c943368173881b
MD5 fa5712213e0934d934b88bc22a248d37
BLAKE2b-256 1ee4bff7bb6157bfdbd392cde785c99ecdd9efb1ed2ef34b591f5d6cf7393c12

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