Book Image

Machine Learning Techniques for Text

By : Nikos Tsourakis
Book Image

Machine Learning Techniques for Text

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)

Creating a retrieval-based chatbot

The implementation in this section is inspired by ELIZA (, an early chatbot, and one of the first programs capable of attempting the Turing test. It simulated a psychotherapist in an initial psychiatric interview to demonstrate the superficiality of the communication between man and machine. The client performed the conversation using pattern matching and substitution methodology.

First, we need to set a list with possible patterns and the relevant responses using the code in the chatbot.ipynb notebook:

from import Chat, reflections
# Pairs of patterns and responses.
pairs = (
        r"I need (.*)",
            "Why do you need %1?",