def loadmodel(self, nameprefix, load_incomplete=False):
        """ Save the model with names according to the prefix.

        Given the prefix of the file paths, load 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).

        :param nameprefix: prefix of the paths of the file
        :param load_incomplete: load encoder only, not decoder and autoencoder file (Default: False; put True for model built in version <= 0.2.1)
        :return: None
        :type nameprefix: str
        :type load_incomplete: bool
        """
        # load the JSON file (parameters)
        parameters = json.load(open(nameprefix + '.json', 'rb'))
        self.nb_topics = parameters['nb_topics']
        self.classlabels = parameters['classlabels']

        self.dictionary = Dictionary.load(nameprefix + '.gensimdict')
        self.encoder = kerasio.load_model(nameprefix + '_encoder')
        self.classtopicvecs = pickle.load(
            open(nameprefix + '_classtopicvecs.pkl', 'r'))
        if not load_incomplete:
            self.decoder = kerasio.load_model(nameprefix + '_decoder')
            self.autoencoder = kerasio.load_model(nameprefix + '_autoencoder')
        self.trained = True
 def loadmodel(self, nameprefix):
     self.model = kerasio.load_model(nameprefix)
     labelfile = open(nameprefix+'_classlabels.txt', 'r')
     self.classlabels = labelfile.readlines()
     labelfile.close()
     self.classlabels = map(lambda s: s.strip(), self.classlabels)
     self.trained = True
Example #3
0
    def loadmodel(self, nameprefix):
        stackedmodeldict = pickle.load(
            open(nameprefix + '_stackedlogistics.pkl', 'r'))
        self.register_classlabels(stackedmodeldict['classlabels'])
        self.classifier2idx = stackedmodeldict['classifiers']
        self.idx2classifier = {}
        for key, val in self.classifier2idx.items():
            self.idx2classifier[val] = key

        self.model = kerasio.load_model(nameprefix + '_stackedlogistics')

        self.trained = True
Example #4
0
    def loadmodel(self, nameprefix):
        """ Save the model with names according to the prefix.

        Given the prefix of the file paths, load 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).

        :param nameprefix: prefix of the paths of the file
        :return: None
        :type nameprefix: str
        """
        self.dictionary = Dictionary.load(nameprefix + '.gensimdict')
        self.encoder = kerasio.load_model(nameprefix + '_encoder')
        self.classtopicvecs = pickle.load(
            open(nameprefix + '_classtopicvecs.pkl', 'r'))
        self.trained = True
    def loadmodel(self, nameprefix):
        """ Load a trained model from files.

        Given the prefix of the file paths, load the model from files with name given by the prefix
        followed by "_classlabels.txt", ".json", and ".h5".

        If this has not been run, or a model was not trained by :func:`~train`,
        a `ModelNotTrainedException` will be raised.

        :param nameprefix: prefix of the file path
        :return: None
        :type nameprefix: str
        """
        self.model = kerasio.load_model(nameprefix)
        labelfile = open(nameprefix+'_classlabels.txt', 'r')
        self.classlabels = labelfile.readlines()
        labelfile.close()
        self.classlabels = map(lambda s: s.strip(), self.classlabels)
        self.trained = True