ComeçarComece de graça

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 .

Este exercício faz parte do curso

Natural Language Processing with spaCy

Ver curso

Instruções do exercício

  • 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.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Generating a documents list of all Doc containers
documents = [____(text) for text in texts]

# Iterate through documents and append sentences in each doc to the sentences list
sentences = []
for doc in documents:
  sentences.append([s for s in ____.____])
  
# Find number of sentences per each doc container
print([len(____) for s in sentences])
Editar e executar o código