官术网_书友最值得收藏!

Corpus

As of 2018, NLTK comes with over 100 collections of large and well-structured text datasets, which are called corpora in NLP. Corpora can be used as dictionaries for checking word occurrences and as training pools for model learning and validating. Some useful and interesting corpora include Web Text corpus, Twitter samples, Shakespeare corpus sample, Sentiment Polarity, Names corpus (it contains lists of popular names, which we will be exploring very shortly), WordNet, and the Reuters benchmark corpus. The full list can be found at http://www.nltk.org/nltk_data. Before using any of these corpus resources, we need to first download them by running the following codes in the Python interpreter:

>>> import nltk
>>> nltk.download()

A new window will pop up and ask us which collections (the Collections tab in the following screenshot) or corpus (the Corpora tab in the following screenshot) to download, and where to keep the data:

Installing the whole popular package is the quick solution, since it contains all important corpora needed for your current study and future research. Installing a particular corpora, as shown in the following screenshot, is also fine:

Once the package or corpus you want to explore is installed, we can now take a look at the Names corpus (make sure the names corpus is installed).

First, import the corpus names:

>>> from nltk.corpus import names

We can check out the first 10 names in the list:

>>> print(names.words()[:10])
['Abagael', 'Abagail', 'Abbe', 'Abbey', 'Abbi', 'Abbie',
'Abby', 'Abigael', 'Abigail', 'Abigale']

There are, in total, 7944 names, as shown in the following output derived by executing the following command:

>>> print(len(names.words()))
7944

Other corpora are also fun to explore.

Besides the easy-to-use and abundant corpora pool, more importantly, NLTK is also good at many NLP and text analysis tasks including tokenization, PoS tagging, named entities recognition, word stemming, and lemmatization.

主站蜘蛛池模板: 遂平县| 大城县| 中宁县| 昌黎县| 德格县| 将乐县| 夏津县| 英超| 安徽省| 许昌市| 上饶市| 涿鹿县| 玉溪市| 大同县| 开平市| 新丰县| 横山县| 辰溪县| 历史| 潼南县| 手机| 会理县| 大竹县| 隆德县| 志丹县| 和平区| 景东| 凤庆县| 建宁县| 革吉县| 永城市| 陇川县| 宣恩县| 南岸区| 文登市| 汽车| 无棣县| 乌什县| 渭源县| 大化| 台州市|