How to install NLTK for Python on Windows 64 bit
Natural Language Processing is a branch of artificial intelligence. It interacts between computer and natural language or helps the computer to understand and manipulate any natural language. 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.
NLTK is a platform for building Python programs to work with natural language data. NLTK is most widely used.
Here is the command to install the nltk package using 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.
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 opens 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 tokenizing 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 ArticlesPython 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