Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Python 3 code please. We begin with a feature extraction function. The features we are going to use are called trigrams. A trigram is simply
Python 3 code please.
We begin with a feature extraction function. The features we are going to use are called trigrams. A trigram is simply a string of three contiguous characters. For example in the string"I love computing", there are lots of trigrams (L-2 to be precise, where L is the length of the string): ["I l"," lo","Lov","ove"] are the first four of them, in sequence. Write a function count trigrams (document) that takes a string and returns a default dictionary with the frequency counts of the trigrams within the string (noting that if you have N repeats of the same trigram in the string, the frequency will be N). Note that the output must be a default dictionary and not a standard dictionary, as it will be useful later. Note also that you should not modify the string in any way (e.g. remove punctuation, remove whitespace or convert to lower case) in calculating the frequencies. Your code should behave as follows: >>> count tr1grams ("hel") defaultdict (
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started