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


Python tensorflow_fold.OneOf方法代码示例

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


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

示例1: dynamic_pooling_blk

# 需要导入模块: import tensorflow_fold [as 别名]
# 或者: from tensorflow_fold import OneOf [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 
开发者ID:Aetf,项目名称:tensorflow-tbcnn,代码行数:22,代码来源:tbcnn.py

示例2: l2loss_blk

# 需要导入模块: import tensorflow_fold [as 别名]
# 或者: from tensorflow_fold import OneOf [as 别名]
def l2loss_blk():
    # rewrite using metric
    leaf_case = td.Composition()
    with leaf_case.scope():
        leaf_case.output.reads(td.FromTensor(tf.constant(1.)))
    nonleaf_case = td.Composition()
    with nonleaf_case.scope():
        direct = direct_embed_blk().reads(nonleaf_case.input)
        com = composed_embed_blk().reads(nonleaf_case.input)
        loss = td.Function(batch_nn_l2loss).reads(direct, com)
        nonleaf_case.output.reads(loss)
    return td.OneOf(lambda node: node['clen'] != 0,
                    {False: leaf_case, True: nonleaf_case})


# generalize to tree_reduce, accepts one block that takes two node, returns a value 
开发者ID:Aetf,项目名称:tensorflow-tbcnn,代码行数:18,代码来源:embedding.py

示例3: composed_embed_blk

# 需要导入模块: import tensorflow_fold [as 别名]
# 或者: from tensorflow_fold import OneOf [as 别名]
def composed_embed_blk():
    leaf_case = direct_embed_blk()
    nonleaf_case = td.Composition(name='composed_embed_nonleaf')
    with nonleaf_case.scope():
        children = td.GetItem('children').reads(nonleaf_case.input)
        clen = td.Scalar().reads(td.GetItem('clen').reads(nonleaf_case.input))
        cclens = td.Map(td.GetItem('clen') >> td.Scalar()).reads(children)
        fchildren = td.Map(direct_embed_blk()).reads(children)

        initial_state = td.Composition()
        with initial_state.scope():
            initial_state.output.reads(
                td.FromTensor(tf.zeros(hyper.word_dim)),
                td.FromTensor(tf.zeros([])),
            )
        summed = td.Zip().reads(fchildren, cclens, td.Broadcast().reads(clen))
        summed = td.Fold(continous_weighted_add_blk(), initial_state).reads(summed)[0]
        added = td.Function(tf.add, name='add_bias').reads(summed, td.FromTensor(param.get('B')))
        normed = clip_by_norm_blk().reads(added)

        act_fn = tf.nn.relu if hyper.use_relu else tf.nn.tanh
        relu = td.Function(act_fn).reads(normed)
        nonleaf_case.output.reads(relu)

    return td.OneOf(lambda node: node['clen'] == 0,
                    {True: leaf_case, False: nonleaf_case}) 
开发者ID:Aetf,项目名称:tensorflow-tbcnn,代码行数:28,代码来源:embedding.py


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