【问题标题】:CountVectorizer Token PatternCountVectorizer 令牌模式
【发布时间】:2017-08-14 02:41:21
【问题描述】:

我需要 scikit-learn CountVectorizer 将包含符号“-”的词识别为一个标记词。这是因为我会处理诸如“烹饪时间”之类的标签,这些标签不应一分为二。

我想重点是在 token_pattern 参数中设置正确的正则表达式,但我无法做到这一点。

我正在尝试类似的东西

token_pattern=u'(?u)\b\w\w+(-)?\w+\b'

【问题讨论】:

  • 应用此正则表达式后的任何正面和反面例子?

标签: python machine-learning scikit-learn


【解决方案1】:

编写自己的分词器更容易,例如:

def Tokenize(text):
    for char in (',', ';', ':'):  # Here the special chars you want to remove
        text.replace(char, '')
    return text.split(' ')

然后直接将 callable(不带尾括号的函数)传递给 CountVectorizer。

【讨论】:

    猜你喜欢
    • 2016-06-22
    • 2018-10-13
    • 1970-01-01
    • 2018-09-23
    • 2014-09-12
    • 2020-09-14
    • 2015-05-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多