C2_W3_Assignment_UNQ_C8 GRADED FUNCTION

Good afternoon
I can’t understand the reason and the result of the code in task No. 8, week 3 does not correspond to what was specified.
The result of the test run is 3 pass and 3 not pass. Please tell me, if anyone has encountered this, what is the reason?

Hello @Mikhail2

Kindly share the output images where you passed 3 test and failed 3 test.

Also make sure not to post any codes from the grader cell.

You could also explain briefly you implementation part of your code if possible.

Regards
DP

Hi, Deepti_Prasad!

  1. “Kindly share the output images where you passed 3 test and failed 3 test.”
  2. “You could also explain briefly you implementation part of your code if possible.”
    Initialization: n_grams is initialized as an empty dictionary to store the n-grams and their counts.
    Looping through Sentences: The code iterates through each sentence in the provided data.
    Padding Tokens: Each sentence is padded with start tokens (represented by start_token) n-1 times at the beginning and one end token (represented by end_token) at the end. This is done to properly create n-grams without boundary issues.
    Looping through Tokens: Within each sentence, a loop iterates through the tokens, forming n-grams.
    Creating n-grams: For each position i in the sentence, an n-gram of size n is extracted, starting from position i.
    Checking Existence: The code checks if the extracted n-gram already exists in the n_grams dictionary.
    Updating Counts: If the n-gram is already in the dictionary, its count is incremented by 1. If not, a new entry for this n-gram is added to the dictionary with an initial count of 1.
    Returning n-grams: After processing all sentences, the dictionary n_grams containing the n-grams and their counts is returned.

Thanks, Mikhail