当前位置: 首页>>代码示例>>Python>>正文


Python Space.vstack方法代码示例

本文整理汇总了Python中composes.semantic_space.space.Space.vstack方法的典型用法代码示例。如果您正苦于以下问题:Python Space.vstack方法的具体用法?Python Space.vstack怎么用?Python Space.vstack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在composes.semantic_space.space.Space的用法示例。


在下文中一共展示了Space.vstack方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_zero_idenity_matrix

# 需要导入模块: from composes.semantic_space.space import Space [as 别名]
# 或者: from composes.semantic_space.space.Space import vstack [as 别名]
def add_zero_idenity_matrix(matrix_space, vector_length):
    zero_mat = np.zeros((1,vector_length * vector_length))
    identity_mat = np.reshape(np.eye(vector_length),(1, vector_length * vector_length))
    matrix = DenseMatrix(np.vstack([zero_mat, identity_mat]))
    rows = ["cg.zeromat","cg.identmat"]
    additional_space = Space(matrix, rows, [])
    return Space.vstack(matrix_space, additional_space)
开发者ID:thenghiapham,项目名称:p_tree_kernel,代码行数:9,代码来源:compute_sentence_vectors_papfunc.py

示例2: vstack

# 需要导入模块: from composes.semantic_space.space import Space [as 别名]
# 或者: from composes.semantic_space.space.Space import vstack [as 别名]
def vstack(s1, s2):
    if not s1:
        return  s2
    if not s2:
        return s1
    else:
        return Space.vstack(s1, s2)
开发者ID:germank,项目名称:genova-demo,代码行数:9,代码来源:reduce_and_plot.py

示例3: add_one_zero_vector

# 需要导入模块: from composes.semantic_space.space import Space [as 别名]
# 或者: from composes.semantic_space.space.Space import vstack [as 别名]
def add_one_zero_vector(core_space):
    length = core_space.cooccurrence_matrix.shape[1]
    zero_vector = np.zeros((1,length))
    one_vector = np.ones((1,length))
    matrix = DenseMatrix(np.vstack([zero_vector, one_vector]))
    rows = ["cg.zerovec","cg.onevec"]
    additional_space = Space(matrix, rows, [])
    return Space.vstack(core_space, additional_space)
开发者ID:thenghiapham,项目名称:p_tree_kernel,代码行数:10,代码来源:compute_sentence_vectors_papfunc.py

示例4: fit

# 需要导入模块: from composes.semantic_space.space import Space [as 别名]
# 或者: from composes.semantic_space.space.Space import vstack [as 别名]
 def fit(self, train_pairs, verbose=False):
     AdditiveModel.fit(self, train_pairs, verbose=verbose)
     if verbose:
         print 'fit: Fitting a weighted additive model on %d pairs' % (len(train_pairs))
     # First, we embed the derived vector into the original space (by simply adding a row)
     vec_space = Space(self.diff_vector, ['pattern_vector'], [])
     self.new_space = Space.vstack(self.space, vec_space)
     #  class is designed to be run on a dataset with different function words (==patterns).
     # We use a dummy function word here.
     train_pairs_ext = [(base, 'pattern_vector', derived) for (base, derived) in train_pairs]
     self.weighted_additive.train(train_pairs_ext, self.new_space, self.new_space)
开发者ID:jsnajder,项目名称:derivsem,代码行数:13,代码来源:Models.py

示例5: train_all_spaces

# 需要导入模块: from composes.semantic_space.space import Space [as 别名]
# 或者: from composes.semantic_space.space.Space import vstack [as 别名]
def train_all_spaces(core_space, an_dn_space, pn_space, sv_space, vo_space):
    core_space = core_space.apply(RowNormalization())
    print "train adj, det"
    a_d_space = train_one_space(core_space, an_dn_space, 0, 3)
    print "train prep"
    prep_space = train_one_space(core_space, pn_space, 1, 3)
    print "train vo"
    v_obj_space = train_one_space(core_space, vo_space, 0, 4)
    print "train sv"
    v_subj_space = train_one_space(core_space, sv_space, 1, 4)
    
    new_v_obj_rows = [row + ".objmat" for row in v_obj_space.id2row]
    v_obj_space._id2row = new_v_obj_rows
    v_obj_space._row2id = list2dict(new_v_obj_rows)
    
    new_v_subj_rows = [row + ".subjmat" for row in v_subj_space.id2row]
    v_subj_space._id2row = new_v_subj_rows
    v_subj_space._row2id = list2dict(new_v_subj_rows)
    
    all_mat_space = Space.vstack(a_d_space, prep_space)
    all_mat_space = Space.vstack(v_obj_space, all_mat_space)
    all_mat_space = Space.vstack(v_subj_space, all_mat_space)
    return all_mat_space
开发者ID:thenghiapham,项目名称:p_tree_kernel,代码行数:25,代码来源:train_plf.py

示例6: len

# 需要导入模块: from composes.semantic_space.space import Space [as 别名]
# 或者: from composes.semantic_space.space.Space import vstack [as 别名]
        recipes[words[0]] = words[1:]
        if len(words)-1 > max_size:
            max_size = len(words)-1

WA = WeightedAdditive(alpha = 1, beta = 1)
last_space = None
number = count()
for size in xrange(max_size,1,-1):
    relevant = (rec for rec in recipes if len(recipes[rec]) == size)
    print(size)
    composition = []
    for recipe in relevant:
        old = recipes[recipe]
        if size == 2:
            name = recipe
        else:
            name = "comp_" + str(next(number))
        if old[-2] in stacked_space.id2row:
            composition.append((old[-1],old[-2],name))
            recipes[recipe].pop(-1)
            recipes[recipe].pop(-1)
            recipes[recipe].append(name)
        else:
            recipes[recipe].pop(-2)
    if composition:
        last_space = WA.compose(composition, stacked_space)
        if size != 2:
            stacked_space = Space.vstack(stacked_space, last_space)

io_utils.save(last_space, "recicomp.pkl")
开发者ID:gastrovec,项目名称:gastrovec-esslli2015,代码行数:32,代码来源:composeRecipes.py

示例7: print

# 需要导入模块: from composes.semantic_space.space import Space [as 别名]
# 或者: from composes.semantic_space.space.Space import vstack [as 别名]
ingredients = []
print("Enter ingredients, enter when done")
while True:
    ingredient = raw_input("> ").replace(" ","_")
    if ingredient == "":
        break
    if ingredient not in stacked.id2row:
        print("(not found, skipping)")
        continue
    ingredients.append(ingredient)

name = ""
while True:
    (a,b) = ingredients.pop(-1),ingredients.pop(-1)
    name = "comp_" + str(next(number))
    ingredients.append(name)
    new_space = WA.compose([(a,b,name)], stacked)
    if len(ingredients) > 1:
        stacked = Space.vstack(stacked, new_space)
    else:
        break

stacked = Space.vstack(recicomp, new_space)
top = []
for recipe in stacked.id2row:
    if recipe == name:
        continue
    sim = stacked.get_sim(recipe, name, CosSimilarity())
    ins(top, (sim,recipe))
print("Nearest neighbors:",", ".join([x[1].replace("_"," ") + " (" + str(x[0]) + ")" for x in top]))
开发者ID:gastrovec,项目名称:gastrovec-esslli2015,代码行数:32,代码来源:makeMeARecipe.py


注:本文中的composes.semantic_space.space.Space.vstack方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。