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

Exercise

Sentence segmentation with spaCy

In this exercise, you will practice sentence segmentation. In NLP, segmenting a document into its sentences is a useful basic operation. It is one of the first steps in many NLP tasks that are more elaborate, such as detecting named entities. Additionally, capturing the number of sentences may provide some insight into the amount of information provided by the text.

You can access ten food reviews in the list called texts.

The en_core_web_sm model has already been loaded for you as nlp and .

Instructions

100 XP
  • Run the spaCy model on each item in the texts list to compile documents, a list of all Doc containers.
  • Extract sentences of each doc container by iterating through documents list and append them to a list called sentences.
  • Count the number of sentences in each doc container using the sentences list.