【发布时间】:2018-12-23 12:22:12
【问题描述】:
如何使“文档中的第一个词是 [目标词]”成为一项功能?
考虑这两句话:
example = ["At the moment, my girlfriend is Jenny. She is working as an artist at the moment.",
"My girlfriend is Susie. She is working as an accountant at the moment."]
如果我试图衡量关系承诺,我希望能够将“此刻”这个短语视为一个特征仅当它以这样的开头出现时。
我希望喜欢能够在词汇表中使用正则表达式...
phrases = ["^at the moment", 'work']
vect = CountVectorizer(vocabulary=phrases, ngram_range=(1, 3), token_pattern=r'\w{1,}')
dtm = vect.fit_transform(example)
但这似乎不起作用。
我也试过这个,但是得到一个“词汇为空”的错误......
CountVectorizer(token_pattern = r"(?u)^currently")
这样做的正确方法是什么?我需要自定义矢量化器吗?有什么简单的教程可以链接我吗?这是我的第一个 sklearn 项目,我已经在谷歌上搜索了好几个小时。非常感谢任何帮助!
【问题讨论】:
标签: python scikit-learn nlp text-classification countvectorizer