You will need Python 3 installed on your system. You can use any IDE to practice the code samples provided in the book, but since the code samples are provided as Jupyter notebooks, we recommend installing the Jupyter IDE. All code examples have been tested on the Windows OS. However, the programs are platform agnostic and should work with other 32/64-bit OSes as well. Other system requirements include RAM of 4 GB or higher, and at least 6 GB of free disk space.
We recommend installing the Python libraries discussed in this book using pip or conda. The code snippets in the book mention the relevant command to install a given library on the Windows OS. Please refer to the source page of the library for installation instructions for other OSes.
Software/hardware covered in the book |
OS requirements |
pandas |
Windows 7 or later, macOS, Linux |
NumPy |
Windows 7 or later, macOS, Linux |
Jupyter |
Windows 7 or later, macOS, Linux |
beautifulsoup4 |
Windows 7 or later, macOS, Linux |
scikit-learn |
Windows 7 or later, macOS, Linux |
Keras |
Windows 7 or later, macOS, Linux |
NLTK |
Windows 7 or later, macOS, Linux |
The last project covered in this book requires a higher-spec machine. However, you can run the program on the Google Colab GPU machine if needs be.
If you are using the digital version of this book, we advise you to type the code yourself or access the code via the GitHub repository (link available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.
Download the example code files
You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.
You can download the code files by following these steps:
- Log in or register at www.packt.com.
- Select the Support tab.
- Click on Code Downloads.
- Enter the name of the book in the Search box and follow the onscreen instructions.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
- WinRAR/7-Zip for Windows
- Zipeg/iZip/UnRarX for Mac
- 7-Zip/PeaZip for Linux
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Hands-On-Python-Natural-Language-Processing. In case there's an update to the code, it will be updated on the existing GitHub repository.
We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Download the color images
We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://static.packt-cdn.com/downloads/9781838989590_ColorImages.pdf.
Conventions used
There are a number of text conventions used throughout this book.
CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "We will be performing preprocessing on the Tips dataset, which comes with the seaborn Python package."
A block of code is set as follows:
import pandas as pd
data = pd.read_csv("amazon_cells_labelled.txt", sep='\t', header=None)
X = data.iloc[:,0] # extract column with review
y = data.iloc[:,-1] # extract column with sentiment
# tokenize the news text and convert data in matrix format
from sklearn.feature_extraction.text import CountVectorizer
vectorizer = CountVectorizer(stop_words='english')
X_vec = vectorizer.fit_transform(X)
X_vec = X_vec.todense() # convert sparse matrix into dense matrix
# Transform data by applying term frequency inverse document frequency (TFIDF)
from sklearn.feature_extraction.text import TfidfTransformer
tfidf = TfidfTransformer()
X_tfidf = tfidf.fit_transform(X_vec)
X_tfidf = X_tfidf.todense()
Any command-line input or output is written as follows:
pip install requests
pip install beautifulsoup4
Bold: Indicates a new term, an important word, or words that you see on screen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "This is called cross-validation and is an important part of ML model training. "