當前位置: 首頁>>代碼示例>>Python>>正文


Python roles.WEIGHT屬性代碼示例

本文整理匯總了Python中blocks.roles.WEIGHT屬性的典型用法代碼示例。如果您正苦於以下問題:Python roles.WEIGHT屬性的具體用法?Python roles.WEIGHT怎麽用?Python roles.WEIGHT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在blocks.roles的用法示例。


在下文中一共展示了roles.WEIGHT屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _allocate

# 需要導入模塊: from blocks import roles [as 別名]
# 或者: from blocks.roles import WEIGHT [as 別名]
def _allocate(self):
        self.W_state = shared_floatx_nans((self.dim, 4*self.dim),
                                          name='W_state')
        self.W_cell_to_in = shared_floatx_nans((self.dim,),
                                               name='W_cell_to_in')
        self.W_cell_to_forget = shared_floatx_nans((self.dim,),
                                                   name='W_cell_to_forget')
        self.W_cell_to_out = shared_floatx_nans((self.dim,),
                                                name='W_cell_to_out')
        # The underscore is required to prevent collision with
        # the `initial_state` application method
        self.initial_state_ = shared_floatx_zeros((self.dim,),
                                                  name="initial_state")
        self.initial_cells = shared_floatx_zeros((self.dim,),
                                                 name="initial_cells")
        add_role(self.W_state, WEIGHT)
        add_role(self.W_cell_to_in, WEIGHT)
        add_role(self.W_cell_to_forget, WEIGHT)
        add_role(self.W_cell_to_out, WEIGHT)
        add_role(self.initial_state_, INITIAL_STATE)
        add_role(self.initial_cells, INITIAL_STATE)

        self.parameters = [
            self.W_state, self.W_cell_to_in, self.W_cell_to_forget,
            self.W_cell_to_out, self.initial_state_, self.initial_cells] 
開發者ID:rizar,項目名稱:attention-lvcsr,代碼行數:27,代碼來源:recurrent.py

示例2: _allocate

# 需要導入模塊: from blocks import roles [as 別名]
# 或者: from blocks.roles import WEIGHT [as 別名]
def _allocate(self):
        self.W_state = shared_floatx_nans((self.dim, 4.5 * self.dim),
                                          name='W_state')
        # The underscore is required to prevent collision with
        # the `initial_state` application method
        self.initial_state_ = shared_floatx_zeros((self.dim,),
                                                  name="initial_state")
        self.initial_cells = shared_floatx_zeros((self.num_copies, self.dim),
                                                 name="initial_cells")
        add_role(self.W_state, WEIGHT)
        # add_role(self.initial_state_, INITIAL_STATE)
        # add_role(self.initial_cells, INITIAL_STATE)

        self.parameters = [self.W_state] 
開發者ID:mohammadpz,項目名稱:Associative_LSTM,代碼行數:16,代碼來源:bricks.py

示例3: _allocate

# 需要導入模塊: from blocks import roles [as 別名]
# 或者: from blocks.roles import WEIGHT [as 別名]
def _allocate(self):
        W = shared_floatx_nans((self.input_dim, self.output_dim), name='W')
        add_role(W, WEIGHT)
        self.parameters.append(W)
        self.add_auxiliary_variable(W.norm(2), name='W_norm')
        if self.use_bias:
            b = shared_floatx_nans((self.output_dim,), name='b')
            add_role(b, BIAS)
            self.parameters.append(b)
            self.add_auxiliary_variable(b.norm(2), name='b_norm') 
開發者ID:rizar,項目名稱:attention-lvcsr,代碼行數:12,代碼來源:simple.py

示例4: _allocate

# 需要導入模塊: from blocks import roles [as 別名]
# 或者: from blocks.roles import WEIGHT [as 別名]
def _allocate(self):
        self.parameters.append(shared_floatx_nans((self.length, self.dim),
                               name='W'))
        add_role(self.parameters[-1], WEIGHT) 
開發者ID:rizar,項目名稱:attention-lvcsr,代碼行數:6,代碼來源:lookup.py

示例5: weight

# 需要導入模塊: from blocks import roles [as 別名]
# 或者: from blocks.roles import WEIGHT [as 別名]
def weight(self, init, name, cast_float32=True, for_conv=False):
        weight = self.shared(init, name, cast_float32, role=WEIGHT)
        if for_conv:
            return weight.dimshuffle('x', 0, 'x', 'x')
        return weight 
開發者ID:CuriousAI,項目名稱:ladder,代碼行數:7,代碼來源:ladder.py

示例6: _allocate

# 需要導入模塊: from blocks import roles [as 別名]
# 或者: from blocks.roles import WEIGHT [as 別名]
def _allocate(self):
        self.parameters.append(shared_floatx_nans((self.dim, self.dim),
                               name='state_to_state'))
        self.parameters.append(shared_floatx_nans((self.dim, 2 * self.dim),
                               name='state_to_gates'))
        for i in range(2):
            if self.parameters[i]:
                add_role(self.parameters[i], WEIGHT) 
開發者ID:mila-iqia,項目名稱:blocks-examples,代碼行數:10,代碼來源:model.py

示例7: main

# 需要導入模塊: from blocks import roles [as 別名]
# 或者: from blocks.roles import WEIGHT [as 別名]
def main(save_to, num_epochs):
    mlp = MLP([Tanh(), Softmax()], [784, 100, 10],
              weights_init=IsotropicGaussian(0.01),
              biases_init=Constant(0))
    mlp.initialize()
    x = tensor.matrix('features')
    y = tensor.lmatrix('targets')
    probs = mlp.apply(x)
    cost = CategoricalCrossEntropy().apply(y.flatten(), probs)
    error_rate = MisclassificationRate().apply(y.flatten(), probs)

    cg = ComputationGraph([cost])
    W1, W2 = VariableFilter(roles=[WEIGHT])(cg.variables)
    cost = cost + .00005 * (W1 ** 2).sum() + .00005 * (W2 ** 2).sum()
    cost.name = 'final_cost'

    mnist_train = MNIST(("train",))
    mnist_test = MNIST(("test",))

    algorithm = GradientDescent(
        cost=cost, parameters=cg.parameters,
        step_rule=Scale(learning_rate=0.1))
    extensions = [Timing(),
                  FinishAfter(after_n_epochs=num_epochs),
                  DataStreamMonitoring(
                      [cost, error_rate],
                      Flatten(
                          DataStream.default_stream(
                              mnist_test,
                              iteration_scheme=SequentialScheme(
                                  mnist_test.num_examples, 500)),
                          which_sources=('features',)),
                      prefix="test"),
                  TrainingDataMonitoring(
                      [cost, error_rate,
                       aggregation.mean(algorithm.total_gradient_norm)],
                      prefix="train",
                      after_epoch=True),
                  Checkpoint(save_to),
                  Printing()]

    if BLOCKS_EXTRAS_AVAILABLE:
        extensions.append(Plot(
            'MNIST example',
            channels=[
                ['test_final_cost',
                 'test_misclassificationrate_apply_error_rate'],
                ['train_total_gradient_norm']]))

    main_loop = MainLoop(
        algorithm,
        Flatten(
            DataStream.default_stream(
                mnist_train,
                iteration_scheme=SequentialScheme(
                    mnist_train.num_examples, 50)),
            which_sources=('features',)),
        model=Model(cost),
        extensions=extensions)

    main_loop.run() 
開發者ID:mila-iqia,項目名稱:blocks-examples,代碼行數:63,代碼來源:__init__.py


注:本文中的blocks.roles.WEIGHT屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。