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.10.0.dev5.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.10.0.dev5-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file swarmauri_embedding_nmf-0.10.0.dev5.tar.gz.

File metadata

  • Download URL: swarmauri_embedding_nmf-0.10.0.dev5.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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.10.0.dev5.tar.gz
Algorithm Hash digest
SHA256 353bc5bfb0df13af64248ee230f3589e649f9c9147c4fde592bdea2dd4e32c08
MD5 66bcfc49388c48ee9c8f3c491bc0d481
BLAKE2b-256 f90c202a58f18db3be317a6d6fa512a0be2a2666f46f497b35254ca02815a17e

See more details on using hashes here.

File details

Details for the file swarmauri_embedding_nmf-0.10.0.dev5-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_embedding_nmf-0.10.0.dev5-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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.10.0.dev5-py3-none-any.whl
Algorithm Hash digest
SHA256 7aadd32814b4a45b568e45c2913ea9075ad16a5fe6976aef9c8268e40ac38529
MD5 103e9447b2ee63bb86abf533cc2c2430
BLAKE2b-256 54b7a0f989e54e373874db9e2af1734fc285417d407009b0c3bc2017394c94d6

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