N_gram_seqs() unit test failed

I am doing the assignment “Week 4: Predicting the next word”. And I am having a problem with the n_gram_seqs() function. The output of the function seems to be as described, even the output when applying the function to the dataset also gives the correct result as shown in the image.


But when running the unit test, I get an error as follows:

I am wondering that according to the input parameter description, corpus is described as a list of strings but the unit test function is using a tensor as input.

I also checked the unit test case and found that the remaining parameter is a TextVectorization but in the unit test case, a tockenizer is used.

Another problem is that my neural network can train normally but seems to be overfit. And the prediction result is also very bad?

Thanks so much for any advise!!!

Are you splitting before transforming text to sequences?

The error is also stating you are suppose to use adapt attribute which you seem to be not using

if you notice one of the arguments also mentions vectorizer is textvectorization class adapted in the corpus

regards
DP

oh, my mistake. You right, no need to adapt the corpus. But after I remove adapt statement, the result very weird. All units test is passed, all results as same as expected but the training result is very poor. The train acc is only 6%.

I already restart kernel to run from the beginning, but the result still poor. It’s funny that the bugged code can train up to 92%, while the correct code can only 6%.

Did you consider increasing the number of units in lstm layer? for training accuracy to improve!!!

Yep, I tried but it didn’t help. I don’t thinks the reason is network architecture because the same network I can get 91% acc with old way.

send screenshots of codes by personal DM for the grade cell throwing error