C3_W1 Deep N-grams: module 'w1_unittest' has no attribute 'test_test_model'

Hi everyone,

I’m having this error in exercise 5 - log_perplexity when trying to run the unit tests:

#UNIT TESTS
w1_unittest.test_test_model(log_perplexity)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[93], line 2
      1 #UNIT TESTS
----> 2 w1_unittest.test_test_model(log_perplexity)

AttributeError: module 'w1_unittest' has no attribute 'test_test_model'

I’ve reloaded the notebook a couple of times to verify that I had imported the unit test module and every other test is working except this one.

Anyone else is getting the same issue?

Ok… I think that there’s a typo here. The module w1_unittest doesn’t have any functions called test_test_model, but it has one called test_log_perplexity

I believe that cell should be written as:

#UNIT TESTS
w1_unittest.test_log_perplexity(log_perplexity)

Hi @Miguel_Alonso

This does seem to be correct as here test_model means the test cases related to log_preplexity in related to w1_unittest.

You attribution error could be basically if your targets and preds related to log_perplexity where recalled correctly or not mixed up. This could also indicate to check the compile_model grade cell once just as a precaution.

Let me know if your issue persists, then you can send a screenshot of the grade cell in question via personal DM

Regards
DP

Hi @Deepti_Prasad

Ehmm… I don’t think that’s the issue…

The compile_model cell works fine and my code is getting a 96% in the grader (everything 10/10 except for the issue described in this other issue in the forums.

The error message is saying that the function test_test_model doesn’t exist in w1_unittest and that can be confirmed by inspecting the w1_unittest module:

from inspect import getmembers, isfunction
print(getmembers(w1_unittest, isfunction))

This will print:

[
    ('Input', <function Input at 0x7fb97cbd0b80>),
    ('comparator', <function comparator at 0x7fb97a4a6700>),
    ('summary', <function summary at 0x7fb97a4a6790>),
    ('test_GRULM', <function test_GRULM at 0x7fb97a4a68b0>),
    ('test_GenerativeModel', <function test_GenerativeModel at 0x7fb97a4a6a60>),
    ('test_compile_model', <function test_compile_model at 0x7fb97a4a6940>),
    ('test_create_batch_dataset', <function test_create_batch_dataset at 0x7fb97a4a6820>),
    ('test_line_to_tensor', <function test_line_to_tensor at 0x7fbafef7e820>),
    ('test_log_perplexity', <function test_log_perplexity at 0x7fb97a4a69d0>)
]

As you can see, there is no test_test_model function but there is a test_log_perplexity function that, when run:

w1_unittest.test_log_perplexity(log_perplexity)

Returns:

All test passed!

hi @Miguel_Alonso

please send a screenshot of the grade cell log perplexity via personal DM.

my File also contains the same unittest mentioned as yours but has passed and when I checked unittest py file even there it is mentioned as you are mentioning, yet I didn’t encounter attribute error with unittrst.test_test_model(log_perplexity)

let me once check your codes once

Also you just mentioned passing the assignment? does this mean, by any chance you run down the test cell without running the previous cells from beginning??

you can check once by restarting the kernel and re-running each cell one by one from beginning to the cell you encountered the issue, does the issue still persist, then let me know.

Regards
DP

Also you just mentioned passing the assignment? does this mean, by any chance you run down the test cell without running the previous cells from beginning??

No, I ran every single cell. The unit tests are in an ungraded cell so they don’t affect the rest of the processing and the grader doesn’t need them at all.

you can check once by restarting the kernel and re-running each cell one by one from beginning to the cell you encountered the issue, does the issue still persist

It is still there. I’ve just done that, just to triple-check.
Selected “Restart the kernel and re-run the whole notebook”. The process ran up until that point and then stopped with the error.

I’ve also resubmitted it to the grader without changes. Still 96%, the other 4% is because of the issue that I linked before. Took screenshots of everything and sent them to you.

Hi @Miguel_Alonso

The reason you are failing that test is because you have added an extra code line at the beginning for squeeze extra dimension. That part of the codes does not exist in my assignment.

It is very important to only write codes where the instructions are already mentioned and not hard code the path

Remove the if condition you mention between prediction batch actual batch and the tf.squeeze assigned to preds. I suppose that code will be used in other assignment of the same course you are doing.

Regards
DP

Please, read my messages (and comments in the code).

That line in the code is to fix an issue with one of the test cases in the grader, you can find more about it in the forums here:

That “code” does nothing in most cases and has nothing to do with this issue.

I have also encountered the same issue. Did not change the code. So it’s the module’s problem.

hi @Miguel_Alonso

i checked the thread @arvyzukai explained to the other learners and as you see explained by him the implementation part has an effect on unittest cell.

also as per my understanding adding extra dimension should not affect the values, but here the issue is more based on the autograder side.

I am tagging L.T of the course to have look on your thread as well as the other one as @arvyzukai has mentioned he has reported this on repo.

@lucas.coutinho can you look into this assignment exercise 10 for learner encountering attribute error on adding extra dimension( which I believe was not part of the updated assignment), and the tagged comment by the learner also seems to be during the time assignment was updated.

P.s. I didn’t encounter this issue, I suspect this issue could be related to other grade cell even though learner has passed other grade cell.

@Miguel_Alonso you can DM your assignment for review once, if you want.

Regards
DP

Hi all!

We are sorry about this issue. I updated this assignment some days ago and left this line unchanged. It is fixed now, you may refresh your workspace to see the new version.

Thanks @Deepti_Prasad for tagging me.

Thank you very much, @lucas.coutinho!