TypeError in Course 3 Week 2 Exercise 5

Hi @Riddhima_Sobti,

In your Ex 4, I believe you made a typo. It is eval_tasks and not eval_task (plural). And you need to pass eval_task as a list.

For your Ex 5, as cautioned to you regarding using solution code that is not your own here, this is your code for Ex 5:

def test_model(preds, target):
    """Function to test the model.

    Args:
        preds (jax.interpreters.xla.DeviceArray): Predictions of a list of batches of tensors corresponding to lines of text.
        target (jax.interpreters.xla.DeviceArray): Actual list of batches of tensors corresponding to lines of text.

    Returns:
        float: log_perplexity of the model.
    """
    ### START CODE HERE ###

    total_log_ppx = ### YOUR CODE # HINT: tl.one_hot() should replace one of the Nones

    non_pad = ### YOUR CODE          # You should check if the target equals 0
    ppx = ### YOUR CODE                       # Get rid of the padding

    log_ppx = ### YOUR CODE
    
    ### END CODE HERE ###
    
    return -log_ppx

And this is the skeleton code we have provided for this exercise:

def test_model(preds, target):
    """Function to test the model.

    Args:
        preds (jax.interpreters.xla.DeviceArray): Predictions of a list of batches of tensors corresponding to lines of text.
        target (jax.interpreters.xla.DeviceArray): Actual list of batches of tensors corresponding to lines of text.

    Returns:
        float: log_perplexity of the model.
    """
    ### START CODE HERE ###

    log_p = np.sum(None * None, axis= -1) # HINT: tl.one_hot() should replace one of the Nones

    non_pad = 1.0 - np.equal(None, None)          # You should check if the target equals 0
    log_p = None * None                             # Get rid of the padding    
    
    log_ppx = np.sum(None, None) / np.sum(None, None) # Remember to set the axis properly when summing up
    log_ppx = np.mean(None) # Compute the mean of the previous expression
    
    
    ### END CODE HERE ###
    
    return -log_ppx

Do you see the difference ?

I’d suggest to get a fresh copy of the notebook by following the instructions and try again, and this time, pay close attention to all of the exercise instructions and hints provided in the notebook.

Best,
Mubsi