Skip to main content

An implementation of TransAct: Transformer-based Realtime User Action Model for Recommendation

Project description

TransAct Twitter

PyPI Run Tests Upload Python Package Code style: black GitHub Super-Linter

GitHub License GitHub stars GitHub followers Twitter Follow

This is NOT the official implementation by the authors of this model architecture. You can find the official pytorch implementation here. This repo is a Tensorflow implementation of TransAct: Transformer-based Realtime User Action Model for Recommendation at Pinterest by Xia, Xue, et al. TransAct is the ranking architecture used by Pinterest's Homefeed to personalize and extract users' short-term preferences from their realtime activities. The paper was presented at KDD 2023.

Installation

PyPI - Not Working Yet

New user registration on PyPI is temporarily suspended due to malicious attacks. Once admins enable, will add. Until then, skip ahead to the docker step.

Run the following to install:

pip install transact-tf

Docker

To install the package using Docker run the following:

docker pull ghcr.io/awadalaa/transact:release

Developing transact

To install transact, along with tools you need to develop and test, run the following in your virtualenv:

git clone https://github.com/awadalaa/transact.git
# or clone your own fork

cd transact
pip install -e .

To run rank and shape tests run any of the following:

python -m transact.test_transact
pytest transact --verbose

Usage

import tensorflow as tf
from transact import TensorflowTransAct, TransActConfig

num_actions = 5
action_vocab = list(range(0, num_actions))
full_seq_len = 10
test_batch_size = 8
action_emb_dim = 32
item_emb_dim = 32
time_window_ms = 1000 * 60 * 60 * 1  # 1 hr
latest_n_emb = 10

# Generate random tensors in TensorFlow as input
action_type_seq = tf.random.uniform(shape=(test_batch_size, full_seq_len), minval=0, maxval=num_actions, dtype=tf.int32)
item_embedding_seq = tf.random.uniform(shape=(test_batch_size, full_seq_len, item_emb_dim), dtype=tf.float32)
action_time_seq = tf.random.uniform(shape=(test_batch_size, full_seq_len), minval=0, maxval=num_actions, dtype=tf.int32)
request_time = tf.random.uniform(shape=(test_batch_size,), minval=500000, maxval=1000000, dtype=tf.int32)
item_embedding = tf.random.uniform(shape=(test_batch_size, item_emb_dim), dtype=tf.float32)
input_features = (
    action_type_seq,
    item_embedding_seq,
    action_time_seq,
    request_time,
    item_embedding,
)

# Initialize the transact module
transact_config = TransActConfig(
    action_vocab=action_vocab,
    action_emb_dim=action_emb_dim,
    item_emb_dim=item_emb_dim,
    time_window_ms=time_window_ms,
    latest_n_emb=latest_n_emb,
    seq_len=full_seq_len,
)
model = TensorflowTransAct(transact_config)

user_embedding = model(*input_features)

Run with Docker

You can also run the example script with Docker.

git clone https://github.com/awadalaa/transact.git
cd transact

docker run -it --rm \
    --mount type=bind,source="$(pwd)"/example,target=/usr/src/transact/docker_example \
    ghcr.io/awadalaa/transact:release \
    python docker_example/docker_example.py

Want to Contribute 🙋‍♂️?

Awesome! If you want to contribute to this project, you're always welcome! See Contributing Guidelines. You can also take a look at open issues for getting more information about current or upcoming tasks.

Want to discuss? 💬

Have any questions, doubts or want to present your opinions, views? You're always welcome. You can start discussions.

Citation

@article{xia2023transact,
  title={TransAct: Transformer-based Realtime User Action Model for Recommendation at Pinterest},
  author={Xia, Xue and Eksombatchai, Pong and Pancha, Nikil and Badani, Dhruvil Deven and Wang, Po-Wei and Gu, Neng and Joshi, Saurabh Vishwas and Farahpour, Nazanin and Zhang, Zhiyuan and Zhai, Andrew},
  journal={arXiv preprint arXiv:2306.00248},
  year={2023}
}

License

Copyright 2023 Alaa Awad

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Download files

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

Source Distribution

transact-tf-0.1.0.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

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

transact_tf-0.1.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file transact-tf-0.1.0.tar.gz.

File metadata

  • Download URL: transact-tf-0.1.0.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for transact-tf-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3dc56e8509ce1794b62192be9a9efccc780f5087856a28ac4a8042865aae6f36
MD5 08d583c6f9f58e85aa26ec661600db05
BLAKE2b-256 aee09d2a03aeb16b13e09ce5717d7d92f2df20d844018a9d245e34b052152c73

See more details on using hashes here.

File details

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

File metadata

  • Download URL: transact_tf-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for transact_tf-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4243e833a95326fb967692a08bb07718c380b99000edba675015805a330b4d2a
MD5 16b9f51dcb1adacd799dcfe2df14c6c1
BLAKE2b-256 56c15a5a476266a1f387f2a6c78bba71c3313eab427d85e70e256964957bb658

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