From 6f24e96b1ef9bb2425afe4244b55492774ed2936 Mon Sep 17 00:00:00 2001 From: Li Fuchen Date: Mon, 23 Mar 2020 10:47:48 +0800 Subject: [PATCH] change fluid.layers.embedding to fluid.embedding to fix a bug of dim (#847) --- 06.understand_sentiment/README.cn.md | 4 ++-- 06.understand_sentiment/README.md | 4 ++-- 06.understand_sentiment/index.cn.html | 4 ++-- 06.understand_sentiment/index.html | 4 ++-- 06.understand_sentiment/train_conv.py | 3 +-- 06.understand_sentiment/train_dyn_rnn.py | 3 +-- 06.understand_sentiment/train_stacked_lstm.py | 3 +-- 7 files changed, 11 insertions(+), 14 deletions(-) diff --git a/06.understand_sentiment/README.cn.md b/06.understand_sentiment/README.cn.md index e09036c..8f35f06 100755 --- a/06.understand_sentiment/README.cn.md +++ b/06.understand_sentiment/README.cn.md @@ -151,7 +151,7 @@ BATCH_SIZE = 128 #batch的大小 ```python #文本卷积神经网络 def convolution_net(data, input_dim, class_dim, emb_dim, hid_dim): - emb = fluid.layers.embedding( + emb = fluid.embedding( input=data, size=[input_dim, emb_dim], is_sparse=True) conv_3 = fluid.nets.sequence_conv_pool( input=emb, @@ -183,7 +183,7 @@ def convolution_net(data, input_dim, class_dim, emb_dim, hid_dim): def stacked_lstm_net(data, input_dim, class_dim, emb_dim, hid_dim, stacked_num): #计算词向量 - emb = fluid.layers.embedding( + emb = fluid.embedding( input=data, size=[input_dim, emb_dim], is_sparse=True) #第一层栈 diff --git a/06.understand_sentiment/README.md b/06.understand_sentiment/README.md index 0220bfe..4a91a5c 100644 --- a/06.understand_sentiment/README.md +++ b/06.understand_sentiment/README.md @@ -140,7 +140,7 @@ Note that `fluid.nets.sequence_conv_pool` contains both convolution and pooling ```python #Textconvolution neural network def convolution_net(data, input_dim, class_dim, emb_dim, hid_dim): - emb = fluid.layers.embedding( + emb = fluid.embedding( input=data, size=[input_dim, emb_dim], is_sparse=True) conv_3 = fluid.nets.sequence_conv_pool( input=emb, @@ -172,7 +172,7 @@ The code of the stack bidirectional LSTM `stacked_lstm_net` is as follows: def stacked_lstm_net(data, input_dim, class_dim, emb_dim, hid_dim, stacked_num): # Calculate word vectorvector - emb = fluid.layers.embedding( + emb = fluid.embedding( input=data, size=[input_dim, emb_dim], is_sparse=True) #First stack diff --git a/06.understand_sentiment/index.cn.html b/06.understand_sentiment/index.cn.html index d111e50..7c55155 100644 --- a/06.understand_sentiment/index.cn.html +++ b/06.understand_sentiment/index.cn.html @@ -193,7 +193,7 @@ BATCH_SIZE = 128 #batch的大小 ```python #文本卷积神经网络 def convolution_net(data, input_dim, class_dim, emb_dim, hid_dim): - emb = fluid.layers.embedding( + emb = fluid.embedding( input=data, size=[input_dim, emb_dim], is_sparse=True) conv_3 = fluid.nets.sequence_conv_pool( input=emb, @@ -225,7 +225,7 @@ def convolution_net(data, input_dim, class_dim, emb_dim, hid_dim): def stacked_lstm_net(data, input_dim, class_dim, emb_dim, hid_dim, stacked_num): #计算词向量 - emb = fluid.layers.embedding( + emb = fluid.embedding( input=data, size=[input_dim, emb_dim], is_sparse=True) #第一层栈 diff --git a/06.understand_sentiment/index.html b/06.understand_sentiment/index.html index 94ce282..c363ba1 100644 --- a/06.understand_sentiment/index.html +++ b/06.understand_sentiment/index.html @@ -182,7 +182,7 @@ Note that `fluid.nets.sequence_conv_pool` contains both convolution and pooling ```python #Textconvolution neural network def convolution_net(data, input_dim, class_dim, emb_dim, hid_dim): - emb = fluid.layers.embedding( + emb = fluid.embedding( input=data, size=[input_dim, emb_dim], is_sparse=True) conv_3 = fluid.nets.sequence_conv_pool( input=emb, @@ -214,7 +214,7 @@ The code of the stack bidirectional LSTM `stacked_lstm_net` is as follows: def stacked_lstm_net(data, input_dim, class_dim, emb_dim, hid_dim, stacked_num): # Calculate word vectorvector - emb = fluid.layers.embedding( + emb = fluid.embedding( input=data, size=[input_dim, emb_dim], is_sparse=True) #First stack diff --git a/06.understand_sentiment/train_conv.py b/06.understand_sentiment/train_conv.py index 46da94e..784e5a9 100644 --- a/06.understand_sentiment/train_conv.py +++ b/06.understand_sentiment/train_conv.py @@ -42,8 +42,7 @@ def parse_args(): def convolution_net(data, input_dim, class_dim, emb_dim, hid_dim): - emb = fluid.layers.embedding( - input=data, size=[input_dim, emb_dim], is_sparse=True) + emb = fluid.embedding(input=data, size=[input_dim, emb_dim], is_sparse=True) conv_3 = fluid.nets.sequence_conv_pool( input=emb, num_filters=hid_dim, diff --git a/06.understand_sentiment/train_dyn_rnn.py b/06.understand_sentiment/train_dyn_rnn.py index b967a21..439bc93 100644 --- a/06.understand_sentiment/train_dyn_rnn.py +++ b/06.understand_sentiment/train_dyn_rnn.py @@ -42,8 +42,7 @@ def parse_args(): def dynamic_rnn_lstm(data, input_dim, class_dim, emb_dim, lstm_size): - emb = fluid.layers.embedding( - input=data, size=[input_dim, emb_dim], is_sparse=True) + emb = fluid.embedding(input=data, size=[input_dim, emb_dim], is_sparse=True) sentence = fluid.layers.fc(input=emb, size=lstm_size * 4, act='tanh') lstm, _ = fluid.layers.dynamic_lstm(sentence, size=lstm_size * 4) diff --git a/06.understand_sentiment/train_stacked_lstm.py b/06.understand_sentiment/train_stacked_lstm.py index 11a5dfd..22cd3bc 100644 --- a/06.understand_sentiment/train_stacked_lstm.py +++ b/06.understand_sentiment/train_stacked_lstm.py @@ -46,8 +46,7 @@ def parse_args(): def stacked_lstm_net(data, input_dim, class_dim, emb_dim, hid_dim, stacked_num): assert stacked_num % 2 == 1 - emb = fluid.layers.embedding( - input=data, size=[input_dim, emb_dim], is_sparse=True) + emb = fluid.embedding(input=data, size=[input_dim, emb_dim], is_sparse=True) fc1 = fluid.layers.fc(input=emb, size=hid_dim) lstm1, cell1 = fluid.layers.dynamic_lstm(input=fc1, size=hid_dim) -- GitLab