The default config is defined by the pipeline component factory and describes
how the component should be configured. You can override its settings via the
config argument on nlp.add_pipe or in your
config.cfg for training. See the
model architectures documentation for details on the
architectures and their arguments and hyperparameters.
# Construction via add_pipe with default modeltok2vec=nlp.add_pipe("tok2vec")# Construction via add_pipe with custom modelconfig={"model":{"@architectures":"my_tok2vec"}}parser=nlp.add_pipe("tok2vec",config=config)# Construction from classfromspacy.pipelineimportTok2Vectok2vec=Tok2Vec(nlp.vocab,model)
Create a new pipeline instance. In your application, you would normally use a
shortcut for this and instantiate the component using its string name and
nlp.add_pipe.
String name of the component instance. Used to add entries to the losses during training.
Tok2Vec.__call__
Apply the pipe to one document. The document is modified in place, and returned.
This usually happens under the hood when the nlp object is called on a text
and all pipeline components are applied to the Doc in order. Both
__call__ and pipe delegate to the
predict and
set_annotations methods.
Example
doc=nlp("This is a sentence.")tok2vec=nlp.add_pipe("tok2vec")# This usually happens under the hoodprocessed=tok2vec(doc)
Name
Type
Description
doc
Doc
The document to process.
RETURNS
Doc
The processed document.
Tok2Vec.pipe
Apply the pipe to a stream of documents. This usually happens under the hood
when the nlp object is called on a text and all pipeline components are
applied to the Doc in order. Both __call__ and
pipe delegate to the predict
and set_annotations methods.
During serialization, spaCy will export several data fields used to restore
different aspects of the object. If needed, you can exclude them from
serialization by passing in the string names via the exclude argument.