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

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.

主站蜘蛛池模板: 同仁县| 遂川县| 永清县| 赤城县| 巴楚县| 商河县| 靖边县| 伊川县| 申扎县| 顺昌县| 定边县| 沧州市| 信阳市| 石渠县| 河津市| 寿阳县| 阳原县| 盖州市| 滕州市| 新乡市| 景洪市| 旬邑县| 延庆县| 鹤壁市| 台州市| 泗洪县| 龙岩市| 正蓝旗| 托里县| 临潭县| 大竹县| 紫金县| 马鞍山市| 宣城市| 深泽县| 兴海县| 桃江县| 铜山县| 望江县| 隆德县| 定日县|