Word2Vec with Matryoshka Representation Learning (Rust+PyO3), gensim-style API, numpy interop.
Project description
word2vec‑matryoshka
Lightweight Word2Vec for Python, backed by Rust (PyO3). It implements a small, practical subset of Word2Vec (Skip‑gram/CBOW with Negative Sampling or Hierarchical Softmax) and adds Matryoshka multi‑level representations: you can train on multiple prefix dimensions and query a prefix level without recomputing vectors.
This project is a learning/practice (“vibe coding”) effort inspired by gensim. It intentionally covers only a tiny part of gensim’s functionality and adds Matryoshka prefix representations. If you need a full‑featured Word2Vec, please try gensim first.
Install
pip install word2vec-matryoshka
Quick start
from word2vec_matryoshka import Word2Vec, KeyedVectors, set_seed
set_seed(42)
corpus = [["hello", "world"], ["computer", "science"]]
model = Word2Vec(
sentences=corpus,
vector_size=64,
window=5,
min_count=1,
workers=2,
negative=5,
sg=1, # 1=Skip-gram, 0=CBOW
hs=0, # 1=Hierarchical Softmax, 0=Negative Sampling
levels=[16, 32, 64], # Matryoshka prefix dimensions
)
# Full vector
vec = model.wv["hello"]
# Top-5 similar at a prefix level (e.g., 32 dims)
sims = model.wv.most_similar("hello", topn=5, level=32)
# Save/load vectors (base path creates .vocab.json + .npy)
model.wv.save("vectors")
wv = KeyedVectors.load("vectors", mmap="r") # zero-copy memmap
vec16 = wv.get_vector("hello", level=16)
# Inspect vocabulary and the vector matrix
print(wv.index_to_key[:5]) # e.g., ['hello', 'computer', ...]
M = wv.vectors # numpy.ndarray with shape (n_words, vector_size)
print(M.shape)
What’s inside
- Word2Vec training: Skip‑gram or CBOW with Negative Sampling or Hierarchical Softmax
- Matryoshka levels: train multiple prefix dimensions and query by
level - Vector I/O:
KeyedVectors.save(base)→base.vocab.json+base.npy;KeyedVectors.load(base, mmap='r')for fast, memory‑mapped reads - Determinism:
set_seed(seed)for reproducible runs
Scope and disclaimer
- Not a drop‑in replacement for gensim. Only a minimal API is provided (
Word2Vec,KeyedVectors,wv[...],most_similar,get_vector). - Built as a small practice project to explore PyO3/Rust performance and Matryoshka prefix training.
- For most production needs, start with gensim first, then evaluate if this project’s Matryoshka feature helps your use case.
License
MIT — see LICENSE.
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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file word2vec_matryoshka-0.1.3.tar.gz.
File metadata
- Download URL: word2vec_matryoshka-0.1.3.tar.gz
- Upload date:
- Size: 67.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ede41038b710000e102b14aebb360a990dbf549227148e5d1ce9a6c78ecc9737
|
|
| MD5 |
6be89389d4728ad310683890f5239ff7
|
|
| BLAKE2b-256 |
617799cfe1cbd67c07ca737285721cfe7afcc9d45478c7ad71fd0a2c9fe45727
|
Provenance
The following attestation bundles were made for word2vec_matryoshka-0.1.3.tar.gz:
Publisher:
publish.yml on feisan/word2vec_matryoshka
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
word2vec_matryoshka-0.1.3.tar.gz -
Subject digest:
ede41038b710000e102b14aebb360a990dbf549227148e5d1ce9a6c78ecc9737 - Sigstore transparency entry: 524034744
- Sigstore integration time:
-
Permalink:
feisan/word2vec_matryoshka@c33764d59b1d876b971e6b18d37a20492a6919b6 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/feisan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c33764d59b1d876b971e6b18d37a20492a6919b6 -
Trigger Event:
release
-
Statement type:
File details
Details for the file word2vec_matryoshka-0.1.3-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: word2vec_matryoshka-0.1.3-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 380.5 kB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d6fbf7dfc43498cc2b5b5147e951e77f7cc0eb0bc284e57b6ac38bb301d8a20
|
|
| MD5 |
fafffb26dfadcf9e553a03f4a43d3ba5
|
|
| BLAKE2b-256 |
aa3c7827c7d5a857549897486c4d1c743e48e2230dbd7c8d91df2dd819ac46c9
|
Provenance
The following attestation bundles were made for word2vec_matryoshka-0.1.3-cp310-abi3-win_amd64.whl:
Publisher:
publish.yml on feisan/word2vec_matryoshka
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
word2vec_matryoshka-0.1.3-cp310-abi3-win_amd64.whl -
Subject digest:
0d6fbf7dfc43498cc2b5b5147e951e77f7cc0eb0bc284e57b6ac38bb301d8a20 - Sigstore transparency entry: 524034749
- Sigstore integration time:
-
Permalink:
feisan/word2vec_matryoshka@c33764d59b1d876b971e6b18d37a20492a6919b6 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/feisan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c33764d59b1d876b971e6b18d37a20492a6919b6 -
Trigger Event:
release
-
Statement type:
File details
Details for the file word2vec_matryoshka-0.1.3-cp310-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: word2vec_matryoshka-0.1.3-cp310-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 567.3 kB
- Tags: CPython 3.10+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f34cdfea9a6363ad5b4966470e8f3f93c721d3f153222477e3da0deeb6862cdb
|
|
| MD5 |
e1c04025c578d0871f4e3564fee9189b
|
|
| BLAKE2b-256 |
5e873ec6ad9bb7b10c860d3babf2157de19762978abf7ee2b47feb90adcd4120
|
Provenance
The following attestation bundles were made for word2vec_matryoshka-0.1.3-cp310-abi3-musllinux_1_2_x86_64.whl:
Publisher:
publish.yml on feisan/word2vec_matryoshka
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
word2vec_matryoshka-0.1.3-cp310-abi3-musllinux_1_2_x86_64.whl -
Subject digest:
f34cdfea9a6363ad5b4966470e8f3f93c721d3f153222477e3da0deeb6862cdb - Sigstore transparency entry: 524034753
- Sigstore integration time:
-
Permalink:
feisan/word2vec_matryoshka@c33764d59b1d876b971e6b18d37a20492a6919b6 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/feisan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c33764d59b1d876b971e6b18d37a20492a6919b6 -
Trigger Event:
release
-
Statement type:
File details
Details for the file word2vec_matryoshka-0.1.3-cp310-abi3-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: word2vec_matryoshka-0.1.3-cp310-abi3-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 488.5 kB
- Tags: CPython 3.10+, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a56a83ee98ccbe294d8d6941bc04437c0da1bfbb08ffc31217099c9663774e0
|
|
| MD5 |
cf7e2096a5634b590810fd1be760f822
|
|
| BLAKE2b-256 |
ac814a93394743385609619fdf9291573044a8c42586f6b2f27929126faeb2fc
|
Provenance
The following attestation bundles were made for word2vec_matryoshka-0.1.3-cp310-abi3-manylinux_2_28_x86_64.whl:
Publisher:
publish.yml on feisan/word2vec_matryoshka
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
word2vec_matryoshka-0.1.3-cp310-abi3-manylinux_2_28_x86_64.whl -
Subject digest:
8a56a83ee98ccbe294d8d6941bc04437c0da1bfbb08ffc31217099c9663774e0 - Sigstore transparency entry: 524034756
- Sigstore integration time:
-
Permalink:
feisan/word2vec_matryoshka@c33764d59b1d876b971e6b18d37a20492a6919b6 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/feisan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c33764d59b1d876b971e6b18d37a20492a6919b6 -
Trigger Event:
release
-
Statement type:
File details
Details for the file word2vec_matryoshka-0.1.3-cp310-abi3-macosx_11_0_universal2.whl.
File metadata
- Download URL: word2vec_matryoshka-0.1.3-cp310-abi3-macosx_11_0_universal2.whl
- Upload date:
- Size: 864.2 kB
- Tags: CPython 3.10+, macOS 11.0+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
294c372a6ad1f0e58a69c7d12db668b9ddad6b7a4479e9fdcf771b52acd351c5
|
|
| MD5 |
58e5136854e5d854abd1355457da2b5f
|
|
| BLAKE2b-256 |
ce9e9136a092299aeb935e09ee590e9f829448fd2a337570b184c07bfee0d543
|
Provenance
The following attestation bundles were made for word2vec_matryoshka-0.1.3-cp310-abi3-macosx_11_0_universal2.whl:
Publisher:
publish.yml on feisan/word2vec_matryoshka
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
word2vec_matryoshka-0.1.3-cp310-abi3-macosx_11_0_universal2.whl -
Subject digest:
294c372a6ad1f0e58a69c7d12db668b9ddad6b7a4479e9fdcf771b52acd351c5 - Sigstore transparency entry: 524034767
- Sigstore integration time:
-
Permalink:
feisan/word2vec_matryoshka@c33764d59b1d876b971e6b18d37a20492a6919b6 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/feisan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c33764d59b1d876b971e6b18d37a20492a6919b6 -
Trigger Event:
release
-
Statement type:
File details
Details for the file word2vec_matryoshka-0.1.3-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: word2vec_matryoshka-0.1.3-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 424.9 kB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73411666076cf242885c8474fe53d9c5c308d8c42c4145248afe53a6edca3058
|
|
| MD5 |
139ea09edd251dd3efeca9714492ca1a
|
|
| BLAKE2b-256 |
cb2b7366be1b4e5516cb6fbef6553f57325e43ea8071313409c4dfde4f9aba31
|
Provenance
The following attestation bundles were made for word2vec_matryoshka-0.1.3-cp310-abi3-macosx_11_0_arm64.whl:
Publisher:
publish.yml on feisan/word2vec_matryoshka
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
word2vec_matryoshka-0.1.3-cp310-abi3-macosx_11_0_arm64.whl -
Subject digest:
73411666076cf242885c8474fe53d9c5c308d8c42c4145248afe53a6edca3058 - Sigstore transparency entry: 524034758
- Sigstore integration time:
-
Permalink:
feisan/word2vec_matryoshka@c33764d59b1d876b971e6b18d37a20492a6919b6 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/feisan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c33764d59b1d876b971e6b18d37a20492a6919b6 -
Trigger Event:
release
-
Statement type: