예제 #1
0
	def from_dict(cls, model_dictionary):
		model_instance = MaxEnt()
		model_instance.label_codebook = Alphabet.from_dict(model_dict['label_alphabet'])
		model_instance.feature_codebook = Alphabet.from_dict(model_dict['feature_alphabet'])
		model_instance.p_x_given_y_table = numpy.array(model_dict['parameters'])

		return model_instance
예제 #2
0
    def from_dict(cls, model_dict):
        model_instance = MaxEnt()
        model_instance.label_codebook = Alphabet.from_dict(model_dict["label_alphabet"])
        model_instance.feature_codebook = Alphabet.from_dict(model_dict["feature_alphabet"])
        model_instance.parameters = numpy.array(model_dict["parameters"])

        return model_instance
예제 #3
0
	def deserialize(self, fname):
		"""Retrieve from serialization; keep defaults where possible."""
		with open(fname, 'rb') as inf:
			d = cPickle.load(inf)
		self.weights = d['weights']
		self.feature_alphabet = Alphabet.from_dict(d['feat_alph'])
		self.label_alphabet = Alphabet.from_dict(d['label_alph'])
		self.feature_generator_list = d['features']
		self.decay = d['decay']
예제 #4
0
	def from_dict(cls, model_dictionary):
		"""Return an instance of MaxEnt based on the dictionary created by to_dict
		
		Add your implementation
		"""
		res = MaxEnt()
		res.label_alphabet = Alphabet.from_dict(model_dictionary['labalph'])
		res.feature_alphabet = Alphabet.from_dict(model_dictionary['feaalph'])
		res.gaussian_prior_variance = model_dictionary['gpv']
		res.parameters = model_dictionary['param']
		return res
예제 #5
0
	def from_dict(cls, model_dict):
		"""Convert a dictionary into NaiveBayes instance
		
		The implementation of this should be in sync with to_dict function.
		"""
		model_instance = NaiveBayes()
		model_instance.label_codebook = Alphabet.from_dict(model_dict['label_alphabet'])
		model_instance.feature_codebook = Alphabet.from_dict(model_dict['feature_alphabet'])
		model_instance.p_x_given_y_table = numpy.array(model_dict['p_x_given_y_table'])
		model_instance.p_y_table = numpy.array(model_dict['p_y_table'])

		return model_instance
예제 #6
0
	def from_dict(model_dict):
		"""Convert a dictionary into HMM instance
		
		The implementation of this should be in sync with to_dict function.
		
		This is fully implemented for you.
		"""
		hmm = HMM()
		hmm.label_alphabet = Alphabet.from_dict(model_dict['label_alphabet'])
		hmm.feature_alphabet = Alphabet.from_dict(model_dict['feature_alphabet'])
		hmm.transition_matrix = numpy.array(model_dict['transition_matrix'])
		hmm.emission_matrix = numpy.array(model_dict['emission_matrix'])
		hmm.initial_probability = numpy.array(model_dict['initial_probability'])
		return hmm
예제 #7
0
	def from_dict(cls, model_dict):
		"""Convert a dictionary into NaiveBayes instance
		
		The implementation of this should be in sync with to_dict function.
		
		Add your implementation
		"""
		res = NaiveBayes()
		res.label_codebook = Alphabet.from_dict(model_dict['label_alphabet'])
		res.feature_codebook = Alphabet.from_dict(model_dict['feature_alphabet'])
		res.count_x_y_table = model_dict['#x&y']
		res.count_y_table = model_dict['#y']
		res.p_x_given_y_table = model_dict['_x|y_table']
		res.p_y_table = model_dict['p_y_table']
		return res