【问题标题】:What is the meaning of hidden_dim and embed_size in LSTM?LSTM中的hidden_​​dim和embed_size是什么意思?
【发布时间】:2019-09-22 21:27:10
【问题描述】:

我正在尝试学习 RNN 和 LSTM。我偶然发现了一个情绪分析教程。下面是我在教程中的代码,其中 word2idx 是具有单词到索引映射的字典

    class SentimentNet(nn.Module):
        def __init__(self, vocab_size, output_size, embedding_dim, hidden_dim, n_layers, drop_prob=0.5):
        super(SentimentNet, self).__init__()
        self.output_size = output_size
        self.n_layers = n_layers
        self.hidden_dim = hidden_dim

        self.embedding = nn.Embedding(vocab_size, embedding_dim)
        self.lstm = nn.LSTM(embedding_dim, hidden_dim, n_layers, dropout=drop_prob, batch_first=True)
        self.dropout = nn.Dropout(drop_prob)
        self.fc = nn.Linear(hidden_dim, output_size)
        self.sigmoid = nn.Sigmoid()

     vocab_size = len(word2idx) + 1
     output_size = 1
     embedding_dim = 400
     hidden_dim = 512
     n_layers = 2

谁能告诉我vocal_size、embedding_dim、hidden_​​dim的含义?

【问题讨论】:

    标签: python lstm recurrent-neural-network


    【解决方案1】:

    循环神经网络 (LSTM) 在最基本的层面上只是一种密集连接的神经网络。

    隐藏维度基本上是每层中的节点数(例如在多层感知器中)

    嵌入大小告诉你特征向量的大小(模型使用嵌入的词作为输入)

    here some details

    【讨论】:

    • @user11619814 不客气。不要忘记接受最佳答案:)
    • input_dim = 5,hidden_​​dim = 10,n_layers = 1, lstm_layer = nn.LSTM(input_dim, hidden_​​dim, n_layers, batch_first=True), batch_size = 1, seq_len = 3, inp = torch.randn (batch_size, seq_len, input_dim), hidden_​​state = torch.randn(n_layers, batch_size, hidden_​​dim), cell_state = torch.randn(n_layers, batch_size, hidden_​​dim), hidden = (hidden_​​state, cell_state), out, hidden = lstm_layer(inp,隐藏),打印(输出)
    • 所以在上面的代码中输入是[1,3,5],输出是[1,3,10],这意味着有3个输出对应于输入长度。如果我们想要在每个时间步输出,我们访问序列中的最后一个输出,所以我想知道第一个和第二个输出对应什么?它们有什么意义?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-07
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 2023-04-03
    相关资源
    最近更新 更多