SyntaxError: only named arguments may follow *expression on nn.Sequential()
def forward(self, x):
    x = x.view(-1)
    fwd = nn.Sequential(self.linear_1, *self.middle, self.output)
    return fwd(x)


It works python3 but not python2.7. The error is:


  fwd = nn.Sequential(self.linear_1, *self.middle, self.output)
  SyntaxError: only named arguments may follow *expression
  )


What can I convert this code to work on python2.7?

You could try the following syntax:

fwd = nn.Sequential(self.linear_1, *(self.middle + [self.output]))


This is assuming that self.middle is a list while self.output is an item (of class nn.Module).

The trick here is to combine self.middle and self.output in a single list and pass that to the nn.Sequential method.
