BaşlayınÜcretsiz Başlayın

Doc similarity with spaCy

Semantic similarity is the process of analyzing multiple sentences to identify similarities between them. In this exercise, you will practice calculating semantic similarities of documents to a given document. The goal is to categorize a list of given reviews that are relevant to canned dog food.

The canned dog food category is stored at category. A sample of five food reviews has been provided for you in a list called texts. en_core_web_md is loaded as nlp.

Bu egzersiz

Natural Language Processing with spaCy

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Create a documents list containing Doc containers of all texts.
  • Create a Doc container of the category and store it as category_document.
  • Iterate through documents and print the similarity scores of each Doc container and the category_document, rounded to three digits.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Create a documents list containing Doc containers
documents = [____ for t in texts]

# Create a Doc container of the category
category = "canned dog food"
category_document = ____(____)

# Print similarity scores of each Doc container and the category_document
for i, doc in enumerate(documents):
  print(f"Semantic similarity with document {i+1}:", round(doc.____(____), 3))
Kodu Düzenle ve Çalıştır