gpt4 book ai didi

python - NLTK - 抛出 Stem() 缺少 1 个必需参数错误

转载 作者:太空宇宙 更新时间:2023-11-03 20:16:07 25 4
gpt4 key购买 nike

我正在关注使用 anaconda 的深度学习教程: https://www.youtube.com/watch?v=ICL7VRKvS_A&list=PLzMcBGfZo4-ndH9FoC4YWHGXG5RZekt-Q&index=4

它提示的行:(根据 michotross 的建议编辑)

words = [stemmer.stem(w.lower()) for w in words if w != "?" and w is not None]

显示的错误是:

Traceback (most recent call last):
File "C:/Users/HP X360/PycharmProjects/Mach_Lrn/bot.py", line 30, in <module>
words = [stemmer.stem(w.lower()) for w in words if w != "?" and w is not None]
File "C:/Users/HP X360/PycharmProjects/Mach_Lrn/bot.py", line 30, in <listcomp>
words = [stemmer.stem(w.lower()) for w in words if w != "?" and w is not None]

TypeError: stem() missing 1 required positional argument: 'word'

我对编码相当陌生,有一点谷歌,但我已经从适用于视频的教程中复制了文本,因此我正在寻求一些帮助,我们将非常感激:)

安娜x

最佳答案

将其更改为:

words = [stemmer.stem(w.lower()) for w in words if w.lower() != "?" and w.lower() is not None]

如果您想查看传递给 Stemmer.stem 的内容,请从列表理解转换为常规循环:

stemmed_words = []
for w in words:
try:
stemmed_words.append(stemmer.stem(w.lower()))
except:
print('WORD ->', w.lower(), '<-')

关于python - NLTK - 抛出 Stem() 缺少 1 个必需参数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58436938/

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