1

我正在尝试使用paddle-paddlehttps://github.com/baidu/Paddle)来训练(编码器-解码器)序列到序列模型以进行 POS 标记。

但是,我不会使用单词索引的一次性嵌入作为输入,而是使用我使用创建的虚构单词向量numpy。我已将单词向量添加到函数中的settings变量中:hook()dataprovider.py

def hook(settings, src_dict, trg_dict, file_list, **kwargs):
    # job_mode = 1: training mode
    # job_mode = 0: generating mode
    settings.job_mode = trg_dict is not None
    settings.src_dict = src_dict
    settings.logger.info("src dict len : %d" % (len(settings.src_dict)))
    settings.sample_count = 0
    settings.thematrix = np.random.rand(len(src_dict), len(trg_dict))
    if settings.job_mode:
        settings.trg_dict = trg_dict
        settings.slots = [
            #integer_value_sequence(len(settings.src_dict)),
            dense_vector_sequence(len(settings.src_dict)),
            integer_value_sequence(len(settings.trg_dict)),
            integer_value_sequence(len(settings.trg_dict)),
        ]
        settings.logger.info("trg dict len : %d" % (len(settings.trg_dict)))
    else:
        settings.slots = [
            integer_value_sequence(len(settings.src_dict)),
            integer_value_sequence(len(open(file_list[0], "r").readlines()))
        ]

在遍历句子及其 POS 标签时,我在https://github.com/alvations/rowrow/blob/master/dataprovider.py#L66上生成了这些虚构的向量而不是单词索引

在序列到序列模型中,由于输入(aka data_layer())不是 one-hot 嵌入,因此我不会使用嵌入层来包裹 one-hot 向量。但相反,我将使用全连接层将向量输入压缩到编码器大小,即https://github.com/alvations/rowrow/blob/master/seqToseq_net.py#L49

src_word_id = data_layer(name='source_language_word', size=source_dict_dim)
src_embedding = fc_layer(input=src_word_id, size=word_vector_dim)   
src_forward = simple_gru(input=src_embedding, size=encoder_size)
src_backward = simple_gru(input=src_embedding, size=encoder_size, reverse=True)
encoded_vector = concat_layer(input=[src_forward, src_backward])
with mixed_layer(size=decoder_size) as encoded_proj:
    encoded_proj += full_matrix_projection(input=encoded_vector)

通常,嵌入层是这样的:

src_embedding = embedding_layer(
    input=src_word_id,
    size=word_vector_dim,
    param_attr=ParamAttr(name='_source_language_embedding'))

神经网络计算图似乎是正确的,因为它在运行train.sh.

但是在获取下一批时会引发错误:

~/Paddle/demo/rowrow$ bash train.sh 
I1104 18:59:42.636052 18632 Util.cpp:151] commandline: /home/ltan/Paddle/binary/bin/../opt/paddle/bin/paddle_trainer --config=train.conf --save_dir=/home/ltan/Paddle/demo/rowrow/model --use_gpu=true --num_passes=100 --show_parameter_stats_period=1000 --trainer_count=4 --log_period=10 --dot_period=5 
I1104 18:59:46.503566 18632 Util.cpp:126] Calling runInitFunctions
I1104 18:59:46.503810 18632 Util.cpp:139] Call runInitFunctions done.
[WARNING 2016-11-04 18:59:46,847 default_decorators.py:40] please use keyword arguments in paddle config.
[INFO 2016-11-04 18:59:46,856 networks.py:1125] The input order is [source_language_word, target_language_word, target_language_next_word]
[INFO 2016-11-04 18:59:46,857 networks.py:1132] The output order is [__cost_0__]
I1104 18:59:46.871026 18632 Trainer.cpp:170] trainer mode: Normal
I1104 18:59:46.871906 18632 MultiGradientMachine.cpp:108] numLogicalDevices=1 numThreads=4 numDevices=4
I1104 18:59:46.988584 18632 PyDataProvider2.cpp:247] loading dataprovider dataprovider::process
[INFO 2016-11-04 18:59:46,990 dataprovider.py:15] src dict len : 45661
[INFO 2016-11-04 18:59:47,316 dataprovider.py:26] trg dict len : 422
I1104 18:59:47.347944 18632 PyDataProvider2.cpp:247] loading dataprovider dataprovider::process
[INFO 2016-11-04 18:59:47,348 dataprovider.py:15] src dict len : 45661
[INFO 2016-11-04 18:59:47,657 dataprovider.py:26] trg dict len : 422
I1104 18:59:47.658279 18632 GradientMachine.cpp:134] Initing parameters..
I1104 18:59:49.244287 18632 GradientMachine.cpp:141] Init parameters done.
F1104 18:59:50.485621 18632 PythonUtil.h:213] Check failed: PySequence_Check(seq_) 
*** Check failure stack trace: ***
    @     0x7f71f521adaa  (unknown)
    @     0x7f71f521ace4  (unknown)
    @     0x7f71f521a6e6  (unknown)
    @     0x7f71f521d687  (unknown)
    @           0x54dac9  paddle::DenseScanner::fill()
    @           0x54f1d1  paddle::SequenceScanner::fill()
    @           0x5543cc  paddle::PyDataProvider2::getNextBatchInternal()
    @           0x5779b2  paddle::DataProvider::getNextBatch()
    @           0x6a01f7  paddle::Trainer::trainOnePass()
    @           0x6a3b57  paddle::Trainer::train()
    @           0x53a2b3  main
    @     0x7f71f4426f45  (unknown)
    @           0x545ae5  (unknown)
    @              (nil)  (unknown)
/home/ltan/Paddle/binary/bin/paddle: line 81: 18632 Aborted                 (core dumped) ${DEBUGGER} $MYDIR/../opt/paddle/bin/paddle_trainer ${@:2}

我试过在 Paddle 的gitter.im上询问,但没有任何回应。

有人知道吗:

  • 错误是什么意思?
  • 如何将密集向量序列输入 Paddle 中的 seqToseq 模型?
  • 为什么 Paddle 在将 dense_vector_sequence 输入到 SeqToseq 模型时会抛出此错误?
4

0 回答 0