Skip to main content

NMF Embedding for Swarmauri.

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_embedding_nmf Discord

Swarmauri Embedding Nmf

swarmauri_embedding_nmf provides a Non-negative Matrix Factorization (NMF) implementation that converts collections of documents into dense numeric vectors. Under the hood it combines TfidfVectorizer and NMF from scikit-learn and wraps the results in Swarmauri's Vector type so the embeddings fit seamlessly into the wider ecosystem.

Installation

Choose the tool that matches your workflow:

# pip
pip install swarmauri_embedding_nmf

# Poetry
poetry add swarmauri_embedding_nmf

# uv
uv add swarmauri_embedding_nmf

Quickstart

from swarmauri_embedding_nmf import NmfEmbedding

documents = [
    "This is the first document",
    "This is the second document",
    "And this is the third one",
]

# n_components must not exceed the number of documents or unique terms
embedder = NmfEmbedding(n_components=3)

# Fit and transform the documents into Swarmauri Vector objects
vectors = embedder.fit_transform(documents)

for document, vector in zip(documents, vectors):
    print(document, vector.value)

print("Vocabulary:", embedder.extract_features())

# Transform a new document after fitting
new_vector = embedder.infer_vector("This is a new document")
print("New vector:", new_vector.value)

fit_transform and infer_vector both return Vector instances. Access the numerical data through each vector's .value attribute when interacting with other libraries or serialising results.

Persisting trained models

After training you can persist the TF-IDF vectoriser and NMF model:

embedder.save_model("nmf_embedding")
embedder.load_model("nmf_embedding")

The save_model method writes two files with _tfidf.joblib and _nmf.joblib suffixes, and load_model restores the same components for future inference sessions.

Swarmauri plugin usage

Installing this package also registers the swarmauri.embeddings.NmfEmbedding entry point. When you already depend on the swarmauri meta-package you can continue to import the embedder via the registry:

from swarmauri.embeddings.NmfEmbedding import NmfEmbedding

Want to help?

If you want to contribute to swarmauri-sdk, read up on our guidelines for contributing that will help you get started.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swarmauri_embedding_nmf-0.11.0.dev1.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

swarmauri_embedding_nmf-0.11.0.dev1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file swarmauri_embedding_nmf-0.11.0.dev1.tar.gz.

File metadata

  • Download URL: swarmauri_embedding_nmf-0.11.0.dev1.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_embedding_nmf-0.11.0.dev1.tar.gz
Algorithm Hash digest
SHA256 c0d434a30faa1c6f4327ae2b1e0f5e8e3266808ca61d3f6372ce2140b4887227
MD5 3f23f3d734361f4ef479d6548ee31602
BLAKE2b-256 d89fa824afedf4ac43b6b81826c1562ac5cebebbaaec355dea803c55272b8bbb

See more details on using hashes here.

File details

Details for the file swarmauri_embedding_nmf-0.11.0.dev1-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_embedding_nmf-0.11.0.dev1-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_embedding_nmf-0.11.0.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 66cc0b383624c5099cff9d51c5f8421bcbac0904080e025c2f028c2d7a3e6192
MD5 52a072a89ab4ab9fb4fe5d1056e779a6
BLAKE2b-256 4a17085e017339f9f611eeaf287f82a1cdf210503f056272c3ae03019b262bca

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