gpt4 book ai didi

list - 使用 Python 和 NLP 从列表中获取最频繁的 POS 标签

转载 作者:行者123 更新时间:2023-12-01 18:27:17 26 4
gpt4 key购买 nike

我正在尝试从列表中获取最常见的 POS 标签(前五个)。

pos_list = nltk.pos_tag(list)
#pos_list = [('caught', 'NN'), ('black', 'NN'), ('a', 'DT'), ('striped', 'JJ'), ('eel', 'NN')]
tag_fd = nltk.FreqDist(tag for (word, tag) in pos_list)

我也试过循环遍历 pos_list 来计算标签,但似乎必须有一种方法可以使用 NLTK 来做到这一点。我还尝试从列表中创建一个字符串并尝试相同的方法,但这也不起作用。

str_of_list = " ".join(list)
tag_fd = nltk.FreqDist(tag for (word, tag) in str_of_list)

感谢任何帮助!

最佳答案

我不确定在 NLTK 中是否有办法做到这一点,但 collections.Counter 肯定有办法:

import collections

pos_list = nltk.pos_tag(list)
pos_counts = collections.Counter((subl[1] for subl in pos_list))
print "the five most common tags are", pos_counts.most_common(5)

关于list - 使用 Python 和 NLP 从列表中获取最频繁的 POS 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26365791/

26 4 0