gpt4 book ai didi

python - 确定一个句子的时态Python

转载 作者:太空狗 更新时间:2023-10-29 18:08:40 26 4
gpt4 key购买 nike

在其他几篇文章之后,[例如Detect English verb tenses using NLTK , Identifying verb tenses in python , Python NLTK figure out tense ] 我编写了以下代码来使用 POS 标记在 Python 中确定句子的时态:

from nltk import word_tokenize, pos_tag

def determine_tense_input(sentence):
text = word_tokenize(sentence)
tagged = pos_tag(text)

tense = {}
tense["future"] = len([word for word in tagged if word[1] == "MD"])
tense["present"] = len([word for word in tagged if word[1] in ["VBP", "VBZ","VBG"]])
tense["past"] = len([word for word in tagged if word[1] in ["VBD", "VBN"]])
return(tense)

这会返回过去/现在/将来动词用法的值,然后我通常将其取最大值作为句子的时态。准确性还算不错,但我想知道是否有更好的方法。

比如现在有没有写一个更专用于提取句子时态的包? [注意 - 3 个堆栈溢出帖子中有 2 个是 4 年前的,所以现在情况可能已经改变]。或者,我应该在 nltk 中使用不同的解析器来提高准确性吗?如果没有,希望上面的代码可以帮助其他人!

最佳答案

您可以通过多种方式加强您的方法。您可以更多地考虑英语语法,并根据您观察到的内容添加更多规则;或者您可以插入统计方法,提取更多(相关)特征并将所有特征扔给分类器。 NLTK 为您提供了大量可供使用的分类器,并且在 NLTK 书中对它们进行了详细记录。

您可以两全其美:手写规则可以采用提供给分类器的特征形式,分类器将决定何时可以依赖它们。

关于python - 确定一个句子的时态Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30016904/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com