python torch和numpy

python torch和numpy

1. super().__init__()

这是用于python中,在你构造一个类的时候首先调用、继承父类的构造函数的一个方法。

import torch from torch import nn

class LandlordLstmModel(nn.Module): def init(self): super().__init__() … … …

结合上面的这段代码来看,我引用了torch中的nn,我在构造子类的初始化的时候,首先使用了super().__init__() 来初始化我的神经网络,之后再具体向网络中填东西。

2. torch中内置的LSTM

PyTorch 中的 torch.nn.LSTM 可以用于构建长短期记忆(LSTM)网络。 其构建的基本格式如下:

torch.nn.LSTM(input_size, hidden_size, num_layers=1, batch_first=False, dropout=0.0, bidirectional=False)


python torch和numpy
https://zrwrz.github.io/2025/10/14/python-torch和numpy/
作者
zrw
发布于
2025年10月14日
许可协议