流水线

EditTreeLemmatizer

classv3.3
String name:trainable_lemmatizerTrainable:
用于词形还原的流水线组件

一个可训练的组件,用于为词元分配基本形式。该词形还原器使用编辑树将词元转换为基本形式。词形还原模型预测哪个编辑树适用于某个词元。该词形还原器使用的编辑树数据结构和构建方法在Joint Lemmatization and Morphological Tagging with Lemming(Thomas Müller等人,2015年)中提出。

如需基于查找和规则的词形还原器,请参阅Lemmatizer

Assigned Attributes

预测结果会被赋值给Token.lemma

位置
Token.lemmaThe lemma (hash). int
Token.lemma_The lemma. str

配置与实现

默认配置由管道组件工厂定义,描述了组件应如何配置。您可以通过nlp.add_pipe中的config参数或在训练用的config.cfg中覆盖其设置。有关架构及其参数和超参数的详细信息,请参阅模型架构文档。

设置描述
modelA model instance that predicts the edit tree probabilities. The output vectors should match the number of edit trees in size, and be normalized as probabilities (all scores between 0 and 1, with the rows summing to 1). Defaults to Tagger. Model[List[Doc], List[Floats2d]]
backoffToken attribute to use when no applicable edit tree is found. Defaults to orth. str
min_tree_freqMinimum frequency of an edit tree in the training set to be used. Defaults to 3. int
overwriteWhether existing annotation is overwritten. Defaults to False. bool
top_kThe number of most probable edit trees to try before resorting to backoff. Defaults to 1. int
scorerThe scoring method. Defaults to Scorer.score_token_attr for the attribute "lemma". Optional[Callable]
explosion/spaCy/master/spacy/pipeline/edit_tree_lemmatizer.py

EditTreeLemmatizer.__init__ 方法

创建一个新的管道实例。在您的应用程序中,通常会使用快捷方式,通过其字符串名称并使用nlp.add_pipe来实例化该组件。

名称描述
vocabThe shared vocabulary. Vocab
modelA model instance that predicts the edit tree probabilities. The output vectors should match the number of edit trees in size, and be normalized as probabilities (all scores between 0 and 1, with the rows summing to 1). Model[List[Doc], List[Floats2d]]
nameString name of the component instance. Used to add entries to the losses during training. str
仅关键字
backoffToken attribute to use when no applicable edit tree is found. Defaults to orth. str
min_tree_freqMinimum frequency of an edit tree in the training set to be used. Defaults to 3. int
overwriteWhether existing annotation is overwritten. Defaults to False. bool
top_kThe number of most probable edit trees to try before resorting to backoff. Defaults to 1. int
scorerThe scoring method. Defaults to Scorer.score_token_attr for the attribute "lemma". Optional[Callable]

EditTreeLemmatizer.__call__ 方法

将管道应用于单个文档。文档会被原地修改并返回。 这通常在调用nlp对象处理文本时自动完成, 所有管道组件会按顺序应用于Doc对象。 __call__pipe方法都会委托给 predictset_annotations方法。

名称描述
docThe document to process. Doc

EditTreeLemmatizer.pipe 方法

将管道应用于文档流。这通常在调用nlp对象处理文本时自动完成,所有流水线组件会按顺序应用于Doc对象。无论是__call__还是pipe方法,最终都会委托给predictset_annotations方法执行。

名称描述
streamA stream of documents. Iterable[Doc]
仅关键字
batch_sizeThe number of documents to buffer. Defaults to 128. int

EditTreeLemmatizer.initialize 方法v3.0

初始化组件以进行训练。get_examples应为一个返回可迭代Example对象的函数。至少需要提供一个示例。这些数据示例用于初始化组件模型,可以是完整的训练数据或代表性样本。初始化过程包括验证网络、推断缺失形状以及根据数据设置标签方案。该方法通常由Language.initialize调用,并允许您通过配置中的[initialize.components]块来自定义接收的参数。

名称描述
get_examplesFunction that returns gold-standard annotations in the form of Example objects. Must contain at least one Example. Callable[[], Iterable[Example]]
仅关键字
nlpThe current nlp object. Defaults to None. Optional[Language]
labelsThe label information to add to the component, as provided by the label_data property after initialization. To generate a reusable JSON file from your data, you should run the init labels command. If no labels are provided, the get_examples callback is used to extract the labels from the data, which may be a lot slower. Optional[Iterable[str]]

EditTreeLemmatizer.predict 方法

将组件的模型应用于一批Doc对象,而不修改它们。

名称描述
docsThe documents to predict. Iterable[Doc]

EditTreeLemmatizer.set_annotations 方法

使用预先计算的树标识符批量修改Doc对象。

名称描述
docsThe documents to modify. Iterable[Doc]
tree_idsThe identifiers of the edit trees to apply, produced by EditTreeLemmatizer.predict.

EditTreeLemmatizer.update 方法

从一批包含预测和黄金标准注释的Example对象中学习,并更新组件的模型。委托给predictget_loss

名称描述
examplesA batch of Example objects to learn from. Iterable[Example]
仅关键字
dropThe dropout rate. float
sgdAn optimizer. Will be created via create_optimizer if not set. Optional[Optimizer]
lossesOptional record of the loss during training. Updated using the component name as the key. Optional[Dict[str, float]]

EditTreeLemmatizer.get_loss 方法

计算这批文档及其预测分数的损失和损失梯度。

名称描述
examplesThe batch of examples. Iterable[Example]
scoresScores representing the model’s predictions.

EditTreeLemmatizer.create_optimizer 方法

为管道组件创建一个优化器。

名称描述

EditTreeLemmatizer.use_params 方法上下文管理器

修改管道的模型,以使用给定的参数值。在上下文结束时,原始参数将被恢复。

名称描述
paramsThe parameter values to use in the model. dict

EditTreeLemmatizer.to_disk 方法

将管道序列化到磁盘。

名称描述
pathA path to a directory, which will be created if it doesn’t exist. Paths may be either strings or Path-like objects. Union[str,Path]
仅关键字
excludeString names of serialization fields to exclude. Iterable[str]

EditTreeLemmatizer.from_disk 方法

从磁盘加载管道。就地修改对象并返回它。

名称描述
pathA path to a directory. Paths may be either strings or Path-like objects. Union[str,Path]
仅关键字
excludeString names of serialization fields to exclude. Iterable[str]

EditTreeLemmatizer.to_bytes 方法

将管道序列化为字节串。

名称描述
仅关键字
excludeString names of serialization fields to exclude. Iterable[str]

EditTreeLemmatizer.from_bytes 方法

从字节串加载管道。原地修改对象并返回它。

名称描述
bytes_dataThe data to load from. bytes
仅关键字
excludeString names of serialization fields to exclude. Iterable[str]

EditTreeLemmatizer.labels 属性

当前添加到组件中的标签。

名称描述

EditTreeLemmatizer.label_data 属性v3.0

当前添加到组件的标签及其内部元信息。 这是由init labels生成的数据,并被 EditTreeLemmatizer.initialize用于 使用预定义的标签集初始化模型。

名称描述

序列化字段

在序列化过程中,spaCy会导出多个用于恢复对象不同方面的数据字段。如果需要,您可以通过exclude参数传入字符串名称来将它们排除在序列化之外。

名称描述
vocabThe shared Vocab.
cfgThe config file. You usually don’t want to exclude this.
modelThe binary model data. You usually don’t want to exclude this.
treesThe edit trees. You usually don’t want to exclude this.