1. Learn
  2. /
  3. Courses
  4. /
  5. Natural Language Processing with spaCy

Exercise

Span similarity with spaCy

Determining semantic similarity can help you to categorize texts into predefined categories or detect relevant texts, or to flag duplicate content. In this exercise, you will practice calculating the semantic similarities of spans of a document to a given document. The goal is to find the most relevant Span of three tokens that are relevant to canned dog food.

The given category of canned dog food is stored at category. A text string is already stored in the text object and the en_core_web_md is loaded as nlp. The Doc container of the text is also already created and stored at document.

Instructions

100 XP
  • Create a Doc container for the category and store at category_document.
  • Print similarity score of a given Span and the category_document, rounded to three digits.