- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 spaCy 解析一些新闻数据,并注意到存在引用的句子分割始终失败。还有其他人解决了这个问题吗?
这是一个可重现的示例 - 请注意下面输出中的句子 4。 spaCy 未能在引用的开头进行拆分,这与我正在处理的其他新闻文章是一致的。
非常感谢。
示例:
原始数据:
u'body': u'\n LONDON Nov 4 Britons hurt by lower incomes and rising food prices after the financial crisis have cut back on fruit and vegetables and turned instead to fatty, sugary, processed food, an academic study showed on Monday.Britain has seen food prices rise much more sharply than most other developed economies between 2005 and 2012, while wage growth has been low and unemployment has risen.The net effect has been that Britons are spending 8.5 percent less in real terms on food purchased at home than before the recession - with the trend even greater for pensioners and families with young children.The research is likely to be politically sensitive at a time when Britain\'s Conservative-led government is under pressure from the opposition Labour Party, over declining standards of living and sharply rising demand at food banks which hand out free food to the poorest Britons. People have economised by buying less food, measured in number of calories, but also on its quality, picking products that are less nutritious and higher in saturated fat and sugar."Various measures of nutritional quality declined over this period, with bigger decreases for pensioner households and households with young children," said the Institute for Fiscal Studies, an economics research body.OBESITY Families with children were prone to switching to more sugary food, while pensioners favoured food high in saturated fat, the study showed. Both groups often have lower incomes.While the economy is starting to show signs of growth after suffering the biggest hit to economic growth since records began during the 2008-09 recession, households\' disposable incomes are no higher than a decade ago. However, the IFS said a lower-quality diet was not an inevitable consequence of having less money, and that some households had been able to eat as healthily as before while spending less. More research was needed to see why this was not the case for other households, the researchers added.The study looked at data on more than 15,000 households\' shopping habits collected by market research company Kantar Worldpanel between 2005 and 2012.The figures do not include meals purchased or provided away from home, for example in restaurants or at schools, which in England provide free lunches for poorer pupils.The study was released alongside a piece of longer-term research from the IFS, which showed the English now consume 15-30 percent fewer calories than in 1980, despite higher obesity rates probably due to less physical activity.This contrasts with the United States, where calorie consumption has risen as well as obesity. The IFS said it was were researching further into trends in Britons\' physical activity over the period.',
要拆分的代码:
from __future__ import unicode_literals
import spacy
nlp = spacy.load('en')
doc1 = nlp(article_to_json['body'].decode('utf-8'), parse=True)
for number, sent in enumerate(doc1.sents):
print number, sent, "\n"
输出:
0 LONDON Nov 4 Britons hurt by lower incomes and rising food prices after the financial crisis have cut back on fruit and vegetables and turned instead to fatty, sugary, processed food, an academic study showed on Monday.
1 Britain has seen food prices rise much more sharply than most other developed economies between 2005 and 2012, while wage growth has been low and unemployment has risen.
2 The net effect has been that Britons are spending 8.5 percent less in real terms on food purchased at home than before the recession - with the trend even greater for pensioners and families with young children.
3 The research is likely to be politically sensitive at a time when Britain's Conservative-led government is under pressure from the opposition Labour Party, over declining standards of living and sharply rising demand at food banks which hand out free food to the poorest Britons.
4 People have economised by buying less food, measured in number of calories, but also on its quality, picking products that are less nutritious and higher in saturated fat and sugar."Various measures of nutritional quality declined over this period, with bigger decreases for pensioner households and households with young children," said the Institute for Fiscal Studies, an economics research body.
5 OBESITY Families with children were prone to switching to more sugary food, while pensioners favoured food high in saturated fat, the study showed.
6 Both groups often have lower incomes.
7 While the economy is starting to show signs of growth after suffering the biggest hit to economic growth since records began during the 2008-09 recession, households' disposable incomes are no higher than a decade ago.
8 However, the IFS said a lower-quality diet was not an inevitable consequence of having less money, and that some households had been able to eat as healthily as before while spending less.
9 More research was needed to see why this was not the case for other households, the researchers added.
10 The study looked at data on more than 15,000 households' shopping habits collected by market research company Kantar Worldpanel between 2005 and 2012.The figures do not include meals purchased or provided away from home, for example in restaurants or at schools, which in England provide free lunches for poorer pupils.
11 The study was released alongside a piece of longer-term research from the IFS, which showed the English now consume 15-30 percent fewer calories than in 1980, despite higher obesity rates probably due to less physical activity.
12 This contrasts with the United States, where calorie consumption has risen as well as obesity.
13 The IFS said it was were researching further into trends in Britons' physical activity over the period.
最佳答案
我用谷歌搜索了原始新闻文章,试图找出为什么你的数据看起来像这样(句子之间缺少空格,而我在正式的新闻文章中不会想到它),看起来最初的问题是没有HTML 段落之间插入空格。如果您可以通过从原始 HTML 中提取文章的方式来解决该问题(在遇到
或
时插入空格),则使用 spacy 或其他工具就不会遇到此问题。标准工具中可用的模型通常会在新闻数据上进行训练,并且可以合理地期望它们能够很好地处理这样的数据,但它们期望句子之间有空格。除非您使用包含句子之间缺少空格的数据重新训练模型(或按照评论中的建议预处理数据),否则您将会遇到此类问题。
关于python - spaCy 句子分割在引号上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44853107/
我有一段文本和索引条目,其中一些指示出现在文本中的重要多词表达 (MWE)(例如生物学文本的“海绵骨”)。我想使用这些条目在 spaCy 中构建自定义匹配器,以便我可以识别文本中出现的 MWE。一个附
我想在 Spacy 中使用德语 lemmatizer,但我对结果感到非常惊讶: import spacy nlp = spacy.load("de_dep_news_trf") [token.lemm
要将我的句子拆分为标记,我正在执行以下操作,这很慢 import spacy nlp = spacy.load("en_core_web_lg") text = "This is a test.
我已经使用空间很长一段时间了,我真的很喜欢这种置换 有没有一种方法可以让我们在网页中从我的数据集中提供多个文本,如一个小箭头,以重定向到下一条记录并标记实体。 我使用的代码如下。 def valida
我有变量 trainData它具有以下简化格式。 [ ('Paragraph_A', {"entities": [(15, 26, 'DiseaseClass'), (443, 449, 'Disea
我正在尝试测试在另一台计算机上运行的模型,但是当我尝试将其导入我的笔记本时,出现以下错误:ModuleNotFoundError:没有名为“spacy.pipeline.pipes”的模块; 'spa
我正在尝试测试在另一台计算机上运行的模型,但是当我尝试将其导入我的笔记本时,出现以下错误:ModuleNotFoundError:没有名为“spacy.pipeline.pipes”的模块; 'spa
当处理数百万文档并将它们保存为空间文档以供以后使用(更多处理、可视化、提取特征)时,一种明显的扩展解决方案是并行/分布式处理。这意味着每个并行进程都将拥有自己的 Vocab,这些 Vocab 可能会随
我正在使用 Spacy 大型模型,但它错误地使用与我的领域无关的类别标记实体,例如“艺术作品”可能导致它无法识别本应属于组织的内容。 是否可以限制 NER 仅返回人员、位置和组织? 最佳答案 简答:
我正在像这样使用 SpaCy 创建一个短语匹配器: import spacy from spacy.matcher import PhraseMatcher nlp = spacy.load("en"
我正在尝试使用 spaCy Matcher 工作获得以下简单示例: import en_core_web_sm from spacy.matcher import Matcher nlp = en_c
它没有出现在 pip list zeke$ pip list | grep spacy spacy (1.7.3) 如何获取模型名称? 我试过了,还是不行 echo "spaCy model:" py
我在 "Training an additional entity type" 中有新 NER 类型的训练数据spaCy 文档的部分。 TRAIN_DATA = [ ("Horses are
给定一个 token ,它是具有多个 token 的命名实体的一部分,是否有直接方法来获取该实体的跨度? 例如,考虑这个有两个词命名实体的句子: >>> doc = nlp("This year wa
如何限制 Spacy 使用的 CPU 数量? 我想从大量句子中提取词性和命名实体。由于 RAM 的限制,我首先使用 Python NLTK 将我的文档解析为句子。然后我遍历我的句子并使用 nlp.pi
显然 for doc in nlp.pipe(sequence) 比运行 for el in order: doc = nlp(el) .. 我遇到的问题是我的序列实际上是一个元组序列,其中包含用于将
显然 for doc in nlp.pipe(sequence) 比运行 for el in order: doc = nlp(el) .. 我遇到的问题是我的序列实际上是一个元组序列,其中包含用于将
我已经下载了 spaCy,但每次尝试 nlp = spacy.load("en_core_web_lg") 命令时,我都会收到此错误: OSError:[E050] 找不到模型“en_core_web
到目前为止,我一直在使用 spacy 2.3.1,并为我的自定义语言类(class)训练并保存了几个管道。但是现在使用 spacy 3.0 和 spacy.load('model-path') 我遇到
我安装了 spacy 使用 python3 install spacy 并使用下载了两个英文模型 python3 -m spacy download en 和 python3 -m spacy dow
我是一名优秀的程序员,十分优秀!