nextrec 0.3.6__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 (37) hide show
  1. nextrec/__version__.py +1 -1
  2. nextrec/basic/layers.py +32 -15
  3. nextrec/basic/model.py +435 -187
  4. nextrec/data/data_processing.py +31 -19
  5. nextrec/data/dataloader.py +40 -10
  6. nextrec/models/generative/hstu.py +3 -2
  7. nextrec/models/match/dssm.py +0 -1
  8. nextrec/models/match/dssm_v2.py +0 -1
  9. nextrec/models/match/mind.py +0 -1
  10. nextrec/models/match/sdm.py +0 -1
  11. nextrec/models/match/youtube_dnn.py +0 -1
  12. nextrec/models/multi_task/esmm.py +5 -7
  13. nextrec/models/multi_task/mmoe.py +10 -6
  14. nextrec/models/multi_task/ple.py +10 -6
  15. nextrec/models/multi_task/poso.py +9 -6
  16. nextrec/models/multi_task/share_bottom.py +10 -7
  17. nextrec/models/ranking/afm.py +113 -21
  18. nextrec/models/ranking/autoint.py +15 -9
  19. nextrec/models/ranking/dcn.py +8 -11
  20. nextrec/models/ranking/deepfm.py +5 -5
  21. nextrec/models/ranking/dien.py +4 -4
  22. nextrec/models/ranking/din.py +4 -4
  23. nextrec/models/ranking/fibinet.py +4 -4
  24. nextrec/models/ranking/fm.py +4 -4
  25. nextrec/models/ranking/masknet.py +4 -5
  26. nextrec/models/ranking/pnn.py +4 -4
  27. nextrec/models/ranking/widedeep.py +4 -4
  28. nextrec/models/ranking/xdeepfm.py +4 -4
  29. nextrec/utils/__init__.py +7 -3
  30. nextrec/utils/device.py +30 -0
  31. nextrec/utils/distributed.py +114 -0
  32. nextrec/utils/synthetic_data.py +413 -0
  33. {nextrec-0.3.6.dist-info → nextrec-0.4.1.dist-info}/METADATA +15 -5
  34. nextrec-0.4.1.dist-info/RECORD +66 -0
  35. nextrec-0.3.6.dist-info/RECORD +0 -64
  36. {nextrec-0.3.6.dist-info → nextrec-0.4.1.dist-info}/WHEEL +0 -0
  37. {nextrec-0.3.6.dist-info → nextrec-0.4.1.dist-info}/licenses/LICENSE +0 -0
nextrec/__version__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.3.6"
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__()