我正在使用 SklearnCountVectorizer
在字符串上但是CountVectorizer
丢弃文本中的所有表情符号。
例如,???? Welcome
应该给我们:["\xf0\x9f\x91\x8b", "welcome"]
但是,运行时:
vect = CountVectorizer()
test.fit_transform(['???? Welcome'])
我只得到:["welcome"]
这与token_pattern
它不将编码的表情符号算作一个单词,但是有一个自定义的token_pattern
处理表情符号?
是的你是对的!token_pattern
必须改变。我们可以将其设置为,而不仅仅是字母数字字符除空格之外的任何字符.
尝试这个!
from sklearn.feature_extraction.text import TfidfVectorizer
s= ['???? Welcome', '???? Welcome']
v = TfidfVectorizer(token_pattern=r'[^\s]+')
v.fit(s)
v.get_feature_names()
# ['welcome', '????']
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)