liveBook · Manning

Chapter 2: Getting started with baselines: Data preprocessing

What you will learn in chapter 2 of Transfer Learning for Natural Language Processing

This introduction explains the purpose of NLP baselines, the limitations of keyword rules, and how to run the book’s notebooks with attention to dependencies.

After this chapter you will be able to

Section by section

Introduction

This introduction explains the purpose of NLP baselines, the limitations of keyword rules, and how to run the book’s notebooks with attention to dependencies.

Key terms: baselines, transfer learning, spam classification, sentiment classification, rule-based methods, keyword-matching, Kaggle notebooks, Copy and Edit Kernel, frozen dependency requirement list

2.1 Preprocessing email spam classification example data

Introduces a supervised spam-classification example built from two email sources and explains why the dataset is assembled rather than taken ready-labeled.

Key terms: supervised classification, Enron email corpus, 419 fraudulent emails, spam, data collection, preprocessing, built and curated

2.1.1 Loading and visualizing the Enron corpus

This section loads and inspects the Enron email corpus, then separates message bodies from headers for content-based spam classification.

Key terms: Enron corpus, Pandas, DataFrame, filepath, message column, header, email body, email package, de-identified

2.1.2 Loading and visualizing the fraudulent email corpus

This section loads fraudulent emails and combines them with Enron emails into a balanced, preprocessed spam-classification dataset.

Key terms: 419 fraudulent email corpus, Latin-1, From r, Pandas DataFrame, class imbalance, 50/50 split, NumPy array, spam, nonspam, tokenization

2.1.3 Converting the email text into numbers

This section converts emails into bag-of-words vectors, shuffles them with their labels, and splits them for classifier training and evaluation.

Key terms: bag-of-words model, word tokens, frequency counts, used_tokens, sparse DataFrame, shuffle, classes, labels, unison, training set

2.2 Preprocessing movie sentiment classification example data

This section prepares IMDB movie reviews for sentiment classification, emphasizing sentiment-sensitive preprocessing, class balance, and a numerical representation.

Key terms: IMDB, sentiment analysis, positive, negative, stop words, header extraction, sentiment, tokenizing, NumPy array, bag-of-words

2.3 Generalized linear models

This section introduces linearity and the generalized linear model framework used for classification.

Key terms: linear models, addition, multiplication, generalized linear model, independent variables, responses, expected value, link function, parameters

2.3.1 Logistic regression

This section introduces logistic regression, applies it to two classification examples, and explains how to evaluate the results.

Key terms: logistic regression, logistic function, categorical output, probability, scikit-learn, hold out, test/validation sets, spam classification, IMDB, accuracy

2.3.2 Support vector machines (SVMs)

This section introduces SVMs as kernel methods and compares their baseline performance with logistic regression on email and movie-review classification.

Key terms: SVM, kernel method, hyperplane, kernel trick, linear kernel, SVM classifier, logistic regression, accuracy score, training time, IMDB

2.4 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 1: What is transfer learning? Chapter 3: Getting started with baselines: Benchmarking and optimization →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.