From b6f542dd0d763ee1e9dce583a4e6bca2d095233d Mon Sep 17 00:00:00 2001 From: Steffy-zxf Date: Wed, 17 Jun 2020 16:26:16 +0800 Subject: [PATCH] update doc_string --- .../text/embedding/word2vec_skipgram/module.py | 2 +- .../emotion_detection_textcnn/module.py | 2 +- .../text/sentiment_analysis/senta_bilstm/net.py | 15 ++++++--------- .../text/sentiment_analysis/senta_bow/net.py | 8 ++++---- .../text/sentiment_analysis/senta_cnn/net.py | 14 ++++---------- .../text/sentiment_analysis/senta_gru/net.py | 10 +++++----- .../text/sentiment_analysis/senta_lstm/net.py | 14 ++++---------- 7 files changed, 25 insertions(+), 40 deletions(-) diff --git a/hub_module/modules/text/embedding/word2vec_skipgram/module.py b/hub_module/modules/text/embedding/word2vec_skipgram/module.py index 0d42b93d..990def7f 100644 --- a/hub_module/modules/text/embedding/word2vec_skipgram/module.py +++ b/hub_module/modules/text/embedding/word2vec_skipgram/module.py @@ -70,7 +70,7 @@ class Word2vecSkipGram(hub.Module): Returns: inputs(dict): the input variables of word2vec_skipgram (words) outputs(dict): the output variables of input words (word embeddings) - main_program(Program): the main_program of Senta with pretrained prameters + main_program(Program): the main_program of word2vec_skipgram with pretrained prameters """ assert num_data >= 1 and num_data <= 3, "num_data(%d) must be 1, 2, or 3" % num_data main_program = fluid.Program() diff --git a/hub_module/modules/text/sentiment_analysis/emotion_detection_textcnn/module.py b/hub_module/modules/text/sentiment_analysis/emotion_detection_textcnn/module.py index 14f70b84..6cda6ff5 100644 --- a/hub_module/modules/text/sentiment_analysis/emotion_detection_textcnn/module.py +++ b/hub_module/modules/text/sentiment_analysis/emotion_detection_textcnn/module.py @@ -61,7 +61,7 @@ class EmotionDetectionTextCNN(hub.NLPPredictionModule): inputs(dict): the input variables of emotion_detection_textcnn (words) outputs(dict): the output variables of input words (word embeddings and label probilities); the sentence embedding and sequence length of the first input text. - main_program(Program): the main_program of Senta with pretrained prameters + main_program(Program): the main_program of emotion_detection_textcnn with pretrained prameters """ assert num_data >= 1 and num_data <= 3, "num_data(%d) must be 1, 2, or 3" % num_data main_program = fluid.Program() diff --git a/hub_module/modules/text/sentiment_analysis/senta_bilstm/net.py b/hub_module/modules/text/sentiment_analysis/senta_bilstm/net.py index 67b0ba62..31d7a20e 100755 --- a/hub_module/modules/text/sentiment_analysis/senta_bilstm/net.py +++ b/hub_module/modules/text/sentiment_analysis/senta_bilstm/net.py @@ -2,8 +2,8 @@ import paddle.fluid as fluid -def bilstm_net(data, - dict_dim, +def bilstm_net(emb, + seq_len, emb_dim=128, hid_dim=128, hid_dim2=96, @@ -12,15 +12,12 @@ def bilstm_net(data, """ Bi-Lstm net """ - # embedding layer - emb = fluid.layers.embedding( - input=data, - size=[dict_dim, emb_dim], - ) + # unpad the token_feature + unpad_feature = fluid.layers.sequence_unpad(emb, length=seq_len) # bi-lstm layer - fc0 = fluid.layers.fc(input=emb, size=hid_dim * 4) - rfc0 = fluid.layers.fc(input=emb, size=hid_dim * 4) + fc0 = fluid.layers.fc(input=unpad_feature, size=hid_dim * 4) + rfc0 = fluid.layers.fc(input=unpad_feature, size=hid_dim * 4) lstm_h, c = fluid.layers.dynamic_lstm( input=fc0, size=hid_dim * 4, is_reverse=False) rlstm_h, c = fluid.layers.dynamic_lstm( diff --git a/hub_module/modules/text/sentiment_analysis/senta_bow/net.py b/hub_module/modules/text/sentiment_analysis/senta_bow/net.py index d9510ba4..173e2fe0 100755 --- a/hub_module/modules/text/sentiment_analysis/senta_bow/net.py +++ b/hub_module/modules/text/sentiment_analysis/senta_bow/net.py @@ -2,15 +2,15 @@ import paddle.fluid as fluid -def bow_net(data, dict_dim, emb_dim=128, hid_dim=128, hid_dim2=96, class_dim=2): +def bow_net(emb, seq_len, hid_dim=128, hid_dim2=96, class_dim=2): """ Bow net """ - # embedding layer - emb = fluid.layers.embedding(input=data, size=[dict_dim, emb_dim]) + # unpad the token_feature + unpad_feature = fluid.layers.sequence_unpad(emb, length=seq_len) # bow layer - bow = fluid.layers.sequence_pool(input=emb, pool_type='sum') + bow = fluid.layers.sequence_pool(input=unpad_feature, pool_type='sum') bow_tanh = fluid.layers.tanh(bow) # full connect layer fc_1 = fluid.layers.fc(input=bow_tanh, size=hid_dim, act="tanh") diff --git a/hub_module/modules/text/sentiment_analysis/senta_cnn/net.py b/hub_module/modules/text/sentiment_analysis/senta_cnn/net.py index 030367b8..652234b6 100755 --- a/hub_module/modules/text/sentiment_analysis/senta_cnn/net.py +++ b/hub_module/modules/text/sentiment_analysis/senta_cnn/net.py @@ -2,22 +2,16 @@ import paddle.fluid as fluid -def cnn_net(data, - dict_dim, - emb_dim=128, - hid_dim=128, - hid_dim2=96, - class_dim=2, - win_size=3): +def cnn_net(emb, seq_len, hid_dim=128, hid_dim2=96, class_dim=2, win_size=3): """ Conv net """ - # embedding layer - emb = fluid.layers.embedding(input=data, size=[dict_dim, emb_dim]) + # unpad the token_feature + unpad_feature = fluid.layers.sequence_unpad(emb, length=seq_len) # convolution layer conv_3 = fluid.nets.sequence_conv_pool( - input=emb, + input=unpad_feature, num_filters=hid_dim, filter_size=win_size, act="tanh", diff --git a/hub_module/modules/text/sentiment_analysis/senta_gru/net.py b/hub_module/modules/text/sentiment_analysis/senta_gru/net.py index b3ae5b8a..7e6a313e 100755 --- a/hub_module/modules/text/sentiment_analysis/senta_gru/net.py +++ b/hub_module/modules/text/sentiment_analysis/senta_gru/net.py @@ -2,8 +2,8 @@ import paddle.fluid as fluid -def gru_net(data, - dict_dim, +def gru_net(emb, + seq_len, emb_dim=128, hid_dim=128, hid_dim2=96, @@ -12,10 +12,10 @@ def gru_net(data, """ gru net """ - # embedding layer - emb = fluid.layers.embedding(input=data, size=[dict_dim, emb_dim]) + # unpad the token_feature + unpad_feature = fluid.layers.sequence_unpad(emb, length=seq_len) - fc0 = fluid.layers.fc(input=emb, size=hid_dim * 3) + fc0 = fluid.layers.fc(input=unpad_feature, size=hid_dim * 3) # GRU layer gru_h = fluid.layers.dynamic_gru(input=fc0, size=hid_dim, is_reverse=False) diff --git a/hub_module/modules/text/sentiment_analysis/senta_lstm/net.py b/hub_module/modules/text/sentiment_analysis/senta_lstm/net.py index 6a50c316..ecf8c532 100755 --- a/hub_module/modules/text/sentiment_analysis/senta_lstm/net.py +++ b/hub_module/modules/text/sentiment_analysis/senta_lstm/net.py @@ -2,20 +2,14 @@ import paddle.fluid as fluid -def lstm_net(data, - dict_dim, - emb_dim=128, - hid_dim=128, - hid_dim2=96, - class_dim=2, - emb_lr=30.0): +def lstm_net(emb, seq_len, hid_dim=128, hid_dim2=96, class_dim=2, emb_lr=30.0): """ Lstm net """ - # embedding layer - emb = fluid.layers.embedding(input=data, size=[dict_dim, emb_dim]) + # unpad the token_feature + unpad_feature = fluid.layers.sequence_unpad(emb, length=seq_len) # Lstm layer - fc0 = fluid.layers.fc(input=emb, size=hid_dim * 4) + fc0 = fluid.layers.fc(input=unpad_feature, size=hid_dim * 4) lstm_h, c = fluid.layers.dynamic_lstm( input=fc0, size=hid_dim * 4, is_reverse=False) # max pooling layer -- GitLab