示例#1
0
 def __init__(self, matrix, dimensionality):
   concept_axes, axis_weights, feature_axes = matrix.svd(k=dimensionality)
   self.predict = divisi2.reconstruct(concept_axes,
                                      axis_weights,
                                      feature_axes)
   self.concept_sim = divisi2.reconstruct_activation(concept_axes,
                                                     axis_weights,
                                                     post_normalize=True)
   self.feature_sim = divisi2.reconstruct_activation(feature_axes,
                                                     axis_weights,
                                                     post_normalize=True)
	def __init__(self, matrix_path=data_path+'feature_matrix_zh.smat'):
		# AnalogySpace
		A = divisi2.load(matrix_path)
		self.A = A.normalize_all()
		self.concept_axes, axis_weights, self.feature_axes = self.A.svd(k=100)
		self.sim = divisi2.reconstruct_similarity(\
				self.concept_axes, axis_weights, post_normalize=False)
		self.predict = divisi2.reconstruct(\
				self.concept_axes, axis_weights, self.feature_axes)
		# Fast spreading activation
		assoc = divisi2.load(data_path+'assoc_matrix_zh.smat')
		self.assoc = assoc.normalize_all()
		U, S, _ = self.assoc.svd(k=100)
		self.spread = divisi2.reconstruct_activation(U, S)
示例#3
0
文件: model.py 项目: blazarus/charmme
 def make_common_sense(model_dir, lang='en', config=None):
     """
     Make a LuminosoModel whose initial matrix contains common sense
     for some language.
     """
     if config is None:
         config = _default_config()
         config['reader'] = 'simplenlp.'+lang
     if os.access(model_dir, os.F_OK):
         raise StudyExists("The model directory %r already exists." % model_dir)
     LOG.info("Making common sense matrix")
     assoc = divisi2.network.conceptnet_assoc(lang)
     (mat_U, diag_S, _) = assoc.normalize_all().svd(k=100)
     rmat = divisi2.reconstruct_activation(
         mat_U, diag_S, post_normalize=True
     )
     model = LuminosoModel.make(model_dir, rmat.left, config)
     model.config['iteration'] = 1000
     return model