Test topic inference in a colab

Try the colab to learn how to load the TensorFlow Lite model used by Chrome to infer topics from hostnames.

Published on Updated on

Translated to: 日本語

Implementation status

Running the colab

A colab—or colaboratory—is a data analysis tool that combines code, output, and descriptive text into one collaborative document. You can run the Topics Model Execution Demo colab to test how the Topics classifier model infers topics of interest to the user, from the hostnames of pages they visit.

  1. From the Classifier tab of the chrome://topics-internals page get the directory path for the .tflite file used by the Topics API. The override list, override_list.pb.gz, is available from the chrome://topics-internals/ page under the current model in the Classifier tab.

    chrome://topics-internals page with Classifier panel selected and tflite file path highlighted.
  2. Open the colab and click on the folder icon.

    Topics API colab.
  3. Click the Upload icon and upload model.tflite and override_list.pb.gz from your computer to the colab.

    Topics API colab file upload.
  4. You can then run all the colab steps, by selecting Run all from the Runtime menu.

    Topics API colab page, 'Run all' selected form the Runtime menu.

This does the following:

  1. Installs the Python packages used by the colab.
  2. Installs the tflite libraries and the Topics taxonomy.
  3. Defines the taxonomy.
  4. Runs each of the Model Execution Demo steps to show how classification works for two example domains.

You'll see a green tick next to each step that completes successfully. (Each step can also be run individually, by clicking the Play button next to it.)

For each of the domains defined, you can see the topic scores inferred by the classifier. Try listing different domains to see how they compare.


For some domains you may notice a difference in topic inference between the colab and the chrome://topics-internals classifier.

The colab only uses the classifier model to infer topics, whereas chrome://topics-internals uses Chrome's Topics implementation. Chrome manually curates list of topics, rather than using the classifier model for the top 10,000 sites. The curated list can be found in override_list.pb.gz, which is available on chrome://topics-internals.

Next steps

If you're an ad tech developer, experiment and participate with the Topics API, and check out the Topics API demo.

Engage and share feedback

Updated on Improve article

This site uses cookies to deliver and enhance the quality of its services and to analyze traffic. If you agree, cookies are also used to serve advertising and to personalize the content and advertisements that you see. Learn more about our use of cookies.