Doubt about Controllable Generation Assignment

For the assignment I have followed the instruction given however I still cannot get the correct output for the Entanglement and Regularization part.

Written in Pseudocode this is what my current implementation has:

other_distances = norm of tensor of original_classifications[other_indices] - current_classifications[other_indices]`

other_class_penalty = negate mean of other_distances * penalty_weight

target_score =  mean of current_classifications[target_indices]

Is there any step that I am missing?
Many thanks


Hi Pablo,
A couple things to look at, based on your pseudocode:

  1. Have you done step 1, mentioned in the comments:
    # Steps: 1) Calculate the change between the original and current classifications (as a tensor)
    #           by indexing into the other_indices you're trying to preserve, like in x[:, features].

  1. Click on the “Optional Hints for get_score” and make sure you’re following all the suggestions. In particular, make sure you are passing a dim argument to torch.norm

Once you have code you think is right, you can also use the unit tests to help you narrow down the problem. You may want to add some print statements temporarily to help you. For example, if a test is failing, you can print the value you’re calculating vs the expected value to help give you some idea about why your value isn’t the same as expected.

  1. Emphasis on taking the mean of ( difference between current and original classifications), ie be careful the order of operations and what is subtracted from what.

After analysing the outputs and running unit tests. I Still cannot figure it out.
This is the error I am getting

Nevermind found the error.
Basically I forgot to put dim = 1 in torch.norm, since I was just calling torch.norm(other_distances, 1) therefore I was calling the p argument not the dim argument of torch.norm
Many thanks for all the help