kaipengm2/2025-tencent-advertising-algorithm-competition-finalist
About
Finalist solution for the 2025 Tencent Advertising Algorithm Competition (Generative Recommendation Challenge)
Other ProjectsWhat you can do
- Mixed negative sampling (in-batch + global)
- Log-q correction
- Hard negative mining & curriculum learning
- Action-conditioned generation
Measured star growth
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- +1
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
Original🏆 A Simple Ticket to the Finals — 2025 Tencent Advertising Algorithm Competition
Generative Recommendation Challenge
This repository presents a simple yet effective generative next-item recommendation framework. Despite using no multimodal inputs, the model achieves:
- Score: 0.129843
- NDCG@10: 0.104463
- HitRate@10: 0.186332
and successfully advances to the finals.
⭐ Highlights
- Mixed negative sampling (in-batch + global)
- Log-q correction
- Hard negative mining & curriculum learning
- Action-conditioned generation
- A purely end-to-end, single-stage training pipeline, free of handcrafted feature engineering or multi-stage complexity.
For more details, see METHOD.md.
📦 Requirements
- polars
- numpy, tqdm, tensorboard
Tested on:
- Python 3.10
- PyTorch 2.7.1 + CUDA 12.3
- 1 NVIDIA H20 (96GB)
Install example:
pip install "torch==2.7.1" polars numpy tqdm tensorboard
🌱 Environment Variables
All I/O directories are configured via environment variables.
run.sh sets these by default, but you may override them manually or via CLI:
TRAIN_DATA_PATH— dataset directoryTRAIN_CKPT_PATH— checkpoint directoryTRAIN_LOG_PATH— log directory (train.log)TRAIN_TF_EVENTS_PATH— TensorBoard events directoryUSER_CACHE_PATH— cache directory for precomputed data
Example override:
export TRAIN_DATA_PATH=/path/to/data
export TRAIN_CKPT_PATH=/path/to/ckpts
export TRAIN_LOG_PATH=/path/to/logs
export TRAIN_TF_EVENTS_PATH=/path/to/tfevents
export USER_CACHE_PATH=/path/to/usrcache
📁 Data
The dataset structure follows the competition’s fully anonymized format.
Training Input
seq.jsonl: Each line contains the full sequence of events associated with a single user.
Every event is represented in the following format:
User re-index ID
Item re-index ID
User features — a dictionary, e.g.
{'feat_id': feat_val, ...}Item features — a dictionary, e.g.
{'feat_id': feat_val, ...}Action type
0= impression1= click2= conversion
Timestamp (in seconds)
[user_id, item_id, user_feat, item_feat, action, ts]
In addition to seq.jsonl, the following files are involved:
data/seq_offsets.pklByte offsets for random-access reads in multi-worker DataLoaders. Each entry maps a user index to its starting byte inseq.jsonl.data/indexer.pklCentralized ID vocabularies:indexer["i"]: rawcreative_id→ re-indexed item id[1, itemnum]indexer["u"]: raw user id → re-indexed user idindexer["f"][fid]: vocabulary for featurefidUsed to deriveitemnum,usernum, and the vocabulary sizes for all features.
data/item_feat_dict.jsonProvides per-item non-embedding side features, consistent with those recorded inseq.jsonl:{ "1": { "100": 12, "117": 3, ... }, "2": { ... } }
For more details, see data_format.md.
Evaluation data
The following files are required under EVAL_DATA_PATH:
eval/indexer.pkl
Sameindexer.pklused during training.eval/item_feat_dict.json
Same item feature dictionary used during training.eval/predict_seq.jsonl— user histories (same format asseq.jsonl)eval/predict_seq_offsets.pkl— byte offsets forpredict_seq.jsonl
A list of file offsets (one per user).eval/user_action_type.json— target action type for each user
A JSON object mapping user ids (strings) to an integer action type:{ "user_123": 3, "user_456": 1, ... }eval/predict_set.jsonl— candidate items for retrieval (Top-K search)This file is in JSON Lines format: each line is a JSON object describing a single candidate creative:
{ "creative_id": "<cid matching indexer['i']>", "features": { "<fid>": <scalar or list>, ... } }where:
creative_idis a string identifier that should be present inindexer["i"]. If it is not found, the item is treated as id0for cold-start handling.featureshas the same schema as the per-item feature dicts initem_feat_dict.json. During inference, any string values (either scalar or inside a list) are mapped to 0 for cold-start handling.
Example
predict_set.jsonl:{"creative_id": "cid_00123456789", "features": {"100": 12, "117": 5, "118": 1024}} {"creative_id": "cid_00987654321", "features": {"100": 3, "117": 8, "118": 2048}}
Optional Dense Multimodal Embeddings (memmap):
While multimodal inputs are currently unused, the implementation supports dense multimodal item embeddings.
Raw embeddings are stored under:
data/creative_emb/emb_{fid}_{D}.pkl(forfid=81), ordata/creative_emb/emb_{fid}_{D}/*.json(otherfidvalues)
On first access, they are converted into memory-mapped tables:
- Path:
$USER_CACHE_PATH/emb_table_{fid}_{D}.mmap - Shape:
(itemnum + 1, D)with row0as a zero/padding vector
- Path:
To disable multimodal embeddings, omit creative_emb or skip setting mm_emb_id in args.
🚀 Training Workflow
Preprocess + train from scratch
Simply run:
./run.sh
This will execute:
get_stat.pymain.pywith all paths sourced fromrun.sh
Note: The run.sh script automatically sets the project directory and required I/O environment variables. If this has already been done, all you need to do is run:
python -u get_stat.py
python -u main.py
In addition, you can also resume training from an existing checkpoint.
python -u train.py --resume checkpoints/global_stepXXXX/ckpt.pt
🔍 Inference — Top-K Retrieval
1. Prepare evaluation data
- Place evaluation files in
eval/(or overrideEVAL_DATA_PATH)
2. Run inference
Basic usage:
./infer.sh MODEL_DIR [TOPK]
MODEL_DIR— directory containing a.ptcheckpoint (e.g.checkpoints/global_stepXXXX)TOPK— number of retrieved items (default: 10)
Example:
./infer.sh checkpoints/global_step136000 10
This will:
Set
MODEL_OUTPUT_PATH=MODEL_DIR(can also be configured via an environment variable)Set
EVAL_DATA_PATH(default:./eval, also overridable through an environment variable) you can also set these environment var yourselfRun:
python -u infer.py --topk 10
Reproducibility
The model at global_step136000 has been verified to achieve a score of 0.129843, with the result being fully reproducible across runs.
📄 License
SPDX-License-Identifier: Apache-2.0
This project is licensed under the Apache License 2.0.
🙏 Acknowledgements
Developed upon the baseline of the 2025 Tencent Advertising Algorithm Competition
References the official HSTU implementation (“Actions Speak Louder than Words: Trillion-Parameter Sequential Transducers for Generative Recommendations”).
Explore related projects
Loading…