Natural Language Processing · TEE · mocks

Q7A · Text classification pipeline

Timed practice · Solved final paper · December 2025

TEE · actual previous paper · 100 marks · 180 minutes

Question. Explain the working of text classification in Natural Language Processing (NLP) and discuss the key steps involved in building a text classification system in context of real-world applications such as spam detection or news categorization. [10 marks]

Answer

Text classification assigns one or more predefined labels to a document or message based on its content. In spam detection the labels may be spam and not-spam; in news categorization they may be sports, business and politics.

Labelled text Prepare and split data Represent text Train classifier Evaluate Classify new text
  1. Define the labels and task. Decide whether each text gets one label or multiple labels. Establish what counts as spam so annotators use a consistent rule.
  2. Collect and label representative examples. Gather messages from the intended application and assign reliable labels. Include enough examples of each class and protect private information.
  3. Split training, validation and test data. Use training data to learn, validation data to choose settings and an untouched test set for final evaluation. Keep duplicate or closely related texts from leaking between splits.
  4. Preprocess consistently. Tokenize and normalize only as appropriate. In spam detection, URLs, currency symbols and capitalisation may contain useful information.
  5. Create features. A classical baseline uses BoW or TF–IDF. A neural system may use embeddings or a pretrained contextual model. Fit the vocabulary and IDF on training data only.
  6. Train a classifier. For example, multinomial Naïve Bayes estimates class priors and word likelihoods; logistic regression learns a decision boundary. Training uses the labelled examples.
  7. Evaluate. Inspect a confusion matrix, precision, recall and F1 as well as accuracy. False spam flags may hide legitimate mail, so the costs of errors matter.
  8. Deploy and monitor. Apply the same preprocessing and feature mapping to new texts. Monitor changing vocabulary and error patterns, and retrain when suitable new labelled data becomes available.

Example prediction

A message such as “Claim your free prize now” is transformed into its feature representation. The classifier compares the evidence for the two labels and outputs spam if its decision score crosses the chosen threshold. The label comes from learned patterns; the mere presence of one word should not be treated as a universally correct rule.

Yaad rakho: Labelled examples → features → model → evaluation → new text ka label.