nextrec 0.4.6__py3-none-any.whl → 0.4.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nextrec/__version__.py +1 -1
- nextrec/basic/callback.py +399 -21
- nextrec/basic/model.py +289 -173
- nextrec/cli.py +27 -1
- nextrec/loss/loss_utils.py +73 -4
- nextrec/models/match/dssm.py +5 -4
- nextrec/models/match/dssm_v2.py +4 -3
- nextrec/models/match/mind.py +5 -4
- nextrec/models/match/sdm.py +5 -4
- nextrec/models/match/youtube_dnn.py +5 -4
- nextrec/utils/cli_utils.py +58 -0
- nextrec/utils/config.py +5 -4
- {nextrec-0.4.6.dist-info → nextrec-0.4.8.dist-info}/METADATA +32 -26
- {nextrec-0.4.6.dist-info → nextrec-0.4.8.dist-info}/RECORD +17 -16
- {nextrec-0.4.6.dist-info → nextrec-0.4.8.dist-info}/WHEEL +0 -0
- {nextrec-0.4.6.dist-info → nextrec-0.4.8.dist-info}/entry_points.txt +0 -0
- {nextrec-0.4.6.dist-info → nextrec-0.4.8.dist-info}/licenses/LICENSE +0 -0
nextrec/cli.py
CHANGED
|
@@ -14,9 +14,11 @@ Examples:
|
|
|
14
14
|
nextrec --mode=predict --predict_config=nextrec_cli_preset/predict_config.yaml
|
|
15
15
|
|
|
16
16
|
Date: create on 06/12/2025
|
|
17
|
+
Checkpoint: edit on 18/12/2025
|
|
17
18
|
Author: Yang Zhou, zyaztec@gmail.com
|
|
18
19
|
"""
|
|
19
20
|
|
|
21
|
+
import sys
|
|
20
22
|
import argparse
|
|
21
23
|
import logging
|
|
22
24
|
import pickle
|
|
@@ -44,6 +46,10 @@ from nextrec.utils.file import (
|
|
|
44
46
|
read_yaml,
|
|
45
47
|
resolve_file_paths,
|
|
46
48
|
)
|
|
49
|
+
from nextrec.utils.cli_utils import (
|
|
50
|
+
get_nextrec_version,
|
|
51
|
+
log_startup_info,
|
|
52
|
+
)
|
|
47
53
|
from nextrec.basic.loggers import setup_logger
|
|
48
54
|
|
|
49
55
|
logger = logging.getLogger(__name__)
|
|
@@ -71,6 +77,9 @@ def train_model(train_config_path: str) -> None:
|
|
|
71
77
|
artifact_root = Path(session_cfg.get("artifact_root", "nextrec_logs"))
|
|
72
78
|
session_dir = artifact_root / session_id
|
|
73
79
|
setup_logger(session_id=session_id)
|
|
80
|
+
logger.info(
|
|
81
|
+
f"[NextRec CLI] Training start | version={get_nextrec_version()} | session_id={session_id} | artifacts={session_dir.resolve()}"
|
|
82
|
+
)
|
|
74
83
|
|
|
75
84
|
processor_path = session_dir / "processor.pkl"
|
|
76
85
|
processor_path = Path(processor_path)
|
|
@@ -324,6 +333,9 @@ def predict_model(predict_config_path: str) -> None:
|
|
|
324
333
|
artifact_root = Path(session_cfg.get("artifact_root", "nextrec_logs"))
|
|
325
334
|
session_dir = Path(cfg.get("checkpoint_path") or (artifact_root / session_id))
|
|
326
335
|
setup_logger(session_id=session_id)
|
|
336
|
+
logger.info(
|
|
337
|
+
f"[NextRec CLI] Predict start | version={get_nextrec_version()} | session_id={session_id} | checkpoint={session_dir.resolve()}"
|
|
338
|
+
)
|
|
327
339
|
|
|
328
340
|
processor_path = Path(session_dir / "processor.pkl")
|
|
329
341
|
if not processor_path.exists():
|
|
@@ -454,6 +466,13 @@ def predict_model(predict_config_path: str) -> None:
|
|
|
454
466
|
|
|
455
467
|
def main() -> None:
|
|
456
468
|
"""Parse CLI arguments and dispatch to train or predict mode."""
|
|
469
|
+
|
|
470
|
+
root = logging.getLogger()
|
|
471
|
+
if not root.handlers:
|
|
472
|
+
handler = logging.StreamHandler(sys.stdout)
|
|
473
|
+
handler.setFormatter(logging.Formatter("%(message)s"))
|
|
474
|
+
root.addHandler(handler)
|
|
475
|
+
|
|
457
476
|
parser = argparse.ArgumentParser(
|
|
458
477
|
description="NextRec: Training and Prediction Pipeline",
|
|
459
478
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
@@ -466,25 +485,32 @@ Examples:
|
|
|
466
485
|
nextrec --mode=predict --predict_config=configs/predict_config.yaml
|
|
467
486
|
""",
|
|
468
487
|
)
|
|
488
|
+
|
|
469
489
|
parser.add_argument(
|
|
470
490
|
"--mode",
|
|
471
491
|
choices=["train", "predict"],
|
|
472
|
-
required=True,
|
|
473
492
|
help="Running mode: train or predict",
|
|
474
493
|
)
|
|
475
494
|
parser.add_argument("--train_config", help="Training configuration file path")
|
|
476
495
|
parser.add_argument("--predict_config", help="Prediction configuration file path")
|
|
477
496
|
args = parser.parse_args()
|
|
478
497
|
|
|
498
|
+
logger.info(get_nextrec_version())
|
|
499
|
+
|
|
500
|
+
if not args.mode:
|
|
501
|
+
parser.error("[NextRec CLI Error] --mode is required (train|predict)")
|
|
502
|
+
|
|
479
503
|
if args.mode == "train":
|
|
480
504
|
config_path = args.train_config
|
|
481
505
|
if not config_path:
|
|
482
506
|
parser.error("[NextRec CLI Error] train mode requires --train_config")
|
|
507
|
+
log_startup_info(logger, mode="train", config_path=config_path)
|
|
483
508
|
train_model(config_path)
|
|
484
509
|
else:
|
|
485
510
|
config_path = args.predict_config
|
|
486
511
|
if not config_path:
|
|
487
512
|
parser.error("[NextRec CLI Error] predict mode requires --predict_config")
|
|
513
|
+
log_startup_info(logger, mode="predict", config_path=config_path)
|
|
488
514
|
predict_model(config_path)
|
|
489
515
|
|
|
490
516
|
|
nextrec/loss/loss_utils.py
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
Loss utilities for NextRec.
|
|
3
3
|
|
|
4
4
|
Date: create on 27/10/2025
|
|
5
|
-
Checkpoint: edit on
|
|
5
|
+
Checkpoint: edit on 17/12/2025
|
|
6
6
|
Author: Yang Zhou, zyaztec@gmail.com
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
|
+
from typing import Literal
|
|
10
|
+
|
|
9
11
|
import torch.nn as nn
|
|
10
12
|
|
|
11
13
|
from nextrec.loss.listwise import (
|
|
@@ -30,14 +32,81 @@ VALID_TASK_TYPES = [
|
|
|
30
32
|
"regression",
|
|
31
33
|
]
|
|
32
34
|
|
|
35
|
+
# Define all supported loss types
|
|
36
|
+
LossType = Literal[
|
|
37
|
+
# Pointwise losses
|
|
38
|
+
"bce",
|
|
39
|
+
"binary_crossentropy",
|
|
40
|
+
"weighted_bce",
|
|
41
|
+
"focal",
|
|
42
|
+
"focal_loss",
|
|
43
|
+
"cb_focal",
|
|
44
|
+
"class_balanced_focal",
|
|
45
|
+
"crossentropy",
|
|
46
|
+
"ce",
|
|
47
|
+
"mse",
|
|
48
|
+
"mae",
|
|
49
|
+
# Pairwise ranking losses
|
|
50
|
+
"bpr",
|
|
51
|
+
"hinge",
|
|
52
|
+
"triplet",
|
|
53
|
+
# Listwise ranking losses
|
|
54
|
+
"sampled_softmax",
|
|
55
|
+
"softmax",
|
|
56
|
+
"infonce",
|
|
57
|
+
"listnet",
|
|
58
|
+
"listmle",
|
|
59
|
+
"approx_ndcg",
|
|
60
|
+
]
|
|
61
|
+
|
|
33
62
|
|
|
34
|
-
def
|
|
63
|
+
def build_cb_focal(kw):
|
|
35
64
|
if "class_counts" not in kw:
|
|
36
65
|
raise ValueError("class_balanced_focal requires class_counts")
|
|
37
66
|
return ClassBalancedFocalLoss(**kw)
|
|
38
67
|
|
|
39
68
|
|
|
40
|
-
def get_loss_fn(loss=None, **kw):
|
|
69
|
+
def get_loss_fn(loss: LossType | nn.Module | None = None, **kw) -> nn.Module:
|
|
70
|
+
"""
|
|
71
|
+
Get loss function by name or return the provided loss module.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
loss: Loss function name or nn.Module instance. Supported options:
|
|
75
|
+
|
|
76
|
+
**Pointwise Losses:**
|
|
77
|
+
- "bce", "binary_crossentropy": Binary Cross-Entropy Loss
|
|
78
|
+
- "weighted_bce": Weighted Binary Cross-Entropy Loss
|
|
79
|
+
- "focal", "focal_loss": Focal Loss (for class imbalance)
|
|
80
|
+
- "cb_focal", "class_balanced_focal": Class-Balanced Focal Loss (requires class_counts parameter)
|
|
81
|
+
- "crossentropy", "ce": Cross-Entropy Loss for multi-class classification
|
|
82
|
+
- "mse": Mean Squared Error Loss
|
|
83
|
+
- "mae": Mean Absolute Error Loss
|
|
84
|
+
|
|
85
|
+
**Pairwise Ranking Losses:**
|
|
86
|
+
- "bpr": Bayesian Personalized Ranking Loss
|
|
87
|
+
- "hinge": Hinge Loss
|
|
88
|
+
- "triplet": Triplet Loss
|
|
89
|
+
|
|
90
|
+
**Listwise Ranking Losses:**
|
|
91
|
+
- "sampled_softmax", "softmax": Sampled Softmax Loss
|
|
92
|
+
- "infonce": InfoNCE Loss
|
|
93
|
+
- "listnet": ListNet Loss
|
|
94
|
+
- "listmle": ListMLE Loss
|
|
95
|
+
- "approx_ndcg": Approximate NDCG Loss
|
|
96
|
+
|
|
97
|
+
**kw: Additional keyword arguments passed to the loss function
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
nn.Module: Loss function instance
|
|
101
|
+
|
|
102
|
+
Raises:
|
|
103
|
+
ValueError: If loss is None or unsupported type
|
|
104
|
+
|
|
105
|
+
Examples:
|
|
106
|
+
>>> loss_fn = get_loss_fn("bce")
|
|
107
|
+
>>> loss_fn = get_loss_fn("focal", alpha=0.25, gamma=2.0)
|
|
108
|
+
>>> loss_fn = get_loss_fn("cb_focal", class_counts=[100, 50, 200])
|
|
109
|
+
"""
|
|
41
110
|
if isinstance(loss, nn.Module):
|
|
42
111
|
return loss
|
|
43
112
|
if loss is None:
|
|
@@ -49,7 +118,7 @@ def get_loss_fn(loss=None, **kw):
|
|
|
49
118
|
if loss in ["focal", "focal_loss"]:
|
|
50
119
|
return FocalLoss(**kw)
|
|
51
120
|
if loss in ["cb_focal", "class_balanced_focal"]:
|
|
52
|
-
return
|
|
121
|
+
return build_cb_focal(kw)
|
|
53
122
|
if loss in ["crossentropy", "ce"]:
|
|
54
123
|
return nn.CrossEntropyLoss(**kw)
|
|
55
124
|
if loss == "mse":
|
nextrec/models/match/dssm.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"""
|
|
2
2
|
Date: create on 09/11/2025
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Checkpoint: edit on 18/12/2025
|
|
4
|
+
Author: Yang Zhou, zyaztec@gmail.com
|
|
5
5
|
Reference:
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
[1] Huang P S, He X, Gao J, et al. Learning deep structured semantic models for web search using clickthrough data[C]
|
|
7
|
+
//Proceedings of the 22nd ACM international conference on Information & Knowledge Management. 2013: 2333-2338.
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
import torch
|
|
@@ -81,6 +81,7 @@ class DSSM(BaseMatchModel):
|
|
|
81
81
|
dense_l1_reg=dense_l1_reg,
|
|
82
82
|
embedding_l2_reg=embedding_l2_reg,
|
|
83
83
|
dense_l2_reg=dense_l2_reg,
|
|
84
|
+
early_stop_patience=early_stop_patience,
|
|
84
85
|
**kwargs,
|
|
85
86
|
)
|
|
86
87
|
|
nextrec/models/match/dssm_v2.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"""
|
|
2
2
|
Date: create on 09/11/2025
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Checkpoint: edit on 18/12/2025
|
|
4
|
+
Author: Yang Zhou, zyaztec@gmail.com
|
|
5
5
|
Reference:
|
|
6
|
-
|
|
6
|
+
DSSM v2 - DSSM with pairwise training using BPR loss
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
9
|
import torch
|
|
@@ -77,6 +77,7 @@ class DSSM_v2(BaseMatchModel):
|
|
|
77
77
|
dense_l1_reg=dense_l1_reg,
|
|
78
78
|
embedding_l2_reg=embedding_l2_reg,
|
|
79
79
|
dense_l2_reg=dense_l2_reg,
|
|
80
|
+
early_stop_patience=early_stop_patience,
|
|
80
81
|
**kwargs,
|
|
81
82
|
)
|
|
82
83
|
|
nextrec/models/match/mind.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"""
|
|
2
2
|
Date: create on 09/11/2025
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Checkpoint: edit on 18/12/2025
|
|
4
|
+
Author: Yang Zhou, zyaztec@gmail.com
|
|
5
5
|
Reference:
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
[1] Li C, Liu Z, Wu M, et al. Multi-interest network with dynamic routing for recommendation at Tmall[C]
|
|
7
|
+
//Proceedings of the 28th ACM international conference on information and knowledge management. 2019: 2615-2623.
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
import torch
|
|
@@ -237,6 +237,7 @@ class MIND(BaseMatchModel):
|
|
|
237
237
|
dense_l1_reg=dense_l1_reg,
|
|
238
238
|
embedding_l2_reg=embedding_l2_reg,
|
|
239
239
|
dense_l2_reg=dense_l2_reg,
|
|
240
|
+
early_stop_patience=early_stop_patience,
|
|
240
241
|
**kwargs,
|
|
241
242
|
)
|
|
242
243
|
|
nextrec/models/match/sdm.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"""
|
|
2
2
|
Date: create on 09/11/2025
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Checkpoint: edit on 18/12/2025
|
|
4
|
+
Author: Yang Zhou, zyaztec@gmail.com
|
|
5
5
|
Reference:
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
[1] Ying H, Zhuang F, Zhang F, et al. Sequential recommender system based on hierarchical attention networks[C]
|
|
7
|
+
//IJCAI. 2018: 3926-3932.
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
import torch
|
|
@@ -84,6 +84,7 @@ class SDM(BaseMatchModel):
|
|
|
84
84
|
dense_l1_reg=dense_l1_reg,
|
|
85
85
|
embedding_l2_reg=embedding_l2_reg,
|
|
86
86
|
dense_l2_reg=dense_l2_reg,
|
|
87
|
+
early_stop_patience=early_stop_patience,
|
|
87
88
|
**kwargs,
|
|
88
89
|
)
|
|
89
90
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"""
|
|
2
2
|
Date: create on 09/11/2025
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Checkpoint: edit on 18/12/2025
|
|
4
|
+
Author: Yang Zhou, zyaztec@gmail.com
|
|
5
5
|
Reference:
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
[1] Covington P, Adams J, Sargin E. Deep neural networks for youtube recommendations[C]
|
|
7
|
+
//Proceedings of the 10th ACM conference on recommender systems. 2016: 191-198.
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
import torch
|
|
@@ -81,6 +81,7 @@ class YoutubeDNN(BaseMatchModel):
|
|
|
81
81
|
dense_l1_reg=dense_l1_reg,
|
|
82
82
|
embedding_l2_reg=embedding_l2_reg,
|
|
83
83
|
dense_l2_reg=dense_l2_reg,
|
|
84
|
+
early_stop_patience=early_stop_patience,
|
|
84
85
|
**kwargs,
|
|
85
86
|
)
|
|
86
87
|
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""
|
|
2
|
+
CLI utilities for NextRec.
|
|
3
|
+
|
|
4
|
+
This module provides small helpers used by command-line entrypoints, such as
|
|
5
|
+
printing startup banners and resolving the installed package version.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import logging
|
|
11
|
+
import os
|
|
12
|
+
import platform
|
|
13
|
+
import sys
|
|
14
|
+
from datetime import datetime
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def get_nextrec_version() -> str:
|
|
18
|
+
"""
|
|
19
|
+
Best-effort version resolver for NextRec.
|
|
20
|
+
|
|
21
|
+
Prefer in-repo `nextrec.__version__`, fall back to installed package metadata.
|
|
22
|
+
"""
|
|
23
|
+
try:
|
|
24
|
+
from nextrec import __version__ # type: ignore
|
|
25
|
+
|
|
26
|
+
if __version__:
|
|
27
|
+
return str(__version__)
|
|
28
|
+
except Exception:
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
try:
|
|
32
|
+
from importlib.metadata import version
|
|
33
|
+
|
|
34
|
+
return version("nextrec")
|
|
35
|
+
except Exception:
|
|
36
|
+
return "unknown"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def log_startup_info(
|
|
40
|
+
logger: logging.Logger, *, mode: str, config_path: str | None
|
|
41
|
+
) -> None:
|
|
42
|
+
"""Log a short, user-friendly startup banner."""
|
|
43
|
+
version = get_nextrec_version()
|
|
44
|
+
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
45
|
+
|
|
46
|
+
lines = [
|
|
47
|
+
"NextRec CLI",
|
|
48
|
+
f"- Version: {version}",
|
|
49
|
+
f"- Time: {now}",
|
|
50
|
+
f"- Mode: {mode}",
|
|
51
|
+
f"- Config: {config_path or '(not set)'}",
|
|
52
|
+
f"- Python: {platform.python_version()} ({sys.executable})",
|
|
53
|
+
f"- Platform: {platform.system()} {platform.release()} ({platform.machine()})",
|
|
54
|
+
f"- Workdir: {os.getcwd()}",
|
|
55
|
+
f"- Command: {' '.join(sys.argv)}",
|
|
56
|
+
]
|
|
57
|
+
for line in lines:
|
|
58
|
+
logger.info(line)
|
nextrec/utils/config.py
CHANGED
|
@@ -62,7 +62,7 @@ def select_features(
|
|
|
62
62
|
|
|
63
63
|
|
|
64
64
|
def register_processor_features(
|
|
65
|
-
processor: DataProcessor,
|
|
65
|
+
processor: "DataProcessor",
|
|
66
66
|
feature_cfg: Dict[str, Any],
|
|
67
67
|
dense_names: List[str],
|
|
68
68
|
sparse_names: List[str],
|
|
@@ -129,6 +129,7 @@ def build_feature_objects(
|
|
|
129
129
|
sparse_names: List of sparse feature names
|
|
130
130
|
sequence_names: List of sequence feature names
|
|
131
131
|
"""
|
|
132
|
+
from nextrec.basic.features import DenseFeature, SparseFeature, SequenceFeature
|
|
132
133
|
|
|
133
134
|
dense_cfg = feature_cfg.get("dense", {}) or {}
|
|
134
135
|
sparse_cfg = feature_cfg.get("sparse", {}) or {}
|
|
@@ -360,9 +361,9 @@ def load_model_class(model_cfg: Dict[str, Any], base_dir: Path) -> type:
|
|
|
360
361
|
def build_model_instance(
|
|
361
362
|
model_cfg: Dict[str, Any],
|
|
362
363
|
model_cfg_path: Path,
|
|
363
|
-
dense_features: List[DenseFeature],
|
|
364
|
-
sparse_features: List[SparseFeature],
|
|
365
|
-
sequence_features: List[SequenceFeature],
|
|
364
|
+
dense_features: List["DenseFeature"],
|
|
365
|
+
sparse_features: List["SparseFeature"],
|
|
366
|
+
sequence_features: List["SequenceFeature"],
|
|
366
367
|
target: List[str],
|
|
367
368
|
device: str,
|
|
368
369
|
) -> Any:
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nextrec
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.8
|
|
4
4
|
Summary: A comprehensive recommendation library with match, ranking, and multi-task learning models
|
|
5
5
|
Project-URL: Homepage, https://github.com/zerolovesea/NextRec
|
|
6
6
|
Project-URL: Repository, https://github.com/zerolovesea/NextRec
|
|
7
7
|
Project-URL: Documentation, https://github.com/zerolovesea/NextRec/blob/main/README.md
|
|
8
8
|
Project-URL: Issues, https://github.com/zerolovesea/NextRec/issues
|
|
9
|
-
Author
|
|
9
|
+
Author: Yang Zhou
|
|
10
|
+
Author-email: zyaztec@gmail.com
|
|
10
11
|
License-File: LICENSE
|
|
11
12
|
Keywords: ctr,deep-learning,match,pytorch,ranking,recommendation
|
|
12
13
|
Classifier: Development Status :: 3 - Alpha
|
|
@@ -65,9 +66,9 @@ Description-Content-Type: text/markdown
|
|
|
65
66
|

|
|
66
67
|

|
|
67
68
|

|
|
68
|
-

|
|
69
70
|
|
|
70
|
-
中文文档 | [English Version](README_en.md)
|
|
71
|
+
中文文档 | [English Version](README_en.md)
|
|
71
72
|
|
|
72
73
|
**统一、高效、可扩展的推荐系统框架**
|
|
73
74
|
|
|
@@ -80,7 +81,7 @@ Description-Content-Type: text/markdown
|
|
|
80
81
|
- [安装](#安装)
|
|
81
82
|
- [架构](#架构)
|
|
82
83
|
- [5分钟快速上手](#5分钟快速上手)
|
|
83
|
-
- [命令行工具](#命令行工具)
|
|
84
|
+
- [命令行工具 NextRec-CLI](#命令行工具)
|
|
84
85
|
- [兼容平台](#兼容平台)
|
|
85
86
|
- [支持模型](#支持模型)
|
|
86
87
|
- [贡献指南](#贡献指南)
|
|
@@ -90,35 +91,30 @@ Description-Content-Type: text/markdown
|
|
|
90
91
|
NextRec是一个基于PyTorch的现代推荐系统框架,旨在为研究工程团队提供快速的建模、训练与评估流。框架内置丰富的模型库、数据处理工具和工程化训练组件。此外提供了易上手的接口,命令行工具及教程,推荐算法学习者能以最快速度了解模型架构,复现学术论文并进行训练和部署。
|
|
91
92
|
|
|
92
93
|
## Why NextRec
|
|
93
|
-
|
|
94
|
-
- **统一的特征工程与数据流水线**:NextRec框架提供了统一的特征定义、可持久化的数据处理、并对批处理进行了优化,符合工业大数据Spark/Hive场景下,基于离线特征的模型训练推理流程。
|
|
95
94
|
- **多场景推荐能力**:覆盖排序(CTR/CVR)、召回、多任务学习、生成式召回等推荐/营销模型,持续跟进业界进展。
|
|
96
|
-
-
|
|
95
|
+
- **统一的特征工程与数据流水线**:NextRec框架提供了统一的特征定义、可持久化的数据处理、批处理优化,符合工业大数据Spark/Hive场景下,基于离线特征的模型训练推理流程。
|
|
96
|
+
- **友好的工程体验**:支持多种格式数据(`csv/parquet/pathlike`)的流式处理/分布式训练/推理与可视化指标监控,方便业务算法工程师和推荐算法学习者快速复现实验。
|
|
97
97
|
- **灵活的命令行工具**:支持通过命令行和配置文件,一键启动训练和推理进程,方便快速实验迭代和敏捷部署。
|
|
98
98
|
- **高效训练与评估**:内置多种优化器、学习率调度、早停、模型检查点与详细的日志管理,开箱即用。
|
|
99
99
|
|
|
100
100
|
## NextRec近期进展
|
|
101
101
|
|
|
102
|
-
- **12/12/2025** 在v0.4.
|
|
102
|
+
- **12/12/2025** 在v0.4.8中加入了[RQ-VAE](/nextrec/models/generative/rqvae.py)模块。配套的[数据集](/dataset/ecommerce_task.csv)和[代码](tutorials/notebooks/zh/使用RQ-VAE构建语义ID.ipynby)已经同步在仓库中
|
|
103
103
|
- **07/12/2025** 发布了NextRec CLI命令行工具,它允许用户根据配置文件进行一键训练和推理,我们提供了相关的[教程](/nextrec_cli_preset/NextRec-CLI_zh.md)和[教学代码](/nextrec_cli_preset)
|
|
104
|
-
- **03/12/2025** NextRec
|
|
104
|
+
- **03/12/2025** NextRec获得了100颗🌟!感谢大家的支持
|
|
105
105
|
- **06/12/2025** 在v0.4.1中支持了单机多卡的分布式DDP训练,并且提供了配套的[代码](tutorials/distributed)
|
|
106
106
|
- **23/11/2025** 在v0.2.2中对basemodel进行了逻辑上的大幅重构和流程统一,并且对listwise/pairwise/pointwise损失进行了统一
|
|
107
107
|
- **11/11/2025** NextRec v0.1.0发布,我们提供了10余种Ranking模型,4种多任务模型和4种召回模型,以及统一的训练/日志/指标管理系统
|
|
108
108
|
|
|
109
109
|
## 架构
|
|
110
110
|
|
|
111
|
-
NextRec
|
|
112
|
-
|
|
113
|
-

|
|
111
|
+
NextRec采用模块化工程设计,核心组件包括:统一特征驱动的BaseModel架构;独立Layer模块;支持训练推理的统一的DataLoader;命令行工具NextCLI等。
|
|
114
112
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
---
|
|
113
|
+

|
|
118
114
|
|
|
119
115
|
## 安装
|
|
120
116
|
|
|
121
|
-
开发者可以通过`pip install nextrec`快速安装NextRec的最新版本,环境要求为Python 3.10
|
|
117
|
+
开发者可以通过`pip install nextrec`快速安装NextRec的最新版本,环境要求为Python 3.10+(对于需要使用CUDA加速的开发者,建议安装对应版本的pytorch)。如果需要执行示例代码,则需要先拉取仓库:
|
|
122
118
|
|
|
123
119
|
```bash
|
|
124
120
|
git clone https://github.com/zerolovesea/NextRec.git
|
|
@@ -245,11 +241,11 @@ nextrec --mode=train --train_config=path/to/train_config.yaml
|
|
|
245
241
|
nextrec --mode=predict --predict_config=path/to/predict_config.yaml
|
|
246
242
|
```
|
|
247
243
|
|
|
248
|
-
> 截止当前版本0.4.
|
|
244
|
+
> 截止当前版本0.4.8,NextRec CLI支持单机训练,分布式训练相关功能尚在开发中。
|
|
249
245
|
|
|
250
246
|
## 兼容平台
|
|
251
247
|
|
|
252
|
-
当前最新版本为0.4.
|
|
248
|
+
当前最新版本为0.4.8,所有模型和测试代码均已在以下平台通过验证,如果开发者在使用中遇到兼容问题,请在issue区提出错误报告及系统版本:
|
|
253
249
|
|
|
254
250
|
| 平台 | 配置 |
|
|
255
251
|
|------|------|
|
|
@@ -273,7 +269,7 @@ nextrec --mode=predict --predict_config=path/to/predict_config.yaml
|
|
|
273
269
|
| [PNN](nextrec/models/ranking/pnn.py) | Product-based Neural Networks for User Response Prediction | ICDM 2016 | 已支持 |
|
|
274
270
|
| [AutoInt](nextrec/models/ranking/autoint.py) | AutoInt: Automatic Feature Interaction Learning | CIKM 2019 | 已支持 |
|
|
275
271
|
| [DCN](nextrec/models/ranking/dcn.py) | Deep & Cross Network for Ad Click Predictions | ADKDD 2017 | 已支持 |
|
|
276
|
-
| [DCN v2](nextrec/models/ranking/dcn_v2.py) | DCN V2: Improved Deep & Cross Network and Practical Lessons for Web-scale Learning to Rank Systems | KDD 2021 |
|
|
272
|
+
| [DCN v2](nextrec/models/ranking/dcn_v2.py) | DCN V2: Improved Deep & Cross Network and Practical Lessons for Web-scale Learning to Rank Systems | KDD 2021 | 已支持 |
|
|
277
273
|
| [DIN](nextrec/models/ranking/din.py) | Deep Interest Network for Click-Through Rate Prediction | KDD 2018 | 已支持 |
|
|
278
274
|
| [DIEN](nextrec/models/ranking/dien.py) | Deep Interest Evolution Network for Click-Through Rate Prediction | AAAI 2019 | 已支持 |
|
|
279
275
|
| [MaskNet](nextrec/models/ranking/masknet.py) | MaskNet: Introducing Feature-wise Gating Blocks for High-dimensional Sparse Recommendation Data | 2020 | 已支持 |
|
|
@@ -337,21 +333,15 @@ nextrec --mode=predict --predict_config=path/to/predict_config.yaml
|
|
|
337
333
|
- 实际行为
|
|
338
334
|
- 环境信息(Python 版本、PyTorch 版本等)
|
|
339
335
|
|
|
340
|
-
---
|
|
341
|
-
|
|
342
336
|
## 许可证
|
|
343
337
|
|
|
344
338
|
本项目采用 [Apache 2.0 许可证](./LICENSE)。
|
|
345
339
|
|
|
346
|
-
---
|
|
347
|
-
|
|
348
340
|
## 联系方式
|
|
349
341
|
|
|
350
342
|
- **GitHub Issues**: [提交问题](https://github.com/zerolovesea/NextRec/issues)
|
|
351
343
|
- **邮箱**: zyaztec@gmail.com
|
|
352
344
|
|
|
353
|
-
---
|
|
354
|
-
|
|
355
345
|
## 致谢
|
|
356
346
|
|
|
357
347
|
NextRec 的开发受到以下优秀项目的启发:
|
|
@@ -362,6 +352,22 @@ NextRec 的开发受到以下优秀项目的启发:
|
|
|
362
352
|
|
|
363
353
|
感谢开源社区的所有贡献者!
|
|
364
354
|
|
|
355
|
+
|
|
356
|
+
## 引用
|
|
357
|
+
|
|
358
|
+
如果您在研究或工作中使用了本框架,欢迎引用本项目:
|
|
359
|
+
|
|
360
|
+
```bibtex
|
|
361
|
+
@misc{nextrec,
|
|
362
|
+
title = {NextRec},
|
|
363
|
+
author = {Yang Zhou},
|
|
364
|
+
year = {2025},
|
|
365
|
+
publisher = {GitHub},
|
|
366
|
+
journal = {GitHub repository},
|
|
367
|
+
howpublished = {\url{https://github.com/zerolovesea/NextRec}},
|
|
368
|
+
note = {A unified, efficient, and extensible PyTorch-based recommendation library}
|
|
369
|
+
}
|
|
370
|
+
```
|
|
365
371
|
---
|
|
366
372
|
|
|
367
373
|
<div align="center">
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
nextrec/__init__.py,sha256=_M3oUqyuvQ5k8Th_3wId6hQ_caclh7M5ad51XN09m98,235
|
|
2
|
-
nextrec/__version__.py,sha256=
|
|
3
|
-
nextrec/cli.py,sha256=
|
|
2
|
+
nextrec/__version__.py,sha256=40-PUZPRIakJU2yYWQcwTYvSJA6iewqiG8XylhxuAQk,22
|
|
3
|
+
nextrec/cli.py,sha256=ItikUEFDju7c_3tDhYQuNPbhvFK6jij9zAujR_MYYK8,19388
|
|
4
4
|
nextrec/basic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
5
|
nextrec/basic/activation.py,sha256=uzTWfCOtBSkbu_Gk9XBNTj8__s241CaYLJk6l8nGX9I,2885
|
|
6
|
-
nextrec/basic/callback.py,sha256=
|
|
6
|
+
nextrec/basic/callback.py,sha256=lELZhkB1TlAT_5My7Ce41u7Rox73rbyaulykWCk-svo,14108
|
|
7
7
|
nextrec/basic/features.py,sha256=kfgU3gCORjYD7ylmKJDrWIrRIL97GcKWCDWeULU5N7g,4339
|
|
8
8
|
nextrec/basic/layers.py,sha256=jDT6nnpCxdgzKMdhU-apxPgjHm-AHujRxjgBum4mBm0,29017
|
|
9
9
|
nextrec/basic/loggers.py,sha256=p9wNmLuRYyvHsOzP0eNOYSlV3hrTDjrt6ggrH_r4RE0,6243
|
|
10
10
|
nextrec/basic/metrics.py,sha256=EicHCyyr2j45J-emHf5KifQN6fnb6IV6gqEBu7ioANQ,26066
|
|
11
|
-
nextrec/basic/model.py,sha256=
|
|
11
|
+
nextrec/basic/model.py,sha256=tYpQAbeW99aXTrsmryoWe9sA8ihG8pHNytRcU_49-pQ,100764
|
|
12
12
|
nextrec/basic/session.py,sha256=UOG_-EgCOxvqZwCkiEd8sgNV2G1sm_HbzKYVQw8yYDI,4483
|
|
13
13
|
nextrec/data/__init__.py,sha256=auT_PkbgU9pUCt7KQl6H2ajcUorRhSyHa8NG3wExcG8,1197
|
|
14
14
|
nextrec/data/batch_utils.py,sha256=FAJiweuDyAIzX7rICVmcxMofdFs2-7RLinovwB-lAYM,2878
|
|
@@ -18,7 +18,7 @@ nextrec/data/dataloader.py,sha256=L4VBpWUZrxozFBV54nhJAAC-ZX5Hg6zFwIwpGnguJ9c,18
|
|
|
18
18
|
nextrec/data/preprocessor.py,sha256=BxoD6GHEre86i-TbxPi58Uwmg_G7oLkiER6f7VfmVHo,41583
|
|
19
19
|
nextrec/loss/__init__.py,sha256=mO5t417BneZ8Ysa51GyjDaffjWyjzFgPXIQrrggasaQ,827
|
|
20
20
|
nextrec/loss/listwise.py,sha256=UT9vJCOTOQLogVwaeTV7Z5uxIYnngGdxk-p9e97MGkU,5744
|
|
21
|
-
nextrec/loss/loss_utils.py,sha256=
|
|
21
|
+
nextrec/loss/loss_utils.py,sha256=8lGJpiJ7GYplUdQqJL5XzHIiQr98g5pRb2cTYdS5VLA,4646
|
|
22
22
|
nextrec/loss/pairwise.py,sha256=X9yg-8pcPt2IWU0AiUhWAt3_4W_3wIF0uSdDYTdoPFY,3398
|
|
23
23
|
nextrec/loss/pointwise.py,sha256=o9J3OznY0hlbDsUXqn3k-BBzYiuUH5dopz8QBFqS_kQ,7343
|
|
24
24
|
nextrec/models/generative/__init__.py,sha256=RU4DRibbfK802rzSXIgf3mSwYsSsYLKJiPzcXqprbvY,350
|
|
@@ -26,11 +26,11 @@ nextrec/models/generative/hstu.py,sha256=ro0ifzvlS0SQaS1PMVDjvGDBgql5RnWEPGCu_iR
|
|
|
26
26
|
nextrec/models/generative/rqvae.py,sha256=yxZ9KNEjRu0yxBjeNtCa2Y0ElB97diV_Z92CS9hbhzE,29255
|
|
27
27
|
nextrec/models/generative/tiger.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
28
28
|
nextrec/models/match/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
29
|
-
nextrec/models/match/dssm.py,sha256=
|
|
30
|
-
nextrec/models/match/dssm_v2.py,sha256=
|
|
31
|
-
nextrec/models/match/mind.py,sha256=
|
|
32
|
-
nextrec/models/match/sdm.py,sha256=
|
|
33
|
-
nextrec/models/match/youtube_dnn.py,sha256
|
|
29
|
+
nextrec/models/match/dssm.py,sha256=W6oBOEMGT-xYvhd-qzmGpYqxm9B-fwIQaXE7nEw2gfI,7923
|
|
30
|
+
nextrec/models/match/dssm_v2.py,sha256=I2eWWyzFd7nIiShOB7VPxNMLoqST5IY98WxjDyvAGa8,6955
|
|
31
|
+
nextrec/models/match/mind.py,sha256=semg4EEThD4l7K8fW1wuRF3i9Ex-smJVI4CNORVajvA,15089
|
|
32
|
+
nextrec/models/match/sdm.py,sha256=kwDjDkFpoTmicfKScXjhJLe500upbg8eDXICQLMW03k,10557
|
|
33
|
+
nextrec/models/match/youtube_dnn.py,sha256=-XuaM7lh02qkLCwJF3KgWxOQGn61p92MnYA100LWG4o,7283
|
|
34
34
|
nextrec/models/multi_task/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
35
35
|
nextrec/models/multi_task/esmm.py,sha256=tQg_jE51VDTyc-F0auviyP8CI9uzYQ_KjybbCAXWp1s,6491
|
|
36
36
|
nextrec/models/multi_task/mmoe.py,sha256=qFWKdCE_VSGpVrMgx0NOO-HtLRNGdVxCWdkMfoEgjLA,8583
|
|
@@ -52,7 +52,8 @@ nextrec/models/ranking/pnn.py,sha256=twwixy26mfAVaI9AqNnMLdwOG-WtDga60xsNiyJrFjI
|
|
|
52
52
|
nextrec/models/ranking/widedeep.py,sha256=Xm2klmKBOoSKWCBQN7FhwLStu0BHSTOgAJ9kwLmtiFY,5077
|
|
53
53
|
nextrec/models/ranking/xdeepfm.py,sha256=kcPLoNC1940YxRMgWZS4mSxIXlwtc_HfNDIae_uYrsU,8156
|
|
54
54
|
nextrec/utils/__init__.py,sha256=zqU9vjRUpVzJepcvdbxboik68K5jnMR40kdVjr6tpXY,2599
|
|
55
|
-
nextrec/utils/
|
|
55
|
+
nextrec/utils/cli_utils.py,sha256=mOI2yKZwCE3lVH5RCKs3WnIKyXYiLI08vHFT8duBRrQ,1497
|
|
56
|
+
nextrec/utils/config.py,sha256=wx2Y-oxQqWhwOlW6DdG6ExLXDf-QDRnj8EQYDjrVhuY,19903
|
|
56
57
|
nextrec/utils/device.py,sha256=DtgmrJnVJQKtgtVUbm0SW0vZ5Le0R9HU8TsvqPnRLZc,2453
|
|
57
58
|
nextrec/utils/distributed.py,sha256=tIkgUjzEjR_FHOm9ckyM8KddkCfxNSogP-rdHcVGhuk,4782
|
|
58
59
|
nextrec/utils/embedding.py,sha256=akAEc062MG2cD7VIOllHaqtwzAirQR2gq5iW7oKpGAU,1449
|
|
@@ -63,8 +64,8 @@ nextrec/utils/model.py,sha256=dYl1XfIZt6aVjNyV2AAhcArwFRMcEAKrjG_pr8AVHs0,1163
|
|
|
63
64
|
nextrec/utils/optimizer.py,sha256=eX8baIvWOpwDTGninbyp6pQfzdHbIL62GTi4ldpYcfM,2337
|
|
64
65
|
nextrec/utils/synthetic_data.py,sha256=V6lxEQCU-yJXMBCoCAeKZZWBMYXpZhvbyfiI8jCmvqs,18112
|
|
65
66
|
nextrec/utils/tensor.py,sha256=Z6MBpSuQpHw4kGjeKxG0cXZMpRBCM45zTKhk9WolyiM,2220
|
|
66
|
-
nextrec-0.4.
|
|
67
|
-
nextrec-0.4.
|
|
68
|
-
nextrec-0.4.
|
|
69
|
-
nextrec-0.4.
|
|
70
|
-
nextrec-0.4.
|
|
67
|
+
nextrec-0.4.8.dist-info/METADATA,sha256=25dlzG2TNFZCvm_V6ZAnqaMTL6qwNNt7xMSRsmaQ_Nk,19460
|
|
68
|
+
nextrec-0.4.8.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
69
|
+
nextrec-0.4.8.dist-info/entry_points.txt,sha256=NN-dNSdfMRTv86bNXM7d3ZEPW2BQC6bRi7QP7i9cIps,45
|
|
70
|
+
nextrec-0.4.8.dist-info/licenses/LICENSE,sha256=2fQfVKeafywkni7MYHyClC6RGGC3laLTXCNBx-ubtp0,1064
|
|
71
|
+
nextrec-0.4.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|