Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Error when using class_weight with DLRMModel #1221

Open
PaulSteffen-betclic opened this issue Oct 23, 2023 · 1 comment
Open

[BUG] Error when using class_weight with DLRMModel #1221

PaulSteffen-betclic opened this issue Oct 23, 2023 · 1 comment
Labels
bug Something isn't working status/needs-triage

Comments

@PaulSteffen-betclic
Copy link

Bug description

When I try to use the class_weight arg in .fit() method of DLRMModel, I got the following error:

image

Can someone know why please ?
As shown in the following link, it seems to work with earlier versions:
https://github.com/NVIDIA-Merlin/publications/blob/2761dade6d725615f0dd2c9491c54f8b397912e0/tutorials/RecSys22tutorial/04-Building-multi-stage-RecSys.ipynb#L731

Thanks

Steps/Code to reproduce bug

import nvtabular as nvt
import tensorflow as tf
import merlin.models.tf as mm

from merlin.models.tf.transforms.negative_sampling import InBatchNegatives
from merlin.dataloader.tensorflow import Loader

processed_train = nvt.Dataset(f"{output_path}/train/*.parquet")
schema = processed_train.schema
target_column = schema.select_by_tag(Tags.TARGET).column_names[0]

batch_size, n_per_positive = 2048, 64
add_negatives = InBatchNegatives(schema, n_per_positive, seed=42, prep_features=True, run_when_testing=True)

train_loader = Loader(processed_train, batch_size=batch_size).map(add_negatives)
valid_loader = Loader(processed_valid, batch_size=batch_size).map(add_negatives)

ranking_model = mm.DLRMModel(
    schema,
    embedding_dim=16,
    bottom_block=mm.MLPBlock([32, 16]),
    top_block=mm.MLPBlock([32, 16, 8]),
    prediction_tasks=mm.BinaryClassificationTask(target_column),
)

ranking_model.compile(optimizer='adam', run_eagerly=False, metrics=[], 
              weighted_metrics=[tf.keras.metrics.BinaryAccuracy(),tf.keras.metrics.AUC()]
             )
ranking_model.fit(train_loader, class_weight = {0: 1, 1: n_per_positive}, epochs=2, train_metrics_steps=100) #error when using class_weight

Expected behavior

Success to use class_weight (required with the negative sampling step).

Environment details

  • Merlin version: 23.8.0
  • Platform: macOs
  • Python version: 3.11.6
  • Tensorflow version (GPU?): 2.12.1 (CPU for dev)
@PaulSteffen-betclic PaulSteffen-betclic added bug Something isn't working status/needs-triage labels Oct 23, 2023
@rnyak
Copy link
Contributor

rnyak commented Nov 2, 2023

@PaulSteffen-betclic can you share your train.schema file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working status/needs-triage
Projects
None yet
Development

No branches or pull requests

2 participants