C3W1_Assignment( Line to Tensor)

Exercise 1 - Line to Tensor
Error in the Unit test
My Result and output is same as the expected , but getting the error in the unit test
AssertionError: Wrong length. Expected: 3 but got 1

My output

1 Like

There are multiple tests. Your code passes the simple test that is in the notebook, but it doesn’t pass the more challenging test that is in the w1_unittest.py file in the “test_line_to_tensor()” function.

You can use the File menu to open that .py file and read what the test is doing.

Typical errors include hard-coding values instead of using variables, and using global variables instead of local function parameters.

1 Like

Here is my code can you please point where I’m making the mistake

{mentor edit: code removed}

1 Like
  1. Sorry, no I can’t, I’m not a mentor for that course. I don’t have access to the notebook or the instructions or the lectures.

  2. The Code of Conduct does not allow students to share their code on the forum. Sharing the error messages is fine - sharing your code isn’t.

1 Like

I see there is a code comment said you should use something called “StringLookup”. Is that what you used? Is there a function by that name in the notebook?

I’m just guessing, as I said I am not familiar with the details of this course.

1 Like

Yes, they literally wrote out the solution for you in the previous code cell using the TF StringLookup function. If you look at the test function, it turns out that it runs a number of tests. Your code fails on the second test, because it does not correctly handle the case in which you have an unknown character in the input that is not in the vocabulary. Your code returns nothing in that case, but the StringLookup returns the [UNK] value (inserted as index 0 in vocab) for the unknown characters.

They covered the insertion of the [UNK] and padding tokens in an earlier cell. They don’t really explain this in any more detail, but apparently the StringLookup function assumes that index 0 of the vocabulary is [UNK] and index 1 is the padding token. As far as I can tell, the test cases don’t use the padding token, so I’m not exactly sure how that would appear.

Note that I’m also not a mentor for this course, but just tried that assignment from scratch and line_to_tensor is the first graded function and was able to see how the test case handled it.

1 Like