Main Content

wordEmbeddingLayer

Word embedding layer for deep learning networks

Description

A word embedding layer maps word indices to vectors.

在深度学习长期记忆(LSTM)网络中使用单词嵌入层。LSTM网络是一种复发性神经网络(RNN),可以在序列数据的时间步骤之间学习长期依赖性。一个单词嵌入层映射了一系列单词索引以嵌入向量,并在训练过程中学习嵌入单词。

该层需要深度学习工具箱™。

创建

Description

例子

layer= Wordembeddinglayer(dimension,,,,数字creates a word embedding layer and specifies the embedding dimension and vocabulary size.

例子

layer= Wordembeddinglayer(dimension,,,,数字,,,,姓名,,,,Value设置可选特性使用一个或多个名称值对。将每个属性名称包装在单引号中。

特性

expand all

Word Embedding

单词嵌入的维度,指定为正整数。

Example:300

Number of words in the model, specified as a positive integer. If the number of unique words in the training data is greater than数字,,,,then the layer maps the out-of-vocabulary words to the same vector.

参数和初始化

Function to initialize the weights, specified as one of the following:

  • 'narrow-normal't -初始化he weights by independently sampling from a normal distribution with zero mean and standard deviation 0.01.

  • “ Glorot”- 使用Glorot初始化器初始化重量[1](也称为Xavier Initializer)。Glorot初始化器独立于均匀分布的均匀分布和方差样本2/(numin + numout),,,,wherenumIn = NumWords + 1andnumout =维度

  • 'he't -初始化he weights with the He initializer[2]。来自均值和方差的正态分布的HE初始化样品样本2/numin,,,,wherenumIn = NumWords + 1

  • '正交'- 初始化输入权重,由QR分解给出的正交基质z=rfor a random matrixzsampled from a unit normal distribution.[3]

  • “零”t -初始化he weights with zeros.

  • 'ones'- 用一个初始化权重。

  • Function handle – Initialize the weights with a custom function. If you specify a function handle, then the function must be of the form重量= func(SZ),,,,whereSZ一世s the size of the weights.

The layer only initializes the weights when the权重属性是空的。

数据类型:char|细绳|function_handle

层权重,指定为Dimension-by-(数字+1) array.

用于输入整数一世less than or equal to数字,,,,the layer outputs the vector重量(:,i)。Otherwise, the layer maps outputs the vector权重(:,numwords+1)

学习费率和正则化

Learning rate factor for the weights, specified as a nonnegative scalar.

The software multiplies this factor by the global learning rate to determine the learning rate for the weights in this layer. For example, if重量应培训一世s 2, then the learning rate for the weights in this layer is twice the current global learning rate. The software determines the global learning rate based on the settings specified with thetrainingOptions(深度学习工具箱)功能。

Example:2

重量的L2正则化因子,指定为非负标量。

该软件将该因子乘以全局L2正则化因子,以确定该层中权重的L2正则化。例如,如果WeightL2FactorIS 2,然后该层中权重的L2正则化是全局L2正则化因子的两倍。您可以使用trainingOptions(深度学习工具箱)功能。

Example:2

Layer

图层名称,,,,specified as a character vector or a string scalar. If姓名一世s set to'',然后该软件在培训时间自动分配名称。

数据类型:char|细绳

Number of inputs of the layer. This layer accepts a single input only.

数据类型:double

输入名称of the layer. This layer accepts a single input only.

数据类型:cell

输出数量of the layer. This layer has a single output only.

数据类型:double

Output names of the layer. This layer has a single output only.

数据类型:cell

Examples

collapse all

创建一个具有嵌入尺寸300和5000个单词的单词嵌入层。

layer = wordEmbeddingLayer(300,5000)
layer = wordembeddinglayer具有属性:名称:''超参数尺寸:300 numwords:5000可学习的参数权重:[]显示所有属性

在LSTM网络中包含一个单词嵌入层。

inputsize = 1;嵌入dimension = 300;numWords = 5000;numhidendunits = 200;数字= 10;layers = [sequenceInputlayer(inputsize)Wordembeddinglayer(embeddingDimension,numwords)lstmlayer(numhidendunits,numhiddenunits,'outputmode',,,,'最后的')完整连接的layerer(numClasses)SoftMaxlayer分类器]
layers = 6x1 Layer array with layers: 1 '' Sequence Input Sequence input with 1 dimensions 2 '' Word Embedding Layer Word embedding layer with 300 dimensions and 5000 unique words 3 '' LSTM LSTM with 200 hidden units 4 '' Fully Connected 10 fully connected layer 5 '' Softmax softmax 6 '' Classification Output crossentropyex

要在深度学习网络中初始化单词嵌入层,并具有验证单词嵌入的权重,请使用word2vecfunction to extract the layer weights and set the“重量”name-value pair of thewordEmbeddingLayer功能。单词嵌入层期望单词向量的列,因此您必须转换word2vec功能。

emb = fastTextWordEmbedding; words = emb.Vocabulary; dimension = emb.Dimension; numWords = numel(words); layer = wordEmbeddingLayer(dimension,numWords,...“重量”,word2vec(emb,word)')
layer = WordEmbeddingLayer with properties: Name: '' Hyperparameters Dimension: 300 NumWords: 999994 Learnable Parameters Weights: [300×999994 single] Show all properties

要创建从单词嵌入单词编码的相应单词,请输入嵌入词汇的单词文字编码function as a list of words.

enc = wordencoding(单词)
enc = wordEncoding with properties: NumWords: 999994 Vocabulary: [1×999994 string]

references

[1] Glorot, Xavier, and Yoshua Bengio. "Understanding the difficulty of training deep feedforward neural networks." InProceedings of the thirteenth international conference on artificial intelligence and statistics,第249-256页。2010年。

[2]他,Kaiming,Xiangyu Zhang,Shaoqing Ren和Jian Sun。“深入研究整流器:超过人类在成像网分类方面的表现。”在Proceedings of the IEEE international conference on computer vision,第1026-1034页。2015。

[3] Saxe,Andrew M.,James L. McClelland和Surya Ganguli。“深层线性神经金宝搏官方网站网络中学习的非线性动力学的确切解决方案。”ARXIV预印ARXIV:1312.6120(2013)。

扩展功能

GPU代码生成
使用GPU CODER™为NVIDIA®GPU生成CUDA®代码。

在R2018B中引入