nextrec 0.3.5__py3-none-any.whl → 0.4.1__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.
Files changed (45) hide show
  1. nextrec/__init__.py +0 -30
  2. nextrec/__version__.py +1 -1
  3. nextrec/basic/layers.py +32 -15
  4. nextrec/basic/loggers.py +1 -1
  5. nextrec/basic/model.py +440 -189
  6. nextrec/basic/session.py +4 -2
  7. nextrec/data/__init__.py +0 -25
  8. nextrec/data/data_processing.py +31 -19
  9. nextrec/data/dataloader.py +51 -16
  10. nextrec/models/generative/__init__.py +0 -5
  11. nextrec/models/generative/hstu.py +3 -2
  12. nextrec/models/match/__init__.py +0 -13
  13. nextrec/models/match/dssm.py +0 -1
  14. nextrec/models/match/dssm_v2.py +0 -1
  15. nextrec/models/match/mind.py +0 -1
  16. nextrec/models/match/sdm.py +0 -1
  17. nextrec/models/match/youtube_dnn.py +0 -1
  18. nextrec/models/multi_task/__init__.py +0 -0
  19. nextrec/models/multi_task/esmm.py +5 -7
  20. nextrec/models/multi_task/mmoe.py +10 -6
  21. nextrec/models/multi_task/ple.py +10 -6
  22. nextrec/models/multi_task/poso.py +9 -6
  23. nextrec/models/multi_task/share_bottom.py +10 -7
  24. nextrec/models/ranking/__init__.py +0 -27
  25. nextrec/models/ranking/afm.py +113 -21
  26. nextrec/models/ranking/autoint.py +15 -9
  27. nextrec/models/ranking/dcn.py +8 -11
  28. nextrec/models/ranking/deepfm.py +5 -5
  29. nextrec/models/ranking/dien.py +4 -4
  30. nextrec/models/ranking/din.py +4 -4
  31. nextrec/models/ranking/fibinet.py +4 -4
  32. nextrec/models/ranking/fm.py +4 -4
  33. nextrec/models/ranking/masknet.py +4 -5
  34. nextrec/models/ranking/pnn.py +4 -4
  35. nextrec/models/ranking/widedeep.py +4 -4
  36. nextrec/models/ranking/xdeepfm.py +4 -4
  37. nextrec/utils/__init__.py +7 -3
  38. nextrec/utils/device.py +32 -1
  39. nextrec/utils/distributed.py +114 -0
  40. nextrec/utils/synthetic_data.py +413 -0
  41. {nextrec-0.3.5.dist-info → nextrec-0.4.1.dist-info}/METADATA +15 -5
  42. nextrec-0.4.1.dist-info/RECORD +66 -0
  43. nextrec-0.3.5.dist-info/RECORD +0 -63
  44. {nextrec-0.3.5.dist-info → nextrec-0.4.1.dist-info}/WHEEL +0 -0
  45. {nextrec-0.3.5.dist-info → nextrec-0.4.1.dist-info}/licenses/LICENSE +0 -0
nextrec/__init__.py CHANGED
@@ -1,33 +1,3 @@
1
- """
2
- NextRec - A Unified Deep Learning Framework for Recommender Systems
3
- ===================================================================
4
-
5
- NextRec provides a comprehensive suite of recommendation models including:
6
- - Ranking models (CTR prediction)
7
- - Matching models (retrieval)
8
- - Multi-task learning models
9
- - Generative recommendation models
10
-
11
- Quick Start
12
- -----------
13
- >>> from nextrec.basic.features import DenseFeature, SparseFeature
14
- >>> from nextrec.models.ranking.deepfm import DeepFM
15
- >>>
16
- >>> # Define features
17
- >>> dense_features = [DenseFeature('age')]
18
- >>> sparse_features = [SparseFeature('category', vocab_size=100, embedding_dim=16)]
19
- >>>
20
- >>> # Build model
21
- >>> model = DeepFM(
22
- ... dense_features=dense_features,
23
- ... sparse_features=sparse_features,
24
- ... targets=['label']
25
- ... )
26
- >>>
27
- >>> # Train model
28
- >>> model.fit(train_data=df_train, valid_data=df_valid)
29
- """
30
-
31
1
  from nextrec.__version__ import __version__
32
2
 
33
3
  __all__ = [
nextrec/__version__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.3.5"
1
+ __version__ = "0.4.1"
nextrec/basic/layers.py CHANGED
@@ -80,9 +80,7 @@ class PredictionLayer(nn.Module):
80
80
  else:
81
81
  raise ValueError(f"[PredictionLayer Error]: Unsupported task_type '{task_type}'.")
82
82
  outputs.append(activation(task_logits))
83
- result = torch.cat(outputs, dim=-1)
84
- if result.shape[-1] == 1:
85
- result = result.squeeze(-1)
83
+ result = torch.cat(outputs, dim=-1) # single: (N,1), multi-task/multi-class: (N,total_dim)
86
84
  return result
87
85
 
88
86
  class EmbeddingLayer(nn.Module):
@@ -235,14 +233,28 @@ class InputMask(nn.Module):
235
233
  super().__init__()
236
234
 
237
235
  def forward(self, x: dict[str, torch.Tensor], feature: SequenceFeature, seq_tensor: torch.Tensor | None = None):
238
- values = seq_tensor if seq_tensor is not None else x[feature.name]
239
- if feature.padding_idx is not None:
240
- mask = (values.long() != feature.padding_idx)
236
+ if seq_tensor is not None:
237
+ values = seq_tensor
241
238
  else:
242
- mask = (values.long() != 0)
239
+ values = x[feature.name]
240
+ values = values.long()
241
+ padding_idx = feature.padding_idx if feature.padding_idx is not None else 0
242
+ mask = (values != padding_idx)
243
+
243
244
  if mask.dim() == 1:
244
- mask = mask.unsqueeze(-1)
245
- return mask.unsqueeze(1).float()
245
+ # [B] -> [B, 1, 1]
246
+ mask = mask.unsqueeze(1).unsqueeze(2)
247
+ elif mask.dim() == 2:
248
+ # [B, L] -> [B, 1, L]
249
+ mask = mask.unsqueeze(1)
250
+ elif mask.dim() == 3:
251
+ # [B, 1, L]
252
+ # [B, L, 1] -> [B, L] -> [B, 1, L]
253
+ if mask.size(1) != 1 and mask.size(2) == 1:
254
+ mask = mask.squeeze(-1).unsqueeze(1)
255
+ else:
256
+ raise ValueError(f"InputMask only supports 1D/2D/3D tensors, got shape {values.shape}")
257
+ return mask.float()
246
258
 
247
259
  class LR(nn.Module):
248
260
  def __init__(
@@ -299,20 +311,25 @@ class MLP(nn.Module):
299
311
  super().__init__()
300
312
  if dims is None:
301
313
  dims = []
302
- layers = list()
314
+ layers = []
315
+ current_dim = input_dim
316
+
303
317
  for i_dim in dims:
304
- layers.append(nn.Linear(input_dim, i_dim))
318
+ layers.append(nn.Linear(current_dim, i_dim))
305
319
  layers.append(nn.BatchNorm1d(i_dim))
306
320
  layers.append(activation_layer(activation))
307
321
  layers.append(nn.Dropout(p=dropout))
308
- input_dim = i_dim
322
+ current_dim = i_dim
323
+
309
324
  if output_layer:
310
- layers.append(nn.Linear(input_dim, 1))
325
+ layers.append(nn.Linear(current_dim, 1))
326
+ self.output_dim = 1
327
+ else:
328
+ self.output_dim = current_dim
311
329
  self.mlp = nn.Sequential(*layers)
312
-
313
330
  def forward(self, x):
314
331
  return self.mlp(x)
315
-
332
+
316
333
  class FM(nn.Module):
317
334
  def __init__(self, reduce_sum: bool = True):
318
335
  super().__init__()
nextrec/basic/loggers.py CHANGED
@@ -99,7 +99,7 @@ def setup_logger(session_id: str | os.PathLike | None = None):
99
99
  session = create_session(str(session_id) if session_id is not None else None)
100
100
  log_dir = session.logs_dir
101
101
  log_dir.mkdir(parents=True, exist_ok=True)
102
- log_file = log_dir / f"{session.experiment_id}.log"
102
+ log_file = log_dir / f"{session.log_basename}.log"
103
103
 
104
104
  console_format = '%(message)s'
105
105
  file_format = '%(asctime)s - %(levelname)s - %(message)s'