From the course: Natural Language Processing for Speech and Text: From Beginner to Advanced

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

N-grams representation using NLTK

N-grams representation using NLTK

- [Instructor] In the previous video, we discussed n-grams. Let's practice how to create them in Python using the NLTK library. First, go to colab.research.google.com or any Python ID you prefer. The first thing we are going to do is to import NLTK and from NLTK.util import the n-grams. Let's still use our formal sentence, natural language processing for speech and text data. The first thing we need to do to apply n-grams is to tokenize our sentences. So we have an error message. And I would like you to pay attention to reading error messages. For example, this error message is saying that it's trying to look up something called Punkt and is not found here, and this is the way to download it. So let's follow this instruction by downloading Punkt. When we run the code now, you can see that it works. So we have input the n-grams from NLTK.util. Let's apply it to our words. Because we like our output as a list, let's put it in the list function. First we will like unigrams, so you can…

Contents