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


Python Space._element_shape方法代码示例

本文整理汇总了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")
开发者ID:anupama-gupta,项目名称:AN_Composition,代码行数:49,代码来源:lex_functions.py


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