gpt4 book ai didi

python - 组合常见搭配的 NLP 过程

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

我有一个语料库,我在 R 中使用 tm 包(并且还在 python 的 NLTK 中镜像相同的脚本)。我正在使用 unigrams,但想要某种解析器将通常位于同一位置的词组合成一个词——即,我不想在我的列表中分别看到“New”和“York”当它们一起出现时的数据集,并看到这个特定的对表示为“New York”,就好像它是一个词,与其他 unigrams 一起出现。

这个过程叫什么,将有意义的、常见的 n-grams 转换到与 unigrams 相同的基础上?这不是一件事吗?最后,tm_map 会是什么?看起来像这个?


mydata.corpus <- tm_map(mydata.corpus, fancyfunction)

和/或在 python 中?

最佳答案

我最近有一个 similar question并尝试搭配

这是我选择用于识别并置词对的解决方案:

from nltk import word_tokenize
from nltk.collocations import *

text = <a long text read in as string string>

tokenized_text = word_tokenize(text)

bigram_measures = nltk.collocations.BigramAssocMeasures(tokenized_text)
finder = BigramCollocationFinder.from_words()
scored = finder.score_ngrams(bigram_measures.raw_freq)

sorted(scored, key=lambda s: s[1], reverse=True)

关于python - 组合常见搭配的 NLP 过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20710593/

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