Skip to main content

NMF Embedding for Swarmauri.

Project description

Swarmauri Logo

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


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


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.9.0.dev31.tar.gz (7.8 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.9.0.dev31-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file swarmauri_embedding_nmf-0.9.0.dev31.tar.gz.

File metadata

  • Download URL: swarmauri_embedding_nmf-0.9.0.dev31.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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.9.0.dev31.tar.gz
Algorithm Hash digest
SHA256 2f3c5ce162f2c39d41dc95e22320269521d91b5b78bde57fce0a95aee2231ab8
MD5 a352e5be8c0aad541e2db9e2faed8294
BLAKE2b-256 fd35b94a34a226f54f93d8c7f1b49caea3c7640cd06c87e60d967075ae437d75

See more details on using hashes here.

File details

Details for the file swarmauri_embedding_nmf-0.9.0.dev31-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_embedding_nmf-0.9.0.dev31-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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.9.0.dev31-py3-none-any.whl
Algorithm Hash digest
SHA256 0cf2c8776627d559afcae0fffdaa9ba9b9cae6e93371443b82714f7d1d1f8262
MD5 325a294879712bf7449d06cda71455c0
BLAKE2b-256 dea9a949d3ff824693d2db61ccdbca8cb59958a0d09092915aff5213b5f693c8

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