LSTM 代码实践中的各种问题以及注释
1、tf.nn.dynamic_rnn 的作用
答案:解决基础的 RNNCell 每次只能在时间上前进了一步的缺点
2、bidirectional_dynamic_rnn 的参数及其注释
def bidirectional_dynamic_rnn(
cell_fw, # 前向RNN
cell_bw, # 后向RNN
inputs, # 输入
sequence_length=None,# 输入序列的实际长度(可选,默认为输入序列的最大长度)
initial_state_fw=None, # 前向的初始化状态(可选)
initial_state_bw=None, # 后向的初始化状态(可选)
dtype=None, # 初始化和输出的数据类型(可选)
parallel_iterations=None, # 并行执行循环的个数
swap_memory=False, # 交换内存
time_major=False,
# 决定了输入输出tensor的格式:如果为true, 向量的形状必须为 `[max_time, batch_size, depth]`.
# 如果为false, tensor的形状必须为`[batch_size, max_time, depth]`.
scope=None
)
————————————————
版权声明:本文为CSDN博主「Ai_践行者」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_41424519/article/details/82112904
3、
class DropoutWrapper(RNNCell):
"""Operator adding dropout to inputs and outputs of the given cell."""
def __init__(self, cell, input_keep_prob=1.0, output_keep_prob=1.0,
state_keep_prob=1.0, variational_recurrent=False,
input_size=None, dtype=None, seed=None,
dropout_state_filter_visitor=None):
函数注释:
这是一个能够对 cell 的输入、状态、输出进行随机缺失的装饰类
参数注释:
cell:一个 RNN cell
input_keep_prob:保持不缺失的可能性
output_keep_prob:保持不缺失的可能性
state_keep_prob:保持不缺失的可能性
variational_recurrent:默认为 False,如果设置为 True,则对每一步都进行缺失屏蔽处理
input_size:输入的维度
dropout_state_filter_visitor:自定义函数
def dropout_state_filter_visitor(s):
if isinstance(s, LSTMCellState):
# Never perform dropout on the c state.
return LSTMCellState(c=False, h=True)
elif isinstance(s, TensorArray):
return False
return True