own pytorch neural network layer
How to Build Your Own PyTorch Neural Network Layer from Scratch
Within the class, we'll need an __init__ dunder function to initialize our linear layer and a forward function to do the forward calculation. We'll use the PyTorch official document as a guideline to build our module. From the document, an nn.Linear module has the following attributes: So we'll get these three attributes in: The class also needs to hold weight and bias parameters so it can be trained. Here we used torch.nn.Parameter to set our weight and bias, otherwise, it won't train. Also, note that we used torch.randn