Skip to main content

Python package for the creation of recommendation systems based on user traces.

Project description

tracerec

Python package for the creation of recommendation systems based on user traces.

Inslation

With pip:

pip install tracerec

With Poetry:

poetry add tracerec

Development

For contributing to the development of this package, you can clone the repository and install the dependencies using Poetry.

# Clone the repository
git clone https://github.com/almtav08/tracerec.git
cd tracerec

# Install dev dependencies
poetry install

Usage

import torch
from tracerec.algorithms.knowledge_based.transe import TransE
from tracerec.data.triples.triples_manager import TriplesManager
from tracerec.samplers.path_based_sampler import PathBasedNegativeSampler


# Create a sample triples manager with some triples
triples = [
    (1, 0, 2),
    (2, 0, 3),
    (3, 0, 4)
]
triples_manager = TriplesManager(triples)

train_x, train_y, test_x, test_y = triples_manager.split(train_ratio=0.8, relation_ratio=True, random_state=42, device='cpu')

# Negative sampling
all_triples = triples_manager.get_triples()
all_entities = triples_manager.get_entities()
entity_paths = triples_manager.get_entity_paths()

sampler = PathBasedNegativeSampler(all_triples, all_entities, corruption_ration=0.5, device='cpu', entity_paths=entity_paths, min_distance=1.0)
train_x_neg = sampler.sample(train_x, num_samples=1, random_state=42)

# Create and compile the TransE model
transe = TransE(num_entities=4, num_relations=1, embedding_dim=10, device='cpu', norm=1)
transe.compile(optimizer=torch.optim.Adam, criterion=torch.nn.MarginRankingLoss(margin=1.0))

# Fit the model
transe.fit(train_x, train_x_neg, train_y, num_epochs=1, batch_size=1, lr=0.001, verbose=True)

License

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 Distribution

tracerec-0.4.3.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

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

tracerec-0.4.3-py3-none-any.whl (32.8 kB view details)

Uploaded Python 3

File details

Details for the file tracerec-0.4.3.tar.gz.

File metadata

  • Download URL: tracerec-0.4.3.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tracerec-0.4.3.tar.gz
Algorithm Hash digest
SHA256 0bd61346941df2e17f8cfd37f61f218d404d3229eaab11d55042f2689f3f4aa8
MD5 79319feb12c5ef10a150866b1a793417
BLAKE2b-256 93a67c5f4cae4dceabc2dc887a0367e377a3c113af3188147d006d8f2256884b

See more details on using hashes here.

Provenance

The following attestation bundles were made for tracerec-0.4.3.tar.gz:

Publisher: python-publish.yml on almtav08/tracerec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tracerec-0.4.3-py3-none-any.whl.

File metadata

  • Download URL: tracerec-0.4.3-py3-none-any.whl
  • Upload date:
  • Size: 32.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tracerec-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 dac86458011b4bfc3c0094bf04003ebd2bea04131b6e213d32b846d3ae1b80ce
MD5 fa590fed569722189f70f76f608d5e3e
BLAKE2b-256 d04c6b8320e0bfbf8dd917b6f1c4456dfec14a77c991e2f6b75d726ccae8e447

See more details on using hashes here.

Provenance

The following attestation bundles were made for tracerec-0.4.3-py3-none-any.whl:

Publisher: python-publish.yml on almtav08/tracerec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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