我正在使用embedding_lookup操作,以便为我的文档中的每个令牌生成密集的向量表示,这些表示被提供给卷积神经网络(网络架构类似于WildML文章中的那个).
一切正常但是当我填充文档时在其中插入填充值时,嵌入查找也会生成此标记的向量.我认为这种方法可以改变分类任务中的结果.我想要实现的是与Torch LookupTableMaskZero类似的东西.
1)我想做什么是正确的?
2)已经实现了这样的东西?
3)如果没有,我如何屏蔽填充值以防止生成相应的向量?
先感谢您,
亚历山德罗
我在Tensorflow中使用了一个while_loop,以迭代张量并提取给定维度上的特定切片.对于每个步骤,我需要使用解码器RNN来生成输出符号序列.我正在使用tf.contrib.seq2seq中提供的代码,特别是tf.contrib.seq2seq.dynamic_decode.代码类似于以下内容:
def decoder_condition(i, data, source_seq_len, ta_outputs):
return tf.less(i, max_loop_len)
def decode_body(i, data, source_seq_len, ta_outputs):
curr_data = data[:, i, :]
curr_source_seq_len = source_seq_len[:, i, :]
attention_mechanism = tf.contrib.seq2seq.LuongAttention(
2 * self.opt["encoder_rnn_h_size"],
curr_data,
memory_sequence_length=curr_source_seq_len
)
cell = GRUCell(num_units)
cell = AttentionWrapper(cell, attention_mechanism)
# ... other code that initialises all the variables required
# for the RNN decoder
outputs = tf.contrib.seq2seq.dynamic_decode(
decoder,
maximum_iterations=self.opt["max_sys_seq_len"],
swap_memory=True
)
with tf.control_dependencies([outputs)]:
ta_outputs = ta_outputs.write(i, outputs)
return i+1, data, ta_outputs
loop_index = tf.constant(0)
gen_outputs …Run Code Online (Sandbox Code Playgroud)