本文整理汇总了Python中composes.semantic_space.space.Space._element_shape方法的典型用法代码示例。如果您正苦于以下问题:Python Space._element_shape方法的具体用法?Python Space._element_shape怎么用?Python Space._element_shape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类composes.semantic_space.space.Space
的用法示例。
在下文中一共展示了Space._element_shape方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: learn_TENSOR_matrix
# 需要导入模块: from composes.semantic_space.space import Space [as 别名]
# 或者: from composes.semantic_space.space.Space import _element_shape [as 别名]
def learn_TENSOR_matrix ( ) :
bigram_space = load_space(args.function[2])
my_comp_list = []
id2row_list = []
adj_list = extract_adj(bigram_space)
for adj in adj_list :
train_data=[]
for bigram in bigram_space.id2row :
pair = bigram.split('_')
if( not pair[0] == adj ) :
continue
train_data.append(("ADJ"+"_"+adj, pair[1], bigram))
# eg ( "ADJ_good", "boy", "good_boy"), where "ADJ_good" -> matrix to learn, boy -> unigram , good_boy -> bigram
my_comp=LexicalFunction() # 1)
#Learn ADJ matrix for each adjective
my_comp.train(train_data, unigram_space, bigram_space)
my_comp_list.append(my_comp.function_space.cooccurrence_matrix)
id2row_list.append(my_comp.function_space.id2row)
my_mat_id2row=id2row_list.pop()
my_mat_space=Space(my_comp_list.pop(),my_mat_id2row,[])
#Create a new space using the ADJ matrices created
for i in range(len(id2row_list)):
my_mat_id2row.extend(id2row_list[i])
my_mat_space=Space(my_mat_space.cooccurrence_matrix.vstack(my_comp_list[i]),my_mat_id2row,[])
my_mat_space._element_shape = my_comp.function_space.element_shape
#Use the ADJ matrices space to learn the tensor matrix
train_data=[('tens_adj',adj,"ADJ"+"_"+adj) for adj in adj_list]
# eg ( "tens_adj", good, ADJ_good )
#where "tens_adj" -> tensor matrix to learn, good -> unigram , ADJ_good -> adjective matrix learnt by 'my_comp' in 1)
my_tens_adj=LexicalFunction()
my_tens_adj.train(train_data, unigram_space, my_mat_space)
# unigram_space -> for "good" , my_mat_space -> for "ADJ_good"
save_space(my_tens_adj, "TENSOR_matrix", "matrices")