【问题标题】:Python operation on CNTK layersCNTK 层上的 Python 操作
【发布时间】:2020-01-21 00:29:47
【问题描述】:

我不是 python 人,想了解如何将一些 Python 代码转换为 C# 代码:

# model parameters
with default_options(bias=False): # all the projections have no bias
    attn_proj_enc   = Stabilizer(enable_self_stabilization=enable_self_stabilization) >> Dense(attention_dim, init=init, input_rank=1) # projects input hidden state, keeping span axes intact
    attn_proj_dec   = Stabilizer(enable_self_stabilization=enable_self_stabilization) >> Dense(attention_dim, init=init, input_rank=1) # projects decoder hidden state, but keeping span and beam-search axes intact
    attn_proj_tanh  = Stabilizer(enable_self_stabilization=enable_self_stabilization) >> Dense(1            , init=init, input_rank=1) # projects tanh output, keeping span and beam-search axes intact
attn_final_stab = Stabilizer(enable_self_stabilization=enable_self_stabilization)

此代码是来自此处的 sn-p:CNTK/bindings/python/cntk/layers/models/attention.py

我的问题是,>> 运算符实际上在做什么?

StabilizerDense 一样是一个层,那么这些层发生了什么?这里有花哨的Bitwise Operation吗?

【问题讨论】:

    标签: c# python bit-manipulation


    【解决方案1】:

    我以前从未见过这种情况,但模型实例化似乎是答案:

    Example:
     >>> model = Dense(500) >> Activation(C.relu) >> Dense(10)
     >>> # is the same as
     >>> model = Dense(500) >> C.relu >> Dense(10)
     >>> # and also the same as
     >>> model = Dense(500, activation=C.relu) >> Dense(10)
    

    发件人:python/cntk/layers/layers.py#L1361

    的:

    Another example is a GRU layer with projection, which could be realized as 
    ``Recurrence(GRU(500) >> Dense(200))``,
    where the projection is applied to the hidden state as fed back to the next 
    step.
    ``F>>G`` is a short-hand for ``Sequential([F, G])``.
    

    发件人:python/cntk/layers/sequence.py#L331

    特别是模型中的序列。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多