Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Interpretable Hyperdimensional Computing for Language Identification

A small, honest demonstration that hyperdimensional computing (HDC) is interpretable by construction. A classifier identifies which of 21 European languages a short sentence is written in, and the same vectors that make the prediction can be read back to show why.

The accuracy is not the point of this project. The interpretation is.

What this is

Each language is represented by a single prototype vector. A sentence is classified by measuring which prototype it is most similar to. On the torchhd European Languages benchmark this reaches 97.34% test accuracy across 21 languages (20,442 of 21,000 test sentences), matching the reference implementation. Everything runs on CPU on a laptop in a few minutes.

How hyperdimensional computing works, in plain words

Hyperdimensional computing represents every piece of information as one very long vector, here 10,000 numbers wide. It relies on three simple operations. Binding combines two vectors into a new one that is dissimilar to both, which lets us tie things together, such as a character and its position in a group. Bundling adds many vectors into one summary vector that stays similar to each of its parts, which lets us pool evidence. Similarity, measured as the cosine between two vectors, tells us how alike two pieces of information are.

In this project each character has its own random vector. A run of three characters is bound into a trigram vector, all the trigram vectors in a sentence are bundled into one sentence vector, and each language is summarised by bundling the vectors of all its training sentences into a single prototype. Classifying a new sentence is then nothing more than checking which language prototype it is most similar to. Because the decision is a plain similarity score you can read it off directly, and because a prototype is just a bundle of trigrams you can ask which trigrams it most resembles and recover the characteristic letter patterns of the language.

Results

Phase 1, the classifier. A torchhd Centroid model over 10,000-dimensional vectors with character 3-grams reaches 97.34% test accuracy on 21 languages.

Phase 2, the interpretation. Two views make the decision transparent.

The per-class similarity view shows that a prediction is a readable score, not a black-box output. Each example sentence is most similar to its own language, and related languages score similarly to each other.

Per-class similarity

The prototype decomposition asks which character trigrams each language vector most resembles. The result recovers each language's real signature: English returns " th", "the", "he ", " an", "ing"; German returns "der", "die", "ein", "ich"; Swedish returns its common endings "-er", "-en", "-ar", "-et". The Swedish list also contains "oer", "aer" and "foe", which shows that the training corpus romanises the letters ö, ä and å as oe, ae and aa, so "för" appears as "foer". This is a small, honest artefact of the data, surfaced by the method rather than hidden by it.

Prototype decomposition into top trigrams

Why this connects to the group's work

The classifier is built with torchhd, the standard PyTorch library for hyperdimensional computing and vector symbolic architectures, co-authored by Denis Kleyko (Heddes et al., 2023), and the interpretability framing follows the account of binding, bundling and similarity set out in his two-part survey of the field (Kleyko et al., 2022; Kleyko et al., 2023).

Honest limitations

This is a small, laptop-scale demonstration and is meant to be read as one. The transform keeps only the letters a to z and space, so accents and non-Latin scripts are dropped before encoding, which is a simplification the reference implementation shares. The model uses a single random seed and no hyperparameter tuning. It works at the character level only, so it captures orthographic patterns rather than any deeper linguistic structure. The trigram decomposition ranks candidate trigrams by similarity to a prototype, which is a faithful but approximate account of what a bundled vector stores.

Reproduce

python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
python src/train_classifier.py   # Phase 1: trains and saves the model
python src/interpret.py          # Phase 2: writes the two figures

References

Heddes, M., Nunes, I., Vergés, P., Kleyko, D., Abraham, D., Givargis, T., Nicolau, A. and Veidenbaum, A. (2023) 'Torchhd: an open source Python library to support research on hyperdimensional computing and vector symbolic architectures', Journal of Machine Learning Research, 24(255), pp. 1–10.

Kanerva, P. (2009) 'Hyperdimensional computing: an introduction to computing in distributed representation with high-dimensional random vectors', Cognitive Computation, 1(2), pp. 139–159.

Kleyko, D., Rachkovskij, D.A., Osipov, E. and Rahimi, A. (2022) 'A survey on hyperdimensional computing aka vector symbolic architectures, Part I: models and data transformations', ACM Computing Surveys, 55(6), Article 130, pp. 1–40.

Kleyko, D., Rachkovskij, D.A., Osipov, E. and Rahimi, A. (2023) 'A survey on hyperdimensional computing aka vector symbolic architectures, Part II: applications, cognitive models, and challenges', ACM Computing Surveys, 55(9), Article 175, pp. 1–52.

Rahimi, A., Kanerva, P. and Rabaey, J.M. (2016) 'A robust and energy-efficient classifier using brain-inspired hyperdimensional computing', in Proceedings of the 2016 International Symposium on Low Power Electronics and Design (ISLPED '16). New York: ACM, pp. 64–69.

About

Interpretable hyperdimensional computing for language identification, built on torchhd. 97% accuracy across 21 languages, with prototype decomposition showing why.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages