我需要scikit learn CountVectorizer来识别包含符号'-‘的单词作为一个令牌。这是因为我处理的是不能一分为二的“烹饪时间”这样的标签。
我想重点是在token_pattern参数中设置正确的正则表达式,但我无法做到这一点。
我正在尝试像这样的东西
token_pattern=u'(?u)\b\w\w+(-)?\w+\b'发布于 2017-03-22 15:36:35
只需编写自己的记号赋予器就更容易了,例如:
def Tokenize(text):
for char in (',', ';', ':'): # Here the special chars you want to remove
text.replace(char, '')
return text.split(' ')然后将可调用函数(不带括号的函数)直接传递给CountVectorizer。
https://stackoverflow.com/questions/42943936
复制相似问题