Skip to content
ml-recall

#nn-module

2 questions from PyTorch

Timed test

2 questions · 2 min · score and explanations at the end

Take a test
Q 1 / 2Score 0 / 0

Question 1: Short answer

mediumAI-checkedPyTorch

What does the last line print?

import torch
from torch import nn

class ListSequential(nn.Module):
    def __init__(self, *args):
        super().__init__()
        self.layers = list(args)       # a plain Python list

    def forward(self, X):
        for layer in self.layers:
            X = layer(X)
        return X

net = ListSequential(nn.Linear(20, 256), nn.ReLU(), nn.Linear(256, 10))
print(len(list(net.parameters())))

a whole number