NMF Embedding for Swarmauri.
Project description
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file swarmauri_embedding_nmf-0.9.0.dev37.tar.gz.
File metadata
- Download URL: swarmauri_embedding_nmf-0.9.0.dev37.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3cd70d9fd96e32238a1e03ed2365776a9dc5bcdcc87039dfecb308b0f6707394
|
|
| MD5 |
bd6ca9bff3e780657d91e94331a2bc5a
|
|
| BLAKE2b-256 |
54d835e3a2e4f3fddc8ccde456d8b0bd7761be24ae656f8d3c605c26530bd742
|
File details
Details for the file swarmauri_embedding_nmf-0.9.0.dev37-py3-none-any.whl.
File metadata
- Download URL: swarmauri_embedding_nmf-0.9.0.dev37-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25ab17da981d12824173170c164f5bd6c6af2efb39b3f411f30063319f36e401
|
|
| MD5 |
a153280273e98ea053043d801e3f7c10
|
|
| BLAKE2b-256 |
7d20c5ca8ef1cb303eb2bcc3eca540690d4aca850830fc49daa618481094cef5
|