spaCy - Span._ _init_ _ Method



This is one of the most useful methods of Span class. As name implies, it is used to construct a Span object from the slice doc[start : end].

Arguments

The table below explains its arguments −

NAME TYPE DESCRIPTION
Doc Doc It represents the parent document.
Start Int It is the index of the first token of the span.
End Int It represents the index of the first token after the span.
Label int / unicode It is the label, which is to attach to the span. For example, the named entities. As of version 2.1, the label can be a unicode string also.
kb_id int / unicode It represents a knowledge base ID, which is to attach to the span. For example, the named entities. This ID can be an integer as well as a unicode string also.
vector numpy.ndarray[ndim=1, dtype='float32'] It is a meaning representation of the span.

Example 1

An example of Span._ _init_ _ method is given below −

import spacy
nlp_model = spacy.load("en_core_web_sm")
doc = nlp_model("This is Tutorialspoint.com.")
span = doc[1:4]
span

Output

When you execute the above code, you should see the following output −

is Tutorialspoint.com.

Example 2

An another example of Span._ _init_ _ method is given below −

[t.text for t in span]

Output

When you execute the above code, you should see the following output −

['is', 'Tutorialspoint.com', '.']
spacy_container_span_class.htm
Advertisements