本文整理汇总了Python中composes.semantic_space.space.Space.export方法的典型用法代码示例。如果您正苦于以下问题:Python Space.export方法的具体用法?Python Space.export怎么用?Python Space.export使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类composes.semantic_space.space.Space
的用法示例。
在下文中一共展示了Space.export方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LexicalFunction
# 需要导入模块: from composes.semantic_space.space import Space [as 别名]
# 或者: from composes.semantic_space.space.Space import export [as 别名]
#.........这里部分代码省略.........
composed_vec_list = []
for i in xrange(len(arg1_list)):
arg1_vec = self._function_space.get_row(arg1_list[i])
arg2_vec = arg_space.get_row(arg2_list[i])
matrix_type = get_type_of_largest([arg1_vec, arg2_vec])
[arg1_vec, arg2_vec] = resolve_type_conflict([arg1_vec, arg2_vec],
matrix_type)
composed_ph_vec = self._compose(arg1_vec, arg2_vec,
self._function_space.element_shape)
composed_vec_list.append(composed_ph_vec)
result_element_shape = self._function_space.element_shape[0:-1]
composed_ph_mat = composed_ph_vec.nary_vstack(composed_vec_list)
log.print_name(logger, self, 1, "\nComposed with composition model:")
log.print_info(logger, 3, "Composed total data points:%s" % len(arg1_list))
log.print_info(logger, 3, "Functional shape of the resulted (composed) elements:%s"
% (result_element_shape,))
log.print_matrix_info(logger, composed_ph_mat, 4,
"Resulted (composed) semantic space:")
log.print_time_info(logger, time.time(), start, 2)
return Space(composed_ph_mat, phrase_list, self.composed_id2column,
element_shape = result_element_shape)
def _compose(self, function_arg_vec, arg_vec, function_arg_element_shape):
new_shape = (np.prod(function_arg_element_shape[0:-1]),
function_arg_element_shape[-1])
function_arg_vec.reshape(new_shape)
if self._has_intercept:
comp_el = function_arg_vec * padd_matrix(arg_vec.transpose(), 0)
else:
comp_el = function_arg_vec * arg_vec.transpose()
return comp_el.transpose()
@classmethod
def _assert_space_match(cls, arg1_space, arg2_space, phrase_space=None):
pass
def set_regression_learner(self, regression_learner):
assert_is_instance(regression_learner, RegressionLearner)
self._regression_learner = regression_learner
def get_regression_learner(self):
return self._regression_learner
regression_learner = property(get_regression_learner, set_regression_learner)
"""
Regression method to be used in training, of type RegressionLearner.
Default is RidgeRegressionLearner(param=1).
"""
def get_function_space(self):
return self._function_space
function_space = property(get_function_space)
"""
Function space parameter, containing the lexical functions, of type Space.
Can be set through training or through initialization, default None.
"""
def get_has_intercept(self):
return self._has_intercept
has_intercept = property(get_has_intercept)
"""
Has intercept parameter, boolean. If True, then the function_space is
assumed to contain intercept. Can be set through training or through
initialization, default is assumed to be False.
"""
def set_min_samples(self, min_samples):
if not is_integer(min_samples):
raise ValueError("expected %s min_samples value, received %s"
% ("integer", type(min_samples)))
self._MIN_SAMPLES = min_samples
def get_min_samples(self):
return self._MIN_SAMPLES
MIN_SAMPLES = property(get_min_samples, set_min_samples)
"""
Minimal number of samples for each training instance. Default 3.
"""
def _export(self, filename):
if self._function_space is None:
raise IllegalStateError("cannot export an untrained LexicalFunction model.")
self._function_space.export(filename, format="dm")