一直在等待,一直会等待 RNN系列--3

1、tf.nn.dynamic_rnn

tf.nn.dynamic_rnn(
    cell,
    inputs,
    sequence_length=None,
    initial_state=None,
    dtype=None,
    parallel_iterations=None,
    swap_memory=False,
    time_major=False,
    scope=None
)

         功能: 通过给定的RNNCell创建递归神经网络,实现输入的全自动展开
         参数:
cell: RNNCell实例
inputs: RNNCell的输入
initial_state: RNN的初始状态,如果cell.state_size为整数,形状为[batch_size, cell.state_size]. 如果cell.state_size为元组tuple,形状为[batch_size, s] for s in cell.state_size.
time_major: 输入输出形状格式,为True时,[max_time, batch_size, depth];为False时,[batch_size, max_time, depth]

         返回值: (outputs, state)
outputs: 输出值,输出格式由time_major决定
state: 最后隐层的状态值
         cell.state_size为整数,shape为 [batch_size, cell.state_size];否则shaped为[batch_size] + cell.state_size.

         注意: RNNCell的两个重要类属性
state_size: 隐层的大小
output_size: 输出的大小
Keras关于LSTM的units参数: https://www.zhihu.com/question/64470274/answer/256379387

        单层RNN代码示例:

# create a BasicRNNCell,隐层大小设置为hidden_size,此处解释为Keras关于LSTM的units参数
rnn_cell = tf.nn.rnn_cell.BasicRNNCell(hidden_size)

# 'outputs' is a tensor of shape [batch_size, max_time, cell_state_size]
# 'inputs' is a tensor of shape [batch_size, max_time, input_size]
# max_time是序列本身的长度,如果为句子,则为10个单词;input_size是输入数据单个序列单个时间维度上固有的长度;

# defining initial state,即时间为0时,RNNCell的状态
initial_state = rnn_cell.zero_state(batch_size, dtype=tf.float32)

# 'state' is a tensor of shape [batch_size, cell_state_size]
outputs, state = tf.nn.dynamic_rnn(rnn_cell, input_data,
                                   initial_state=initial_state,
                                   dtype=tf.float32)

        多层RNN代码示例:

# create 2 LSTMCells
rnn_layers = [tf.nn.rnn_cell.LSTMCell(size) for size in [128, 256]]

# create a RNN cell composed sequentially of a number of RNNCells
multi_rnn_cell = tf.nn.rnn_cell.MultiRNNCell(rnn_layers)

# 'outputs' is a tensor of shape [batch_size, max_time, 256]
# 'state' is a N-tuple where N is the number of LSTMCells containing a
# tf.contrib.rnn.LSTMStateTuple for each cell
outputs, state = tf.nn.dynamic_rnn(cell=multi_rnn_cell,
                                   inputs=data,
                                   dtype=tf.float32)

2、tf.nn.rnn_cell.DropoutWrapper

__init__(
    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
)

tensorflow.python.array_ops.split

@tf_export("split")
def split(value, num_or_size_splits, axis=0, num=None, name="split"):
Splits a tensor into sub tensors.

  If `num_or_size_splits` is an integer type, then `value` is split
  along dimension `axis` into `num_split` smaller tensors.
  Requires that `num_split` evenly divides `value.shape[axis]`.

  If `num_or_size_splits` is not an integer type, it is presumed to be a Tensor
  `size_splits`, then splits `value` into `len(size_splits)` pieces. The shape
  of the `i`-th piece has the same size as the `value` except along dimension
  `axis` where the size is `size_splits[i]`.

  For example:


  # 'value' is a tensor with shape [5, 30]
  # Split 'value' into 3 tensors with sizes [4, 15, 11] along dimension 1
  split0, split1, split2 = tf.split(value, [4, 15, 11], 1)
  tf.shape(split0)  # [5, 4]
  tf.shape(split1)  # [5, 15]
  tf.shape(split2)  # [5, 11]
  
  # Split 'value' into 3 tensors along dimension 1
  split0, split1, split2 = tf.split(value, num_or_size_splits=3, axis=1)
  tf.shape(split0)  # [5, 10]

tf.nn.rnn_cell.LSTMStateTuple

         Tuple used by LSTM Cells for state_size, zero_state, and output state. Stores two elements: (c, h), in that order. Where c is the hidden state and h is the output. Only used when state_is_tuple=True.

### 回答1: CNN-RNN-CTC是一种用于语音识别的深度学习模型。这个模型结合了卷积神经网络(CNN),循环神经网络(RNN)和连续标签分类(CTC)的算法。 首先,卷积神经网络(CNN)被用来从原始语音信号中提取特征。CNN通过一系列卷积和池化操作,可以有效地捕捉到语音信号中的时频特征。这些特征在后续的处理中起到了很重要的作用。 其次,循环神经网络(RNN)在特征提取后的序列数据上进行处理。RNN具有记忆功能,可以处理变长的序列数据。这使得RNN能够更好地建模语音信号的时序关系,从而提高语音识别的性能。 最后,连续标签分类(CTC)是一种解决无对齐标签序列训练问题的方法。在语音识别中,输入序列和输出序列之间的对齐是未知的,这使得传统的监督学习方法难以应用。CTC通过引入一个空白标签和重复标签,可以将输入序列的输出序列映射到最有可能的标签序列。通过优化CTC损失函数,我们可以训练模型来进行语音识别,并且不需要进行手工的对齐。 总而言之,CNN-RNN-CTC模型将卷积神经网络的特征提取能力,循环神经网络的序列建模能力和连续标签分类的对齐能力相结合,能够有效地解决语音识别中的训练问题,提高语音识别的性能。 ### 回答2: CNN-RNN-CTC是一种常用的深度学习模型,适用于序列标注任务,如语音识别或文本识别。该模型结合了卷积神经网络(CNN)、循环神经网络(RNN)和连续条件随机场(CTC)的优势。 首先,CNN经常被用于图像处理任务,能够有效提取图像特征。在CNN-RNN-CTC模型中,CNN用来对输入的声学特征或图像进行特征提取,将其转化为更适合序列任务的形式。 其次,RNN是一种能够处理序列数据的神经网络,能够捕捉到数据的时间依赖关系。在CNN-RNN-CTC模型中,RNN用来对CNN提取的特征进行进一步处理,从而得到更加准确的序列标注结果。 最后,CTC是一种解决序列对齐问题的方法。在CNN-RNN-CTC模型中,CTC用来实现无对齐标签的序列学习,可以自动进行对齐和标注的训练。它中的条件随机场层可以根据输入序列和标签序列之间的对应关系,计算出最可能的标签序列。 综上所述,CNN-RNN-CTC模型能够利用CNN提取输入的特征,RNN处理序列数据,CTC解决标签对齐问题,从而有效地解决序列标注任务。在语音识别或文本识别等方面有较好的应用效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值