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


Python roles.PARAMETER属性代码示例

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


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

示例1: test_collect

# 需要导入模块: from blocks import roles [as 别名]
# 或者: from blocks.roles import PARAMETER [as 别名]
def test_collect():
    x = tensor.matrix()
    mlp = MLP(activations=[Logistic(), Logistic()], dims=[784, 100, 784],
              use_bias=False)
    cost = SquaredError().apply(x, mlp.apply(x))
    cg = ComputationGraph(cost)
    var_filter = VariableFilter(roles=[PARAMETER])
    W1, W2 = var_filter(cg.variables)
    for i, W in enumerate([W1, W2]):
        W.set_value(numpy.ones_like(W.get_value()) * (i + 1))
    new_cg = collect_parameters(cg, cg.shared_variables)
    collected_parameters, = new_cg.shared_variables
    assert numpy.all(collected_parameters.get_value()[:784 * 100] == 1.)
    assert numpy.all(collected_parameters.get_value()[784 * 100:] == 2.)
    assert collected_parameters.ndim == 1
    W1, W2 = VariableFilter(roles=[COLLECTED])(new_cg.variables)
    assert W1.eval().shape == (784, 100)
    assert numpy.all(W1.eval() == 1.)
    assert W2.eval().shape == (100, 784)
    assert numpy.all(W2.eval() == 2.) 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:22,代码来源:test_graph.py

示例2: setup_model

# 需要导入模块: from blocks import roles [as 别名]
# 或者: from blocks.roles import PARAMETER [as 别名]
def setup_model(p):
    ladder = LadderAE(p)
    # Setup inputs
    input_type = TensorType('float32', [False] * (len(p.encoder_layers[0]) + 1))
    x_only = input_type('features_unlabeled')
    x = input_type('features_labeled')
    y = theano.tensor.lvector('targets_labeled')
    ladder.apply(x, y, x_only)

    # Load parameters if requested
    if p.get('load_from'):
        with open(p.load_from + '/trained_params.npz') as f:
            loaded = numpy.load(f)
            cg = ComputationGraph([ladder.costs.total])
            current_params = VariableFilter(roles=[PARAMETER])(cg.variables)
            logger.info('Loading parameters: %s' % ', '.join(loaded.keys()))
            for param in current_params:
                assert param.get_value().shape == loaded[param.name].shape
                param.set_value(loaded[param.name])

    return ladder 
开发者ID:CuriousAI,项目名称:ladder,代码行数:23,代码来源:run.py

示例3: _setitem

# 需要导入模块: from blocks import roles [as 别名]
# 或者: from blocks.roles import PARAMETER [as 别名]
def _setitem(self, key, value):
        if isinstance(value, Variable):
            add_role(value, PARAMETER)
            add_annotation(value, self.brick) 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:6,代码来源:base.py

示例4: test_variable_filter_roles_error

# 需要导入模块: from blocks import roles [as 别名]
# 或者: from blocks.roles import PARAMETER [as 别名]
def test_variable_filter_roles_error():
    # Creating computation graph
    brick1 = Linear(input_dim=2, output_dim=2, name='linear1')

    x = tensor.vector()
    h1 = brick1.apply(x)
    cg = ComputationGraph(h1)
    # testing role error
    VariableFilter(roles=PARAMETER)(cg.variables) 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:11,代码来源:test_variable_filter.py

示例5: shared

# 需要导入模块: from blocks import roles [as 别名]
# 或者: from blocks.roles import PARAMETER [as 别名]
def shared(self, init, name, cast_float32=True, role=PARAMETER, **kwargs):
        p = self.shareds.get(name)
        if p is None:
            p = shared_param(init, name, cast_float32, role, **kwargs)
            self.shareds[name] = p
        return p 
开发者ID:CuriousAI,项目名称:ladder,代码行数:8,代码来源:ladder.py

示例6: init_tparams

# 需要导入模块: from blocks import roles [as 别名]
# 或者: from blocks.roles import PARAMETER [as 别名]
def init_tparams(params):
    tparams = OrderedDict()
    for kk, pp in params.iteritems():
        tparams[kk] = theano.shared(params[kk], name=kk, borrow=True)
        add_role(tparams[kk], PARAMETER)
    return tparams


# make prefix-appended name 
开发者ID:nyu-dl,项目名称:dl4mt-multi,代码行数:11,代码来源:utils.py


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