zoukankan      html  css  js  c++  java
  • pytorch RNN层api的几个参数说明

    classtorch.nn.RNN(*args**kwargs)

    input_size – The number of expected features in the input x

    hidden_size – The number of features in the hidden state h

    num_layers – Number of recurrent layers. E.g., setting num_layers=2 would mean stacking two RNNs together to form a stacked RNN, with the second RNN taking in outputs of the first RNN and computing the final results. Default: 1

    nonlinearity – The non-linearity to use. Can be either ‘tanh’ or ‘relu’. Default: ‘tanh’

    bias – If False, then the layer does not use bias weights b_ih and b_hh. Default: True

    batch_first – If True, then the input and output tensors are provided as (batch, seq, feature)

    dropout – If non-zero, introduces a Dropout layer on the outputs of each RNN layer except the last layer, with dropout probability equal to dropout. Default: 0

    bidirectional – If True, becomes a bidirectional RNN. Default: False

    有个参数一直理解错误,导致了认知困难

    首先,RNN这里的序列长度,是动态的,不写在参数里的,具体会由输入的input参数而定

    而num_layers并不是RNN的序列长度,而是堆叠层数,由上一层每个时间节点的输出作为下一层每个时间节点的输入

    RNN的对象接受的参数,input维度是(seq_len, batch_size, input_dim),h0维度是(num_layers * directions, batch_size, hidden_dim)

    其中,input的seq_len决定了序列的长度,h0是提供给每层RNN的初始输入,所有num_layers要和RNN的num_layers对得上

    返回两个值,一个output,一个hn

    hn的维度是(num_layers * directions, batch_size, hidden_dim),是RNN的右侧输出,如果是双向的话,就还有一个左侧输出

    output的维度是(seq_len, batch_size, hidden_dim * directions),是RNN的上侧输出

  • 相关阅读:
    CSS书写技巧(转)
    OutputCache祥解
    [推荐/译文/转]从底层角度看ASP.NETA lowlevel Look at the ASP.NET Architecture
    [转]ASP.NET页面解析
    .NET开发中你可能会用到的常用方法总结
    asp.net 页面清除缓存
    ASP.NET内部原理(HttpHandler和HttpModule)
    .NET开发中你可能会用到的常用方法总结(2)
    C#解析HTML
    如何理解IIS 7的两种应用程序池的管道模式(Managed Pipeline Mode)
  • 原文地址:https://www.cnblogs.com/catnip/p/8991212.html
Copyright © 2011-2022 走看看