nextrec 0.2.7__py3-none-any.whl → 0.3.2__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/activation.py +4 -8
- nextrec/basic/callback.py +1 -1
- nextrec/basic/features.py +33 -25
- nextrec/basic/layers.py +164 -601
- nextrec/basic/loggers.py +4 -5
- nextrec/basic/metrics.py +39 -115
- nextrec/basic/model.py +257 -177
- nextrec/basic/session.py +1 -5
- nextrec/data/__init__.py +12 -0
- nextrec/data/data_utils.py +3 -27
- nextrec/data/dataloader.py +26 -34
- nextrec/data/preprocessor.py +2 -1
- nextrec/loss/listwise.py +6 -4
- nextrec/loss/loss_utils.py +10 -6
- nextrec/loss/pairwise.py +5 -3
- nextrec/loss/pointwise.py +7 -13
- nextrec/models/generative/__init__.py +5 -0
- nextrec/models/generative/hstu.py +399 -0
- nextrec/models/match/mind.py +110 -1
- nextrec/models/multi_task/esmm.py +46 -27
- nextrec/models/multi_task/mmoe.py +48 -30
- nextrec/models/multi_task/ple.py +156 -141
- nextrec/models/multi_task/poso.py +413 -0
- nextrec/models/multi_task/share_bottom.py +43 -26
- nextrec/models/ranking/__init__.py +2 -0
- nextrec/models/ranking/dcn.py +20 -1
- nextrec/models/ranking/dcn_v2.py +84 -0
- nextrec/models/ranking/deepfm.py +44 -18
- nextrec/models/ranking/dien.py +130 -27
- nextrec/models/ranking/masknet.py +13 -67
- nextrec/models/ranking/widedeep.py +39 -18
- nextrec/models/ranking/xdeepfm.py +34 -1
- nextrec/utils/common.py +26 -1
- nextrec/utils/optimizer.py +7 -3
- nextrec-0.3.2.dist-info/METADATA +312 -0
- nextrec-0.3.2.dist-info/RECORD +57 -0
- nextrec-0.2.7.dist-info/METADATA +0 -281
- nextrec-0.2.7.dist-info/RECORD +0 -54
- {nextrec-0.2.7.dist-info → nextrec-0.3.2.dist-info}/WHEEL +0 -0
- {nextrec-0.2.7.dist-info → nextrec-0.3.2.dist-info}/licenses/LICENSE +0 -0
nextrec/__version__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.2
|
|
1
|
+
__version__ = "0.3.2"
|
nextrec/basic/activation.py
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Activation function definitions
|
|
3
3
|
|
|
4
4
|
Date: create on 27/10/2025
|
|
5
|
-
|
|
5
|
+
Checkpoint: edit on 29/11/2025
|
|
6
|
+
Author: Yang Zhou, zyaztec@gmail.com
|
|
6
7
|
"""
|
|
7
8
|
|
|
8
9
|
import torch
|
|
@@ -31,25 +32,20 @@ class Dice(nn.Module):
|
|
|
31
32
|
# For 3D input (batch_size, seq_len, emb_size), reshape to 2D
|
|
32
33
|
batch_size, seq_len, emb_size = x.shape
|
|
33
34
|
x = x.view(-1, emb_size)
|
|
34
|
-
|
|
35
35
|
x_norm = self.bn(x)
|
|
36
36
|
p = torch.sigmoid(x_norm)
|
|
37
37
|
output = p * x + (1 - p) * self.alpha * x
|
|
38
|
-
|
|
39
38
|
if len(original_shape) == 3:
|
|
40
39
|
output = output.view(original_shape)
|
|
41
|
-
|
|
42
40
|
return output
|
|
43
41
|
|
|
44
42
|
|
|
45
43
|
def activation_layer(activation: str, emb_size: int | None = None):
|
|
46
44
|
"""Create an activation layer based on the given activation name."""
|
|
47
|
-
|
|
48
45
|
activation = activation.lower()
|
|
49
|
-
|
|
50
46
|
if activation == "dice":
|
|
51
47
|
if emb_size is None:
|
|
52
|
-
raise ValueError("emb_size is required for Dice activation")
|
|
48
|
+
raise ValueError("[ActivationLayer Error]: emb_size is required for Dice activation")
|
|
53
49
|
return Dice(emb_size)
|
|
54
50
|
elif activation == "relu":
|
|
55
51
|
return nn.ReLU()
|
|
@@ -88,4 +84,4 @@ def activation_layer(activation: str, emb_size: int | None = None):
|
|
|
88
84
|
elif activation in ["none", "linear", "identity"]:
|
|
89
85
|
return nn.Identity()
|
|
90
86
|
else:
|
|
91
|
-
raise ValueError(f"Unsupported activation function: {activation}")
|
|
87
|
+
raise ValueError(f"[ActivationLayer Error]: Unsupported activation function: {activation}")
|
nextrec/basic/callback.py
CHANGED
nextrec/basic/features.py
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Feature definitions
|
|
3
3
|
|
|
4
4
|
Date: create on 27/10/2025
|
|
5
|
-
|
|
5
|
+
Checkpoint: edit on 29/11/2025
|
|
6
|
+
Author: Yang Zhou, zyaztec@gmail.com
|
|
6
7
|
"""
|
|
7
|
-
|
|
8
|
-
from typing import List, Sequence, Optional
|
|
8
|
+
import torch
|
|
9
9
|
from nextrec.utils.embedding import get_auto_embedding_dim
|
|
10
10
|
|
|
11
11
|
class BaseFeature(object):
|
|
@@ -34,7 +34,6 @@ class SequenceFeature(BaseFeature):
|
|
|
34
34
|
l2_reg: float = 1e-5,
|
|
35
35
|
trainable: bool = True,
|
|
36
36
|
):
|
|
37
|
-
|
|
38
37
|
self.name = name
|
|
39
38
|
self.vocab_size = vocab_size
|
|
40
39
|
self.max_len = max_len
|
|
@@ -60,8 +59,10 @@ class SparseFeature(BaseFeature):
|
|
|
60
59
|
init_params: dict|None = None,
|
|
61
60
|
l1_reg: float = 0.0,
|
|
62
61
|
l2_reg: float = 1e-5,
|
|
63
|
-
trainable: bool = True
|
|
64
|
-
|
|
62
|
+
trainable: bool = True,
|
|
63
|
+
pretrained_weight: torch.Tensor | None = None,
|
|
64
|
+
freeze_pretrained: bool = False,
|
|
65
|
+
):
|
|
65
66
|
self.name = name
|
|
66
67
|
self.vocab_size = vocab_size
|
|
67
68
|
self.embedding_name = embedding_name or name
|
|
@@ -73,32 +74,40 @@ class SparseFeature(BaseFeature):
|
|
|
73
74
|
self.l1_reg = l1_reg
|
|
74
75
|
self.l2_reg = l2_reg
|
|
75
76
|
self.trainable = trainable
|
|
77
|
+
self.pretrained_weight = pretrained_weight
|
|
78
|
+
self.freeze_pretrained = freeze_pretrained
|
|
76
79
|
|
|
77
80
|
class DenseFeature(BaseFeature):
|
|
78
|
-
def __init__(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
def __init__(
|
|
82
|
+
self,
|
|
83
|
+
name: str,
|
|
84
|
+
embedding_dim: int | None = 1,
|
|
85
|
+
input_dim: int = 1,
|
|
86
|
+
use_embedding: bool = False,
|
|
87
|
+
):
|
|
82
88
|
self.name = name
|
|
83
|
-
self.
|
|
84
|
-
|
|
89
|
+
self.input_dim = max(int(input_dim or 1), 1)
|
|
90
|
+
self.embedding_dim = embedding_dim or self.input_dim
|
|
91
|
+
if embedding_dim is not None and embedding_dim > 1:
|
|
92
|
+
self.use_embedding = True
|
|
93
|
+
else:
|
|
94
|
+
self.use_embedding = use_embedding # user decides for dim <= 1
|
|
85
95
|
|
|
86
96
|
class FeatureSpecMixin:
|
|
87
97
|
"""
|
|
88
98
|
Mixin that normalizes dense/sparse/sequence feature lists and target/id columns.
|
|
89
99
|
"""
|
|
90
|
-
|
|
91
100
|
def _set_feature_config(
|
|
92
101
|
self,
|
|
93
|
-
dense_features:
|
|
94
|
-
sparse_features:
|
|
95
|
-
sequence_features:
|
|
96
|
-
target: str |
|
|
97
|
-
id_columns: str |
|
|
102
|
+
dense_features: list[DenseFeature] | None = None,
|
|
103
|
+
sparse_features: list[SparseFeature] | None = None,
|
|
104
|
+
sequence_features: list[SequenceFeature] | None = None,
|
|
105
|
+
target: str | list[str] | None = None,
|
|
106
|
+
id_columns: str | list[str] | None = None,
|
|
98
107
|
) -> None:
|
|
99
|
-
self.dense_features
|
|
100
|
-
self.sparse_features
|
|
101
|
-
self.sequence_features
|
|
108
|
+
self.dense_features = list(dense_features) if dense_features else []
|
|
109
|
+
self.sparse_features = list(sparse_features) if sparse_features else []
|
|
110
|
+
self.sequence_features = list(sequence_features) if sequence_features else []
|
|
102
111
|
|
|
103
112
|
self.all_features = self.dense_features + self.sparse_features + self.sequence_features
|
|
104
113
|
self.feature_names = [feat.name for feat in self.all_features]
|
|
@@ -107,17 +116,16 @@ class FeatureSpecMixin:
|
|
|
107
116
|
|
|
108
117
|
def _set_target_id_config(
|
|
109
118
|
self,
|
|
110
|
-
target: str |
|
|
111
|
-
id_columns: str |
|
|
119
|
+
target: str | list[str] | None = None,
|
|
120
|
+
id_columns: str | list[str] | None = None,
|
|
112
121
|
) -> None:
|
|
113
122
|
self.target_columns = self._normalize_to_list(target)
|
|
114
123
|
self.id_columns = self._normalize_to_list(id_columns)
|
|
115
124
|
|
|
116
125
|
@staticmethod
|
|
117
|
-
def _normalize_to_list(value: str |
|
|
126
|
+
def _normalize_to_list(value: str | list[str] | None) -> list[str]:
|
|
118
127
|
if value is None:
|
|
119
128
|
return []
|
|
120
129
|
if isinstance(value, str):
|
|
121
130
|
return [value]
|
|
122
131
|
return list(value)
|
|
123
|
-
|