gpt4 book ai didi

machine-learning - 如何在 countVectorizer 中使用二元组 + 三元组 + 字标词汇?

转载 作者:行者123 更新时间:2023-11-30 09:31:25 26 4
gpt4 key购买 nike

我使用朴素贝叶斯和 countVectorizer 进行文本分类来对方言进行分类。我读过一篇研究论文,作者使用了以下组合:

bigrams + trigrams + word-marks vocabulary 

他在这里所说的词标是指特定于某种方言的词。

如何调整 countVectorizer 中的这些参数?

文字标记

这些是文字标记的示例,但这不是我所拥有的,因为我的是阿拉伯语。所以我翻译了它们。

word_marks=['love', 'funny', 'happy', 'amazing']

它们用于对文本进行分类。

此外,在这篇文章中: Understanding the `ngram_range` argument in a CountVectorizer in sklearn

有这样的答案:

>>> v = CountVectorizer(ngram_range=(1, 2), vocabulary={"keeps", "keeps the"})
>>> v.fit_transform(["an apple a day keeps the doctor away"]).toarray()
array([[1, 1]]) # unigram and bigram found

我无法理解输出,[1,1] 这里是什么意思?他是如何将 ngram 与词汇结合使用的呢?两者不是互相排斥的吗?

最佳答案

您想要使用 n_gram 范围参数来使用二元组和三元组。在您的情况下,它将是 CountVectorizer(ngram_range=(1, 3))。

查看已接受的答案 to this question了解更多详情。

请为您的问题的其他部分提供“文字标记”的示例。

您可能需要运行 CountVectorizer 两次 - 一次针对 n-gram,一次针对您的自定义字标词汇表。然后,您可以连接两个 CountVectorizer 的两个输出,以获得 n 元语法计数和自定义词汇计数的单个功能集。上述问题的答案还解释了如何为 CountVectorizer 的第二次使用指定自定义词汇表。

这是一个SO answer关于连接数组

关于machine-learning - 如何在 countVectorizer 中使用二元组 + 三元组 + 字标词汇?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56083449/

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