目录

前言

一、什么是Skip-gram算法

二、目标是什么

三、定义表示法

3.1 one-hot向量

3.2 词向量(word vector)

3.3 单词矩阵

3.4 单词相似度

3.5 softmax函数

3.6 算法过程

3.7 求softmax

四、skipgram代码实现

4.1 如何把词转换为向量

4.2 CBOW和Skip-gram的算法实现

Skip-gram的理想实现

Skip-gram的实际实现

4.3 使用Pytorch实现Skip-gram

数据处理

网络定义

网络训练


前言

本文主要参考了一篇知乎文章和一篇飞浆文章,文章末尾有注明来处,在此基础上加入了个人的理解与思考,并用自己的数据集进行了代码复现,并提出了基于知网数据集下一步的改进方向。

一、什么是Skip-gram算法

Skip-gram算法就是在给出目标单词(中心单词)的情况下,预测它的上下文单词(除中心单词外窗口内的其他单词,这里的窗口大小是2,也就是左右各两个单词)。

以下图为例:

图中的love是目标单词,其他是上下文单词,那么我们就是求P(w_{you}|w_{love}) 、P(w_{Do}|w_{love}) 、P(w_{deep}|w_{love})P(w_{learning}|w_{love})

二、目标是什么

理解了Skip-gram算法的定义,我们很容易得出:我们的目标是计算在给定单词的条件下,其他单词出现的概率,问题来了,在实践中,怎么计算这个概率?接下来让我们一步一步理解这个过程,首先从定义表示法开始。

三、定义表示法

3.1 one-hot向量

one-hot向量就是利用一个R^{|V|\times 1}向量来表示单词。|V|是词表中单词的数量。一个单词在英文词汇表中的索引位置是多少,那么相对应的那一行元素就是1,其他元素都是0。

w^{word}=\begin{bmatrix} 0\\ 0\\ \vdots \\ 1\\ \vdots \\ 0\\ 0\end{bmatrix}

还是以我们的例句"Do you love deep learning"为例。

love的one-hot向量就是:

w^{love}=\begin{bmatrix} 0\\ 0\\ 1\\ 0\\ 0\end{bmatrix}

由于我们只有5个单词,因此,ong-hot向量的行数是5,love是第3个单词,因此索引3位置的数是1。我们用w_c来表示目标单词的one-hot向量。

3.2 词向量(word vector)

词向量就是用一组d维的向量代表单词,如下:3

v^{c}=\begin{bmatrix} 0.2\\ 0.4\\ 1.3\\ \vdots \\0.9\end{bmatrix}

注意这是个d维的向量。这里我们用v_c表示目标单词的词向量

3.3 单词矩阵

单词矩阵是所有单词的词向量的集合。

注意,我们这里要用到两个单词矩阵,一个是目标单词的词向量组成的矩阵,用 W表示。W的尺寸是d\times V

另外一个矩阵是由除目标单词外的其他单词词向量的转置组成的矩阵,用{W^{}}'表示,尺寸是V\times d,这里用与上一个W的尺寸相反,至于为什么我们后面解释。

另外需要说明的是,由于每一个单词都有可能作为目标单词或其他单词,因此,实际上这两个矩阵是分别包含所有单词的词向量的。

3.4 单词相似度

我们先考虑这个问题:怎么表示两个单词之间的相似度?一个简单方法就是:两个单词间的词向量求内积。这里,我们用v_c代表目标单词的词向量,u_x代表除目标单词窗口内第x个单词的词向量。

那么求内积: u_x^{T}v_c就是两个单词的相似度,因为两个单词内积越大,说明两个单词的相似程度越高。

3.5 softmax函数

我们需要知道的是softmax函数就是能够把输入转换为概率分布,也就是说使输入的实数变成分数。除此之外的内容我们暂不讨论。softmax函数的公式如下:

\sigma(Z)_j=\frac{e^{z_j}}{\sum_{k=1}^{K}e^{z_k}}      for j=1,...,K.

这里面的z就是我们的相似度 u_x^{T}v_c

w_c表示目标单词的one-hot向量

v_c表示目标单词的词向量

u_x表示除目标单词外第x个单词的词向量

W表示目标单词矩阵

{W^{}}'表示其他单词矩阵

词向量的维度是d

词汇表的维度是V

3.6 算法过程

求相似度 u_x^{T}v_c 总共分几步?

第一步:求v_c

v_c=Ww_c 这里W是d\times V的矩阵,w_cV\times 1的矩阵,因此v_cd\times 1的向量。直观理解:矩阵与one-hot向量的内积,相当于把one-hot向量中索引为1在向量矩阵中对应的那一列提取出来。

第二步:求 u_x^{T}v_c组成的向量

这个向量是W{}'v_c,这里的W{}'V\times d的矩阵,v_cd\times 1的向量,因此u_x^{T}v_cV\times 1的向量。

直观理解:下面要说的很重要!用 W{}' 与 v_c 相乘,相当于 v_c 和词汇表中的所有词向量的转置都分别求内积,得到的结果组成了一个向量。

下图是直观描述。

3.7 求softmax

这步比较简单,把得到的相似度矩阵代入softmax公式,

就得到了一个满足概率分布的矩阵。至此,我们的目标已经实现:得到了一个向量。

向量中的数值代表在给定单词的条件下,其他单词出现的概率!大功告成!

四、skipgram代码实现

在自然语言处理任务中,词向量(Word Embedding)是表示自然语言里单词的一种方法,即把每个词都表示为一个N维空间内的点,即一个高维空间内的向量。通过这种方法,实现把自然语言计算转换为向量计算。

如 图1 所示的词向量计算任务中,先把每个词(如queen,king等)转换成一个高维空间的向量,这些向量在一定意义上可以代表这个词的语义信息。再通过计算这些向量之间的距离,就可以计算出词语之间的关联关系,从而达到让计算机像计算数值一样去计算自然语言的目的。

图1:词向量计算示意图

因此,大部分词向量模型都需要回答两个问题:

1. 如何把词转换为向量?

自然语言单词是离散信号,比如“香蕉”,“橘子”,“水果”在我们看来就是3个离散的词。

如何把每个离散的单词转换为一个向量?

2. 如何让向量具有语义信息?

比如,我们知道在很多情况下,“香蕉”和“橘子”更加相似,而“香蕉”和“句子”就没有那么相似,同时“香蕉”和“食物”、“水果”的相似程度可能介于“橘子”和“句子”之间。

那么,我们该如何让词向量具备这样的语义信息?

4.1 如何把词转换为向量

自然语言单词是离散信号,比如“我”、“ 爱”、“人工智能”。如何把每个离散的单词转换为一个向量?通常情况下,我们可以维护一个如 图2 所示的查询表。表中每一行都存储了一个特定词语的向量值,每一列的第一个元素都代表着这个词本身,以便于我们进行词和向量的映射(如“我”对应的向量值为 [0.3,0.5,0.7,0.9,-0.2,0.03] )。给定任何一个或者一组单词,我们都可以通过查询这个excel,实现把单词转换为向量的目的,这个查询和替换过程称之为Embedding Lookup。

图2:词向量查询表

上述过程也可以使用一个字典数据结构实现。事实上如果不考虑计算效率,使用字典实现上述功能是个不错的选择。然而在进行神经网络计算的过程中,需要大量的算力,常常要借助特定硬件(如GPU)满足训练速度的需求。GPU上所支持的计算都是以张量(Tensor)为单位展开的,因此在实际场景中,我们需要把Embedding Lookup的过程转换为张量计算,如 图3 所示。

图3:张量计算示意图

假设对于句子"我,爱,人工,智能",把Embedding Lookup的过程转换为张量计算的流程如下:

  1. 通过查询字典,先把句子中的单词转换成一个ID(通常是一个大于等于0的整数),这个单词到ID的映射关系可以根据需求自定义(如图3中,我=>1, 人工=>2,爱=>3,...)。

  2. 得到ID后,再把每个ID转换成一个固定长度的向量。假设字典的词表中有5000个词,那么,对于单词“我”,就可以用一个5000维的向量来表示。由于“我”的ID是1,因此这个向量的第一个元素是1,其他元素都是0([1,0,0,…,0]);同样对于单词“人工”,第二个元素是1,其他元素都是0。用这种方式就实现了用一个向量表示一个单词。由于每个单词的向量表示都只有一个元素为1,而其他元素为0,因此我们称上述过程为One-Hot Encoding。

  3. 经过One-Hot Encoding后,句子“我,爱,人工,智能”就被转换成为了一个形状为 4×5000的张量,记为VVV。在这个张量里共有4行、5000列,从上到下,每一行分别代表了“我”、“爱”、“人工”、“智能”四个单词的One-Hot Encoding。最后,我们把这个张量VVV和另外一个稠密张量WWW相乘,其中WWW张量的形状为5000 × 128(5000表示词表大小,128表示每个词的向量大小)。经过张量乘法,我们就得到了一个4×128的张量,从而完成了把单词表示成向量的目的。

如何让向量具有语义信息

得到每个单词的向量表示后,我们需要思考下一个问题:比如在多数情况下,“香蕉”和“橘子”更加相似,而“香蕉”和“句子”就没有那么相似;同时,“香蕉”和“食物”、“水果”的相似程度可能介于“橘子”和“句子”之间。那么如何让存储的词向量具备这样的语义信息呢?

我们先学习自然语言处理领域的一个小技巧。在自然语言处理研究中,科研人员通常有一个共识:使用一个单词的上下文来了解这个单词的语义,比如:

“苹果手机质量不错,就是价格有点贵。”

“这个苹果很好吃,非常脆。”

“菠萝质量也还行,但是不如苹果支持的APP多。”

在上面的句子中,我们通过上下文可以推断出第一个“苹果”指的是苹果手机,第二个“苹果”指的是水果苹果,而第三个“菠萝”指的应该也是一个手机。事实上,在自然语言处理领域,使用上下文描述一个词语或者元素的语义是一个常见且有效的做法。我们可以使用同样的方式训练词向量,让这些词向量具备表示语义信息的能力。

2013年,Mikolov提出的经典word2vec算法就是通过上下文来学习语义信息。word2vec包含两个经典模型:CBOW(Continuous Bag-of-Words)和Skip-gram,如 图4 所示。

  • CBOW:通过上下文的词向量推理中心词。
  • Skip-gram:根据中心词推理上下文。

图4:CBOW和Skip-gram语义学习示意图

假设有一个句子“Pineapples are spiked and yellow”,两个模型的推理方式如下:

  • CBOW中,先在句子中选定一个中心词,并把其它词作为这个中心词的上下文。如 图4 CBOW所示,把“Spiked”作为中心词,把“Pineapples、are、and、yellow”作为中心词的上下文。在学习过程中,使用上下文的词向量推理中心词,这样中心词的语义就被传递到上下文的词向量中,如“Spiked → pineapple”,从而达到学习语义信息的目的。

  • Skip-gram中,同样先选定一个中心词,并把其他词作为这个中心词的上下文。如 图4 Skip-gram所示,把“Spiked”作为中心词,把“Pineapples、are、and、yellow”作为中心词的上下文。不同的是,在学习过程中,使用中心词的词向量去推理上下文,这样上下文定义的语义被传入中心词的表示中,如“pineapple → Spiked”, 从而达到学习语义信息的目的。


说明:

一般来说,CBOW比Skip-gram训练速度快,训练过程更加稳定,原因是CBOW使用上下文average的方式进行训练,每个训练step会见到更多样本。而在生僻字(出现频率低的字)处理上,skip-gram比CBOW效果更好,原因是skip-gram不会刻意回避生僻字(CBOW结构中输入中存在生僻字时,生僻字会被其它非生僻字的权重冲淡)。


4.2 CBOW和Skip-gram的算法实现

我们以这句话:“Pineapples are spiked and yellow”为例分别介绍CBOW和Skip-gram的算法实现。

如 图5 所示,CBOW是一个具有3层结构的神经网络,分别是:

图5:CBOW的算法实现

  • 输入层: 一个形状为C×V的one-hot张量,其中C代表上线文中词的个数,通常是一个偶数,我们假设为4;V表示词表大小,我们假设为5000,该张量的每一行都是一个上下文词的one-hot向量表示,比如“Pineapples, are, and, yellow”。
  • 隐藏层: 一个形状为V×N的参数张量W1,一般称为word-embedding,N表示每个词的词向量长度,我们假设为128。输入张量和word embedding W1进行矩阵乘法,就会得到一个形状为C×N的张量。综合考虑上下文中所有词的信息去推理中心词,因此将上下文中C个词相加得一个1×N的向量,是整个上下文的一个隐含表示。
  • 输出层: 创建另一个形状为N×V的参数张量,将隐藏层得到的1×N的向量乘以该N×V的参数张量,得到了一个形状为1×V的向量。最终,1×V的向量代表了使用上下文去推理中心词,每个候选词的打分,再经过softmax函数的归一化,即得到了对中心词的推理概率。

如 图6 所示,Skip-gram是一个具有3层结构的神经网络,分别是:

图6:Skip-gram算法实现

  • Input Layer(输入层):接收一个one-hot张量 V\in R^{1\times vocabsize}作为网络的输入,里面存储着当前句子中心词的one-hot表示。
  • Hidden Layer(隐藏层):将张量V乘以一个word embedding张量W_1\in R^{vocabsize\times embedsize},并把结果作为隐藏层的输出,得到一个形状为R^{1\times embedsize}的张量,里面存储着当前句子中心词的词向量。
  • Output Layer(输出层):将隐藏层的结果乘以另一个word embedding张量W_2\in R^{embedsize\times vocabsize},得到一个形状为R^{1\times vocabsize}的张量。这个张量经过softmax变换后,就得到了使用当前中心词对上下文的预测结果。根据这个softmax的结果,我们就可以去训练词向量模型。

在实际操作中,使用一个滑动窗口(一般情况下,长度是奇数),从左到右开始扫描当前句子。每个扫描出来的片段被当成一个小句子,每个小句子中间的词被认为是中心词,其余的词被认为是这个中心词的上下文。

Skip-gram的理想实现

使用神经网络实现Skip-gram中,模型接收的输入应该有2个不同的tensor:

  • 代表中心词的tensor:假设我们称之为center_words V,一般来说,这个tensor是一个形状为[batch_size, vocab_size]的one-hot tensor,表示在一个mini-batch中,每个中心词的ID,对应位置为1,其余为0。

  • 代表目标词的tensor:目标词是指需要推理出来的上下文词,假设我们称之为target_words T,一般来说,这个tensor是一个形状为[batch_size, 1]的整型tensor,这个tensor中的每个元素是一个[0, vocab_size-1]的值,代表目标词的ID。

在理想情况下,我们可以使用一个简单的方式实现skip-gram。即把需要推理的每个目标词都当成一个标签,把skip-gram当成一个大规模分类任务进行网络构建,过程如下:

  1. 声明一个形状为[vocab_size, embedding_size]的张量,作为需要学习的词向量,记为W0​。对于给定的输入V,使用向量乘法,将V乘以W0​,这样就得到了一个形状为[batch_size, embedding_size]的张量,记为H=V×W0​。这个张量H就可以看成是经过词向量查表后的结果。
  2. 声明另外一个需要学习的参数W1​,这个参数的形状为[embedding_size, vocab_size]。将上一步得到的H去乘以W1,得到一个新的tensor O=H×W1,此时的O是一个形状为[batch_size, vocab_size]的tensor,表示当前这个mini-batch中的每个中心词预测出的目标词的概率。
  3. 使用softmax函数对mini-batch中每个中心词的预测结果做归一化,即可完成网络构建。

Skip-gram的实际实现

然而在实际情况中,vocab_size通常很大(几十万甚至几百万),导致W0和W1也会非常大。对于W0而言,所参与的矩阵运算并不是通过一个矩阵乘法实现,而是通过指定ID,对参数W0进行访存的方式获取。然而对W1而言,仍要处理一个非常大的矩阵运算(计算过程非常缓慢,需要消耗大量的内存/显存)。为了缓解这个问题,通常采取负采样(negative_sampling)的方式来近似模拟多分类任务。此时新定义的W0和W1​均为形状为[vocab_size, embedding_size]的张量。

假设有一个中心词ccc和一个上下文词正样本tp。在Skip-gram的理想实现里,需要最大化使用c推理tp的概率。在使用softmax学习时,需要最大化tp的推理概率,同时最小化其他词表中词的推理概率。之所以计算缓慢,是因为需要对词表中的所有词都计算一遍。然而我们还可以使用另一种方法,就是随机从词表中选择几个代表词,通过最小化这几个代表词的概率,去近似最小化整体的预测概率。比如,先指定一个中心词(如“人工”)和一个目标词正样本(如“智能”),再随机在词表中采样几个目标词负样本(如“日本”,“喝茶”等)。有了这些内容,我们的skip-gram模型就变成了一个二分类任务。对于目标词正样本,我们需要最大化它的预测概率;对于目标词负样本,我们需要最小化它的预测概率。通过这种方式,我们就可以完成计算加速。上述做法,我们称之为负采样。

在实现的过程中,通常会让模型接收3个tensor输入:

  • 代表中心词的tensor:假设我们称之为center_words V,一般来说,这个tensor是一个形状为[batch_size, vocab_size]的one-hot tensor,表示在一个mini-batch中每个中心词具体的ID。

  • 代表目标词的tensor:假设我们称之为target_words T,一般来说,这个tensor同样是一个形状为[batch_size, vocab_size]的one-hot tensor,表示在一个mini-batch中每个目标词具体的ID。

  • 代表目标词标签的tensor:假设我们称之为labels L,一般来说,这个tensor是一个形状为[batch_size, 1]的tensor,每个元素不是0就是1(0:负样本,1:正样本)。

模型训练过程如下:

  1. 用V去查询W0​,用T去查询W1​,分别得到两个形状为[batch_size, embedding_size]的tensor,记为H1​和H2。
  2. 将这两个tensor进行点积运算,最终得到一个形状为[batch_size]的tensor O = [O_i=\sum_{j}^{}H_0[i,j]\times H_1[i,j]]_{i=1}^{batchsize}
  3. 使用sigmoid函数作用在O上,将上述点积的结果归一化为一个0-1的概率值,作为预测概率,根据标签信息L训练这个模型即可。

在结束模型训练之后,一般使用W0作为最终要使用的词向量,用W0的向量表示。通过向量点乘的方式,计算不同词之间的相似度。

4.3 使用Pytorch实现Skip-gram

接下来我们将学习使用飞桨实现Skip-gram模型的方法。流程如下:

  1. 数据处理:选择需要使用的数据,并做好必要的预处理工作。

  2. 网络定义:使用飞桨定义好网络结构,包括输入层,中间层,输出层,损失函数和优化算法。

  3. 网络训练:将准备好的数据送入神经网络进行学习,并观察学习的过程是否正常,如损失函数值是否在降低,也可以打印一些中间步骤的结果出来等。

  4. 网络评估:使用测试集合测试训练好的神经网络,看看训练效果如何。

在数据处理前,需要先加载飞桨平台(如果用户在本地使用,请确保已经安装飞桨)。

# encoding=utf8
import io
import os
import sys
import requests
from collections import OrderedDict
import math
import random
import numpy as np
import paddle
from paddle.nn import Embedding
import paddle.nn.functional as F

数据处理

首先,找到一个合适的语料用于训练word2vec模型。使用知网数据集,通过批量下载知网数据集,共搜索关键词“人工智能”下载11764篇相关文献后的文件被保存在当前目录的“人工智能11706.csv”文件内。

接下来,把下载的语料读取到程序里,并打印前500个字符查看语料的格式,代码如下(因为知网数据关键词为半结构化数据,顾不用去停用词stopwords):


import jieba
import pandas as pd
# 创建停用词列表
# def stopwordslist():
#     stopwords = [line.strip() for line in open('./stopwords.txt',encoding='UTF-8').readlines()]## .strp()去除首尾空格
#     return stopwords# # 对句子进行中文分词
# def seg_depart(sentence):
#     # 对文档中的每一行进行中文分词
#     # print("正在分词")
#     sentence_depart = jieba.cut(sentence.strip())
#     # 创建一个停用词列表
#     stopwords = stopwordslist()
#     # 输出结果为outstr
#     outstr = ''
#     # 去停用词
#     for word in sentence_depart:
#         if word not in stopwords:
#             if word != '\t':
#                 outstr += word
#                 outstr += " "
#     return outstr# 给出文档路径
filename = "./人工智能11706.csv"
outfilename = "./outAiguanjianci.txt"
inputs = pd.read_csv(filename, encoding='UTF-8')
outputs = open(outfilename, 'w', encoding='UTF-8')# 将输出结果写入ou.txt中
for line in inputs['关键词']:print(line)# line_seg = seg_depart(line)outputs.write(line + '\t')# print("-------------------正在分词和去停用词-----------")
outputs.close()
# inputs.close()
# print("删除停用词和分词成功!!!")
# 读取关键词数据
def load_text8():with open("./outAiguanjianci.txt", "r") as f:corpus = f.read().replace('\n', ' ').replace('\r', ' ')# corpus = f.read().strip()# corpus = f.read().strip("\n")f.close()return corpuscorpus = load_text8()# 打印前500个字符,简要看一下这个语料的样子
print(corpus[:500])
人工智能 教育人工智能 EAI 机器学习  人工智能 社会风险 法律挑战 制度安排 人工智能 人工智能+教育 智能教育 教育人工智能    人工智能 智能作品 自然人 版权    人工智能 人工智能教育应用 人工智能教师 协同共存   人工智能 AI 人工智能教育应用 教育生态系统 独创性 人工智能 机器学习   人工智能 刑事风险 刑事责任 严格责任 人工智能 AI 智能教学系统 学习分析 人工智能 智慧教育 教育应用  人工智能 刑事责任 主体地位 刑罚目的 人工智能 社会风险 法律规制 智慧社会 机器学习 智慧教育 人工智能 个性化学习    人工智能 法律人格 人权 数据安全   人工智能 深度学习 ITS 自动化测评 人工智能 法律认知 法律规则 法律价值 自动驾驶汽车 智能机器人 严格责任 差别化责任 人工智能 AI教育 AI课程与教学 计算思维  人工智能创造物 人类受众 作者 知识产权    人工智能 未来教育 教育信息化 人工智能 电力系统 综合能源系统 机器学习   人工智能 网络社会 大数据 美国    人工智能 人工智能生成内容 著作权 独创性   类脑智能 人工智能 认知计算 认知脑计算模型  弱人工智能 强人工智能 

一般来说,在自然语言处理中,需要先对语料进行切词。因为知网数据集为半结构化,所以可以比较简单地直接使用空格进行切词,代码如下:

# 对语料进行预处理(分词)
def data_preprocess(corpus):# 由于英文单词出现在句首的时候经常要大写,所以我们把所有英文字符都转换为小写,# 以便对语料进行归一化处理(Apple vs apple等)# corpus = corpus.strip().lower()corpus = corpus.split()#去除误把空格当做单词的内容return corpuscorpus = data_preprocess(corpus)
print(corpus[:50])
['人工智能', '教育人工智能', 'EAI', '机器学习', '人工智能', '社会风险', '法律挑战', '制度安排', '人工智能', '人工智能+教育', '智能教育', '教育人工智能', '人工智能', '智能作品', '自然人', '版权', '人工智能', '人工智能教育应用', '人工智能教师', '协同共存', '人工智能', 'AI', '人工智能教育应用', '教育生态系统', '独创性', '人工智能', '机器学习', '人工智能', '刑事风险', '刑事责任', '严格责任', '人工智能', 'AI', '智能教学系统', '学习分析', '人工智能', '智慧教育', '教育应用', '人工智能', '刑事责任', '主体地位', '刑罚目的', '人工智能', '社会风险', '法律规制', '智慧社会', '机器学习', '智慧教育', '人工智能', '个性化学习']

在经过切词后,需要对语料进行统计,为每个词构造ID。一般来说,可以根据每个词在语料中出现的频次构造ID,频次越高,ID越小,便于对词典进行管理。代码如下:

# 构造词典,统计每个词的频率,并根据频率将每个词转换为一个整数id
def build_dict(corpus):# 首先统计每个不同词的频率(出现的次数),使用一个词典记录word_freq_dict = dict()for word in corpus:if word not in word_freq_dict:word_freq_dict[word] = 0word_freq_dict[word] += 1# 将这个词典中的词,按照出现次数排序,出现次数越高,排序越靠前# 一般来说,出现频率高的高频词往往是:I,the,you这种代词,而出现频率低的词,往往是一些名词,如:nlpword_freq_dict = sorted(word_freq_dict.items(), key = lambda x:x[1], reverse = True)# 构造3个不同的词典,分别存储,# 每个词到id的映射关系:word2id_dict# 每个id出现的频率:word2id_freq# 每个id到词的映射关系:id2word_dictword2id_dict = dict()word2id_freq = dict()id2word_dict = dict()# 按照频率,从高到低,开始遍历每个单词,并为这个单词构造一个独一无二的idfor word, freq in word_freq_dict:curr_id = len(word2id_dict)word2id_dict[word] = curr_idword2id_freq[word2id_dict[word]] = freqid2word_dict[curr_id] = wordreturn word2id_freq, word2id_dict, id2word_dictword2id_freq, word2id_dict, id2word_dict = build_dict(corpus)
vocab_size = len(word2id_freq)
print("there are totoally %d different words in the corpus" % vocab_size)
for _, (word, word_id) in zip(range(50), word2id_dict.items()):print("word %s, its id %d, its word freq %d" % (word, word_id, word2id_freq[word_id]))
there are totoally 2807 different words in the corpus
word 人工智能, its id 0, its word freq 1358
word 大数据, its id 1, its word freq 103
word 深度学习, its id 2, its word freq 55
word 机器学习, its id 3, its word freq 50
word 著作权, its id 4, its word freq 33
word 机器人, its id 5, its word freq 33
word 人工智能技术, its id 6, its word freq 31
word 应用, its id 7, its word freq 30
word 智能机器人, its id 8, its word freq 25
word 计算机网络技术, its id 9, its word freq 22
word 图书馆, its id 10, its word freq 21
word 算法, its id 11, its word freq 20
word 就业, its id 12, its word freq 20
word 法律主体, its id 13, its word freq 19
word 伦理, its id 14, its word freq 17
word 教育, its id 15, its word freq 17
word 独创性, its id 16, its word freq 16
word 作品, its id 17, its word freq 16
word 高等教育, its id 18, its word freq 16
word AI, its id 19, its word freq 15
word 强人工智能, its id 20, its word freq 15
word 人才培养, its id 21, its word freq 15
word 人工智能时代, its id 22, its word freq 15
word 智能教育, its id 23, its word freq 14
word 智慧教育, its id 24, its word freq 14
word 法律人格, its id 25, its word freq 14
word 神经网络, its id 26, its word freq 14
word 人工智能创作物, its id 27, its word freq 13
word 弱人工智能, its id 28, its word freq 12
word 人工智能生成物, its id 29, its word freq 12
word 职业教育, its id 30, its word freq 12
word 风险, its id 31, its word freq 12
word 管理会计, its id 32, its word freq 12
word 大数据时代, its id 33, its word freq 12
word 人工智能+教育, its id 34, its word freq 11
word 刑事责任, its id 35, its word freq 11
word 知识产权, its id 36, its word freq 11
word 专家系统, its id 37, its word freq 11
word 发展趋势, its id 38, its word freq 11
word 智慧图书馆, its id 39, its word freq 10
word 法律, its id 40, its word freq 10
word 人类智能, its id 41, its word freq 10
word 人机协同, its id 42, its word freq 10
word 可专利性, its id 43, its word freq 10
word 智能制造, its id 44, its word freq 10
word 会计行业, its id 45, its word freq 10
word 权利归属, its id 46, its word freq 10
word 影响, its id 47, its word freq 10
word 财务会计, its id 48, its word freq 10
word 教育人工智能, its id 49, its word freq 9

得到word2id词典后,还需要进一步处理原始语料,把每个词替换成对应的ID,便于神经网络进行处理,代码如下:

# 把语料转换为id序列
def convert_corpus_to_id(corpus, word2id_dict):# 使用一个循环,将语料中的每个词替换成对应的id,以便于神经网络进行处理corpus = [word2id_dict[word] for word in corpus]return corpuscorpus = convert_corpus_to_id(corpus, word2id_dict)
print("%d tokens in the corpus" % len(corpus))
print(corpus[:50])
6191 tokens in the corpus
[0, 49, 298, 3, 0, 142, 199, 619, 0, 34, 23, 49, 0, 620, 621, 50, 0, 67, 622, 299, 0, 19, 67, 623, 16, 0, 3, 0, 61, 35, 300, 0, 19, 143, 301, 0, 24, 51, 0, 35, 302, 624, 0, 142, 52, 81, 3, 24, 0, 82]

接下来,需要使用二次采样法处理原始文本。二次采样法的主要思想是降低高频词在语料中出现的频次。方法是随机将高频的词抛弃,频率越高,被抛弃的概率就越大;频率越低,被抛弃的概率就越小。标点符号或冠词这样的高频词就会被抛弃,从而优化整个词表的词向量训练效果,代码如下(此部分省略,因为高频词跟实际关注此有高关联性):若运行一下代码,则会限制部分高频词

二次采样

文本数据中一般会出现一些高频词,如英文中的“the”“a”和“in”。通常来说,在一个背景窗口中,一个词(如“chip”)和较低频词(如“microprocessor”)同时出现比和较高频词(如“the”)同时出现对训练词嵌入模型更有益。因此,训练词嵌入模型时可以对词进行二次采样。 具体来说,数据集中每个被索引词 w_i将有一定概率被丢弃,该丢弃概率为

P(w_i)=max(1-\sqrt{\frac{t}{f(w_i)}},0)

其中f(w_i)是数据集中词w_i 的个数与总词数之比,常数 t 是一个超参数(实验中设置为10^{-4})。可见,只有当 f(w_i)> t 时,我们才有可能在二次采样中丢弃词w_i ,并且越高频的词被丢弃的概率越大。

# 使用二次采样算法(subsampling)处理语料,强化训练效果
def subsampling(corpus, word2id_freq):# 这个discard函数决定了一个词会不会被替换,这个函数是具有随机性的,每次调用结果不同# 如果一个词的频率很大,那么它被遗弃的概率就很大def discard(word_id):return random.uniform(0, 1) < 1 - math.sqrt(1e-4 / word2id_freq[word_id] * len(corpus))corpus = [word for word in corpus if not discard(word)]return corpuscorpus = subsampling(corpus, word2id_freq)
print("%d tokens in the corpus" % len(corpus))
print(corpus[:50])

在完成语料数据预处理之后,需要构造训练数据。根据上面的描述,我们需要使用一个滑动窗口对语料从左到右扫描,在每个窗口内,中心词需要预测它的上下文,并形成训练数据。

在实际操作中,由于词表往往很大(50000,100000等),对大词表的一些矩阵运算(如softmax)需要消耗巨大的资源,因此可以通过负采样的方式模拟softmax的结果。

  • 给定一个中心词和一个需要预测的上下文词,把这个上下文词作为正样本。
  • 通过词表随机采样的方式,选择若干个负样本。
  • 把一个大规模分类问题转化为一个2分类问题,通过这种方式优化计算速度。
# 构造数据,准备模型训练
# max_window_size代表了最大的window_size的大小,程序会根据max_window_size从左到右扫描整个语料
# negative_sample_num代表了对于每个正样本,我们需要随机采样多少负样本用于训练,
# 一般来说,negative_sample_num的值越大,训练效果越稳定,但是训练速度越慢。
def build_data(corpus, word2id_dict, word2id_freq, max_window_size = 3, negative_sample_num = 10):# 使用一个list存储处理好的数据dataset = []# 从左到右,开始枚举每个中心点的位置for center_word_idx in range(len(corpus)):# 以max_window_size为上限,随机采样一个window_size,这样会使得训练更加稳定window_size = random.randint(1, max_window_size)# 当前的中心词就是center_word_idx所指向的词center_word = corpus[center_word_idx]# 以当前中心词为中心,左右两侧在window_size内的词都可以看成是正样本positive_word_range = (max(0, center_word_idx - window_size), min(len(corpus) - 1, center_word_idx + window_size))positive_word_candidates = [corpus[idx] for idx in range(positive_word_range[0], positive_word_range[1]+1) if idx != center_word_idx]# 对于每个正样本来说,随机采样negative_sample_num个负样本,用于训练for positive_word in positive_word_candidates:# 首先把(中心词,正样本,label=1)的三元组数据放入dataset中,# 这里label=1表示这个样本是个正样本dataset.append((center_word, positive_word, 1))# 开始负采样i = 0while i < negative_sample_num:negative_word_candidate = random.randint(0, vocab_size-1)if negative_word_candidate not in positive_word_candidates:# 把(中心词,正样本,label=0)的三元组数据放入dataset中,# 这里label=0表示这个样本是个负样本dataset.append((center_word, negative_word_candidate, 0))i += 1return dataset
corpus_light = corpus[:int(len(corpus)*0.2)]
dataset = build_data(corpus_light, word2id_dict, word2id_freq)
for _, (center_word, target_word, label) in zip(range(50), dataset):print("center_word %s, target %s, label %d" % (id2word_dict[center_word],id2word_dict[target_word], label))
center_word 人工智能, target 教育人工智能, label 1
center_word 人工智能, target 简史, label 0
center_word 人工智能, target 教学案例库, label 0
center_word 人工智能, target 计算机信息系统安全, label 0
center_word 人工智能, target 数据挖掘, label 0
center_word 人工智能, target 云平台, label 0
center_word 人工智能, target 智能产业, label 0
center_word 人工智能, target 技术进步, label 0
center_word 人工智能, target 网络时代, label 0
center_word 人工智能, target 大数据分析, label 0
center_word 人工智能, target 拟制, label 0
center_word 人工智能, target EAI, label 1
center_word 人工智能, target 技术交叉与融合, label 0
center_word 人工智能, target 未来教育, label 0
center_word 人工智能, target 税收征管, label 0
center_word 人工智能, target 治理风险, label 0
center_word 人工智能, target 应用探索, label 0
center_word 人工智能, target 先验现象学, label 0
center_word 人工智能, target 数据分析, label 0
center_word 人工智能, target 客服系统, label 0
center_word 人工智能, target 教育机器人, label 0
center_word 人工智能, target 服务体系, label 0
center_word 教育人工智能, target 人工智能, label 1
center_word 教育人工智能, target 智能化创新, label 0
center_word 教育人工智能, target 机器的资本主义应用, label 0
center_word 教育人工智能, target 数据样本产生, label 0
center_word 教育人工智能, target 北美洲, label 0
center_word 教育人工智能, target 自动化控制, label 0
center_word 教育人工智能, target 类型化, label 0
center_word 教育人工智能, target 教育变革, label 0
center_word 教育人工智能, target 互联网+, label 0
center_word 教育人工智能, target OECD国家, label 0
center_word 教育人工智能, target 劳动收入份额, label 0
center_word 教育人工智能, target EAI, label 1
center_word 教育人工智能, target 出版业转型, label 0
center_word 教育人工智能, target 媒介伦理, label 0
center_word 教育人工智能, target 就业结构, label 0
center_word 教育人工智能, target 研发者, label 0
center_word 教育人工智能, target 规避路径, label 0
center_word 教育人工智能, target 大学生就业, label 0
center_word 教育人工智能, target 道, label 0
center_word 教育人工智能, target 积极作用, label 0
center_word 教育人工智能, target 外卖骑手, label 0
center_word 教育人工智能, target 数据分析, label 0
center_word 教育人工智能, target 机器学习, label 1
center_word 教育人工智能, target 生态系统, label 0
center_word 教育人工智能, target 制度构建, label 0
center_word 教育人工智能, target 技术伦理, label 0
center_word 教育人工智能, target 劳动就业迭代, label 0
center_word 教育人工智能, target 算法调查, label 0

训练数据准备好后,把训练数据都组装成mini-batch,并准备输入到网络中进行训练,代码如下:

# 构造mini-batch,准备对模型进行训练
# 我们将不同类型的数据放到不同的tensor里,便于神经网络进行处理
# 并通过numpy的array函数,构造出不同的tensor来,并把这些tensor送入神经网络中进行训练
def build_batch(dataset, batch_size, epoch_num):# center_word_batch缓存batch_size个中心词center_word_batch = []# target_word_batch缓存batch_size个目标词(可以是正样本或者负样本)target_word_batch = []# label_batch缓存了batch_size个0或1的标签,用于模型训练label_batch = []for epoch in range(epoch_num):# 每次开启一个新epoch之前,都对数据进行一次随机打乱,提高训练效果random.shuffle(dataset)for center_word, target_word, label in dataset:# 遍历dataset中的每个样本,并将这些数据送到不同的tensor里center_word_batch.append([center_word])target_word_batch.append([target_word])label_batch.append(label)# 当样本积攒到一个batch_size后,我们把数据都返回回来# 在这里我们使用numpy的array函数把list封装成tensor# 并使用python的迭代器机制,将数据yield出来# 使用迭代器的好处是可以节省内存if len(center_word_batch) == batch_size:yield np.array(center_word_batch).astype("int64"), \np.array(target_word_batch).astype("int64"), \np.array(label_batch).astype("float32")center_word_batch = []target_word_batch = []label_batch = []if len(center_word_batch) > 0:yield np.array(center_word_batch).astype("int64"), \np.array(target_word_batch).astype("int64"), \np.array(label_batch).astype("float32")for _, batch in zip(range(10), build_batch(dataset, 128, 3)):print(batch)
(array([[ 927],[ 996],[  23],[ 960],[ 868],[   0],[ 160],[  25],[  57],[1049],[ 352],[ 674],[ 672],[ 641],[   0],[ 631],[   4],[ 163],[   0],[   0],[1010],[ 874],[ 723],[   0],[ 783],[   0],[  23],[ 619],[   0],[ 627],[ 349],[   0],[ 242],[ 330],[  16],[   0],[ 345],[ 117],[   0],[ 838],[   0],[ 346],[   0],[   0],[ 366],[   0],[ 125],[ 886],[ 713],[ 313],[ 230],[ 848],[ 825],[ 795],[ 968],[   0],[   0],[1005],[ 974],[   0],[ 654],[   0],[   0],[  24],[ 105],[ 773],[  25],[   0],[ 328],[1017],[   0],[   0],[ 636],[   0],[   0],[  15],[ 943],[   0],[ 201],[   0],[ 859],[ 370],[ 830],[ 105],[ 911],[   1],[ 945],[ 790],[   0],[ 952],[ 909],[   8],[   0],[ 805],[   0],[1017],[  25],[ 740],[ 816],[ 977],[   0],[ 941],[ 737],[ 726],[   5],[ 783],[   0],[   0],[ 631],[   0],[   0],[   1],[ 160],[   0],[   0],[   4],[ 776],[ 123],[ 199],[ 122],[   0],[  13],[ 160],[ 160],[  30],[ 239],[   0],[ 846]]), array([[2045],[ 997],[1795],[1732],[ 780],[2516],[ 374],[2784],[2539],[2012],[2572],[2494],[ 673],[2299],[2247],[2497],[2504],[ 665],[ 321],[2496],[  92],[ 812],[1913],[1747],[ 881],[ 469],[ 850],[2711],[ 855],[1244],[ 754],[2371],[2483],[ 240],[   0],[ 579],[  85],[ 760],[1725],[ 225],[1116],[ 800],[2426],[1176],[ 624],[ 683],[ 237],[2755],[ 896],[  10],[ 295],[1456],[   0],[1927],[  30],[2403],[ 813],[1248],[ 834],[1959],[ 285],[2313],[  82],[2100],[2449],[ 920],[ 400],[2072],[ 371],[ 656],[ 512],[2023],[1082],[1217],[ 846],[ 108],[2239],[1730],[1844],[ 762],[  29],[1809],[1684],[1952],[1534],[2789],[1408],[1734],[1310],[2671],[   0],[1704],[  72],[ 372],[1246],[2643],[1362],[2763],[ 247],[  47],[2781],[ 691],[ 394],[1733],[1704],[2484],[ 470],[ 215],[ 457],[ 665],[ 757],[1239],[ 188],[ 564],[1204],[ 774],[2638],[1180],[1180],[1703],[2273],[2564],[1314],[1579],[1814],[2063],[1543],[ 797]]), array([0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0.,0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 1., 0., 0., 0.,1., 0., 1., 1., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 1., 0.,0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0.], dtype=float32))
(array([[  70],[   0],[ 830],[ 796],[ 866],[ 950],[ 393],[ 847],[   1],[ 119],[ 939],[ 765],[  23],[ 716],[   0],[ 173],[ 410],[   0],[   0],[   0],[ 998],[ 790],[ 367],[   0],[  10],[ 893],[   0],[  73],[ 373],[ 367],[ 872],[ 116],[   0],[  86],[ 163],[ 349],[ 670],[ 653],[ 112],[ 885],[ 361],[ 385],[   0],[ 302],[ 794],[ 842],[   0],[  19],[  81],[  83],[ 331],[  29],[  69],[ 836],[  39],[   0],[ 727],[  42],[ 225],[ 741],[   0],[1041],[ 367],[ 872],[ 822],[ 748],[  25],[ 221],[ 983],[  10],[ 656],[  25],[ 147],[1039],[   1],[ 817],[   0],[ 879],[  71],[ 935],[1045],[1030],[ 828],[  52],[ 674],[ 986],[ 320],[   6],[ 894],[ 343],[ 870],[ 171],[  26],[  74],[  23],[  49],[   0],[ 199],[ 755],[ 807],[  28],[ 875],[ 148],[  14],[ 333],[ 766],[ 386],[ 221],[   0],[ 669],[ 208],[ 980],[ 236],[ 880],[   2],[1036],[ 733],[   5],[   3],[   8],[   0],[ 911],[1005],[ 338],[   0],[   0],[ 968],[   8]]), array([[1362],[ 252],[1317],[2561],[1821],[  36],[2015],[1763],[1977],[ 382],[ 725],[1169],[ 301],[1128],[2757],[ 661],[   0],[ 230],[2097],[2733],[1042],[ 509],[1422],[1657],[1514],[ 831],[ 651],[ 569],[ 419],[1078],[2752],[2167],[2533],[  65],[ 220],[  55],[  27],[1249],[1399],[ 207],[ 120],[ 842],[2287],[   0],[2789],[2647],[2175],[ 160],[1646],[1365],[2162],[1536],[ 735],[2522],[ 277],[1839],[1060],[  24],[ 736],[2492],[1900],[1960],[2792],[  81],[1079],[2482],[ 418],[1060],[2577],[2702],[2084],[  87],[2073],[2114],[ 503],[ 248],[1280],[ 330],[2018],[1051],[1022],[2519],[ 266],[ 223],[1339],[ 239],[2416],[ 510],[2136],[ 486],[1680],[1137],[  37],[ 932],[ 151],[1477],[ 617],[2282],[2391],[  23],[2440],[2245],[ 193],[1962],[ 909],[2469],[2310],[2506],[2232],[ 578],[2279],[2456],[ 127],[ 520],[1512],[2400],[ 537],[1582],[ 967],[ 271],[1797],[2073],[1814],[1328],[ 888],[2111],[1517],[2137]]), array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.,0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 1., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0.,1., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 1., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 1., 0., 0., 0.], dtype=float32))
(array([[ 331],[  18],[  67],[ 932],[  70],[ 854],[  29],[   0],[ 839],[ 654],[   0],[   0],[ 649],[ 364],[ 853],[ 952],[   0],[ 706],[ 206],[ 384],[ 981],[ 654],[   1],[ 785],[ 632],[ 817],[ 760],[ 763],[ 823],[ 333],[  53],[ 788],[ 117],[ 719],[   0],[ 316],[  67],[   5],[ 396],[ 890],[ 691],[   0],[ 408],[ 844],[   2],[ 644],[ 104],[   0],[   0],[   0],[   0],[   2],[ 872],[   0],[ 122],[  41],[   0],[ 961],[ 375],[1002],[1012],[   0],[   0],[ 165],[  20],[ 703],[   0],[  19],[   0],[ 844],[  26],[   0],[   0],[ 877],[   0],[  86],[ 670],[ 353],[ 228],[ 902],[ 230],[1007],[   0],[ 202],[   2],[ 651],[ 836],[1010],[ 218],[ 319],[ 216],[ 395],[ 848],[ 372],[ 732],[  16],[   0],[ 300],[ 346],[   1],[   0],[   0],[ 694],[   0],[ 327],[ 963],[ 871],[   0],[ 904],[ 620],[   0],[ 815],[ 105],[  16],[  34],[  67],[  34],[   0],[ 737],[ 300],[ 328],[   0],[   0],[ 105],[   0],[1037],[ 147],[ 938]]), array([[1049],[1341],[2138],[1229],[   0],[2133],[1846],[1150],[1873],[1861],[2132],[2049],[2267],[2277],[1747],[  26],[2484],[1957],[2260],[ 897],[1813],[1551],[2600],[2660],[2210],[1325],[1332],[ 410],[1877],[ 918],[1806],[2546],[2764],[1772],[1416],[ 410],[ 299],[ 104],[ 100],[1250],[ 972],[ 779],[ 829],[ 369],[ 814],[2680],[1667],[ 751],[ 937],[1119],[ 856],[ 775],[1147],[  19],[   2],[ 848],[2294],[ 962],[ 232],[2140],[1445],[2222],[2770],[2165],[1558],[1158],[ 299],[1593],[1257],[2726],[1721],[2304],[   1],[ 698],[1823],[1584],[ 105],[1772],[ 635],[1915],[ 132],[1862],[1442],[1824],[1073],[1811],[1610],[1282],[ 812],[ 204],[2286],[ 724],[1580],[1012],[ 731],[ 626],[ 122],[1232],[1175],[2463],[  70],[2227],[ 623],[2527],[2081],[2038],[2694],[2133],[1408],[1100],[1973],[ 388],[  31],[ 301],[1564],[2166],[1483],[1538],[ 303],[   0],[2356],[ 192],[ 261],[1438],[ 296],[1382],[1572],[1363]]), array([0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0.,0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 1., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 1., 1., 0., 0.,0., 0., 0., 0., 0., 0., 1., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 1., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,1., 0., 0., 0., 0., 0., 0., 0., 0.], dtype=float32))
(array([[   0],[ 338],[ 383],[   0],[ 913],[   0],[  49],[   5],[ 688],[ 316],[ 379],[ 827],[   0],[   0],[ 378],[   1],[  49],[ 691],[ 346],[   0],[ 799],[ 338],[ 912],[   5],[ 108],[   0],[  31],[ 299],[1035],[ 821],[   0],[ 961],[   0],[  23],[ 925],[   0],[   0],[   0],[ 338],[ 203],[ 168],[1022],[ 312],[ 924],[ 378],[  37],[ 746],[   0],[ 309],[ 309],[  10],[   8],[   0],[ 322],[ 723],[   0],[ 737],[ 961],[   0],[ 109],[ 123],[   0],[ 315],[ 792],[   0],[  15],[ 719],[   0],[  73],[ 804],[ 790],[ 300],[1012],[ 144],[  54],[   5],[   0],[ 153],[  67],[  14],[  41],[ 148],[   0],[   3],[ 963],[   0],[ 328],[ 700],[   0],[ 685],[   0],[   0],[  86],[ 121],[  72],[ 309],[   0],[ 949],[   0],[   0],[ 223],[ 684],[ 308],[ 147],[ 881],[ 831],[ 917],[ 984],[ 626],[  13],[   3],[  12],[1039],[1028],[ 303],[   0],[ 826],[ 783],[   0],[   0],[ 624],[ 222],[   5],[   0],[ 149],[ 965],[ 633],[ 355]]), array([[ 937],[2494],[2292],[2200],[ 733],[2411],[ 784],[ 573],[ 674],[2673],[  93],[ 931],[ 795],[1680],[2713],[1519],[2632],[  72],[   0],[ 112],[1246],[ 863],[2354],[1842],[1103],[  51],[2723],[ 542],[ 889],[1846],[1132],[ 178],[2779],[2070],[1606],[ 300],[ 972],[2116],[1453],[1574],[  54],[ 846],[2665],[1213],[2516],[ 682],[1228],[ 897],[1989],[1409],[1808],[2693],[2698],[1710],[2556],[2293],[1385],[1266],[ 898],[ 762],[2077],[1653],[  16],[1685],[  11],[2501],[2088],[1923],[ 696],[2233],[2789],[ 717],[1800],[2101],[ 433],[1708],[ 368],[1309],[2708],[2623],[ 734],[1277],[ 654],[2537],[2257],[ 238],[1449],[ 699],[ 918],[1584],[2477],[ 110],[ 717],[ 107],[ 871],[1084],[ 382],[   0],[1777],[2745],[2452],[1411],[1141],[2138],[ 739],[ 586],[ 674],[2425],[2323],[2573],[2778],[1888],[ 701],[2040],[1986],[1478],[ 530],[2201],[2076],[ 502],[2327],[1713],[2090],[ 890],[  92],[2804],[ 590],[ 609]]), array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 1., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.,0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 0., 0., 0.,1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 1., 1., 0., 0., 0., 0., 0., 0., 0., 1., 1., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0.], dtype=float32))
(array([[  34],[   0],[ 918],[ 149],[   0],[   0],[   8],[   0],[ 985],[ 326],[   0],[   5],[ 997],[ 319],[   5],[   0],[ 799],[ 655],[ 147],[   0],[ 357],[ 321],[   0],[   0],[  15],[  15],[   0],[ 320],[ 908],[ 813],[  82],[ 656],[ 885],[   0],[   0],[  55],[ 354],[   0],[ 200],[   0],[   8],[ 955],[ 842],[ 699],[ 206],[  52],[   0],[ 299],[   0],[ 740],[ 989],[ 380],[   0],[ 731],[ 845],[ 827],[ 105],[  62],[ 749],[ 683],[   0],[ 302],[ 858],[ 956],[   1],[ 370],[ 806],[ 148],[ 627],[ 162],[   3],[ 635],[ 862],[ 149],[ 105],[   0],[ 770],[   0],[ 709],[   0],[  43],[ 784],[ 117],[   0],[ 385],[ 157],[   0],[ 305],[ 224],[   0],[  22],[   0],[ 366],[ 843],[ 327],[ 979],[ 762],[ 408],[  72],[ 878],[ 313],[   8],[  37],[  13],[ 712],[ 716],[ 317],[ 629],[ 312],[ 750],[ 753],[  53],[   3],[ 118],[   0],[1009],[ 334],[   8],[  29],[1019],[ 935],[ 681],[ 207],[  16],[  14],[ 909],[ 367],[  13]]), array([[1337],[1171],[2185],[1784],[2361],[ 800],[1731],[ 853],[   0],[  97],[ 405],[ 334],[2351],[ 149],[1690],[ 538],[   0],[1100],[2047],[1484],[ 310],[1796],[ 116],[ 637],[ 518],[ 993],[2286],[ 204],[ 174],[2611],[1991],[ 549],[1871],[2300],[1856],[1829],[1021],[1235],[ 940],[   8],[ 404],[ 737],[1250],[1627],[ 974],[1310],[2465],[1580],[ 103],[1538],[2165],[ 420],[ 565],[ 112],[ 844],[ 752],[ 885],[ 541],[1773],[1238],[2309],[1939],[2246],[1666],[ 751],[1202],[1115],[1051],[1728],[1729],[1816],[2355],[2019],[2028],[ 274],[ 370],[ 772],[2255],[   0],[1464],[ 701],[ 147],[1282],[1685],[2205],[ 448],[  53],[ 129],[ 932],[1697],[2047],[1147],[2353],[ 203],[ 511],[1492],[1395],[2425],[2381],[1639],[ 407],[2103],[ 907],[ 669],[1334],[   0],[1927],[1505],[2078],[1282],[ 802],[ 380],[  16],[2665],[1514],[ 474],[ 505],[1825],[ 566],[1255],[2087],[2212],[1460],[ 343],[ 454],[ 465],[2370],[2512]]), array([0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 0., 0., 1.,0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.,0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 1., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0.], dtype=float32))
(array([[   0],[   0],[ 952],[   0],[ 327],[ 119],[ 911],[   0],[   0],[ 153],[ 101],[ 111],[   0],[ 619],[ 118],[   0],[ 199],[ 160],[   0],[   6],[  22],[ 738],[ 765],[ 381],[   0],[  14],[ 955],[   0],[ 203],[ 977],[1038],[ 225],[ 359],[   0],[   0],[ 322],[  15],[ 381],[   0],[1044],[ 374],[ 379],[  24],[   0],[ 863],[ 962],[  68],[ 677],[ 839],[   1],[ 619],[ 373],[1022],[   0],[   0],[1021],[ 621],[ 116],[  14],[ 725],[   3],[   1],[ 207],[  25],[ 926],[   0],[  72],[  25],[  17],[   0],[ 638],[ 899],[  76],[ 118],[ 905],[  12],[  49],[  76],[ 770],[ 383],[ 773],[   0],[   0],[   2],[   0],[  82],[  86],[ 635],[ 792],[   0],[ 866],[ 712],[   0],[ 624],[ 627],[ 728],[  68],[ 635],[   0],[ 111],[ 739],[   0],[   3],[  35],[ 734],[ 674],[   0],[ 382],[ 994],[ 679],[ 162],[   0],[ 729],[ 912],[   0],[ 299],[1010],[ 691],[ 115],[ 152],[   0],[ 144],[   0],[ 778],[  86],[   0],[ 358],[  17]]), array([[1329],[ 801],[ 576],[1293],[2034],[ 810],[1628],[ 809],[ 963],[1138],[1517],[2448],[ 576],[2540],[ 100],[2801],[   0],[1401],[ 922],[  49],[  25],[ 441],[ 115],[ 890],[2653],[2181],[ 738],[ 926],[2053],[2630],[ 953],[ 618],[1995],[ 942],[2162],[ 242],[ 528],[1003],[1458],[1966],[2779],[2533],[1191],[2713],[ 592],[2543],[1143],[1945],[2132],[ 895],[1709],[2389],[2665],[2216],[1875],[1120],[ 969],[2646],[2671],[ 525],[1025],[ 770],[ 186],[1880],[ 708],[ 911],[1404],[1140],[2377],[2412],[ 424],[1440],[   0],[   0],[2130],[1251],[1114],[1408],[ 455],[   3],[ 771],[2785],[ 201],[1035],[ 316],[1830],[1508],[ 556],[1148],[ 274],[ 867],[1558],[ 256],[ 494],[1757],[2146],[1079],[2018],[ 578],[   0],[1091],[ 529],[1638],[ 300],[1213],[2753],[ 203],[2225],[ 896],[2215],[1144],[2096],[  61],[ 149],[1672],[ 365],[1606],[1329],[1985],[1068],[ 934],[ 742],[ 564],[1416],[1043],[2187],[ 965],[  17]]), array([0., 0., 0., 0., 0., 1., 0., 1., 1., 0., 0., 0., 0., 0., 0., 0., 1.,0., 0., 1., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 1., 1., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 1.,0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0.,0., 1., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 1., 0., 0., 0., 0., 0., 1., 0.], dtype=float32))
(array([[ 325],[   0],[  67],[ 361],[ 830],[ 789],[ 169],[   0],[ 907],[ 147],[ 948],[   0],[ 858],[ 950],[ 741],[ 679],[1029],[ 850],[   0],[   0],[   0],[  23],[  61],[   0],[   0],[  89],[1007],[ 958],[1000],[ 848],[ 893],[ 667],[   0],[  11],[1014],[ 858],[ 316],[ 374],[ 741],[ 713],[ 243],[   0],[   0],[   0],[ 623],[ 884],[ 674],[ 908],[1024],[   0],[   0],[  68],[ 890],[ 163],[ 230],[ 109],[   0],[ 823],[   0],[   1],[   0],[ 322],[ 117],[ 954],[ 699],[ 748],[ 396],[  49],[ 115],[ 387],[ 715],[  83],[   0],[ 374],[   2],[ 304],[  10],[   0],[ 665],[ 336],[ 143],[ 819],[   3],[   0],[ 942],[ 695],[ 723],[ 704],[   0],[ 728],[ 107],[  16],[ 691],[ 995],[ 222],[ 158],[ 738],[  10],[   0],[ 112],[  83],[ 846],[ 142],[ 367],[ 113],[   0],[ 842],[ 401],[  39],[  22],[ 673],[ 905],[ 325],[ 143],[  70],[   0],[   1],[  49],[ 408],[  56],[  41],[ 109],[ 372],[ 795],[   0],[  67],[   0],[  10]]), array([[2059],[1448],[ 209],[ 647],[ 680],[ 743],[1630],[ 457],[1626],[ 818],[2765],[ 266],[2255],[ 240],[1218],[2654],[2448],[1487],[2005],[ 462],[1060],[1973],[2684],[ 364],[1933],[1708],[ 742],[2470],[1610],[1786],[ 355],[2369],[1177],[2567],[ 908],[ 623],[2199],[ 575],[2688],[ 409],[1182],[2129],[2272],[1600],[  22],[ 909],[1434],[ 594],[2721],[  66],[1723],[2046],[1026],[ 661],[2305],[2010],[2525],[ 361],[2443],[   0],[1084],[1604],[1121],[1076],[2260],[ 981],[ 972],[   0],[1518],[2732],[ 114],[1100],[1725],[2772],[ 626],[ 851],[2790],[1627],[1595],[2051],[1907],[  36],[2267],[2249],[1271],[ 567],[2080],[ 506],[ 200],[ 325],[ 774],[  23],[ 593],[ 555],[  18],[1871],[ 790],[1336],[ 204],[2586],[ 545],[ 772],[1739],[ 819],[ 163],[1011],[ 160],[2562],[ 376],[2769],[2213],[ 385],[  80],[  59],[  51],[2721],[ 537],[1224],[ 242],[1535],[ 300],[ 724],[1009],[ 634],[ 686],[1150],[2641],[1762]]), array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 1., 1.,0., 0., 1., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.,0., 0., 0., 0., 0., 0., 0., 0., 0.], dtype=float32))
(array([[   0],[ 711],[ 782],[  73],[ 684],[ 329],[   0],[ 642],[   0],[  81],[ 302],[ 635],[  42],[ 961],[ 404],[   0],[   0],[ 883],[ 847],[  71],[   0],[  29],[ 722],[ 336],[ 722],[ 814],[   0],[   3],[   4],[ 223],[   0],[   0],[   0],[ 885],[1048],[   0],[ 107],[ 105],[   0],[   0],[ 230],[ 874],[ 149],[ 359],[   0],[ 120],[   0],[ 105],[   0],[ 339],[   0],[1003],[ 663],[ 336],[ 301],[ 867],[   0],[   0],[ 215],[   0],[ 753],[ 200],[   0],[   0],[ 109],[ 364],[   0],[  86],[  49],[ 749],[1036],[ 159],[   0],[ 103],[   0],[   0],[1022],[  29],[ 947],[ 385],[ 821],[  30],[   0],[ 861],[   0],[ 124],[  55],[   0],[   0],[  19],[  19],[  68],[   0],[ 958],[   0],[   0],[ 910],[  34],[ 379],[   0],[ 948],[ 968],[  11],[   0],[ 226],[   0],[ 813],[ 619],[ 988],[  23],[ 997],[ 147],[   0],[ 764],[   0],[ 229],[ 623],[1005],[ 766],[  15],[ 806],[   0],[   0],[ 736],[1048],[ 955],[ 725],[  17]]), array([[ 626],[ 732],[ 249],[2437],[ 683],[ 172],[ 143],[2621],[ 277],[2492],[2137],[1446],[1027],[2593],[2718],[2100],[1013],[   0],[ 476],[ 933],[ 228],[2278],[   0],[2688],[2510],[2716],[ 908],[  75],[2020],[ 786],[ 314],[1490],[2039],[ 652],[2039],[1270],[ 405],[1780],[1837],[1943],[2767],[ 216],[1984],[1720],[2386],[ 573],[1714],[1795],[1051],[2576],[2168],[ 615],[1915],[1455],[1405],[ 151],[1897],[1330],[ 237],[ 568],[ 752],[2645],[1777],[2367],[ 740],[ 211],[2408],[1044],[1948],[ 345],[2166],[1953],[ 881],[ 440],[1345],[ 541],[2268],[1304],[1472],[1216],[2265],[1891],[2116],[1777],[ 375],[   2],[ 248],[  13],[2152],[  94],[ 392],[ 311],[2188],[ 163],[1217],[ 805],[ 982],[2237],[ 884],[ 602],[ 388],[ 656],[2562],[2195],[2383],[1229],[ 213],[ 186],[2414],[1268],[ 998],[ 111],[2394],[ 927],[2215],[1583],[2331],[ 388],[ 426],[1278],[ 983],[ 499],[1806],[ 735],[1617],[ 820],[1309],[ 624]]), array([0., 0., 0., 0., 1., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,1., 0., 0., 0., 0., 1., 0., 0., 0., 1., 0., 0., 1., 1., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0.,0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,1., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 1., 0.,0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 1., 0., 0., 0., 0.], dtype=float32))
(array([[ 785],[ 909],[ 221],[ 170],[ 780],[  20],[ 797],[ 202],[ 113],[ 825],[ 937],[ 309],[  71],[ 388],[ 748],[ 363],[ 115],[ 331],[   0],[   0],[  27],[ 915],[   4],[ 161],[ 846],[ 169],[ 335],[1041],[   0],[1016],[  27],[ 114],[  35],[ 963],[ 652],[ 215],[  16],[  14],[ 374],[   0],[  74],[  20],[ 772],[ 625],[  13],[   0],[   0],[ 794],[ 755],[ 383],[ 708],[ 625],[   0],[  17],[1016],[ 808],[ 326],[   0],[ 867],[   0],[ 811],[   0],[ 303],[ 795],[   0],[ 122],[   0],[   0],[ 382],[ 241],[  15],[ 365],[ 346],[ 149],[ 814],[  16],[ 105],[ 365],[ 118],[  85],[   0],[ 407],[   0],[   6],[  10],[ 848],[ 379],[ 813],[ 107],[   0],[1049],[1022],[ 782],[  61],[  39],[ 780],[ 368],[1035],[  24],[  70],[1031],[ 371],[   1],[   0],[ 377],[ 939],[1047],[  61],[   1],[ 207],[ 745],[  26],[ 362],[ 300],[ 876],[   0],[ 329],[ 949],[ 649],[   0],[ 154],[ 142],[  12],[ 300],[ 984],[ 881],[ 399],[   2]]), array([[ 784],[1404],[1215],[1479],[   0],[1806],[ 226],[ 983],[ 222],[1565],[ 769],[2573],[1113],[ 254],[ 372],[1331],[1304],[2042],[1927],[ 829],[1799],[ 936],[ 460],[ 919],[ 390],[1839],[1882],[2238],[1888],[ 163],[2578],[ 691],[2422],[ 392],[2026],[1201],[2082],[2574],[ 143],[2051],[ 151],[2464],[ 220],[ 394],[1655],[ 988],[ 459],[   0],[ 615],[1287],[1538],[2179],[1685],[ 885],[ 236],[  16],[2592],[ 973],[2701],[2396],[ 297],[1082],[2576],[ 305],[1803],[ 692],[1971],[1522],[2032],[ 472],[2498],[2316],[ 546],[2620],[1870],[ 694],[2217],[2343],[ 634],[2582],[ 100],[1315],[ 132],[ 678],[ 480],[1002],[2581],[ 969],[ 194],[2806],[1689],[1020],[2776],[2387],[2629],[2739],[ 840],[ 762],[1599],[1386],[2730],[1935],[1014],[ 241],[ 882],[ 465],[ 166],[1285],[1019],[1481],[2666],[ 924],[ 576],[2648],[1721],[2026],[1707],[   0],[1746],[  55],[ 258],[   3],[2456],[ 966],[2298],[ 236],[2726],[ 135]]), array([1., 0., 0., 0., 1., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.,0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 1., 0., 1., 0., 0., 0.,0., 0., 1., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.,0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0.,0., 0., 1., 0., 0., 0., 0., 0., 0.], dtype=float32))
(array([[ 660],[ 914],[ 939],[   0],[  24],[   2],[ 208],[ 224],[ 625],[ 370],[ 782],[ 855],[ 153],[   0],[ 938],[  73],[ 915],[ 893],[  41],[   0],[  61],[   0],[   0],[ 958],[  27],[   0],[ 870],[   0],[ 686],[ 231],[   0],[ 801],[   0],[   0],[ 741],[   0],[ 796],[ 723],[1031],[  22],[ 382],[ 866],[ 342],[   0],[  20],[  51],[ 236],[ 988],[   0],[   6],[   0],[  17],[ 773],[ 679],[ 148],[1023],[ 109],[   0],[ 773],[   0],[  23],[ 928],[   0],[  10],[  20],[ 688],[ 394],[ 891],[  23],[ 633],[ 166],[  13],[ 998],[ 302],[  55],[   0],[ 812],[ 807],[ 984],[ 728],[   0],[ 964],[ 911],[ 224],[   0],[  29],[ 380],[1045],[ 313],[ 384],[  83],[   4],[  81],[ 813],[ 670],[ 208],[  52],[   0],[ 744],[ 104],[   0],[1003],[ 766],[ 699],[ 161],[1035],[   0],[   3],[ 103],[ 200],[ 895],[ 223],[   0],[ 880],[   0],[ 872],[ 366],[   3],[   5],[ 624],[ 241],[ 701],[ 168],[ 940],[ 967],[   3],[ 925],[  23]]), array([[1987],[2552],[1569],[ 228],[2381],[1903],[ 439],[2507],[1462],[1422],[ 661],[2248],[  24],[2578],[2700],[ 278],[ 504],[2699],[2501],[ 147],[2185],[2124],[ 339],[2705],[2197],[1594],[2046],[2789],[1104],[ 706],[2324],[2631],[2365],[1455],[1313],[2252],[1315],[ 541],[ 495],[2180],[   0],[1248],[ 991],[ 330],[1493],[ 672],[2128],[2287],[  91],[ 968],[ 709],[ 215],[2382],[2352],[1632],[ 470],[   0],[2453],[1936],[1873],[1550],[ 930],[ 985],[1013],[ 212],[2536],[2275],[1626],[1605],[ 631],[1889],[ 967],[ 599],[ 282],[ 366],[1610],[ 813],[1200],[ 206],[2043],[1619],[2562],[ 343],[2174],[2393],[2099],[ 474],[  48],[1713],[  29],[ 266],[1375],[ 338],[2529],[1192],[1291],[2022],[ 929],[2682],[2030],[1671],[1128],[ 375],[ 496],[1894],[2515],[1399],[2550],[ 906],[ 403],[ 839],[ 606],[1074],[ 809],[2518],[2762],[1528],[1892],[ 856],[2772],[ 255],[ 325],[2270],[ 489],[1457],[1639],[2539],[1841]]), array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 1., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.,0., 1., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0.], dtype=float32))

网络定义

定义skip-gram的网络结构,用于模型训练。在飞桨动态图中,对于任意网络,都需要定义一个继承自paddle.nn.layer的类来搭建网络结构、参数等数据的声明。同时需要在forward函数中定义网络的计算逻辑。值得注意的是,我们仅需要定义网络的前向计算逻辑,飞桨会自动完成神经网络的后向计算。

在skip-gram的网络结构中,使用的最关键的API是paddle.nn.Embedding函数,可以用其实现Embedding的网络层。通过查询飞桨的API文档,可以得到如下更详细的说明:

paddle.nn.Embedding(numembeddings, embeddingdim, paddingidx=None, sparse=False, weightattr=None, name=None)

该接口用于构建 Embedding 的一个可调用对象,其根据input中的id信息从embedding矩阵中查询对应embedding信息,并会根据输入的size (num_embeddings, embedding_dim)自动构造一个二维embedding矩阵。 输出Tensor的shape是在输入Tensor shape的最后一维后面添加了emb_size的维度。注:input中的id必须满足 0 =< id < size[0],否则程序会抛异常退出。

#定义skip-gram训练网络结构
#使用paddlepaddle的2.0.0版本
#一般来说,在使用paddle训练的时候,我们需要通过一个类来定义网络结构,这个类继承了paddle.nn.layer
class SkipGram(paddle.nn.Layer):def __init__(self, vocab_size, embedding_size, init_scale=0.1):# vocab_size定义了这个skipgram这个模型的词表大小# embedding_size定义了词向量的维度是多少# init_scale定义了词向量初始化的范围,一般来说,比较小的初始化范围有助于模型训练super(SkipGram, self).__init__()self.vocab_size = vocab_sizeself.embedding_size = embedding_size# 使用Embedding函数构造一个词向量参数# 这个参数的大小为:[self.vocab_size, self.embedding_size]# 数据类型为:float32# 这个参数的初始化方式为在[-init_scale, init_scale]区间进行均匀采样self.embedding = Embedding( num_embeddings = self.vocab_size,embedding_dim = self.embedding_size,weight_attr=paddle.ParamAttr(initializer=paddle.nn.initializer.Uniform( low=-init_scale, high=init_scale)))# 使用Embedding函数构造另外一个词向量参数# 这个参数的大小为:[self.vocab_size, self.embedding_size]# 这个参数的初始化方式为在[-init_scale, init_scale]区间进行均匀采样self.embedding_out = Embedding(num_embeddings = self.vocab_size,embedding_dim = self.embedding_size,weight_attr=paddle.ParamAttr(initializer=paddle.nn.initializer.Uniform(low=-init_scale, high=init_scale)))# 定义网络的前向计算逻辑# center_words是一个tensor(mini-batch),表示中心词# target_words是一个tensor(mini-batch),表示目标词# label是一个tensor(mini-batch),表示这个词是正样本还是负样本(用0或1表示)# 用于在训练中计算这个tensor中对应词的同义词,用于观察模型的训练效果def forward(self, center_words, target_words, label):# 首先,通过self.embedding参数,将mini-batch中的词转换为词向量# 这里center_words和eval_words_emb查询的是一个相同的参数# 而target_words_emb查询的是另一个参数center_words_emb = self.embedding(center_words)target_words_emb = self.embedding_out(target_words)# 我们通过点乘的方式计算中心词到目标词的输出概率,并通过sigmoid函数估计这个词是正样本还是负样本的概率。word_sim = paddle.multiply(center_words_emb, target_words_emb)word_sim = paddle.sum(word_sim, axis=-1)word_sim = paddle.reshape(word_sim, shape=[-1])pred = F.sigmoid(word_sim)# 通过估计的输出概率定义损失函数,注意我们使用的是binary_cross_entropy_with_logits函数# 将sigmoid计算和cross entropy合并成一步计算可以更好的优化,所以输入的是word_sim,而不是predloss = F.binary_cross_entropy_with_logits(word_sim, label)loss = paddle.mean(loss)# 返回前向计算的结果,飞桨会通过backward函数自动计算出反向结果。return pred, loss

网络训练

完成网络定义后,就可以启动模型训练。由于数据集较小,我们定义每隔10步打印一次Loss,以确保当前的网络是正常收敛的。同时,我们每隔10步观察一下skip-gram计算出来的同义词(使用 embedding的乘积),可视化网络训练效果,代码如下:

# 开始训练,定义一些训练过程中需要使用的超参数
batch_size = 512
epoch_num = 3
embedding_size = 200
step = 0
learning_rate = 0.001#定义一个使用word-embedding查询同义词的函数
#这个函数query_token是要查询的词,k表示要返回多少个最相似的词,embed是我们学习到的word-embedding参数
#我们通过计算不同词之间的cosine距离,来衡量词和词的相似度
#具体实现如下,x代表要查询词的Embedding,Embedding参数矩阵W代表所有词的Embedding
#两者计算Cos得出所有词对查询词的相似度得分向量,排序取top_k放入indices列表
def get_similar_tokens(query_token, k, embed):W = embed.numpy()x = W[word2id_dict[query_token]]cos = np.dot(W, x) / np.sqrt(np.sum(W * W, axis=1) * np.sum(x * x) + 1e-9)flat = cos.flatten()indices = np.argpartition(flat, -k)[-k:]indices = indices[np.argsort(-flat[indices])]for i in indices:print('for word %s, the similar word is %s' % (query_token, str(id2word_dict[i])))# 将模型放到GPU上训练
paddle.set_device('cpu')# 通过我们定义的SkipGram类,来构造一个Skip-gram模型网络
skip_gram_model = SkipGram(vocab_size, embedding_size)# 构造训练这个网络的优化器
adam = paddle.optimizer.Adam(learning_rate=learning_rate, parameters = skip_gram_model.parameters())# 使用build_batch函数,以mini-batch为单位,遍历训练数据,并训练网络
for center_words, target_words, label in build_batch(dataset, batch_size, epoch_num):# 使用paddle.to_tensor,将一个numpy的tensor,转换为飞桨可计算的tensorcenter_words_var = paddle.to_tensor(center_words)target_words_var = paddle.to_tensor(target_words)label_var = paddle.to_tensor(label)# 将转换后的tensor送入飞桨中,进行一次前向计算,并得到计算结果pred, loss = skip_gram_model(center_words_var, target_words_var, label_var)# 程序自动完成反向计算loss.backward()# 程序根据loss,完成一步对参数的优化更新adam.step()# 清空模型中的梯度,以便于下一个mini-batch进行更新adam.clear_grad()# 每经过100个mini-batch,打印一次当前的loss,看看loss是否在稳定下降step += 1if step % 10 == 0:print("step %d, loss %.3f" % (step, loss.numpy()[0]))# 每隔10000步,打印一次模型对以下查询词的相似词,这里我们使用词和词之间的向量点积作为衡量相似度的方法,只打印了5个最相似的词if step % 10 ==0:get_similar_tokens('人工智能', 20, skip_gram_model.embedding.weight)
step 10, loss 0.693
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 会计行业
for word 人工智能, the similar word is 军用机器人(技术)
for word 人工智能, the similar word is 劳动
for word 人工智能, the similar word is 就业替代效应
for word 人工智能, the similar word is 功能性动作模式评估
for word 人工智能, the similar word is 人机协作智能
for word 人工智能, the similar word is 电视媒介
for word 人工智能, the similar word is 人的发展
for word 人工智能, the similar word is 互联网+政务服务
for word 人工智能, the similar word is 计算机网络技术
for word 人工智能, the similar word is 监管
for word 人工智能, the similar word is 未来战争
for word 人工智能, the similar word is 科学立法
for word 人工智能, the similar word is 刑事责任能力
for word 人工智能, the similar word is 中小学
for word 人工智能, the similar word is 人机边界
for word 人工智能, the similar word is 智能体
for word 人工智能, the similar word is 应用场景
for word 人工智能, the similar word is 层级树语言
step 20, loss 0.691
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 会计行业
for word 人工智能, the similar word is 军用机器人(技术)
for word 人工智能, the similar word is 劳动
for word 人工智能, the similar word is 就业替代效应
for word 人工智能, the similar word is 功能性动作模式评估
for word 人工智能, the similar word is 人机协作智能
for word 人工智能, the similar word is 电视媒介
for word 人工智能, the similar word is 计算机网络技术
for word 人工智能, the similar word is 智能体
for word 人工智能, the similar word is 刑事责任能力
for word 人工智能, the similar word is 未来战争
for word 人工智能, the similar word is 互联网+政务服务
for word 人工智能, the similar word is 监管
for word 人工智能, the similar word is 科学立法
for word 人工智能, the similar word is 人的发展
for word 人工智能, the similar word is 人机边界
for word 人工智能, the similar word is 中小学
for word 人工智能, the similar word is 应用场景
for word 人工智能, the similar word is 电气自动化控制
step 30, loss 0.691
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 会计行业
for word 人工智能, the similar word is 军用机器人(技术)
for word 人工智能, the similar word is 劳动
for word 人工智能, the similar word is 就业替代效应
for word 人工智能, the similar word is 功能性动作模式评估
for word 人工智能, the similar word is 人机协作智能
for word 人工智能, the similar word is 电视媒介
for word 人工智能, the similar word is 刑事责任能力
for word 人工智能, the similar word is 智能体
for word 人工智能, the similar word is 计算机网络技术
for word 人工智能, the similar word is 科学立法
for word 人工智能, the similar word is 未来战争
for word 人工智能, the similar word is 监管
for word 人工智能, the similar word is 互联网+政务服务
for word 人工智能, the similar word is 多指手
for word 人工智能, the similar word is 应用场景
for word 人工智能, the similar word is 人机边界
for word 人工智能, the similar word is 电气自动化控制
for word 人工智能, the similar word is 科技乌托邦
step 40, loss 0.691
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 会计行业
for word 人工智能, the similar word is 军用机器人(技术)
for word 人工智能, the similar word is 劳动
for word 人工智能, the similar word is 就业替代效应
for word 人工智能, the similar word is 刑事责任能力
for word 人工智能, the similar word is 人机协作智能
for word 人工智能, the similar word is 智能体
for word 人工智能, the similar word is 功能性动作模式评估
for word 人工智能, the similar word is 科学立法
for word 人工智能, the similar word is 电视媒介
for word 人工智能, the similar word is 计算机网络技术
for word 人工智能, the similar word is 未来战争
for word 人工智能, the similar word is 多指手
for word 人工智能, the similar word is 监管
for word 人工智能, the similar word is 司法判断
for word 人工智能, the similar word is 应用场景
for word 人工智能, the similar word is 互联网+政务服务
for word 人工智能, the similar word is 科技乌托邦
for word 人工智能, the similar word is 中小学
step 50, loss 0.689
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 会计行业
for word 人工智能, the similar word is 军用机器人(技术)
for word 人工智能, the similar word is 就业替代效应
for word 人工智能, the similar word is 劳动
for word 人工智能, the similar word is 刑事责任能力
for word 人工智能, the similar word is 智能体
for word 人工智能, the similar word is 人机协作智能
for word 人工智能, the similar word is 功能性动作模式评估
for word 人工智能, the similar word is 未来战争
for word 人工智能, the similar word is 电视媒介
for word 人工智能, the similar word is 科学立法
for word 人工智能, the similar word is 计算机网络技术
for word 人工智能, the similar word is 司法判断
for word 人工智能, the similar word is 多指手
for word 人工智能, the similar word is 应用场景
for word 人工智能, the similar word is 科技乌托邦
for word 人工智能, the similar word is 互联网+政务服务
for word 人工智能, the similar word is 监管
for word 人工智能, the similar word is 中小学
step 60, loss 0.686
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 会计行业
for word 人工智能, the similar word is 军用机器人(技术)
for word 人工智能, the similar word is 就业替代效应
for word 人工智能, the similar word is 劳动
for word 人工智能, the similar word is 刑事责任能力
for word 人工智能, the similar word is 智能体
for word 人工智能, the similar word is 人机协作智能
for word 人工智能, the similar word is 功能性动作模式评估
for word 人工智能, the similar word is 司法判断
for word 人工智能, the similar word is 未来战争
for word 人工智能, the similar word is 多指手
for word 人工智能, the similar word is 电视媒介
for word 人工智能, the similar word is 科学立法
for word 人工智能, the similar word is 计算机网络技术
for word 人工智能, the similar word is 可视化分析
for word 人工智能, the similar word is 人类命运
for word 人工智能, the similar word is 涉人工智能犯罪
for word 人工智能, the similar word is 应用场景
for word 人工智能, the similar word is 科技乌托邦
step 70, loss 0.686
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 会计行业
for word 人工智能, the similar word is 军用机器人(技术)
for word 人工智能, the similar word is 就业替代效应
for word 人工智能, the similar word is 刑事责任能力
for word 人工智能, the similar word is 智能体
for word 人工智能, the similar word is 劳动
for word 人工智能, the similar word is 可视化分析
for word 人工智能, the similar word is 功能性动作模式评估
for word 人工智能, the similar word is 司法判断
for word 人工智能, the similar word is 人机协作智能
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 科学立法
for word 人工智能, the similar word is 未来战争
for word 人工智能, the similar word is 人类命运
for word 人工智能, the similar word is 多指手
for word 人工智能, the similar word is 涉人工智能犯罪
for word 人工智能, the similar word is 计算机网络技术
for word 人工智能, the similar word is 电视媒介
for word 人工智能, the similar word is 应用场景
step 80, loss 0.682
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 会计行业
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 智能体
for word 人工智能, the similar word is 就业替代效应
for word 人工智能, the similar word is 军用机器人(技术)
for word 人工智能, the similar word is 可视化分析
for word 人工智能, the similar word is 刑事责任能力
for word 人工智能, the similar word is 劳动
for word 人工智能, the similar word is 机器学习
for word 人工智能, the similar word is 司法判断
for word 人工智能, the similar word is 人类命运
for word 人工智能, the similar word is 功能性动作模式评估
for word 人工智能, the similar word is 科学立法
for word 人工智能, the similar word is 独创性
for word 人工智能, the similar word is 智慧学习
for word 人工智能, the similar word is 哥德尔
for word 人工智能, the similar word is 人机协作智能
for word 人工智能, the similar word is 教育信息化
for word 人工智能, the similar word is 未来战争
step 90, loss 0.679
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 会计行业
for word 人工智能, the similar word is 机器学习
for word 人工智能, the similar word is 智能体
for word 人工智能, the similar word is 可视化分析
for word 人工智能, the similar word is 人类命运
for word 人工智能, the similar word is 刑事责任能力
for word 人工智能, the similar word is 就业替代效应
for word 人工智能, the similar word is 司法判断
for word 人工智能, the similar word is 军用机器人(技术)
for word 人工智能, the similar word is 独创性
for word 人工智能, the similar word is 教育信息化
for word 人工智能, the similar word is 劳动
for word 人工智能, the similar word is 科学立法
for word 人工智能, the similar word is 哥德尔
for word 人工智能, the similar word is 智慧学习
for word 人工智能, the similar word is 演进路线
for word 人工智能, the similar word is 涉人工智能犯罪
for word 人工智能, the similar word is 人机协作智能
step 100, loss 0.677
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 机器学习
for word 人工智能, the similar word is 会计行业
for word 人工智能, the similar word is 可视化分析
for word 人工智能, the similar word is 人类命运
for word 人工智能, the similar word is 司法判断
for word 人工智能, the similar word is 刑事责任能力
for word 人工智能, the similar word is 独创性
for word 人工智能, the similar word is 智能体
for word 人工智能, the similar word is 教育信息化
for word 人工智能, the similar word is 就业替代效应
for word 人工智能, the similar word is 法律主体
for word 人工智能, the similar word is 军用机器人(技术)
for word 人工智能, the similar word is 哥德尔
for word 人工智能, the similar word is 科学立法
for word 人工智能, the similar word is 司法审判
for word 人工智能, the similar word is 演进路线
for word 人工智能, the similar word is 深度学习
for word 人工智能, the similar word is 智慧学习
step 110, loss 0.654
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 机器学习
for word 人工智能, the similar word is 独创性
for word 人工智能, the similar word is 可视化分析
for word 人工智能, the similar word is 刑事责任能力
for word 人工智能, the similar word is 人类命运
for word 人工智能, the similar word is 司法判断
for word 人工智能, the similar word is 会计行业
for word 人工智能, the similar word is 深度学习
for word 人工智能, the similar word is 法律主体
for word 人工智能, the similar word is 教育信息化
for word 人工智能, the similar word is 智能体
for word 人工智能, the similar word is 人工智能生成物
for word 人工智能, the similar word is 教育
for word 人工智能, the similar word is 云计算
for word 人工智能, the similar word is 就业替代效应
for word 人工智能, the similar word is 司法审判
for word 人工智能, the similar word is 哥德尔
for word 人工智能, the similar word is 军用机器人(技术)
step 120, loss 0.648
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 机器学习
for word 人工智能, the similar word is 独创性
for word 人工智能, the similar word is 可视化分析
for word 人工智能, the similar word is 深度学习
for word 人工智能, the similar word is 刑事责任能力
for word 人工智能, the similar word is 法律主体
for word 人工智能, the similar word is 司法判断
for word 人工智能, the similar word is 人类命运
for word 人工智能, the similar word is 教育信息化
for word 人工智能, the similar word is 云计算
for word 人工智能, the similar word is 人工智能生成物
for word 人工智能, the similar word is 教育
for word 人工智能, the similar word is 会计行业
for word 人工智能, the similar word is 智能机器人
for word 人工智能, the similar word is 通用人工智能
for word 人工智能, the similar word is 智能体
for word 人工智能, the similar word is 演进路线
for word 人工智能, the similar word is 公共政策
step 130, loss 0.638
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 机器学习
for word 人工智能, the similar word is 独创性
for word 人工智能, the similar word is 深度学习
for word 人工智能, the similar word is 可视化分析
for word 人工智能, the similar word is 法律主体
for word 人工智能, the similar word is 刑事责任能力
for word 人工智能, the similar word is 智能机器人
for word 人工智能, the similar word is 司法判断
for word 人工智能, the similar word is 云计算
for word 人工智能, the similar word is 人类命运
for word 人工智能, the similar word is 人工智能生成物
for word 人工智能, the similar word is 教育信息化
for word 人工智能, the similar word is 教育
for word 人工智能, the similar word is 通用人工智能
for word 人工智能, the similar word is 智能教育
for word 人工智能, the similar word is 公共政策
for word 人工智能, the similar word is 智慧教育
for word 人工智能, the similar word is 教育应用
step 140, loss 0.625
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 机器学习
for word 人工智能, the similar word is 独创性
for word 人工智能, the similar word is 深度学习
for word 人工智能, the similar word is 可视化分析
for word 人工智能, the similar word is 法律主体
for word 人工智能, the similar word is 智能机器人
for word 人工智能, the similar word is 刑事责任能力
for word 人工智能, the similar word is 司法判断
for word 人工智能, the similar word is 云计算
for word 人工智能, the similar word is 人类命运
for word 人工智能, the similar word is 智能教育
for word 人工智能, the similar word is 教育
for word 人工智能, the similar word is 人工智能生成物
for word 人工智能, the similar word is 教育信息化
for word 人工智能, the similar word is 通用人工智能
for word 人工智能, the similar word is 智慧教育
for word 人工智能, the similar word is 公共政策
for word 人工智能, the similar word is 教育应用
step 150, loss 0.617
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 机器学习
for word 人工智能, the similar word is 独创性
for word 人工智能, the similar word is 深度学习
for word 人工智能, the similar word is 法律主体
for word 人工智能, the similar word is 可视化分析
for word 人工智能, the similar word is 智能机器人
for word 人工智能, the similar word is 云计算
for word 人工智能, the similar word is 智能教育
for word 人工智能, the similar word is 刑事责任能力
for word 人工智能, the similar word is 教育
for word 人工智能, the similar word is 公共政策
for word 人工智能, the similar word is 人类命运
for word 人工智能, the similar word is 司法判断
for word 人工智能, the similar word is 智慧教育
for word 人工智能, the similar word is 通用人工智能
for word 人工智能, the similar word is 人工智能生成物
for word 人工智能, the similar word is 教育信息化
for word 人工智能, the similar word is 教育应用
step 160, loss 0.621
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 机器学习
for word 人工智能, the similar word is 独创性
for word 人工智能, the similar word is 深度学习
for word 人工智能, the similar word is 法律主体
for word 人工智能, the similar word is 智能机器人
for word 人工智能, the similar word is 可视化分析
for word 人工智能, the similar word is 智慧教育
for word 人工智能, the similar word is 云计算
for word 人工智能, the similar word is 智能教育
for word 人工智能, the similar word is 教育
for word 人工智能, the similar word is 公共政策
for word 人工智能, the similar word is 人类命运
for word 人工智能, the similar word is 通用人工智能
for word 人工智能, the similar word is 刑事责任能力
for word 人工智能, the similar word is 教育应用
for word 人工智能, the similar word is 教育信息化
for word 人工智能, the similar word is 司法判断
for word 人工智能, the similar word is 人工智能生成物
step 170, loss 0.601
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 机器学习
for word 人工智能, the similar word is 独创性
for word 人工智能, the similar word is 深度学习
for word 人工智能, the similar word is 法律主体
for word 人工智能, the similar word is 智能机器人
for word 人工智能, the similar word is 智慧教育
for word 人工智能, the similar word is 智能教育
for word 人工智能, the similar word is 可视化分析
for word 人工智能, the similar word is 云计算
for word 人工智能, the similar word is 教育
for word 人工智能, the similar word is 教育信息化
for word 人工智能, the similar word is 公共政策
for word 人工智能, the similar word is 教育人工智能
for word 人工智能, the similar word is 通用人工智能
for word 人工智能, the similar word is 人类命运
for word 人工智能, the similar word is 刑事责任能力
for word 人工智能, the similar word is 人工智能生成物
for word 人工智能, the similar word is 教育应用
step 180, loss 0.585
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 机器学习
for word 人工智能, the similar word is 深度学习
for word 人工智能, the similar word is 独创性
for word 人工智能, the similar word is 法律主体
for word 人工智能, the similar word is 智能机器人
for word 人工智能, the similar word is 智慧教育
for word 人工智能, the similar word is 智能教育
for word 人工智能, the similar word is 云计算
for word 人工智能, the similar word is 教育
for word 人工智能, the similar word is 可视化分析
for word 人工智能, the similar word is 教育信息化
for word 人工智能, the similar word is 教育人工智能
for word 人工智能, the similar word is 通用人工智能
for word 人工智能, the similar word is 机器人
for word 人工智能, the similar word is 人工智能生成物
for word 人工智能, the similar word is 公共政策
for word 人工智能, the similar word is 刑事责任能力
for word 人工智能, the similar word is 教育应用
step 190, loss 0.586
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 机器学习
for word 人工智能, the similar word is 深度学习
for word 人工智能, the similar word is 法律主体
for word 人工智能, the similar word is 独创性
for word 人工智能, the similar word is 智慧教育
for word 人工智能, the similar word is 智能机器人
for word 人工智能, the similar word is 智能教育
for word 人工智能, the similar word is 云计算
for word 人工智能, the similar word is 教育
for word 人工智能, the similar word is 机器人
for word 人工智能, the similar word is 可视化分析
for word 人工智能, the similar word is 教育信息化
for word 人工智能, the similar word is 教育人工智能
for word 人工智能, the similar word is 通用人工智能
for word 人工智能, the similar word is 人工智能生成物
for word 人工智能, the similar word is 人工智能教育应用
for word 人工智能, the similar word is 刑事责任能力
for word 人工智能, the similar word is 教育应用
step 200, loss 0.568
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 机器学习
for word 人工智能, the similar word is 深度学习
for word 人工智能, the similar word is 独创性
for word 人工智能, the similar word is 法律主体
for word 人工智能, the similar word is 智慧教育
for word 人工智能, the similar word is 智能机器人
for word 人工智能, the similar word is 智能教育
for word 人工智能, the similar word is 机器人
for word 人工智能, the similar word is 教育
for word 人工智能, the similar word is 云计算
for word 人工智能, the similar word is 可视化分析
for word 人工智能, the similar word is 教育信息化
for word 人工智能, the similar word is 教育人工智能
for word 人工智能, the similar word is 人工智能教育应用
for word 人工智能, the similar word is 通用人工智能
for word 人工智能, the similar word is 算法
for word 人工智能, the similar word is 教育应用
for word 人工智能, the similar word is 人工智能生成物
step 210, loss 0.539
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 机器学习
for word 人工智能, the similar word is 深度学习
for word 人工智能, the similar word is 独创性
for word 人工智能, the similar word is 法律主体
for word 人工智能, the similar word is 智慧教育
for word 人工智能, the similar word is 智能机器人
for word 人工智能, the similar word is 智能教育
for word 人工智能, the similar word is 机器人
for word 人工智能, the similar word is 教育
for word 人工智能, the similar word is 云计算
for word 人工智能, the similar word is 可视化分析
for word 人工智能, the similar word is 算法
for word 人工智能, the similar word is 人工智能教育应用
for word 人工智能, the similar word is 教育信息化
for word 人工智能, the similar word is 教育人工智能
for word 人工智能, the similar word is 通用人工智能
for word 人工智能, the similar word is 人工智能+教育
for word 人工智能, the similar word is 图书馆
step 220, loss 0.519
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 机器学习
for word 人工智能, the similar word is 深度学习
for word 人工智能, the similar word is 独创性
for word 人工智能, the similar word is 法律主体
for word 人工智能, the similar word is 智慧教育
for word 人工智能, the similar word is 智能教育
for word 人工智能, the similar word is 智能机器人
for word 人工智能, the similar word is 机器人
for word 人工智能, the similar word is 教育
for word 人工智能, the similar word is 云计算
for word 人工智能, the similar word is 算法
for word 人工智能, the similar word is 人工智能教育应用
for word 人工智能, the similar word is 教育信息化
for word 人工智能, the similar word is 图书馆
for word 人工智能, the similar word is 人工智能+教育
for word 人工智能, the similar word is 可视化分析
for word 人工智能, the similar word is 教育人工智能
for word 人工智能, the similar word is 教育应用
step 230, loss 0.498
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 机器学习
for word 人工智能, the similar word is 深度学习
for word 人工智能, the similar word is 独创性
for word 人工智能, the similar word is 法律主体
for word 人工智能, the similar word is 智慧教育
for word 人工智能, the similar word is 智能教育
for word 人工智能, the similar word is 机器人
for word 人工智能, the similar word is 智能机器人
for word 人工智能, the similar word is 教育
for word 人工智能, the similar word is 云计算
for word 人工智能, the similar word is 算法
for word 人工智能, the similar word is 图书馆
for word 人工智能, the similar word is 人工智能教育应用
for word 人工智能, the similar word is 人工智能+教育
for word 人工智能, the similar word is 教育应用
for word 人工智能, the similar word is 教育人工智能
for word 人工智能, the similar word is 教育信息化
for word 人工智能, the similar word is 人工智能技术
step 240, loss 0.493
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 机器学习
for word 人工智能, the similar word is 深度学习
for word 人工智能, the similar word is 独创性
for word 人工智能, the similar word is 法律主体
for word 人工智能, the similar word is 智能教育
for word 人工智能, the similar word is 智慧教育
for word 人工智能, the similar word is 机器人
for word 人工智能, the similar word is 智能机器人
for word 人工智能, the similar word is 教育
for word 人工智能, the similar word is 云计算
for word 人工智能, the similar word is 图书馆
for word 人工智能, the similar word is 算法
for word 人工智能, the similar word is 人工智能教育应用
for word 人工智能, the similar word is 教育人工智能
for word 人工智能, the similar word is 人工智能+教育
for word 人工智能, the similar word is 教育应用
for word 人工智能, the similar word is 教育信息化
for word 人工智能, the similar word is AI
step 250, loss 0.502
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 机器学习
for word 人工智能, the similar word is 深度学习
for word 人工智能, the similar word is 独创性
for word 人工智能, the similar word is 法律主体
for word 人工智能, the similar word is 智能教育
for word 人工智能, the similar word is 智慧教育
for word 人工智能, the similar word is 机器人
for word 人工智能, the similar word is 智能机器人
for word 人工智能, the similar word is 云计算
for word 人工智能, the similar word is 教育
for word 人工智能, the similar word is 教育人工智能
for word 人工智能, the similar word is 教育信息化
for word 人工智能, the similar word is 图书馆
for word 人工智能, the similar word is 算法
for word 人工智能, the similar word is 人工智能+教育
for word 人工智能, the similar word is 人工智能教育应用
for word 人工智能, the similar word is 教育应用
for word 人工智能, the similar word is AI
step 260, loss 0.469
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 机器学习
for word 人工智能, the similar word is 深度学习
for word 人工智能, the similar word is 独创性
for word 人工智能, the similar word is 法律主体
for word 人工智能, the similar word is 智慧教育
for word 人工智能, the similar word is 智能教育
for word 人工智能, the similar word is 机器人
for word 人工智能, the similar word is 智能机器人
for word 人工智能, the similar word is 云计算
for word 人工智能, the similar word is 教育
for word 人工智能, the similar word is 人工智能+教育
for word 人工智能, the similar word is 教育人工智能
for word 人工智能, the similar word is 教育信息化
for word 人工智能, the similar word is 算法
for word 人工智能, the similar word is 图书馆
for word 人工智能, the similar word is 教育应用
for word 人工智能, the similar word is 人工智能教育应用
for word 人工智能, the similar word is 智能教学系统
step 270, loss 0.464
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 机器学习
for word 人工智能, the similar word is 深度学习
for word 人工智能, the similar word is 独创性
for word 人工智能, the similar word is 法律主体
for word 人工智能, the similar word is 智慧教育
for word 人工智能, the similar word is 智能教育
for word 人工智能, the similar word is 机器人
for word 人工智能, the similar word is 智能机器人
for word 人工智能, the similar word is 云计算
for word 人工智能, the similar word is 教育
for word 人工智能, the similar word is 人工智能+教育
for word 人工智能, the similar word is 教育人工智能
for word 人工智能, the similar word is 教育信息化
for word 人工智能, the similar word is 算法
for word 人工智能, the similar word is 教育应用
for word 人工智能, the similar word is 图书馆
for word 人工智能, the similar word is 人工智能教育应用
for word 人工智能, the similar word is 智能教学系统
step 280, loss 0.436
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 机器学习
for word 人工智能, the similar word is 深度学习
for word 人工智能, the similar word is 独创性
for word 人工智能, the similar word is 法律主体
for word 人工智能, the similar word is 智慧教育
for word 人工智能, the similar word is 智能教育
for word 人工智能, the similar word is 智能机器人
for word 人工智能, the similar word is 机器人
for word 人工智能, the similar word is 教育
for word 人工智能, the similar word is 人工智能+教育
for word 人工智能, the similar word is 云计算
for word 人工智能, the similar word is 教育人工智能
for word 人工智能, the similar word is 算法
for word 人工智能, the similar word is 教育信息化
for word 人工智能, the similar word is 教育应用
for word 人工智能, the similar word is 图书馆
for word 人工智能, the similar word is 人工智能教育应用
for word 人工智能, the similar word is 可视化分析
step 290, loss 0.445
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 机器学习
for word 人工智能, the similar word is 深度学习
for word 人工智能, the similar word is 独创性
for word 人工智能, the similar word is 法律主体
for word 人工智能, the similar word is 智慧教育
for word 人工智能, the similar word is 智能教育
for word 人工智能, the similar word is 智能机器人
for word 人工智能, the similar word is 机器人
for word 人工智能, the similar word is 人工智能+教育
for word 人工智能, the similar word is 教育
for word 人工智能, the similar word is 云计算
for word 人工智能, the similar word is 教育人工智能
for word 人工智能, the similar word is 算法
for word 人工智能, the similar word is 教育信息化
for word 人工智能, the similar word is 人工智能教育应用
for word 人工智能, the similar word is 图书馆
for word 人工智能, the similar word is 教育应用
for word 人工智能, the similar word is 可视化分析
step 300, loss 0.399
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 机器学习
for word 人工智能, the similar word is 深度学习
for word 人工智能, the similar word is 独创性
for word 人工智能, the similar word is 法律主体
for word 人工智能, the similar word is 智慧教育
for word 人工智能, the similar word is 智能教育
for word 人工智能, the similar word is 智能机器人
for word 人工智能, the similar word is 人工智能+教育
for word 人工智能, the similar word is 机器人
for word 人工智能, the similar word is 教育
for word 人工智能, the similar word is 云计算
for word 人工智能, the similar word is 教育人工智能
for word 人工智能, the similar word is 算法
for word 人工智能, the similar word is 图书馆
for word 人工智能, the similar word is 人工智能教育应用
for word 人工智能, the similar word is 教育信息化
for word 人工智能, the similar word is 教育应用
for word 人工智能, the similar word is 可视化分析
step 310, loss 0.414
for word 人工智能, the similar word is 人工智能
for word 人工智能, the similar word is 大数据
for word 人工智能, the similar word is 机器学习
for word 人工智能, the similar word is 深度学习
for word 人工智能, the similar word is 独创性
for word 人工智能, the similar word is 智慧教育
for word 人工智能, the similar word is 智能教育
for word 人工智能, the similar word is 法律主体
for word 人工智能, the similar word is 智能机器人
for word 人工智能, the similar word is 人工智能+教育
for word 人工智能, the similar word is 机器人
for word 人工智能, the similar word is 教育
for word 人工智能, the similar word is 云计算
for word 人工智能, the similar word is 算法
for word 人工智能, the similar word is 教育人工智能
for word 人工智能, the similar word is 图书馆
for word 人工智能, the similar word is 人工智能教育应用
for word 人工智能, the similar word is 教育应用
for word 人工智能, the similar word is 教育信息化
for word 人工智能, the similar word is 可视化分析

我们可以发现loss越来越低,可视化结果也是越来越精准。下一步考虑如何基于每一篇文献的关键词活动窗口(或固定window_size为3)的重新构建正负样本,来观察效果。

参考文章:

1. Word2Vec介绍:直观理解skip-gram模型 - 知乎

2. 词向量Word Embedding - 飞桨AI Studio - 人工智能学习实训社区 (baidu.com)

一文弄懂Word2Vec之skip-gram(含详细代码)相关推荐

  1. 一文弄懂元学习 (Meta Learing)(附代码实战)《繁凡的深度学习笔记》第 15 章 元学习详解 (上)万字中文综述

    <繁凡的深度学习笔记>第 15 章 元学习详解 (上)万字中文综述(DL笔记整理系列) 3043331995@qq.com https://fanfansann.blog.csdn.net ...

  2. 一文弄懂神经网络中的反向传播法

    最近在看深度学习的东西,一开始看的吴恩达的UFLDL教程,有中文版就直接看了,后来发现有些地方总是不是很明确,又去看英文版,然后又找了些资料看,才发现,中文版的译者在翻译的时候会对省略的公式推导过程进 ...

  3. 一文弄懂各种loss function

    有模型就要定义损失函数(又叫目标函数),没有损失函数,模型就失去了优化的方向.大家往往接触的损失函数比较少,比如回归就是MSE,MAE,分类就是log loss,交叉熵.在各个模型中,目标函数往往都是 ...

  4. 一文弄懂神经网络中的反向传播法——BackPropagation【转】

    本文转载自:https://www.cnblogs.com/charlotte77/p/5629865.html 一文弄懂神经网络中的反向传播法--BackPropagation 最近在看深度学习的东 ...

  5. 一文弄懂String的所有小秘密

    文章目录 简介 String是不可变的 传值还是传引用 substring() 导致的内存泄露 总结 一文弄懂String的所有小秘密 简介 String是java中非常常用的一个对象类型.可以说ja ...

  6. 一文弄懂EnumMap和EnumSet

    文章目录 简介 EnumMap 什么时候使用EnumMap EnumSet 总结 一文弄懂EnumMap和EnumSet 简介 一般来说我们会选择使用HashMap来存储key-value格式的数据, ...

  7. CAD2010 为了保护_一文弄懂,锂电池的充电电路,以及它的保护电路方案设计

    原标题:一文弄懂,锂电池的充电电路,以及它的保护电路方案设计 锂电池特性 首先,芯片哥问一句简单的问题,为什么很多电池都是锂电池? 锂电池,工程师对它都不会感到陌生.在电子产品项目开发的过程中,尤其是 ...

  8. deque stack java_一文弄懂java中的Queue家族

    简介 java中Collection集合有三大家族List,Set和Queue.当然Map也算是一种集合类,但Map并不继承Collection接口. List,Set在我们的工作中会经常使用,通常用 ...

  9. 一文弄懂Flink网络流控及反压

    一文弄懂Flink网络流控及反压 1. 为什么需要网络流控? 2. 网络流控的实现:静态限速 3. 网络流控的实现:动态反馈/自动反压 3.1 案例一:Storm 反压实现 3.2 案例二:Spark ...

最新文章

  1. 【转载】利用Matlab制作钟表
  2. Nginx的配置文件
  3. Sublime Text3配置Lua运行环境
  4. 控制ASP.NET Web API 调用频率与限流
  5. dell服务器硬盘锁_服务器十大排行
  6. 程序员如何打破 30 岁职业瓶颈?
  7. EditPlus注册码 亲测最新版可用
  8. 用 Node.js 把玩一番 Alfred Workflow
  9. AI+进入科学界:人工智能将主导原子世界的科学发现进程
  10. php匿名聊天室开源,[开源项目]基于WebSocket的匿名聊天室
  11. 一文熟练使用spring data jpa
  12. 中外十大武侠片排行榜
  13. Kali BeEF MSF的使用
  14. wps教鞭功能_三个PPT2010新增实用功能
  15. 怎样才能走进区块链行业?
  16. Android手机导出的已安装的APK到电脑
  17. 2022年全球气候金融产品研究报告
  18. 使用 Docker 来快速上手中文 Stable Diffusion 模型:太乙
  19. C语言图形编程(绘图函数部分),C语言图形编程(三、绘图函数-02)12
  20. 说说python程序的执行过程_《师说》的“说”

热门文章

  1. 每周分享第 60 期
  2. 国内外做视频会议比较牛的公司有哪些?
  3. pythonsklearn多元回归回归_sklearn入门之多元线性回归
  4. 制作千兆以太网FPGA PCB拓展板 实现基于B50610以太网摄像头采集方案
  5. Java中文编程开发,让Java编写更加容易
  6. html+css 实现红绿灯效果
  7. 总结归纳“windows 找不到文件‘cmd’,命令提示符无法执行和打开”的多种错误方法规避,错误重现以及正确解决方法
  8. 少儿编程C++画图之GOC编程 视频和资料集
  9. 大学生都说学计算机专业难,大学单身率很高的4个专业,男女比例严重失调,想谈恋爱太难了...
  10. 【iOS底层】11:消息转发