首页 > 解决方案 > pytorch lstm weight是什么意思?

问题描述

我有一个简单的 lstm pytorch 模型,模型结构是:

LSTM(
  (lstm): LSTM(1, 2)
  (fc): Linear(in_features=2, out_features=1, bias=True)
)

这是一个简单的任务,我想预测字母序列。

这意味着:x 是 [[[1, 2, 3]]] - > [4] (1-A, 2-B, 3-C),我想输入'ABC',训练后输出'D' ,我想更多地了解我的 lstm 层。所以我打印这样的模型参数:

n [7]: l = a._modules['lstm']

In [8]: l.__dict__
Out[8]: 
{'training': True,
 '_parameters': OrderedDict([('weight_ih_l0',
               Parameter containing:
               tensor([[ 0.2127],
                       [ 1.5807],
                       [-0.8566],
                       [ 1.0215],
                       [-0.7563],
                       [ 0.8248],
                       [-0.7307],
                       [ 1.4174]], dtype=torch.float64, requires_grad=True)),
              ('weight_hh_l0',
               Parameter containing:
               tensor([[ 0.0245, -0.5089],
                       [ 0.0338,  2.8269],
                       [-1.0781, -0.4691],
                       [-0.2368,  2.2788],
                       [-1.0743,  0.5130],
                       [ 0.8970, -0.0829],
                       [-0.7051, -4.8892],
                       [-0.5335,  1.8777]], dtype=torch.float64, requires_grad=True)),
              ('bias_ih_l0',
               Parameter containing:
               tensor([ 1.7890,  2.4625, -0.4471,  0.8364, -1.2260,  1.5116,  2.1067,  1.6485],
                      dtype=torch.float64, requires_grad=True)),
              ('bias_hh_l0',
               Parameter containing:
               tensor([ 1.5659,  2.6634, -0.2972,  0.6908, -1.1136,  0.8588,  1.4372,  1.6157],
                      dtype=torch.float64, requires_grad=True))]),
 '_buffers': OrderedDict(),
 '_non_persistent_buffers_set': set(),
 '_backward_hooks': OrderedDict(),
 '_is_full_backward_hook': None,
 '_forward_hooks': OrderedDict(),
 '_forward_pre_hooks': OrderedDict(),
 '_state_dict_hooks': OrderedDict(),
 '_load_state_dict_pre_hooks': OrderedDict(),
 '_modules': OrderedDict(),
 'mode': 'LSTM',
 'input_size': 1,
 'hidden_size': 2,
 'num_layers': 1,
 'bias': True,
 'batch_first': False,
 'dropout': 0.0,
 'bidirectional': False,
 'proj_size': 0,
 '_flat_weights_names': ['weight_ih_l0',
  'weight_hh_l0',
  'bias_ih_l0',
  'bias_hh_l0'],
 '_all_weights': [['weight_ih_l0',
   'weight_hh_l0',
   'bias_ih_l0',
   'bias_hh_l0']],
 '_flat_weights': [Parameter containing:
  tensor([[ 0.2127],
          [ 1.5807],
          [-0.8566],
          [ 1.0215],
          [-0.7563],
          [ 0.8248],
          [-0.7307],
          [ 1.4174]], dtype=torch.float64, requires_grad=True),
  Parameter containing:
  tensor([[ 0.0245, -0.5089],
          [ 0.0338,  2.8269],
          [-1.0781, -0.4691],
          [-0.2368,  2.2788],
          [-1.0743,  0.5130],
          [ 0.8970, -0.0829],
          [-0.7051, -4.8892],
          [-0.5335,  1.8777]], dtype=torch.float64, requires_grad=True),
  Parameter containing:
  tensor([ 1.7890,  2.4625, -0.4471,  0.8364, -1.2260,  1.5116,  2.1067,  1.6485],
         dtype=torch.float64, requires_grad=True),
  Parameter containing:
  tensor([ 1.5659,  2.6634, -0.2972,  0.6908, -1.1136,  0.8588,  1.4372,  1.6157],
         dtype=torch.float64, requires_grad=True)]}

weight_ih_10你能帮助理解模型输出吗,weight_hh_10,bias_hh_10和其他东西的含义是什么?

标签: pythonpytorchlstm

解决方案


推荐阅读