Skip to main content

NWF for recommendation systems: matrix factorization with (z, sigma) for users and items. MovieLens, HR@k, incremental learning.

Project description

nwf-recsys

PyPI version Python 3.9+ License: MIT

NWF for Recommendation Systems

nwf-recsys provides matrix factorization encoders that produce semantic charges (z, sigma) for users and items. Recommendations are made by searching the item index with the user charge; supports incremental addition of users and items.

Features

  • MatrixFactorEncoder — neural matrix factorization with uncertainty for users and items
  • Output (z, sigma) — compatible with nwf-core Field and Mahalanobis search
  • Recommendations — build item Field, search by user charge for top-k items
  • Incremental — add new items to index without retraining; cold-start via content (planned)
  • Metrics — HR@k, NDCG@k

Installation

pip install nwf-core nwf-recsys

Requires: nwf-core>=0.2.3, torch, numpy, scikit-learn.


Quick Start

from nwf import Charge, Field
from nwf.recsys import MatrixFactorEncoder
import numpy as np

enc = MatrixFactorEncoder(n_users=1000, n_items=1700, latent_dim=64)
enc.fit(user_ids, item_ids, ratings, epochs=20)

# Build item index
field = Field()
for j in range(n_items):
    z, s = enc.encode_item(j)
    field.add(Charge(z=z, sigma=s), labels=[j], ids=[j])

# Recommend for user
z_u, s_u = enc.encode_user(user_id)
q = Charge(z=z_u, sigma=s_u)
distances, indices, labels = field.search(q, k=10)

API

MatrixFactorEncoder

Parameter Description
n_users Number of users (0..n_users-1)
n_items Number of items (0..n_items-1)
latent_dim Embedding dimension
sigma_init Initial sigma (default 0.5)
Method Description
fit(user_ids, item_ids, ratings, epochs, batch_size, lr) Train on rating triples
encode_user(user_id) Returns (z, sigma) for user
encode_item(item_id) Returns (z, sigma) for item

Example: MovieLens 100k

cd examples && python movielens_100k.py
  • Downloads MovieLens 100k automatically
  • Trains MatrixFactorEncoder (15 epochs)
  • Builds item Field, computes HR@10
  • Simulates cold-start for new user

License

MIT


nwf-recsys (Русский)

NWF для рекомендательных систем

nwf-recsys предоставляет матричную факторизацию с выходом семантических зарядов (z, sigma) для пользователей и товаров. Рекомендации: поиск в индексе товаров по заряду пользователя.

Компоненты

  • MatrixFactorEncoder — нейросетевая матричная факторизация с неопределённостью
  • Выход (z, sigma) — совместим с Field и поиском по Махаланобису
  • Рекомендации — поиск top-k товаров по заряду пользователя
  • Инкрементальность — добавление новых товаров в индекс без переобучения

Установка

pip install nwf-core nwf-recsys

Пример

from nwf.recsys import MatrixFactorEncoder
from nwf import Charge, Field

enc = MatrixFactorEncoder(n_users=943, n_items=1682, latent_dim=32)
enc.fit(user_ids, item_ids, ratings)
z_u, s_u = enc.encode_user(user_id)
field.search(Charge(z=z_u, sigma=s_u), k=10)

Лицензия

MIT

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

nwf_recsys-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file nwf_recsys-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: nwf_recsys-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for nwf_recsys-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8c23796374da9069d92d2fadc76e6c5f43724780aa280b943d27759dd73ed034
MD5 063a69b39ffa7eece4e7b9816f97d83a
BLAKE2b-256 6a7f3123abdb8d562fdf3e3bb7fb7ed88d1e71266a52a7f25093d0d90051ab53

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