本文整理汇总了Python中tensorflow_fold.TensorType方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow_fold.TensorType方法的具体用法?Python tensorflow_fold.TensorType怎么用?Python tensorflow_fold.TensorType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow_fold
的用法示例。
在下文中一共展示了tensorflow_fold.TensorType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: coding_blk
# 需要导入模块: import tensorflow_fold [as 别名]
# 或者: from tensorflow_fold import TensorType [as 别名]
def coding_blk():
"""Input: node dict
Output: TensorType([1, hyper.word_dim])
"""
Wcomb1 = param.get('Wcomb1')
Wcomb2 = param.get('Wcomb2')
blk = td.Composition()
with blk.scope():
direct = embedding.direct_embed_blk().reads(blk.input)
composed = embedding.composed_embed_blk().reads(blk.input)
Wcomb1 = td.FromTensor(param.get('Wcomb1'))
Wcomb2 = td.FromTensor(param.get('Wcomb2'))
direct = td.Function(embedding.batch_mul).reads(direct, Wcomb1)
composed = td.Function(embedding.batch_mul).reads(composed, Wcomb2)
added = td.Function(tf.add).reads(direct, composed)
blk.output.reads(added)
return blk
示例2: dynamic_pooling_blk
# 需要导入模块: import tensorflow_fold [as 别名]
# 或者: from tensorflow_fold import TensorType [as 别名]
def dynamic_pooling_blk():
"""Input: root node dic
Output: pooled, TensorType([hyper.conv_dim, ])
"""
leaf_case = feature_detector_blk()
pool_fwd = td.ForwardDeclaration(td.PyObjectType(), td.TensorType([hyper.conv_dim, ]))
pool = td.Composition()
with pool.scope():
cur_fea = feature_detector_blk().reads(pool.input)
children = td.GetItem('children').reads(pool.input)
mapped = td.Map(pool_fwd()).reads(children)
summed = td.Reduce(td.Function(tf.maximum)).reads(mapped)
summed = td.Function(tf.maximum).reads(summed, cur_fea)
pool.output.reads(summed)
pool = td.OneOf(lambda x: x['clen'] == 0,
{True: leaf_case, False: pool})
pool_fwd.resolve_to(pool)
return pool
示例3: tri_combined_blk
# 需要导入模块: import tensorflow_fold [as 别名]
# 或者: from tensorflow_fold import TensorType [as 别名]
def tri_combined_blk():
blk = td.Function(tri_combined, infer_output_type=False)
blk.set_output_type(td.TensorType([hyper.word_dim, hyper.conv_dim]))
return blk
示例4: weighted_feature_blk
# 需要导入模块: import tensorflow_fold [as 别名]
# 或者: from tensorflow_fold import TensorType [as 别名]
def weighted_feature_blk():
"""Input: (feature , idx , pclen, depth, max_depth)
(TensorType([hyper.word_dim, ]), Scalar, Scalar, Scalar, Scalar)
Output: weighted_feature
TensorType([hyper.conv_dim, ])
"""
blk = td.Composition()
with blk.scope():
fea = blk.input[0]
Wi = tri_combined_blk().reads(blk.input[1], blk.input[2], blk.input[3], blk.input[4])
weighted_fea = td.Function(embedding.batch_mul).reads(fea, Wi)
blk.output.reads(weighted_fea)
return blk
示例5: feature_detector_blk
# 需要导入模块: import tensorflow_fold [as 别名]
# 或者: from tensorflow_fold import TensorType [as 别名]
def feature_detector_blk(max_depth=2):
"""Input: node dict
Output: TensorType([hyper.conv_dim, ])
Single patch of the conv. Depth is max_depth
"""
blk = td.Composition()
with blk.scope():
nodes_in_patch = collect_node_for_conv_patch_blk(max_depth=max_depth).reads(blk.input)
# map from python object to tensors
mapped = td.Map(td.Record((coding_blk(), td.Scalar(), td.Scalar(),
td.Scalar(), td.Scalar()))).reads(nodes_in_patch)
# mapped = [(feature, idx, depth, max_depth), (...)]
# compute weighted feature for each elem
weighted = td.Map(weighted_feature_blk()).reads(mapped)
# weighted = [fea, fea, fea, ...]
# add together
added = td.Reduce(td.Function(tf.add)).reads(weighted)
# added = TensorType([hyper.conv_dim, ])
# add bias
biased = td.Function(tf.add).reads(added, td.FromTensor(param.get('Bconv')))
# biased = TensorType([hyper.conv_dim, ])
# tanh
tanh = td.Function(tf.nn.tanh).reads(biased)
# tanh = TensorType([hyper.conv_dim, ])
blk.output.reads(tanh)
return blk
# generalize to tree_fold, accepts one block that takes two node, returns a value
示例6: tree_sum_blk
# 需要导入模块: import tensorflow_fold [as 别名]
# 或者: from tensorflow_fold import TensorType [as 别名]
def tree_sum_blk(loss_blk):
# traverse the tree to sum up the loss
tree_sum_fwd = td.ForwardDeclaration(td.PyObjectType(), td.TensorType([]))
tree_sum = td.Composition()
with tree_sum.scope():
myloss = loss_blk().reads(tree_sum.input)
children = td.GetItem('children').reads(tree_sum.input)
mapped = td.Map(tree_sum_fwd()).reads(children)
summed = td.Reduce(td.Function(tf.add)).reads(mapped)
summed = td.Function(tf.add).reads(summed, myloss)
tree_sum.output.reads(summed)
tree_sum_fwd.resolve_to(tree_sum)
return tree_sum