def savemodel(self, nameprefix):
     if not self.trained:
         raise ModelNotTrainedException()
     kerasio.save_model(nameprefix, self.model)
     labelfile = open(nameprefix+'_classlabels.txt', 'w')
     labelfile.write('\n'.join(self.classlabels))
     labelfile.close()
Esempio n. 2
0
    def savemodel(self, nameprefix):
        if not self.trained:
            raise e.ModelNotTrainedException()

        stackedmodeldict = {
            'classifiers': self.classifier2idx,
            'classlabels': self.classlabels
        }
        pickle.dump(stackedmodeldict,
                    open(nameprefix + '_stackedlogistics.pkl', 'w'))
        kerasio.save_model(nameprefix + '_stackedlogistics', self.model)
    def savemodel(self, nameprefix):
        """ Save the trained model into files.

        Given the prefix of the file paths, save the model into files, with name given by the prefix.
        There will be three files produced, one name ending with "_classlabels.txt", one name
        ending with ".json", and one name ending with ".h5".
        If there is no trained model, a `ModelNotTrainedException` will be thrown.

        :param nameprefix: prefix of the file path
        :return: None
        :type nameprefix: str
        :raise: ModelNotTrainedException
        """
        if not self.trained:
            raise e.ModelNotTrainedException()
        kerasio.save_model(nameprefix, self.model)
        labelfile = open(nameprefix+'_classlabels.txt', 'w')
        labelfile.write('\n'.join(self.classlabels))
        labelfile.close()
    def savemodel(self, nameprefix, save_complete_autoencoder=True):
        """ Save the model with names according to the prefix.

        Given the prefix of the file paths, save the model into files, with name given by the prefix.
        There are files with names ending with "_encoder.json" and "_encoder.h5", which are
        the JSON and HDF5 files for the encoder respectively. They also include a gensim dictionary (.gensimdict).

        If `save_complete_autoencoder` is True,
        then there are also files with names ending with "_decoder.json" and "_decoder.h5".

        If neither :func:`~train` nor :func:`~loadmodel` was run, it will raise `ModelNotTrainedException`.

        :param nameprefix: prefix of the paths of the file
        :param save_complete_autoencoder: whether to store the decoder and the complete autoencoder (Default: True; but False for version <= 0.2.1)
        :return: None
        :type nameprefix: str
        :type save_complete_autoencoder: bool
        """
        if not self.trained:
            raise e.ModelNotTrainedException()

        parameters = {}
        parameters['nb_topics'] = self.nb_topics
        parameters['classlabels'] = self.classlabels
        json.dump(parameters, open(nameprefix + '.json', 'wb'))

        self.dictionary.save(nameprefix + '.gensimdict')
        kerasio.save_model(nameprefix + '_encoder', self.encoder)
        if save_complete_autoencoder:
            kerasio.save_model(nameprefix + '_decoder', self.decoder)
            kerasio.save_model(nameprefix + '_autoencoder', self.autoencoder)
        pickle.dump(self.classtopicvecs,
                    open(nameprefix + '_classtopicvecs.pkl', 'w'))