Natural Language Processing · Intermediate level

Intermediate level · Module 2 of 8 · 13 guided hours

Feature Extraction and TF-IDF

Representing documents for machine learning: counts, n-grams, vocabulary control, TF-IDF weighting and similarity, with a worked TF-IDF table on short public notices.

Learning objectives

  • Build count and n-gram features with vocabulary controls
  • Calculate and interpret TF-IDF weights
  • Compare documents with cosine similarity

Topics

  • counts and binary features
  • n-grams
  • min_df, max_df and max_features
  • term frequency and inverse document frequency
  • TfidfVectorizer
  • cosine similarity

Lessons

  1. Lesson 1 N-grams and Vocabulary Control

    Learners add word pairs (bigrams) to capture short phrases such as 'not paid' and control vocabulary size with min_df, max_df and max_features.

    unigram and bigramngram_rangemin_dfmax_dfmax_features

  2. Lesson 2 TF-IDF: Weighting Important Words

    Learners calculate TF-IDF by hand and with TfidfVectorizer to see why words that are frequent in one document but rare in the collection get high weights.

    term frequencydocument frequencyinverse document frequencysmoothingL2 normalisation

  3. Lesson 3 Document Similarity with Cosine Similarity

    Learners compare documents using cosine similarity on TF-IDF vectors to find duplicates and related documents, a building block for search and recommendation.

    vector space modelcosine similaritycosine_similaritynear-duplicatessimilarity threshold

Practical activity

Build the project's feature layer: chosen n-gram and vocabulary settings, TF-IDF features, top keywords per document and corpus deduplication.

Expected outcomes

  • Sound feature extraction for documents
  • Practical use of TF-IDF and similarity

Assessment

Hand-calculation test on TF-IDF (30%) and the feature-layer notebook (70%).

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.