Question: Complete the cell below to fill out the word_counts dictionary variable. word_counts keeps track of how many times a word type appears across the corpus.

Complete the cell below to fill out the word_counts dictionary variable. word_counts keeps track of how many times a word type appears across the corpus. For instance, word_counts["movie"] should store the number 61492 -- the count of how many times the word movie appears in the corpus.

import glob

import codecs

word_counts = Counter() # Counters are often useful for NLP in python

for label in [POS_LABEL, NEG_LABEL]:

for directory in [TRAIN_DIR, TEST_DIR]:

for fn in glob.glob(directory + "/" + label + "/*txt"):

doc = codecs.open(fn, 'r', 'utf8') # Open the file with UTF-8 encoding

###### IMPLEMENT ######

pass

if word_counts["movie"] == 61492:

print ("yay! there are {} total instances of the word type movie in the corpus".format(word_counts["movie"]))

else:

print ("hmm. Something seems off. Double check your code")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!