2017-06-15 6 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.'''