Skip to main content

Word2Vec with Matryoshka Representation Learning (Rust+PyO3), gensim-style API, numpy interop.

Project description

word2vec‑matryoshka

Ask DeepWiki

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

word2vec_matryoshka-0.1.5.tar.gz (70.0 kB view details)

Uploaded Source

Built Distributions

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

word2vec_matryoshka-0.1.5-cp310-abi3-win_amd64.whl (382.1 kB view details)

Uploaded CPython 3.10+Windows x86-64

word2vec_matryoshka-0.1.5-cp310-abi3-musllinux_1_2_x86_64.whl (567.5 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

word2vec_matryoshka-0.1.5-cp310-abi3-manylinux_2_28_x86_64.whl (488.6 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

word2vec_matryoshka-0.1.5-cp310-abi3-macosx_11_0_universal2.whl (867.0 kB view details)

Uploaded CPython 3.10+macOS 11.0+ universal2 (ARM64, x86-64)

word2vec_matryoshka-0.1.5-cp310-abi3-macosx_11_0_arm64.whl (426.1 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file word2vec_matryoshka-0.1.5.tar.gz.

File metadata

  • Download URL: word2vec_matryoshka-0.1.5.tar.gz
  • Upload date:
  • Size: 70.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for word2vec_matryoshka-0.1.5.tar.gz
Algorithm Hash digest
SHA256 574802b1d8f313c9072c9e7e7e440bb961ced0b5aa19d53672bfe6ad1cf59d85
MD5 f9f540c344c1bb5a92e4988889b8b8b5
BLAKE2b-256 a5d0da3997e800b7e8a3f648dc9a679055eeaab5a9ad982f927a1fbc40188f1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for word2vec_matryoshka-0.1.5.tar.gz:

Publisher: publish.yml on feisan/word2vec_matryoshka

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file word2vec_matryoshka-0.1.5-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for word2vec_matryoshka-0.1.5-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9f835f21810bbda95bb79ffe2babe72696ae08d897a74de1df622c3b3dec0a7f
MD5 214941793f9bdffa1ee000f0fbf98aa8
BLAKE2b-256 95750ce9dbab0d56cabe7a55cf48db6f711b6834f6b3a683f764c2f34907f585

See more details on using hashes here.

Provenance

The following attestation bundles were made for word2vec_matryoshka-0.1.5-cp310-abi3-win_amd64.whl:

Publisher: publish.yml on feisan/word2vec_matryoshka

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file word2vec_matryoshka-0.1.5-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for word2vec_matryoshka-0.1.5-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f7addefea57872e2185cda683c7cf3141b82207725d589de8b3b4d25f6eddd30
MD5 61ce98e36e9461ffdfc7b72becc1a2e2
BLAKE2b-256 a87e2419fb2d20170898f02a13ee71a8b33387e1a7ea8e620085fdbbf5790721

See more details on using hashes here.

Provenance

The following attestation bundles were made for word2vec_matryoshka-0.1.5-cp310-abi3-musllinux_1_2_x86_64.whl:

Publisher: publish.yml on feisan/word2vec_matryoshka

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file word2vec_matryoshka-0.1.5-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for word2vec_matryoshka-0.1.5-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6ef88d69a54b3856f4428933ee72667c0f758476e8faf4f0950308e75899216a
MD5 a1ace90f613f3bec9805364594c3b8c5
BLAKE2b-256 4003c67c685397bf15889fcc94083fb2ed67e36fc9dd5182b486312b7f1ed2e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for word2vec_matryoshka-0.1.5-cp310-abi3-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on feisan/word2vec_matryoshka

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file word2vec_matryoshka-0.1.5-cp310-abi3-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for word2vec_matryoshka-0.1.5-cp310-abi3-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 6535515f6d5f09ef8a7fb046a4b97a83d9922def41037702abe323f3d0f3260f
MD5 fae5e53cf002304bc4998d2c86a6ddf2
BLAKE2b-256 e8ebbd446856c2aaea4a681d7df352db50252781c89abc8d9d4bf648efb7571e

See more details on using hashes here.

Provenance

The following attestation bundles were made for word2vec_matryoshka-0.1.5-cp310-abi3-macosx_11_0_universal2.whl:

Publisher: publish.yml on feisan/word2vec_matryoshka

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file word2vec_matryoshka-0.1.5-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for word2vec_matryoshka-0.1.5-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 863cb8f03f8f4958cac762fe9142cbc2deca79733d8b3ac358c932c46ae18d70
MD5 a8c7bdbf6f97b7cab8a78beb90ca5c44
BLAKE2b-256 1137afaac875a064f5d14acf3d2a2b18ea37922159908f9a1e9047e0bc28fc2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for word2vec_matryoshka-0.1.5-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: publish.yml on feisan/word2vec_matryoshka

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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