Package: torch-hd
TorchhdTorchhd is a Python library forHyperdimensional Computing(also known asVector Symbolic Architectures).Easy-to-use:Torchhd makes it painless to develop a wide range of Hyperdimensional Computing (HDC) applications and algorithms. For someone new to the field, we provide Pythonic abstractions and examples to get you started fast. For the experienced researchers, we made the library modular by design, giving you endless flexibility to prototype new ideas in no-time.Performant:The library is build on top of the high-performancePyTorchlibrary, giving you optimized tensor execution without the headaches. Moreover, PyTorch makes it effortless to accelerate your code on a GPU.InstallationTorchhd is hosted onPyPiandAnaconda. First, install PyTorch using theirinstallation instructions. Then, use one of the following commands to install Torchhd:pipinstalltorch-hdcondainstall-ctorchhdtorchhdDocumentationYou can find documentation for Torchhdon the website.Check out theGetting Startedpage for a quick overview.The API documentation is divided into several sections:torchhdtorchhd.embeddingstorchhd.structurestorchhd.modelstorchhd.memorytorchhd.datasetsYou can improve the documentation by sending pull requests to this repository.ExamplesWe have several examplesin the repository. Here is a simple one to get you started:importtorch,torchhdd=10000# number of dimensions# create the hypervectors for each symbolkeys=torchhd.random(3,d)country,capital,currency=keysusa,mex=torchhd.random(2,d)# United States and Mexicowdc,mxc=torchhd.random(2,d)# Washington D.C. and Mexico Cityusd,mxn=torchhd.random(2,d)# US Dollar and Mexican Peso# create country representationsus_values=torch.stack([usa,wdc,usd])us=torchhd.hash_table(keys,us_values)mx_values=torch.stack([mex,mxc,mxn])mx=torchhd.hash_table(keys,mx_values)# combine all the associated informationmx_us=torchhd.bind(torchhd.inverse(us),mx)# query for the dollar of mexicousd_of_mex=torchhd.bind(mx_us,usd)memory=torch.cat([keys,us_values,mx_values],dim=0)torchhd.cosine_similarity(usd_of_mex,memory)# tensor([-0.0062,  0.0123, -0.0057, -0.0019, -0.0084, -0.0078,  0.0102,  0.0057,  0.3292])# The hypervector for the Mexican Peso is the most similar.This example is from the paperWhat We Mean When We Say "What's the Dollar of Mexico?": Prototypes and Mapping in Concept Spaceby Kanerva. It first creates hypervectors for all the symbols that are used in the computation, i.e., the variables forcountry,capital, andcurrencyand their values for both countries. These hypervectors are then combined to make a single hypervector for each country using a hash table structure. A hash table encodes key-value pairs as:k1 * v1 + k2 * v2 + ... + kn * vn. The hash tables are then bound together to form their combined representation which is finally queried by binding with the Dollar hypervector to obtain the approximate Mexican Peso hypervector. The similarity output shows that the Mexican Peso hypervector is indeed the most similar one.Supported HDC/VSA modelsCurrently, the library supports the following HDC/VSA models:Multiply-Add-Permute (MAP)Binary Spatter Codes (BSC)Holographic Reduced Representations (HRR)Fourier Holographic Reduced Representations (FHRR)Binary Sparse Block Codes (B-SBC)Vector-Derived Transformation Binding (VTB)We welcome anyone to help with contributing more models to the library!AboutInitial development of Torchhd was performed byMike HeddesandIgor Nunesas part of their research in Hyperdimensional Computing at the University of California, Irvine. The library was extended with significant contributions from Pere Vergés and Dheyay Desai. Torchhd later merged with a project by Rishikanth Chandrasekaran, who worked on similar problems as part of his research at the University of California, San Diego.ContributingWe are always looking for people that want to contribute to the library. If you are considering contributing for the first time we acknowledgde that this can be daunting, but fear not! You can look through theopen issuesfor inspiration on the kind of problems you can work on. If you are a researcher and want to contribute your work to the library, feel free to open a new issue so we can discuss the best strategy for integrating your work.DocumentationTo build the documentation locally do the following:Usepip install -r docs/requirements.txtto install the required packages.Usesphinx-build -b html docs buildto generate the html documentation in the/builddirectory.To create a clean build, remove the/buildand/docs/generateddirectories.Creating a New ReleaseIncrement the version number inversion.pyusingsemantic versioning.Create a new GitHub release. Set the tag according toPEP 440, e.g., v1.5.2, and provide a clear description of the changes. You can use GitHub's "auto-generate release notes" button. Look at previous releases for examples.A GitHub release triggers a GitHub action that builds the library and publishes it to PyPi and Conda in addition to the documentation website.Running testsTo run the unit tests located intorchhd/testsdo the following:Usepip install -r dev-requirements.txtto install the required development packages.Then run the tests using justpytest.Optionally, to measure the code coverage usecoverage run -m --omit="torchhd/tests/**" pytestto create the coverage report. You can then view this report withcoverage report.LicenseThis library isMIT licensed.To add the license to all source files, first installlicenseheadersand then uselicenseheaders -t ./LICENSE -d ./torchhd.CiteConsider citingour paperpublished in the Journal of Machine Learning Research (JMLR) if you use Torchhd in your work:@article{JMLR:v24:23-0300,
  author  = {Heddes, Mike and Nunes, Igor and Vergés, Pere and Kleyko, Denis and Abraham, Danny and Givargis, Tony and Nicolau, Alexandru and Veidenbaum, Alex},
  title   = {Torchhd: An Open Source Python Library to Support Research on Hyperdimensional Computing and Vector Symbolic Architectures},
  journal = {Journal of Machine Learning Research},
  year    = {2023},
  volume  = {24},
  number  = {255},
  pages   = {1--10},
  url     = {http://jmlr.org/papers/v24/23-0300.html}
}