创建 Softmax 输出层

state_below 是 2D Tensor 时,U 是 2D 权重矩阵,bclass_size-length 向量:

logits = tf.matmul(state_below, U) + b
return tf.nn.softmax(logits)

state_below 是 3D 张量时,Ub 和以前一样:

def softmax_fn(current_input):
    logits = tf.matmul(current_input, U) + b
    return tf.nn.softmax(logits)

raw_preds = tf.map_fn(softmax_fn, state_below)