word2vec 小测试
Bag-of-words Model
Previous state-of-the-art document representations were based on the bag-of-words model, which represent input documents as a fixed-length vector. For example, borrowing from the Wikipedia article, the two documents
(1) John likes to watch movies. Mary likes movies too.
(2) John also likes to watch football games.
are used to construct a length 10 list of words["John", "likes", "to", "watch", "movies", "Mary", "too", "also", "football", "games"]
so then we can represent the two documents as fixed length vectors whose elements are the frequencies of the corresponding words in our list
(1) [1, 2, 1, 1, 2, 1, 1, 0, 0, 0]
(2) [1, 1, 1, 1, 0, 0, 0, 1, 1, 1]
Bag-of-words models are surprisingly effective but still lose information about word order. Bag of n-grams models consider word phrases of length n to represent documents as fixed-length vectors to capture local word order but suffer from data sparsity and high dimensionality.
word2vec 中的数学原理详解
自己动手写word2vec (一):主要概念和流程
1、稀疏向量,又称为one-hot representation2、密集向量,又称distributed representation,即分布式表示。其实word2vec做的事情很简单,大致来说,就是构建了一个多层神经网络,然后在给定文本中获取对应的输入和输出,在训练过程中不断修正神经网络中的参数,最后得到词向量。word2vec采用的是n元语法模型(n-gram model),即假设一个词只与周围n个词有关,而与文本中的其他词无关。这种模型构建简单直接,也有后续的各种平滑方法。CBOW模型:输入是某个词A周围的n个单词的词向量之和,输出是词A本身的词向量;skip-gram模型:输入是词A本身,输出是词A周围的n个单词的词向量(要循环n遍)。 tensorflow笔记:使用tf来实现word2vec
利用Python实现中文情感极性分析
#-*- coding:utf-8 -*-
from sklearn.datasets import fetch_20newsgroups from bs4 import BeautifulSoup import nltk import re from gensim.models import word2vec news = fetch_20newsgroups(subset='all') X, y = news.data, news.target def news_to_sentences(news): news_text = BeautifulSoup(news, 'html.parser').get_text() #分成句子 tokenizer = nltk.data.load('tokenizers/punkt/english.pickle') raw_sentences = tokenizer.tokenize(news_text) #分成单词 sentences = [] for sent in raw_sentences: sentences.append(re.sub('[^a-zA-Z]', ' ', sent.lower().strip()).split()) return sentences sentences = [] for x in X: sentences += news_to_sentences(x) # Set values for various parameters num_features = 300 # Word vector dimensionality min_word_count = 20 # Minimum word count num_workers = 2 # Number of threads to run in parallel context = 5 # Context window size downsampling = 1e-3 # Downsample setting for frequent words model = word2vec.Word2Vec(sentences, workers=num_workers, \ size=num_features, min_count = min_word_count, \ window = context, sample = downsampling) model.init_sims(replace=True) print model.most_similar('morning')
word2vec 小测试的更多相关文章
- Cad 二次开发关于SelectCrossingPolygon和SelectFence返回结果Status为error的小测试
CAD2008的二次开发,有个很奇怪的现象,只要你选择的点集不在当前视图上SelectCrossingPolygon和SelectFence返回结果Status就会为error,所以要获取正确的结果, ...
- python 程序小测试
python 程序小测试 对之前写的程序做简单的小测试 ... # -*- encoding:utf-8 -*- ''' 对所写程序做简单的测试 @author: bpf ''' def GameOv ...
- PHP中使用PDO操作事务的一些小测试
关于事务的问题,我们就不多解释了,以后在学习 MySQL 的相关内容时再深入的了解.今天我们主要是对 PDO 中操作事务的一些小测试,或许能发现一些比较好玩的内容. 在 MyISAM 上使用事务会怎么 ...
- HTTP性能小测试
一直说node.js如何如何好,就来测试一下吧~~ 首先接受一个小工具 Apache Bench简称ab 可以用来测试http性能 利用Apache Bench测试Web引擎性能关于此工具的详细介绍参 ...
- mysql注入小测试
转自:http://www.jb51.net/article/46163.htm 在开发网站的时候,出于安全考虑,需要过滤从页面传递过来的字符.通常,用户可以通过以下接口调用数据库的内容:URL地址栏 ...
- SpringMvc拦截器小测试
前言 俗话说做项目是让人成长最快的方案,最近小编写项目的时候遇到了一个小问题.小编在项目中所负责的后台系统,但是后台系统是通过系统的页面是通过ifame联动的,那么这时候问题就来了,后台所做的所有操作 ...
- 曲演杂坛--Update的小测试
今天偶然想起一个UPDATE相关的小问题,正常情况下,如果我们将UPDATE改写成与之对应的SELECT语句,其SELECT查询结果应与UPDATE的目标表存在一对一的关系,例如: 对于UPDATE语 ...
- Python之小测试:用正则表达式写一个小爬虫用于保存贴吧里的所有图片
很简单的两步: 1.获取网页源代码 2.利用正则表达式提取出图片地址 3.下载 #!/usr/bin/python #coding=utf8 import re # 正则表达式 import urll ...
- Unity 联网小测试(WWW)
研究了很多联网的方式,甚至把TCP/IP,shock,HTTP的关系都搞清楚了,终于弄明白怎么在Unity中用GET或POST的方式通信了,还是有点小激动的,但是不排除有更好的方式,听说Unity还是 ...
随机推荐
- MongoDB(课时22 过期索引)
3.6.2 过期索引 在一些程序的站点会出现若干秒之后信息被删除的情况,例如:手机信息验证码,那么在MongoDB里面可以轻松实现过期索引.但这个时间往往不怎么准确. 范例:设置过期索引(实现过期索引 ...
- 使用 apply 函数族
之前,我们讨论过可以使用 for 循环,在一个向量或列表上进行迭代,重复执行某个表达式.但是在实践中,for 循环往往是最后的选择,因为每次迭代都是相互独立的,所以我们可以使用更简洁更方便的读写方式来 ...
- Tomcat启动之异常java.lang.IllegalStateException
严重: Exception sending context destroyed event to listener instance of class org.springframework.web. ...
- 链表排序 Sort List
2018-08-11 23:50:30 问题描述: 问题求解: 解法一.归并排序 public ListNode sortList(ListNode head) { if (head == null ...
- 在 Confluence 6 中的 Jira 高级权限
启用嵌套用户组(Enable Nested Groups) 为嵌套组启用或禁用支持. 在启用嵌套用户组之前,你需要检查你在 JIRA 服务器中的嵌套用户组是否启用了.当嵌套用户组启用成功后,你可以将一 ...
- 『Kaggle』Sklearn中几种分类器的调用&词袋建立
几种分类器的基本调用方法 本节的目的是基本的使用这些工具,达到熟悉sklearn的流程而已,既不会设计超参数的选择原理(后面会进行介绍),也不会介绍数学原理(应该不会涉及了,打公式超麻烦,而且近期也没 ...
- hdu3294 manacher
One day, sailormoon girls are so delighted that they intend to research about palindromic strings. O ...
- thinkphp3.2导出
public function test() { set_time_limit(0); ini_set('memory_limit', '500M'); //导入PHPExcel类库,因为PHPExc ...
- OC Block(代码块)
#import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...
- CentOS 7中firewall防火墙详解和配置以及切换为iptables防火墙
官方文档介绍地址: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Security_Gui ...