- spaCy - Discussion
- spaCy - Useful Resources
- spaCy - Quick Guide
- Updating Neural Network Model
- Training Neural Network Model
- spaCy - Container Lexeme Class
- spaCy - Span Class Properties
- spaCy - Container Span Class
- spaCy - Token Properties
- spaCy - Container Token Class
- Doc Class ContextManager and Property
- spaCy - Containers
- spaCy - Compatibility Functions
- spaCy - Utility Functions
- spaCy - Visualization Function
- spaCy - Top-level Functions
- spaCy - Command Line Helpers
- spaCy - Architecture
- spaCy - Models and Languages
- spaCy - Getting Started
- spaCy - Introduction
- spaCy - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Doc Class ContextManager and Property
In this chapter, let us learn about the context manager and the properties of Doc Class in spaCy.
Context Manager
It is a context manager, which is used to handle the retokenization of the Doc class. Let us now learn about the same in detail.
Doc.retokenize
When you use this context manager, it will first modify the Doc’s tokenization, store it, and then, make all at once, when the context manager exists.
The advantage of this context manager is that it is more efficient and less error prone.
Example 1
Refer the example for Doc.retokenize context manager given below −
import spacy nlp_model = spacy.load("en_core_web_sm") from spacy.tokens import Doc doc = nlp_model("This is Tutorialspoint.com.") with doc.retokenize() as retokenizer: retokenizer.merge(doc[0:0]) doc
Output
You will see the following output −
is Tutorialspoint.com.
Example 2
Here is another example of Doc.retokenize context manager −
import spacy nlp_model = spacy.load("en_core_web_sm") from spacy.tokens import Doc doc = nlp_model("This is Tutorialspoint.com.") with doc.retokenize() as retokenizer: retokenizer.merge(doc[0:2]) doc
Output
You will see the following output −
This is Tutorialspoint.com.
Retokenize Methods
Given below is the table, which provides information about the retokenize methods in a nutshell. The two retokenize methods are explained below the table in detail.
Sr.No. | Method & Description |
---|---|
1 | It will mark a span for merging. |
2 | It will mark a token for spptting into the specified orths. |
Properties
The properties of Doc Class in spaCy are explained below −
Sr.No. | Doc Property & Description |
---|---|
1 | Used for the named entities in the document. |
2 | Used to iterate over the base noun phrases in a particular document. |
3 | Used to iterate over the sentences in a particular document. |
4 | Represents a Boolean value which indicates whether a word vector is associated with the object or not. |
5 | Represents a real-valued meaning. |
6 | Represents the L2 norm of the document’s vector representation. |