当前位置:网站首页>深度学习——词汇表征
深度学习——词汇表征
2022-06-30 07:22:00 【头发没了还会再长】
词嵌入
(word embeddings),是语言表示的一种方式,可以让算法自动的理解一些类似的词,比如男人对女人,比如国王对王后,还有其他很多的例子。通过词嵌入的概念你就可以构建 NLP 应用了,即使你的模型标记的训练集相对较小。
词汇表示
目前为止我们一直都是用词汇表来表示词,上周提到的词汇表,可能是 10000 个单词,我们一直用 one-hot 向量来表示词。比如如果 man在词典里是第 5391 个,那么就可以表示成一个向量,只在第 5391 处为 1,我们用𝑂5391代表这个量,这里的𝑂代表 one-hot。这种表示方法的一大缺点就是它把每个词孤立起来,这样使得算法对相关词的泛化能力不强。
举个例子,假如你已经学习到了一个语言模型,当你看到“I want a glass of orange ___”,那么下一个词会是什么?很可能是 juice。即使你的学习算法已经学到了“I want a glass of orange juice”这样一个很可能的句子,但如果看到“I want a glass of apple ___”,因为算法不知道 apple 和 orange 的关系很接近,就像 man 和 woman,king 和 queen 一样。所以算法很难从已经知道的 orange juice 是一个常见的东西,而明白 apple juice 也是很常见的东西或者说常见的句子。这是因为任何两个 one-hot 向量的内积都是 0,如果你取两个向量,比如 king和 queen,然后计算它们的内积,结果就是 0。如果用 apple 和 orange 来计算它们的内积,结果也是 0。很难区分它们之间的差别,因为这些向量内积都是一样的,所以无法知道 apple和 orange 要比 king 和 orange,或者 queen 和 orange 相似地多。
如果我们不用 one-hot 表示,而是用特征化的表示来表示每个词,man,woman,king,queen,apple,orange 或者词典里的任何一个单词,我们学习这些词的特征或者数值。
举个例子,对于这些词,比如我们想知道这些词与 Gender(性别)的关系。假定男性的性别为-1,女性的性别为+1,那么 man 的性别值可能就是-1,而 woman 就是1。最终根据经验 king 就是-0.95,queen 是+0.97,apple 和 orange 没有性别可言。另一个特征可以是这些词有多 Royal(高贵),所以这些词,man,woman 和高贵没太关系,所以它们的特征值接近 0。而 king 和 queen 很高贵,apple 和 orange 跟高贵也没太大关系。
所以你可以想很多的特征,为了说明,我们假设有 300 个不同的特征,这样的话你就有了这一列数字,这里我只写了 4 个,实际上是 300 个数字,这样就组成了一个 300 维的向量来表示 man 这个词。接下来,我想用𝑒5391这个符号来表示,就像这样。同样这个 300 维的向量,我用𝑒9853代表这个 300 维的向量用来表示woman 这个词,这些其他的例子也一样。现在,如果用这种表示方法来表示 apple 和 orange 这些词,那么 apple 和 orange 的这种表示肯定会非常相似,可能有些特征不太一样,因为 orange 的颜色口味,apple 的颜色口味,或者其他的一些特征会不太一样,但总的来说 apple 和 orange 的大部分特征实际上都一样,或者说都有相似的值。这样对于已经知道 orange juice 的算法很大几率上也会明白 apple juice 这个东西,这样对于不同的单词算法会泛化的更好。
如果我们能够学习到一个 300 维的特征向量,或者说 300 维的词嵌入,通常我们可以做一件事,把这 300 维的数据嵌入到一个二维空间里,这样就可以可视化了。常用的可视化算法是 t-SNE 算法,来自于 Laurens van der Maaten 和 Geoff Hinton 的论文。如果观察这种词嵌入的表示方法,你会发现 man 和 woman 这些词聚集在一块,king 和queen 聚集在一块,这些都是人,也都聚集在一起。动物都聚集在一起,水果也都聚集在一起,像 1、 2、3、4 这些数字也聚集在一起。如果把这些生物看成一个整体,他们也聚集在一起。
这种词嵌入算法对于相近的概念,学到的特征也比较类似,在对这些概念可视化的时候,这些概念就比较相似,最终把它们映射为相似的特征向量。这种表示方式用的是在 300 维空间里的特征表示,这叫做嵌入
(embeddings)。
叫嵌入的原因是,你可以想象一个 300 维的空间,我画不出来 300 维的空间,这里用个 3 维的代替。现在取每一个单词比如 orange,它对应一个 3 维的特征向量,所以这个词就被嵌在这
个 300 维空间里的一个点上了,apple 这个词就被嵌在这个 300 维空间的另一个点上了。为了可视化,t-SNE
算法把这个空间映射到低维空间,你可以画出一个 2 维图像然后观察,这就是这个术语嵌入的来源。
边栏推荐
- Use of ecostruxure (2) IEC61499 to establish function blocks
- Final review -php learning notes 1
- 期末複習-PHP學習筆記5-PHP數組
- Variable storage unit and pointer
- Final review -php learning notes 3-php process control statement
- 25岁,从天坑行业提桶跑路,在经历千辛万苦转行程序员,属于我的春天终于来了
- Efga design open source framework fabulous series (I) establishment of development environment
- Line fitting (least square method)
- 线程池——C语言
- Deloitte: investment management industry outlook in 2022
猜你喜欢
Final review -php learning notes 6- string processing
Keil plug-in Usage Summary
Network, network card and IP configuration
Self study notes -- use of 74h573
Research Report on search business value in the era of big search in 2022
Final review -php learning notes 1
Processes, jobs, and services
Final review -php learning notes 4-php custom functions
Investment and financing analysis report of Supply Chain & logistics industry in 2021
線程池——C語言
随机推荐
NMOS model selection
Periodic planning work
Commands and permissions for directories and files
Use of ecostruxure (2) IEC61499 to establish function blocks
STM32 infrared communication 3 brief
Network, network card and IP configuration
1、 Output debugging information: makefile file debugging information $(warning "tests" $(mkfile\u path)); makefile file path
Deloitte: investment management industry outlook in 2022
Xiashuo think tank: 50 planet updates reported today (including the global architects Summit Series)
Shell command, how much do you know?
right four steps of SEIF SLAM
Cubemx completes STM32F103 dual serial port 485 transceiver transmission
Directory of software
Binary tree related operations (based on recursion, implemented in C language)
342 maps covering exquisite knowledge, one of which is classic and pasted on the wall
Spring Festival inventory of Internet giants in 2022
Program acceleration
next InitializeSecurityContext failed: Unknown error (0x80092012) - 吊销功能无法检查证书是否吊销。
Minecraft 1.16.5模组开发(五十) 书籍词典 (Guide Book)
Halcon: read the camera and binary it