def __init__(self, encoderParam, decoderParam, verbose=1):
        '''
            A-Bot Model

            Uses an encoder network for input sequences (questions, answers and
            history) and a decoder network for generating a response (answer).
        '''
        super(Answerer, self).__init__()
        self.encType = encoderParam['type']
        self.decType = decoderParam['type']

        # Encoder
        if verbose:
            print('Encoder: ' + self.encType)
            print('Decoder: ' + self.decType)
        if 'hre' in self.encType:
            self.encoder = hre_enc.Encoder(**encoderParam)
        else:
            raise Exception('Unknown encoder {}'.format(self.encType))

        # Decoder
        if 'gen' == self.decType:
            self.decoder = gen_dec.Decoder(**decoderParam)
        else:
            raise Exception('Unkown decoder {}'.format(self.decType))

        # Share word embedding parameters between encoder and decoder
        self.decoder.wordEmbed = self.encoder.wordEmbed

        # Initialize weights
        utils.initializeWeights(self.encoder)
        utils.initializeWeights(self.decoder)
        self.reset()
    def __init__(self,
                 encoderParam,
                 decoderParam,
                 imgFeatureSize=0,
                 verbose=1,
                 multiGPU=False):
        '''
            Q-Bot Model

            Uses an encoder network for input sequences (questions, answers and
            history) and a decoder network for generating a response (question).
        '''
        super(Questioner, self).__init__()
        self.encType = encoderParam['type']
        self.decType = decoderParam['type']
        self.dropout = encoderParam['dropout']
        self.rnnHiddenSize = encoderParam['rnnHiddenSize']
        self.imgFeatureSize = imgFeatureSize
        encoderParam = encoderParam.copy()
        encoderParam['isAnswerer'] = False

        # Encoder
        if verbose:
            print('Encoder: ' + self.encType)
            print('Decoder: ' + self.decType)
        if 'hre' in self.encType:
            self.encoder = hre_enc.Encoder(**encoderParam)
            if multiGPU:
                self.encoder = nn.DataParallel(self.encoder)
        else:
            raise Exception('Unknown encoder {}'.format(self.encType))

        # Decoder
        if 'gen' == self.decType:
            self.decoder = gen_dec.Decoder(**decoderParam)
            if multiGPU:
                self.decoder = nn.DataParallel(self.decoder)
        else:
            raise Exception('Unkown decoder {}'.format(self.decType))

        # Share word embedding parameters between encoder and decoder
        if multiGPU:
            self.decoder.module.wordEmbed = self.encoder.module.wordEmbed
        else:
            self.decoder.wordEmbed = self.encoder.wordEmbed

        # Setup feature regressor
        if self.imgFeatureSize:
            self.featureNet = nn.Linear(self.rnnHiddenSize,
                                        self.imgFeatureSize)
            if multiGPU:
                self.featureNet = nn.DataParallel(self.featureNet)
            self.featureNetInputDropout = nn.Dropout(0.5)

        # Initialize weights
        utils.initializeWeights(self.encoder)
        utils.initializeWeights(self.decoder)
        self.reset()
Exemple #3
0
    def __init__(self,
                 encoderParam,
                 decoderParam,
                 imgFeatureSize=0,
                 verbose=1):
        """
            Q-Bot Model

            Uses an encoder network for input sequences (questions, answers and
            history) and a decoder network for generating a response (question).
        """
        super(Questioner, self).__init__()
        self.encType = encoderParam["type"]
        self.decType = decoderParam["type"]
        self.dropout = encoderParam["dropout"]
        self.rnnHiddenSize = encoderParam["rnnHiddenSize"]
        self.imgFeatureSize = imgFeatureSize
        encoderParam = encoderParam.copy()
        encoderParam["isAnswerer"] = False

        # Encoder
        if verbose:
            print("Encoder: " + self.encType)
            print("Decoder: " + self.decType)
        if "hre" in self.encType:
            self.encoder = hre_enc.Encoder(**encoderParam)
        else:
            raise Exception("Unknown encoder {}".format(self.encType))

        # Decoder
        if "gen" == self.decType:
            self.decoder = gen_dec.Decoder(**decoderParam)
        else:
            raise Exception("Unkown decoder {}".format(self.decType))

        # Share word embedding parameters between encoder and decoder
        self.decoder.wordEmbed = self.encoder.wordEmbed

        # Setup feature regressor
        if self.imgFeatureSize:
            self.featureNet = nn.Linear(self.rnnHiddenSize,
                                        self.imgFeatureSize)
            self.featureNetInputDropout = nn.Dropout(0.5)

        # Initialize weights
        utils.initializeWeights(self.encoder)
        utils.initializeWeights(self.decoder)
        self.reset()