Nltk FreqDist Function with example
In this tutorial, you will learn about Nltk FreqDist function with example.
This function is used to find the frequency of words within a text. It returns a dictionary. We need to pass keys and values to get the data.
import nltk from nltk import FreqDist sentence='''The Natural Language Toolkit (NLTK) is an open source Python library for Natural Language Processing.''' tokens = nltk.word_tokenize(sentence) fdist=FreqDist(tokens) print(fdist.keys()) print(fdist.values())
Output:
dict_keys(['The', 'Natural', 'Language', 'Toolkit', '(', 'NLTK', ')', 'is', 'an', 'open', 'source', 'Python', 'library', 'for', 'Processing', '.']) dict_values([1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])