Text Classification — Text Categorization

Machine Learning
Type
Supervised NLP classification task

What does it do?

Text classification, also called text categorization, is a supervised natural-language-processing task that assigns documents to predefined categories, learning from labelled examples.

Joachims (1998) applied support vector machines to this problem. Typical applications include spam detection and topic classification.

The intuition behind the method

When you have many documents that each belong to one of a fixed set of categories, sorting them by hand does not scale. Text classification learns the patterns that separate one category from another from a set of already-labelled examples, then applies those patterns to label new, unseen documents automatically — much like teaching a sorter by showing it pre-sorted piles and letting it file the rest.

History

Joachims (1998) applied support vector machines to text categorization and framed the task as learning with many relevant features. Text classification has been explored extensively in the data mining literature, where instance-based, Bayes and SVM methods are the classifier families most commonly used for text.

When to use it

Use text classification when your documents are text, each one should receive a label from a fixed and predefined set of categories, and you have a labelled set of examples to learn from. Every category should have enough labelled documents to be learned and evaluated, and a reasonably balanced spread of documents across categories is preferred. Do not use it when the categories are not known in advance, because the task needs a predefined label set; grouping unlabelled documents is the task of document clustering. If you have no text data and your variables are categorical, general classification on that structured data is the appropriate alternative.

Limitations and considerations

  • Requires a labelled training set, and the labels must be produced before the classifier can be trained.
  • Learns only the categories present in the training labels, so a new category requires new labelled documents and retraining.
  • Skewed category distributions make some categories hard to learn, because the classifier sees few examples of them.
  • The number of labelled documents needed depends on how many categories there are and how many examples each category has; with only a few examples per category, the learned patterns are unlikely to generalise.
  • Word-based features are affected by synonymy and polysemy: different words can express the same idea, and one word can have several meanings, which blurs the signal that separates the categories.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Learns the features that separate the categories directly from labelled examples, rather than from hand-written rules.
  • Handles the large number of word-based features that text produces, as the support vector machine application of Joachims (1998) illustrates.
  • Returns a single label per document from a predefined set, which suits triage and routing tasks such as spam filtering and topic assignment.

Applications

  • Spam detection: separating unwanted messages from legitimate ones.
  • Topic classification: assigning documents or articles to subject categories.
  • Organising and triaging large document collections by predefined category.

How it works

How it works

1

The process starts with a corpus in which every training document already carries one of the predefined category labels. The label set is fixed in advance, so every category the classifier should recognise must be represented in this labelled data. How evenly the documents are spread across categories affects how well each category can be learned.

2

The raw text is cleaned and normalised so that documents can be compared. Common operations include stopword removal, Porter stemming, conversion of text to uppercase, lowercase or proper case, and extraction of words or tokens based on named entities or regular expressions. The text is then transformed into vector or other numerical form. Errors at this stage carry forward, because the features built from the text depend on it.

3

Each cleaned document is converted into numeric features, so that the classifier can work with which terms occur in it. A common representation is a vector of term frequencies, with one value per term. TF-IDF weighting, which scales term frequencies by how distinctive a term is across the collection, is another frequent choice (see the related TF-IDF page). Joachims (1998) is titled with the phrase 'many relevant features', reflecting that text yields a large number of such features.

4

A supervised classifier is fitted to the labelled, vectorised training documents. It learns how the feature patterns relate to each category label, and is then used to assign a label to documents it has not seen. Instance-based methods, Bayes methods and support vector machines (SVMs) are the classifier families most commonly used for text, whereas decision trees are not particularly popular for text data. Instance-based methods need to be modified to account for synonymy and polysemy. The multinomial Bayes model is particularly popular for long documents, and SVMPerf is commonly used for efficient text classification with SVMs. Joachims (1998) applied SVMs to this step.

5

The trained classifier is tested on labelled documents that were held out from training, and its misclassifications are examined. Results should be reported per category, for example with per-class precision and recall, because overall accuracy can hide poor performance on small categories.

Common pitfalls

  • Training on very small labelled sets risks overfitting, so the model may fit the training documents without generalising to new ones.
  • Skipping or poorly designing preprocessing lets noisy tokens enter the features and degrade the classifier.
  • With imbalanced classes, overall accuracy can look high while rare categories are misclassified; inspect performance per category instead.
  • Applying the method when there is no text data at all is a category error; the method needs text as its input.

Frequently asked questions

How much labelled data do I need?

There is no single required number. The amount depends on how many categories there are and how many examples each category has. Every category needs enough labelled documents both to learn from and to evaluate, and a larger labelled set gives the classifier more examples of each category to learn from.

Does class balance matter?

Yes. A balanced spread of documents across categories is preferred so the classifier can learn each category. With skewed classes, judge performance per category rather than relying on overall accuracy.

What if I have no text data?

Text classification cannot run without text. If your variables are categorical instead, use general classification methods on that structured data.

How is it different from document clustering?

Text classification is supervised: it assigns documents to predefined categories learned from labelled examples. Document clustering is unsupervised and groups similar documents without predefined labels.

Related methods

Sources

  1. Joachims, T. (1998). Text Categorization with Support Vector Machines: Learning with Many Relevant Features. ECML 1998. Lecture Notes in Computer Science, vol 1398. Springer.

    Open DOI reference
  2. Aggarwal, C. C. & Zhai, C. (2012). Mining Text Data. Springer.

    ISBN: 978-1-4614-3222-7
  3. 2015_Book_DataMining, p. ?

  4. Learn R for Applied Statistics_ With Data Visualizations, Regressions, and Statistics, p. 10