流水线

词形还原器

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

该组件用于根据词性标签或查找表规则为词元分配基本形式。不同的Language子类可以通过特定语言的工厂实现自己的词形还原组件。默认使用的数据由spacy-lookups-data扩展包提供。

关于可训练的词汇还原器,请参阅EditTreeLemmatizer

Assigned Attributes

由规则生成或预测的词元将被保存到Token.lemma中。

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

配置与实现

默认配置由管道组件工厂定义,描述了组件应如何配置。您可以通过nlp.add_pipe上的config参数或在训练用的config.cfg中覆盖其设置。要查看基于查找和规则的词形还原器使用的查找数据格式示例,请参阅spacy-lookups-data

设置描述
modeThe lemmatizer mode, e.g. "lookup" or "rule". Defaults to lookup if no language-specific lemmatizer is available (see the following table). str
overwriteWhether to overwrite existing lemmas. Defaults to False. bool
modelNot yet implemented: the model to use. Model
仅关键字
scorerThe scoring method. Defaults to Scorer.score_token_attr for the attribute "lemma". Optional[Callable]

许多语言如果存在更好的词形还原器,会指定默认的词形还原模式而非lookup。词形还原模式rulepos_lookup需要来自前一个流水线组件的token.pos(参见预训练流水线设计细节中的示例配置),或依赖第三方库(pymorphy3)。

语言默认模式
bnrule
capos_lookup
elrule
enrule
esrule
farule
frrule
itpos_lookup
mkrule
nbrule
nlrule
plpos_lookup
rupymorphy3
svrule
ukpymorphy3
explosion/spaCy/master/spacy/pipeline/lemmatizer.py

Lemmatizer.__init__ 方法

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

名称描述
vocabThe shared vocabulary. Vocab
modelNot yet implemented: The model to use. Model
nameString name of the component instance. Used to add entries to the losses during training. str
仅关键字
modeThe lemmatizer mode, e.g. "lookup" or "rule". Defaults to "lookup". str
overwrite是否覆盖现有词元。bool

Lemmatizer.__call__ 方法

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

名称描述
docThe document to process. Doc

Lemmatizer.pipe 方法

将管道应用于文档流。这通常在调用nlp对象处理文本时自动完成,所有流水线组件会按顺序应用于Doc

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

Lemmatizer.initialize 方法

初始化词形还原器并加载所有数据资源。该方法通常由Language.initialize调用,允许您通过配置中的[initialize.components]块来自定义接收的参数。加载过程仅在初始化期间进行,通常在训练之前。运行时所有数据都从磁盘加载。

名称描述
get_examplesFunction that returns gold-standard annotations in the form of Example objects. Defaults to None. Optional[Callable[[], Iterable[Example]]]
仅关键字
nlpThe current nlp object. Defaults to None. Optional[Language]
lookupsThe lookups object containing the tables such as "lemma_rules", "lemma_index", "lemma_exc" and "lemma_lookup". If None, default tables are loaded from spacy-lookups-data. Defaults to None. Optional[Lookups]

Lemmatizer.lookup_lemmatize 方法

使用基于查找的方法对标记进行词形还原。如果未找到词元,则返回原始字符串。

名称描述
tokenThe token to lemmatize. Token

Lemmatizer.rule_lemmatize 方法

使用基于规则的方法对标记进行词形还原。通常依赖于词性标注。

名称描述
tokenThe token to lemmatize. Token

Lemmatizer.is_base_form 方法

检查我们是否在处理一个无屈折变化的范式,这样我们可以完全避免词形还原。

名称描述
tokenThe token to analyze. Token

Lemmatizer.get_lookups_config 类方法

返回给定模式下的查找表配置设置,用于Lemmatizer.load_lookups

名称描述
modeThe lemmatizer mode. str

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

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

Lemmatizer.to_bytes 方法

将管道序列化为字节串。

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

Lemmatizer.from_bytes 方法

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

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

属性

名称描述
vocabThe shared Vocab. Vocab
lookupsThe lookups object. Lookups
modeThe lemmatizer mode. str

序列化字段

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

名称描述
vocabThe shared Vocab.
lookupsThe lookups. You usually don’t want to exclude this.