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

Uploaded Python 3

File details

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

File metadata

  • Download URL: swarmauri_embedding_nmf-0.9.0.dev32.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.dev32.tar.gz
Algorithm Hash digest
SHA256 30444b1634af101bb929613facf1a64fd088d8254ba9320d32f7876edb0dec74
MD5 60bdb9c4230bea644e8d53ecfcd78a65
BLAKE2b-256 25052028d7903acbc9a018243ba487c9fd6bc149bed6704ba5ed7cd15e0c3c28

See more details on using hashes here.

File details

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

File metadata

  • Download URL: swarmauri_embedding_nmf-0.9.0.dev32-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.dev32-py3-none-any.whl
Algorithm Hash digest
SHA256 90a3de01cddb8c551ab875bf6b5d206ba7d0702bb1d42a280fdbbf9deb9296a7
MD5 54666257592e5ebdebf8e86388d687f2
BLAKE2b-256 6e59716aa2a3517fe791ea4c3399e98f95564087ab1b6f15f1032de2b5609e5b

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