作者ctr1 (【积π】)
看板DataScience
标题Fw: [问题] Bag of words 中文单字词问题
时间Tue Jun 26 11:12:34 2018
※ [本文转录自 Python 看板 #1RCQbiCM ]
作者: ctr1 (【积π】) 看板: Python
标题: [问题] Bag of words 中文单字词问题
时间: Tue Jun 26 10:48:06 2018
from sklearn.feature_extraction.text import CountVectorizer
text = [
"我|爱你",
"他|爱狗",
"猫|爱鼠"
]
vectorizer = CountVectorizer()
vectorizer.fit(text)
vector = vectorizer.transform(text)
print (vectorizer.vocabulary_)
# 维度
print (vector.shape)
print (vector.toarray())
▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂
输出:
{'爱你': 0, '爱狗': 1, '爱鼠': 2}
(3, 3)
[[1 0 0]
[0 1 0]
[0 0 1]]
▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂
想请问版上的各位大大
若是我希望单字(我、他、猫)也要放在bag内
要如何改写这段程式
或要用什麽关键字去google查询呢
谢谢打家
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 59.124.158.195
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1529981292.A.316.html
※ 编辑: ctr1 (59.124.158.195), 06/26/2018 10:50:29
※ 发信站: 批踢踢实业坊(ptt.cc)
※ 转录者: ctr1 (59.124.158.195), 06/26/2018 11:12:34
1F:推 jr55662003: 用结巴断词? 06/26 16:29
2F:推 b24333666: 把 |换成空白 06/27 07:05
3F:→ b24333666: google tokenization nlp 06/27 07:07
4F:→ ctr1: |就是用结巴断词出来的,换成空白还是一样呢。 06/27 08:29