The amazing power of word vectors | the morning paper (acolyer.org)

What is a word vector?

At one level, it’s simply a vector of weights. In a simple 1-of-N (or ‘one-hot’) encoding every element in the vector is associated with a word in the vocabulary. The encoding of a given word is simply the vector in which the corresponding element is set to one, and all other elements are zero.

从某种角度来说,词向量(word vector)仅仅是对应单词的权重用的向量化表示。在独热编码中,向量中的每个编码元素与一个文本对应的词汇表中的特定的一个单词有联系,一个单词会对应一个独热向量,这个独热向量中对应这个单词的维度的元素会被置为1,其余的全都置为0.

Suppose our vocabulary has only five words: King, Queen, Man, Woman, and Child. We could encode the word ‘Queen’ as:

假设我们的词汇表只有5个单词,国王、女王、男人、女人和孩子,那么我们可以把“女王”编码为:

Using such an encoding, there’s no meaningful comparison we can make between word vectors other than equality testing.

但是这样的编码会使得两个向量之间没有什么比较意义,除了判断两个向量是否相等。

In word2vec, a distributed representation of a word is used. Take a vector with several hundred dimensions (say 1000). Each word is representated by a distribution of weights across those elements. So instead of a one-to-one mapping between an element in the vector and a word, the representation of a word is spread across all of the elements in the vector, and each element in the vector contributes to the definition of many words.

在word2vec中,我们对单词使用了一种数值分散(非零数值分散)的表示方法。假设一个向量有好几百维(比如1000维),每个单词都会被1000个权重表示,这些权重很有可能非零而且表示的是与其他单词的关系的大小。所以一个单词的表示会与这个1000维的向量的所有其他元素都有关系,每个元素都会对这个单词的定义做或多或少的贡献,所以我们会用其代替使用一 一映射的独热编码来表示单词或词组。

royaling:与皇室相关的;masculining:与男子汉气概相关的;feminining:与女子特点相关的;Age:年龄。

从图中我们可以看到,King和Queen与royaling很相关,这显而易见,所以这个维度上King和Queen的分数应该要高点,其他也是如此。

另外可以这样思考:VGueen - VWoman = [0.97 0.04 -0.069 0.1](记为Vt),这个向量表示什么意思?Vman+Vt 等于什么呢?约等于VKing吗?下面会给出答案。

Reasoning with word vectors

We find that the learned word representations in fact capture meaningful syntactic and semantic regularities in a very simple way. Specifically, the regularities are observed as constant vector offsets between pairs of words sharing a particular relationship. For example, if we denote the vector for word i as xi, and focus on the singular/plural relation, we observe that xapple – xapples ≈ xcar – xcars, xfamily – xfamilies ≈ xcar – xcars, and so on. Perhaps more surprisingly, we find that this is also the case for a variety of semantic relations, as measured by the SemEval 2012 task of measuring relation similarity.

我们发现模型学习到的词表示方法(词向量)实际上能够以一种很简单的方式表示单词对应的语法(Kings,King)和语义规律。更具体的来说,这些规律是用拥有特定关系的词对所对应的两个向量的差来表示的。例如,假设我们把单词i对应的向量记为Vi,那么对于表示单复数这个维度上的数值K来说应该有:applesk – applek ≈ carsk – cark, ≈  familiesk – familyk .可能更让人惊讶的是,我们发现在2012年的SemEval关系相似度测量任务中,各种各样的语义(语义:这个单词是什么意思)关系都可以有上述所说的性质。

The vectors are very good at answering analogy questions of the form a is to b as c is to ?. For example, man is to woman as uncle is to ? (aunt) using a simple vector offset method based on cosine distance.

这样的向量非常适合于分析“a对应b,那么c对应什么”这样的分析性问题。例如,如果男人对应女人,那么伯父应该对应什么?(伯母)

For example, here are vector offsets for three word pairs illustrating the gender relation:

如下图所示,图中用向量的差(相对偏移量)表示了三个词对之间的性别关系。

And here we see the singular plural relation:

另外还有单复数的关系:

This kind of vector composition also lets us answer “King – Man + Woman = ?” question and arrive at the result “Queen” !

上图所展示的向量有助于我们回答“国王-男人+女士=?”的问题,另外答案就是“女王”。

利用词向量进行推理(Reasoning with word vectors)的更多相关文章

  1. NLP(二十) 利用词向量实现高维词在二维空间的可视化

    准备 Alice in Wonderland数据集可用于单词抽取,结合稠密网络可实现其单词的可视化,这与编码器-解码器架构类似. 代码 from __future__ import print_fun ...

  2. NLP︱高级词向量表达(一)——GloVe(理论、相关测评结果、R&python实现、相关应用)

    有很多改进版的word2vec,但是目前还是word2vec最流行,但是Glove也有很多在提及,笔者在自己实验的时候,发现Glove也还是有很多优点以及可以深入研究对比的地方的,所以对其进行了一定的 ...

  3. NLP︱词向量经验总结(功能作用、高维可视化、R语言实现、大规模语料、延伸拓展)

    R语言由于效率问题,实现自然语言处理的分析会受到一定的影响,如何提高效率以及提升词向量的精度是在当前软件环境下,比较需要解决的问题. 笔者认为还存在的问题有: 1.如何在R语言环境下,大规模语料提高运 ...

  4. PyTorch基础——词向量(Word Vector)技术

    一.介绍 内容 将接触现代 NLP 技术的基础:词向量技术. 第一个是构建一个简单的 N-Gram 语言模型,它可以根据 N 个历史词汇预测下一个单词,从而得到每一个单词的向量表示. 第二个将接触到现 ...

  5. 词向量word2vec(图学习参考资料)

    介绍词向量word2evc概念,及CBOW和Skip-gram的算法实现. 项目链接: https://aistudio.baidu.com/aistudio/projectdetail/500940 ...

  6. 【CS224n-2019学习笔记】Lecture 1: Introduction and Word Vectors

    附上斯坦福cs224n-2019链接:https://web.stanford.edu/class/archive/cs/cs224n/cs224n.1194/ 文章目录 1.课程简单介绍 1.1 本 ...

  7. 词向量 词嵌入 word embedding

    词嵌入 word embedding embedding 嵌入 embedding: 嵌入, 在数学上表示一个映射f:x->y, 是将x所在的空间映射到y所在空间上去,并且在x空间中每一个x有y ...

  8. Word Representations 词向量

    常用的词向量方法word2vec. 一.Word2vec 1.参考资料: 1.1) 总览 https://zhuanlan.zhihu.com/p/26306795 1.2) 基础篇:  深度学习wo ...

  9. 词袋模型(BOW,bag of words)和词向量模型(Word Embedding)概念介绍

    例句: Jane wants to go to Shenzhen. Bob  wants to go to Shanghai. 一.词袋模型 将所有词语装进一个袋子里,不考虑其词法和语序的问题,即每个 ...

随机推荐

  1. wayne编译支持k8s1.16+

    GitHub: https://github.com/Qihoo360/wayne 文档: 由于wayne 官方文档链接已经失效了,我们可以通过这里查看 wayne 文档, 除了这个地方,我们询问之前 ...

  2. 【LeetCode】825. Friends Of Appropriate Ages 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/friends-o ...

  3. 【LeetCode】589. N-ary Tree Preorder Traversal 解题报告 (Python&C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 迭代 日期 题目地址:https://leetc ...

  4. LeetCode1239串联字符串的最大长度

    题目 给定一个字符串数组 arr,字符串 s 是将 arr 某一子序列字符串连接所得的字符串,如果 s 中的每一个字符都只出现过一次,那么它就是一个可行解. 请返回所有可行解 s 中最长长度. 解题 ...

  5. Robust Pre-Training by Adversarial Contrastive Learning

    目录 概 主要内容 代码 Jiang Z., Chen T., Chen T. & Wang Z. Robust Pre-Training by Adversarial Contrastive ...

  6. PlatformIO+Jlink进行调试

    PlatformIO自带调试功能具体配置如下 https://docs.platformio.org/en/latest/plus/debug-tools/jlink.html     我是用的是直接 ...

  7. Cython编译动态库、引用C/C++文件

    将某些.py 编译成动态库 设置好要编译的module们: compile_to_c_modules = [ 'package.module' ] 将它们转换成cythonize可识别的参数: def ...

  8. 编写Java程序,使用Swing布局管理器和常用控件,实现仿QQ登录界面

    返回本章节 返回作业目录 需求说明: 使用Swing布局管理器和常用控件,实现仿QQ登录界面 实现思路: 创建登录界面的类QQLogin,该类继承父类JFrame,在该类中创建无参数的构造方法,在构造 ...

  9. nginx 安装配置及使用 启动权限拒绝问题

    安装 yum install -y nginx 查看安装的路径 whereis nginx 可能会有所不同 需要根据自己的查看 执行目录:/usr/sbin/nginx 模块所在目录:/usr/lib ...

  10. Zookeeper基础教程(二):Zookeeper安装

    上一篇说了,一个Zookeeper集群一般认为至少需要3个节点,所以我们这里安装需要准备三台虚拟机: # 192.168.209.133 test1 # 192.168.209.134 test2 # ...