def __init__(self, config, usegpu): super(HLSTMSeq, self).__init__() self.encoder = LSTMEncoder(config, usegpu) self.decoder = LSTMDecoder(config, usegpu) self.trans_linear = nn.Linear(self.encoder.feature_len, self.decoder.feature_len) self.dropout = nn.Dropout(config.getfloat("train", "dropout"))
class MultiLSTM(nn.Module): def __init__(self, config, usegpu): super(MultiLSTM, self).__init__() self.encoder = LSTMEncoder(config, usegpu) self.decoder = FCDecoder(config, usegpu) self.dropout = nn.Dropout(config.getfloat("train", "dropout")) def init_hidden(self, config, usegpu): self.encoder.init_hidden(config, usegpu) def forward(self, x, doc_len, config): x = self.encoder(x, doc_len, config) x = self.dropout(x) x = self.decoder(x, doc_len, config) return x
class Article(nn.Module): def __init__(self, config, usegpu): super(Article, self).__init__() self.encoder = LSTMEncoder(config, usegpu) self.decoder = LSTMArticleDecoder(config, usegpu) self.dropout = nn.Dropout(config.getfloat("train", "dropout")) def init_hidden(self, config, usegpu): self.encoder.init_hidden(config, usegpu) self.decoder.init_hidden(config, usegpu) def forward(self, x, doc_len, config): x = self.encoder(x, doc_len, config) x = self.dropout(x) x = self.decoder(x, doc_len, config, self.encoder.attention) return x
class MultiLSTMSeq(nn.Module): def __init__(self, config, usegpu): super(MultiLSTMSeq, self).__init__() self.encoder = LSTMEncoder(config, usegpu) self.decoder = LSTMDecoder(config, usegpu) self.trans_linear = nn.Linear(self.encoder.feature_len, self.decoder.feature_len) self.dropout = nn.Dropout(config.getfloat("train", "dropout")) def init_hidden(self, config, usegpu): self.encoder.init_hidden(config, usegpu) self.decoder.init_hidden(config, usegpu) def forward(self, x, doc_len, config): x = self.encoder(x, doc_len, config) if self.encoder.feature_len != self.decoder.feature_len: x = self.trans_linear(x) x = self.dropout(x) x = self.decoder(x, doc_len, config, self.encoder.attention) return x
def __init__(self, config, usegpu): super(Article, self).__init__() self.encoder = LSTMEncoder(config, usegpu) self.decoder = LSTMArticleDecoder(config, usegpu) self.dropout = nn.Dropout(config.getfloat("train", "dropout"))