Written by Gabriele Tomassetti
in Natural Language Processing

    This is a review of the book Natural Language Processing for Hackers* by George-Bogdan Ivanov, a NLP expert.

    When something is written for Hackers there are two possibilities:

    • it is a pragmatic book designed to help you build something practical
    • or an excuse to avoid explaining half of the stuff mentioned because the reader is supposed to be an hacker that can figure stuff out.

    This is a book of the first kind: a source of ready-to-use knowledge and Python code. What I really liked about this book is that it taught me to create something that I did not even know was reasonably easy to make: a Chatbot. This was exciting, and that is the argument of the last part of the book.

    Is This Book for You?

    When it comes to programming books is important to understand the audience of the book. There is generally a big divide in tastes between people that like theory and people that like practice. Some want to understand how stuff works and other want to just know the necessary to write some code. As the name implies, this is a book for the second type of people, and it packs a great density of information and code in 176 pages.

    This does not mean that it is a book for people that already know the theory of Natural Language Processing and just want help writing some code. You do not need to know the theory; this book will explain what you need to know. For instance, these are the explanations for stemmers and lemmatizers:

    How stemmers work

    When stemming, what you actually do is to apply various rules to a specific word form until you reduce the word to its basic form and no other rule can be applied.

    [..]

    How lemmatizers work

    You can think of lemmatizers as a huge Python dictionary where the word forms are the keys and the base form of the words are the values

    Chapter NLTK Fundamentals, pages 18-19

    These are basic, but also effective and useful definitions. You do not really need to know anything more to work with them.

    It is also important to know that this is a book for Python: it relies on Python libraries such as NLTK. You could transfer the same techniques mentioned in the book to other languages, but you would also need to find replacements for the basic components used to performs the grunt work of machine learning: regressions, training, etc. This is also not a reference book: you cannot pick and choose the sections to read.

    How the Book is Organized

    The book is divided in five parts: three are dedicated to design a specific service or task (e.g., a social media monitoring service) and the other two are meant to teach you the basic components used in the remaining parts. Except for the initial part, most of the NLP techniques covered are related to machine learning. Each part is then divided in chapters.

    The five parts are:

    • Introduction to NLTK. The first one is dedicated to learning basic definitions (such as lemming) and understanding how to use important resources such as NLTK and WordNet. You can think of it as a section roughly dedicated to teaching you Natural Language Processing operations on single words.
    • Create a Text Analysis service. After an introduction to scikit-learn, this part teaches you the basic steps to build a text analysis service, like how to find the data, building the model, etc. Apart from the technical knowledge (e.g., how do to feature extraction on the data), I liked the perspective on where and how to find and use the data for your model.
    • Create a Social Media Monitoring Service. This is focused on creating a sentiment analysis service based on Twitter data. In this section my favorite parts are the tips on how to handle tricky elements, like negations. There are also the stuff you expect such as how to build an effective pipeline that supports continual development of your project.
    • Build Your Own NLP Toolkit. The fourth part is for learning how to create middleware NLP tools, like a Part-of-speech Tagger or a Dependency Parser. You can think of it as a section roughly dedicated to NLP operations on sentences. Personally, this is my favorite section because I was already familiar with using such tools, but I never thought that I could build one. Do you know that thrilling realization when you feel you are actually learning something new?
    • Build Your Own Chatbot Engine. The last part focus on creating a chatbot that can perform actions based on questions by the users. As the author himself says, this is a toy chatbot compared to the one provided by Microsoft or Facebook, but the end result is still quite effective. This works because the chatbot is basically designed to be an accessible interface to another service (in this case the Movie DB API) and nothing more.

    The book is very well organized. The parts define a clear and interesting purpose and each chapter fulfill a specific task. Honestly this is one of the better organized book I ever read. This is hard to do outside of reference books.

    Should You Buy This Book?

    The meat of the book is the design of a few NLP systems. You will learn how to combine the foundational NLP concepts and tools into working services. However, I also liked learning some tips about the foundations of NLP like feature extraction. You can think of feature extraction as understanding on what you should train the machine learning algorithm. For instance, if you want to create a service to distinguish between male and female name should you tell the algorithm to look on the last letter of the name? Or is it better to check whether the name contains a specific letter?

    This is because many such steps of machine learning are basically black magic: to understand them you have to do a lot of trial-and-error. This book helps you shorten this learning time. A small flaw is that sometimes this information is just delivered and not explained: for example, you will read that you should use the specific Classifier X, why? Because it is the best one for the task. As I said this is a pragmatic book, not a theoretical one, so it is not a big flaw. However, sometimes I wish for a bit more in-depth explanations.

    I also loved learning about how to find the optimal combinations of parameters (the answer is Grid Search, page 69). For example, if you need to design a sentiment analysis service you might have to choose among many features: the use of negation, counting the numbers of times each word is used in a sentence, whether to transform in lowercase all words, etc. Even if you can just manually test to find the best individual choice, it is impractical to find the best combination of all features. Let the machine doing the calculations! And you can do that using Grid Search.

    Summary

    If you are interested in learning how to create NLP tools to understand text this is a great book to help you started. It is full of information and practical suggestions. There is also plenty of code to immediately start with a working project that you can then optimize for your needs. I like the small practical suggestions that let you see how the author really writes from the perspective of the newcomer. For instance, once you build a chatbot, how do you test in on Facebook (or any other public service)?

    Most likely, you are running your chatbot on localhost, same as me, so you will need to install a tool called ngrok that creates
    a HTTPS a tunnel with a public IP. If this is not your case, use your assigned public IP.

    Chapter MovieBot, page 155

    The only problem with the book is the editing: there are a few convoluted phrases and missing bulleted lists (e.g., a series of phrases preceded by * should have been transformed into a bulleted list). I do not mind, but some people do. I know because we also receive some complaints about the typos in our articles (we always try our best, but keep reporting us any error you find).

    Disclaimer: the publisher gave us a copy of the book for the review and we do have an affiliate agreement, but our review is honest. To avoid a conflict of interest we simply do not publish reviews of books we do not like.

    Download the guide with 68 resources on Creating Programming Languages

    Receive the guide to your inbox to read it on all your devices when you have time

    Powered by ConvertKit