Book Image

Machine Learning Techniques for Text

By : Nikos Tsourakis
5 (1)
Book Image

Machine Learning Techniques for Text

5 (1)
By: Nikos Tsourakis

Overview of this book

With the ever-increasing demand for machine learning and programming professionals, it's prime time to invest in the field. This book will help you in this endeavor, focusing specifically on text data and human language by steering a middle path among the various textbooks that present complicated theoretical concepts or focus disproportionately on Python code. A good metaphor this work builds upon is the relationship between an experienced craftsperson and their trainee. Based on the current problem, the former picks a tool from the toolbox, explains its utility, and puts it into action. This approach will help you to identify at least one practical use for each method or technique presented. The content unfolds in ten chapters, each discussing one specific case study. For this reason, the book is solution-oriented. It's accompanied by Python code in the form of Jupyter notebooks to help you obtain hands-on experience. A recurring pattern in the chapters of this book is helping you get some intuition on the data and then implement and contrast various solutions. By the end of this book, you'll be able to understand and apply various techniques with Python for text preprocessing, text representation, dimensionality reduction, machine learning, language modeling, visualization, and evaluation.
Table of Contents (13 chapters)

Performing exploratory data analysis

After browsing the online dataset, we observe different files corresponding to various product categories. But before we focus on any particular group, we can explore the data found in the categories.txt.gz file (https://snap.stanford.edu/data/amazon/categories.txt.gz). Looking at its extension, we deduce that it is a compressed archive to occupy less storage space. Furthermore, each product is specified by a unique identifier and can be part of multiple categories. Figure 4.1 shows two examples from the dataset:

Figure 4.1 – Sample product IDs along with their categories

Python offers the gzip module to read data from a compressed file. So, first, we need to parse categories.txt.gz and read both the ID and the categories for each product. In the following code snippet, we define a method that does exactly that: iterates over all lines in the file, checks whether it refers to a product ID or category, and stores the...