如何使用 spaCy 中 NER 或 EntityRuler 匹配的实体来训练 TextCategorizer?

发布于 2025-01-12 18:29:38 字数 400 浏览 3 评论 0原文

我试图了解如何根据早期管道组件找到的命名实体(而不仅仅是原始文本)对文档进行分类。

说我有文件 “毛工资 50 美元。净工资 40 美元。税 10 美元”

我想将整个文本分类为多标签文本猫中的工资单。

通过一些自定义 EntityRuler 模式,我可以轻松预测文档实体标签,如下所示: “总工资 [金钱]。净工资 [金钱]。税收 [金钱]”

我的问题是,如何使用这些标签(存储在 doc.ents / Token.ent_type 中)作为特征来训练 TextCategorizer,以便它只关心是否令牌是金钱,并且在预测类别时不区分不同的数量($50、$40、$10)?即,如何根据所有或部分文档标记的 token.ent_type 而不是 token.text 对文档进行分类?

我正在使用 spaCy 3.2

I'm trying to understand how to classify a document based on named entities found by earlier pipeline components rather than just the raw text.

Say I have the document
"Gross Pay $50. Net Pay $40. Tax $10"

I want to classify the whole text as a PAYSLIP in a multilabel textcat.

With some custom EntityRuler patterns I can easily predict the document entity labels as something like:
"Gross Pay [MONEY]. Net Pay [MONEY]. Tax [MONEY]"

My question is, how do I use these labels (stored in doc.ents / Token.ent_type) as features to train a TextCategorizer so it only cares whether a token is MONEY and doesn't distinguish between the different quantities ($50, $40, $10) when predicting a category? ie, how do I classify documents based on token.ent_type and not token.text for all or some of the documents' tokens?

I'm using spaCy 3.2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文