Skip to content
Coding Script or NotebookGoogle ColabAcademy

Topic Clustering Notebook for Internal Linking: BERTopic and K-means

ForInternal linkingContent analysis

By Sam Torres· Updated 5 Dec 2026

Topic clusters give your linking rules fences: pages in the same cluster are natural link partners, and links across clusters can be chosen on purpose. This Google Colab notebook builds those clusters from your own content.

What it helps you do

  • Run BERTopic and K-means on the same pages, side by side, and compare the results
  • Label each topic automatically, and give every URL a cluster ID and a topic label
  • Reuse the embeddings you made in the previous lab, so you don’t need an API key (there is a fallback if you skipped that step)
  • Export a cluster map for the scoring and automation steps that follow

A written walkthrough of the lab comes with it.

Where it is used

Lesson 3.4, after the clustering theory in Lesson 3.3. Sam Torres notes it is a method she uses on all kinds of SEO projects, well beyond linking.

It comes with the AI-powered Internal Linking Audit and Automation course, led by Sam Torres. If you want to build the whole pipeline from audit to measured links with her, that is the place to start.

What’s included

  • BERTopic and K-means side by side on the same pages
  • Automatic topic labels
  • A cluster ID and topic label for every URL
  • Reuses the embeddings from the previous lab, so no API key is needed
  • Exports a cluster map for the scoring and automation steps