Samrat Hasan
Samrat Hasan

Reputation: 383

AttributeError in creating module

I am getting the following error.

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

I have a class as follows.

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)

What I am doing wrong here? I am beginner in PyTorch, please help!

Upvotes: 0

Views: 495

Answers (1)

Wasi Ahmad
Wasi Ahmad

Reputation: 37691

The first thing you should always do when you create a module is call its super constructor. So, your class should look like this:

class Classifier(nn.Module):

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

Upvotes: 1

Related Questions