Paddle icon indicating copy to clipboard operation
Paddle copied to clipboard

是否支持nested integer sequence的输入类型 (seq of integer seq)

Open rulai-huiyingl opened this issue 9 years ago • 2 comments

想要做的是每个word的representation由char-lstm和glove vector拼接而成。 每个word的每个char有一个char embedding,然后所有的char embedding经过一个lstm/cnn生成一个vector, 这个vector和word本身的glove vector拼在一起,提供给上层。 这样的话一个句子会有[32,14, 234,...]这种的word index seq来look up, 这是正常支持的,但还会有 [[88,46,21],[42,11],[45,61,40],...]来look up char embedding。好像没发现支持的。 请问一般这种情况是怎样处理的呢? 这种char 和word结合表示一个词还挺常见的 多谢多谢!

rulai-huiyingl avatar Nov 29 '17 04:11 rulai-huiyingl

找到了一个数据类型: integer_value_sub_sequence 请问为什么API里没有关于这个类型的描述以及有无使用的例子? 谢谢!

rulai-huiyingl avatar Dec 21 '17 21:12 rulai-huiyingl

希望实现的等价的tensorflow代码如下。 请问怎样可以同时得到word和char的index,并且在char index/emb上能够做convolution. 谢谢!

    char_input = tf.placeholder(tf.int32,shape=[batch_size, num_steps, max_word_len],name="char_input")
    
    with tf.variable_scope('char_embedding'):
        char_embedding = tf.get_variable("char_embedding",
            [char_vocab_size,char_emb_size], 
            initializer=charemb_initializer(char_emb_size),
            dtype=tf.float32)
        input_embedded = tf.nn.embedding_lookup(char_embedding, char_input)
        input_embedded = tf.reshape(input_embedded, [-1, max_word_len, char_emb_size])

    char_rep = char_cnn(input_embedded, filter_sizes, nfilters)  #apply convolution
    char_rep = tf.reshape(char_rep, [batch_size, num_steps, -1])    

    word_input = tf.placeholder(tf.int32, shape=[batch_size, num_steps], name='word_input')
    L = tf.Variable(pretrain_embedding, dtype=tf.float32, trainable=False)
    word_embedding = tf.nn.embedding_lookup(L, word_input)   

    word_rep = tf.concat([word_embedding, char_rep], axis=-1)    #concat char-cnn vector and word vector

word presentation部分的结构图如下 untitled1 其中char representation的结构图如下 untitled

rulai-huiyingl avatar Dec 21 '17 21:12 rulai-huiyingl