0

我收到以下错误。

AttributeError:不能在模块之前分配模块。初始化()调用

我有一堂课如下。

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 的初学者,请帮忙!

4

1 回答 1

1

创建模块时,您应该始终做的第一件事就是调用它的超级构造函数。所以,你的班级应该是这样的:

class Classifier(nn.Module):

    def __init__(self, dictionary, embeddings_index, max_seq_length, args): 
        super(Classifier, self).__init__() 
        '''Rest of your code goes here.'''
于 2017-06-15T21:46:03.583 回答