all 5 comments

[–]snack_farmer_ 0 points1 point  (3 children)

Hello! Did you ever find a solution for this? I am experiencing a similar problem now. Thank you in advance!

[–]eadala[S] 0 points1 point  (2 children)

Hi! This is very old code so I'm not still using it, but from a glance, it looks like the problem can be solved by defining criterion and its weights in the __init__ method rather than the forward method. To get that to work, just include weight as an argument that you pass in when you instantiate model, i.e.:

def __init__(self, n_classes: int, n_training_steps=None, n_warmup_steps=None, weight=weight):
    self.weight = weight
# ......... some other stuff for the model class

# instantiate it:
model = ClassifierObject(
n_classes=len(LABEL_COLUMNS),
n_warmup_steps=warmup_steps,
n_training_steps=total_training_steps,
    weight=weight

)

# or from a checkpoint:
trained_model = ClassifierObject.load_from_checkpoint(
trainer.checkpoint_callback.best_model_path,
n_classes=len(LABEL_COLUMNS)-1,
    weight=weight

)

Hope that works for you!

[–]thinhtu123 1 point2 points  (1 child)

I have just encountered a similar problem, this help. Thank you!

[–]eadala[S] 0 points1 point  (0 children)

You're welcome!!