2017-06-15 101 views
0

我收到以下錯誤消息。創建模塊時出現AttributeError

AttributeError: cannot assign module before Module.init() call

我有一個類如下。

class Classifier(nn.Module): 

    def __init__(self, dictionary, embeddings_index, max_seq_length, args): 
     self.embedding = EmbeddingLayer(len(dictionary), args.emsize, args.dropout) 
     self.drop = nn.Dropout(args.dropout) 

我在做什麼錯在這裏?我是PyTorch的初學者,請幫忙!

回答

2

創建模塊時,應該始終執行的第一件事是調用其超級構造函數。所以,你的班級應該是這樣的:

class Classifier(nn.Module): 

    def __init__(self, dictionary, embeddings_index, max_seq_length, args): 
     super(Classifier, self).__init__() 
     '''Rest of your code goes here.'''