The process of deciding from where the sentences actually start or end in NLP or we can simply say that here we are dividing a paragraph based on sentences. This process is known as Sentence Segmentation. In Python, we implement this part of NLP using the spacy library.
Spacy is used for Natural Language Processing in Python.
To use this library in our python program we first need to install it.
Command to install this library:
pip install spacy python -m spacy download en_core_web_sm Here en_core_web_sm means core English Language available online of small size.
we have the following paragraph: "I Love Coding. Geeks for Geeks helped me in this regard very much. I Love Geeks for Geeks." here there are 3 sentences. 1. I Love Coding. 2. Geeks for Geeks helped me in this regard very much. 3. I Love Geeks for Geeks
.sents is used for sentence segmentation which is present inside spacy. The output is given by
.sents is a generator and we need to use the list if we want to print them randomly.
Now if we try to use doc.sents randomly then what happens:
Code: To overcome this error we first need to convert this generator into a list using list function.
- Python | Word Similarity using spaCy
- Python | Named Entity Recognition (NER) using spaCy
- Python | PoS Tagging and Lemmatization using spaCy
- Image segmentation using Morphological operations in Python
- Image Segmentation using K Means Clustering
- Perform addition and subtraction using CherryPy
- Python | Perform append at beginning of list
- Python | Perform operation on each key dictionary
- perform method - Action Chains in Selenium Python
- How to perform modulo with negative values in Python?
- Python Program to perform cross join in Pandas
- Python | Remove all duplicates words from a given sentence
- Python | Sort words of sentence in ascending order
- Python | Reverse each word in a sentence
- Python program to count words in a sentence
- Python | Spilt a sentence into list of words
- Python | Check if given words appear together in a list of sentence
- Program to replace a word with asterisks in a sentence
- NLP | Training a tokenizer and filtering stopwords in a sentence
- NLP | How tokenizing text, sentence, words works
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.