首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在不松开句子主语的情况下进行分词?

如何在不松开句子主语的情况下进行分词?
EN

Data Science用户
提问于 2022-03-07 10:08:00
回答 2查看 263关注 0票数 3

我有一些长度不同的文本,我想把它分成不同的分句,但我也想保留主题。

例如;

代码语言:javascript
运行
复制
# single subject
Original: "Coffee is very good, but wasn't hot enough"
split: ["Coffee is very good", "Coffee wasn't hot enough"]

Original: "Joe was the top performer of last year's dance competition, he is also a good singer"
split: ["Joe was the top performer of last year's dance competition", "Joe is a good singer"]

# multiple subjects
Original: "Delicious food service, but we struggled with the app."
split: ["Delicious food service", "We struggled with the app"]

我不知道如何做到这一点,我们可以根据标点符号和连词来分割句子(可能不准确),但我们如何保留它的主题。

如果你需要更多的信息,请告诉我。

EN

回答 2

Data Science用户

回答已采纳

发布于 2022-03-10 05:15:21

经过大量的研究,我想出了如何用各自的主语来代替代词。它利用neuralcoref作为spaCy 2.1+的流水线扩展,利用神经网络对同轴电缆簇进行标注和解析。

但是,它只适用于spacy v2和python3.7 --我在conda环境中使用以下工具版本对其进行了测试

代码语言:javascript
运行
复制
python==3.7
spacy==2.1.0
neuralcoref

解决办法是这样的

代码语言:javascript
运行
复制
import spacy
import neuralcoref

nlp = spacy.load('en_core_web_sm')
neuralcoref.add_to_pipe(nlp)

doc = nlp("Coffee is good but it wasn't hot enough!")
print(f'\n[REPLACED]:\n{doc._.coref_resolved}')

# output
Coffee is good but Coffee wasn't hot enough!

更多样本输出

代码语言:javascript
运行
复制
[Enter your text]:
Joe was the top performer of last year's dance competition, he is also a good singer

[REPLACED]:
Joe was the top performer of last year's dance competition, Joe is also a good singer

[CONTINUE(Y/N)?]: y

[Enter your text]:
Paul was amazing and so was our waiter I loved the squash pizza and the dessert he recommended will definitely come back soon.

[REPLACED]:
Paul was amazing and so was our waiter I loved the squash pizza and the dessert Paul recommended will definitely come back soon.

我还在努力找出一种更好的方法来分句。一旦我想出答案就会更新答案。

票数 2
EN

Data Science用户

发布于 2022-03-07 13:18:55

这不是真正的句子切分,因为输入已经是一个句子。

这是接近关系提取,但我不知道它是否适用于这里。很明显,至少需要进行一些最小的语义分析才能识别主题。这可以用依赖分析依赖分析来完成,然后可能是语义角色标注

请注意,如果句子是被动的,或者在其他各种情况下,例如“去年表现最好的是乔”,事情就会变得复杂起来。

票数 3
EN
页面原文内容由Data Science提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://datascience.stackexchange.com/questions/108832

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档