流水线

SpanResolver

class,experimental
String name:span_resolverTrainable:
用于将标记解析为跨度的流水线组件

一个SpanResolver组件接收标记(表示为长度为1的Span对象),并将它们解析为任意长度的Span对象。最初的应用场景是作为词级别共指消解的后处理步骤。用于存储Span对象的输入和输出键是可配置的。

Assigned Attributes

预测结果将保存到Doc.spans中作为SpanGroups

输入标记跨度将使用输入前缀读取,默认为"coref_head_clusters",输出跨度将使用输出前缀(默认为"coref_clusters")加上从1开始的序列号保存。这些前缀是可配置的。

位置
Doc.spans[output_prefix + "_" + cluster_number]One group of predicted spans. Cluster number starts from 1. SpanGroup

配置与实现

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

设置描述
modelThe Model powering the pipeline component. Defaults to SpanResolver. Model
input_prefixThe prefix to use for input SpanGroups. Defaults to coref_head_clusters. str
output_prefixThe prefix for predicted SpanGroups. Defaults to coref_clusters. str

SpanResolver.__init__ 方法

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

名称描述
vocabThe shared vocabulary. Vocab
modelThe Model powering the pipeline component. Model
nameString name of the component instance. Used to add entries to the losses during training. str
仅关键字
input_prefixThe prefix to use for input SpanGroups. Defaults to coref_head_clusters. str
output_prefixThe prefix for predicted SpanGroups. Defaults to coref_clusters. str

SpanResolver.__call__ 方法

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

名称描述
docThe document to process. Doc

SpanResolver.pipe 方法

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

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

SpanResolver.initialize 方法

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

名称描述
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]

SpanResolver.predict 方法

将组件的模型应用于一批Doc对象,而不修改它们。预测结果以MentionClusters列表形式返回,每个输入Doc对应一个。MentionClusters实例实际上是由整数对列表组成的列表,其中每个项对应一个输入SpanGroup,而这些整数对则对应标记索引。

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

SpanResolver.set_annotations 方法

修改一批文档,使用Doc.spans中的输出前缀保存预测结果。

名称描述
docsThe documents to modify. Iterable[Doc]
spansThe predicted spans for the docs. List[MentionClusters]

SpanResolver.update 方法

从一批Example对象中学习。委托给predict

名称描述
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]]

SpanResolver.create_optimizer 方法

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

名称描述

SpanResolver.use_params 方法上下文管理器

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

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

SpanResolver.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]

SpanResolver.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]

SpanResolver.to_bytes 方法

将管道序列化为字节串。

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

SpanResolver.from_bytes 方法

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

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

序列化字段

在序列化过程中,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.