How to Clean Text for Machine Learning with Python

Last Updated on August 7, 2019

You cannot go straight from raw text to fitting a machine learning or deep learning model.

You must clean your text first, which means splitting it into words and handling punctuation and case.

In fact, there is a whole suite of text preparation methods that you may need to use, and the choice of methods really depends on your natural language processing task.

In this tutorial, you will discover how you can clean and prepare your text ready for modeling with machine learning.

After completing this tutorial, you will know:

  • How to get started by developing your own very simple text cleaning tools.
  • How to take a step up and use the more sophisticated methods in the NLTK library.
  • How to prepare text when using modern text representation methods like word embeddings.

Kick-start your project with my new book Deep Learning for Natural Language Processing, including step-by-step tutorials and the Python source code files for all examples.

Let’s get started.

  • Update Nov/2017: Fixed a code typo in the ‘split into words’ section, thanks David Comfort.
How to Develop Multilayer Perceptron Models
<a href=To finish reading, please visit source site