How to install NLTK for Python on Windows 64 bit
In this post, you will learn how to install Python NLTK on Windows 64-bit.
Natural Language Processing is a branch of artificial intelligence. It interacts between a computer and natural-language or helps the computer to understand and manipulate any natural language. It was developed by Steven Bird and Edward Loper. With the intensity of Machine learning, Natural Language Processing is getting well known and simpler to implement. It is fundamentally a technique to connect with people and perform activities on voice orders.
Natural Language Toolkit (NLTK) is a Python API for the analysis of text written in natural languages. It contains libraries for text processing, such as, tokenization, parsing, classification, stemming, tagging, punctuation, character count, and semantic reasoning. It has more than 50 corpora and lexical sources such as WordNet, Problem Report Corpus, Penn Treebank Corpus, etc.
NLTK is a platform for building Python programs to work with natural language data. NLTK is most widely used.
Install nltk
Here is the command to install the nltk package using the pip tool.
(env) c:\python37\Scripts\projects>pip install nltk
You can see the output as in the below screenshot.
Once you've installed NLTK, start up the Python interpreter as before, and install the data required by typing the following two commands at the Python prompt.
import nltk
nltk.download ()
The above command opens the NLTK downloader where you can choose what to download.
Test Installation of NLTK
Let's check the successful installation of the package with a small Python script. In the given script, we have imported the brown corpus. Corpus is a large set of texts that may be formed of a single language and multiple languages.
from nltk.corpus import brown
print(brown.words())
Execute NLTK Script
We are going to discuss how to execute the NLTK script on the local machine. First, create a Python file 'first_nltk.py' and open it in your code editor and paste the following code.
from nltk.tokenize import sent_tokenize, word_tokenize
text = "Hello John, how are you working? The last deal was great, and the team worked well. We will conduct meeting soon. Enjoy your day."
print(sent_tokenize(text))
The above code tokenizes sentences using sent_tokenize() method. When we execute the above code, it returns the following.
['Hello John, how are you working?', 'The last deal was great, and the team worked well.', 'We will conduct meeting soon.', 'Enjoy your day.']
Similarly, we can tokenize the word using word_tokenize() method-
from nltk.tokenize import sent_tokenize, word_tokenize
text = "Hello John, how are you working? The last deal was great, and the team worked well. We will conduct meeting soon. Enjoy your day."
print(word_tokenize(text))
This shows the output as-
['Hello', 'John', ',', 'how', 'are', 'you', 'working', '?', 'The', 'last', 'deal', 'was', 'great', ',', 'and', 'the', 'team', 'worked', 'well', '.', 'We', 'will', 'conduct', 'meeting', 'soon', '.', 'Enjoy', 'your', 'day', '.']
Related Articles
Find the stop words in nltk PythonRemove stop words in Python
Python Weather API Script
Lemmatization nltk
Python Spell Checker Program
Python SimpleHTTPServer
Python send mail to multiple recipients using SMTP server
How to generate QR Code in Python using PyQRCode
Python programs to check Palindrome strings and numbers
CRUD operations in Python using MYSQL Connector
Fibonacci Series Program in Python
Python File Handler - Create, Read, Write, Access, Lock File
Python convert XML to JSON
Python convert xml to dict
Python convert dict to xml
Python program to multiply two numbers
Multiply all elements in list Python
Python program to input week number and print week day
Python program to map two lists into a dictionary
Python program to check leap year