ValueError 在 Word2vec 中解包

发布于 2025-01-16 13:36:06 字数 375 浏览 5 评论 0原文

我有停用词和列表 1,希望在删除停用词后获得列表 2

stopwords= [" I ", " in ", " a ", " m ", " of ", " It ", " is "," all ",  " about ", " you ", " to ", " at "]

list1 = ["I order food in a restaurant","I m fan of soccer","It is all about passion","you want to stay at home"]

list2 = [["order" "food","restaurant"],["fan","soccer"],["passion"],["want","stay","home"]

I have stopwords and list1 and want to get list 2 after removing stopwords

stopwords= [" I ", " in ", " a ", " m ", " of ", " It ", " is "," all ",  " about ", " you ", " to ", " at "]

list1 = ["I order food in a restaurant","I m fan of soccer","It is all about passion","you want to stay at home"]

list2 = [["order" "food","restaurant"],["fan","soccer"],["passion"],["want","stay","home"]

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七分※倦醒 2025-01-23 13:36:06

我不知道你的主题与你所呈现的代码有什么关系,但这里有一种方法可以完成你所要求的:

stopwords= [" I ", " in ", " a ", " m ", " of ", " It ", " is "," all ", " about ", " you ", " to ", " at "]

list1 = ["I order food in a restaurant","I m fan of soccer","It is all about passion","you want to stay at home"]

# remove spaces and lowerize each stop word
stopwords = [w.lower().strip() for w in stopwords]

# process each sentence, and for each sentence, each word
list2 = [[word for word in words.split() if word.lower() not in stopwords] for words in list1]

print(list2)

结果:

[['order', 'food', 'restaurant'], ['fan', 'soccer'], ['passion'], ['want', 'stay', 'home']]

I don't know what your subject has to do with the code you're presenting, but here's a way to accomplish what you're asking for:

stopwords= [" I ", " in ", " a ", " m ", " of ", " It ", " is "," all ", " about ", " you ", " to ", " at "]

list1 = ["I order food in a restaurant","I m fan of soccer","It is all about passion","you want to stay at home"]

# remove spaces and lowerize each stop word
stopwords = [w.lower().strip() for w in stopwords]

# process each sentence, and for each sentence, each word
list2 = [[word for word in words.split() if word.lower() not in stopwords] for words in list1]

print(list2)

Result:

[['order', 'food', 'restaurant'], ['fan', 'soccer'], ['passion'], ['want', 'stay', 'home']]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文