Gensim学习笔记-1--理解corpora.Dictionary
2015-08-17 09:10
288 查看
gensim使用python标准的logging包,引入方式为:
import logging
logging.basicConfig(format=’%(asctime)s : %(levelname)s : %(message)s’, level=logging.INFO)
学习任何开源项目首先都要理解其中的专业术语。
gensim中的必须理解的概念有:
1 raw strings 原始字符串
2 corpora 语料库
3 sparse vectors 稀疏向量
4 vector space model 向量空间模型
5 transformation 转换,指由稀疏向量组成的稀疏矩阵生成某个向量空间模型。
6 index 索引
……
要深入理解开源项目的运行原理,需要认真研究其中的核心对象。
1 corpora.Dictionary 对象
可以理解为python中的字典对象, 其Key是字典中的词,其Val是词对应的唯一数值型ID
构造方法
Dictionary(documents=None, prune_at=2000000)
document参数
Each document is a list of tokens = tokenized and normalized strings (either utf8 or unicode).
也可以是列表的列表例如常见的文档矩阵:
pprint(texts)
[[‘human’, ‘interface’, ‘computer’],
[‘survey’, ‘user’, ‘computer’, ‘system’, ‘response’, ‘time’],
[‘eps’, ‘user’, ‘interface’, ‘system’]]
dictionary = corpora.Dictionary(texts)
prune_at参数
起到控制向量的维数的作用
keeping the total number of unique words <= prune_at
To disable this pruning, set prune_at=None.
常用方法
添加document
add_documents(documents, prune_at=2000000)
压实,使得ID更加紧凑
compactify()
将一个raw string 转换为根据本词典构构造的向量
doc2bow(document, allow_update=False, return_missing=False)¶
If allow_update is set, then also update dictionary in the process: create ids for new words. At the same time, update document frequencies – for each word appearing in this document, increase its document frequency (self.dfs) by one.
去低频、高频词
filter_extremes(no_below=5, no_above=0.5, keep_n=100000)
从已有的语料库中构造
static from_corpus(corpus, id2word=None)¶
合并Dictionary
merge_with(other)
import logging
logging.basicConfig(format=’%(asctime)s : %(levelname)s : %(message)s’, level=logging.INFO)
学习任何开源项目首先都要理解其中的专业术语。
gensim中的必须理解的概念有:
1 raw strings 原始字符串
2 corpora 语料库
3 sparse vectors 稀疏向量
4 vector space model 向量空间模型
5 transformation 转换,指由稀疏向量组成的稀疏矩阵生成某个向量空间模型。
6 index 索引
……
要深入理解开源项目的运行原理,需要认真研究其中的核心对象。
1 corpora.Dictionary 对象
可以理解为python中的字典对象, 其Key是字典中的词,其Val是词对应的唯一数值型ID
构造方法
Dictionary(documents=None, prune_at=2000000)
document参数
Each document is a list of tokens = tokenized and normalized strings (either utf8 or unicode).
也可以是列表的列表例如常见的文档矩阵:
pprint(texts)
[[‘human’, ‘interface’, ‘computer’],
[‘survey’, ‘user’, ‘computer’, ‘system’, ‘response’, ‘time’],
[‘eps’, ‘user’, ‘interface’, ‘system’]]
dictionary = corpora.Dictionary(texts)
prune_at参数
起到控制向量的维数的作用
keeping the total number of unique words <= prune_at
To disable this pruning, set prune_at=None.
常用方法
添加document
add_documents(documents, prune_at=2000000)
压实,使得ID更加紧凑
compactify()
将一个raw string 转换为根据本词典构构造的向量
doc2bow(document, allow_update=False, return_missing=False)¶
If allow_update is set, then also update dictionary in the process: create ids for new words. At the same time, update document frequencies – for each word appearing in this document, increase its document frequency (self.dfs) by one.
去低频、高频词
filter_extremes(no_below=5, no_above=0.5, keep_n=100000)
从已有的语料库中构造
static from_corpus(corpus, id2word=None)¶
合并Dictionary
merge_with(other)
相关文章推荐
- 实现iOS 9 Task Switcher动画
- UVA 10651 Pebble Solitaire
- 《Java设计模式》之观察者模式(1)
- oracle 导入导出语句
- Android开发自学笔记(Android Studio1.3.1)—2.开始第一个Android应用
- 源码推荐(8.17):闪屏效果,简易动画引擎,iOS UIView自定义四个边角的圆角
- HDOJ-1698-线段树成段更新
- 关于私有继承
- CSS实现跨浏览器兼容性的盒阴影效果
- TCP/IP三次握手和四次挥手
- 给网站外链进行重定向跳转
- html选中图片时,在页面回写图片
- 使用select函数改进客户端/服务器端程序
- sed删掉换行符
- 网站设计
- java学习之JAXB解析xml
- recordset.editmode
- nyoj448 寻找最大数
- Tomcat创建虚拟目录和程序热部署
- XlistView改进