容器

示例

classv3
一个训练实例

一个Example保存了一个训练实例的信息。它存储了两个Doc对象:一个用于保存黄金标准参考数据,另一个用于保存管道的预测结果。一个Alignment对象存储了这两个文档之间的对齐关系,因为它们的标记化可能不同。

Example.__init__ 方法

predicted文档和reference文档构建一个Example对象。如果alignmentNone,则会根据两个文档中的单词进行初始化。

名称描述
predictedThe document containing (partial) predictions. Cannot be None. Doc
referenceThe document containing gold-standard annotations. Cannot be None. Doc
仅关键字
alignmentAn object holding the alignment between the tokens of the predicted and reference documents. Optional[Alignment]

Example.from_dict 类方法

predicted文档和以字典形式提供的参考标注中构建一个Example对象。有关所需格式的更多详细信息,请参阅训练格式文档

名称描述
predictedThe document containing (partial) predictions. Cannot be None. Doc
example_dictThe gold-standard annotations as a dictionary. Cannot be None. Dict[str, Any]

Example.text 属性

这个Examplepredicted文档的文本内容。

名称描述

Example.predicted 属性

包含预测结果的Doc对象。有时也被称为example.x

名称描述

Example.reference 属性

包含黄金标准标注的Doc对象。有时也被称为example.y

名称描述

Example.alignment 属性

Alignment对象将predicted文档的标记映射到reference文档的标记。

名称描述

Example.get_aligned 方法

获取某个词符属性的对齐视图,由其整型ID或字符串名称表示。

名称描述
fieldAttribute ID or string name. Union[int, str]
as_stringWhether or not to return the list of values as strings. Defaults to False. bool

Example.get_aligned_parse 方法

获取依存句法分析的对齐视图。如果projectivize参数设置为True,非投射依存树将通过Nivre和Nilsson(2005)提出的伪投射依存句法分析算法转换为投射结构。

名称描述
projectivizeWhether or not to projectivize the dependency trees. Defaults to True. bool

Example.get_aligned_ner 方法

获取NER BILUO 标签的对齐视图。

名称描述

Example.get_aligned_spans_y2x 方法

获取定义在Example.reference上的任意一组Span对象的对齐视图。生成的span索引将与Example.predicted中的分词结果对齐。

名称描述
y_spansSpan objects aligned to the tokenization of reference. Iterable[Span]
allow_overlapWhether the resulting Span objects may overlap or not. Set to False by default. bool

Example.get_aligned_spans_x2y 方法

获取定义在Example.predicted上的任意一组Span对象的对齐视图。生成的span索引将与Example.reference中的分词对齐。该方法特别适用于根据原始黄金标准标注评估预测实体的准确性。

名称描述
x_spansSpan objects aligned to the tokenization of predicted. Iterable[Span]
allow_overlapWhether the resulting Span objects may overlap or not. Set to False by default. bool

Example.to_dict 方法

返回该Example中包含的参考注释的字典表示

名称描述

Example.split_sents 方法

将一个Example分割成多个Example对象,每个句子对应一个。

名称描述

对齐 v3.0

计算两种分词之间的对齐表。

对齐属性

对齐属性通过AlignmentArray进行管理,这是Thinc库中Ragged类型的简化版本,仅支持datalength属性。

名称描述
x2yThe AlignmentArray object holding the alignment from x to y. AlignmentArray
y2xThe AlignmentArray object holding the alignment from y to x. AlignmentArray

Alignment.from_strings 函数

名称描述
AString values of candidate tokens to align. List[str]
BString values of reference tokens to align. List[str]