tensorflow
다차원 softmax
수색…
Softmax 출력 레이어 만들기
state_below 가 2D Tensor 인 경우 U 는 2D 가중치 행렬이고, b 는 class_size length 벡터입니다.
logits = tf.matmul(state_below, U) + b
return tf.nn.softmax(logits)
state_below 가 3D 텐서 인 경우 U 와 b 는 이전과 같습니다.
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)
Softmax 출력 레이어의 컴퓨팅 비용
사용 tf.nn.sparse_softmax_cross_entropy_with_logits 하지만의 출력을 받아 들일 수 있음을 조심 tf.nn.softmax . 대신, 비 눈금 활성화 및 비용을 계산하십시오.
logits = tf.matmul(state_below, U) + b
cost = tf.nn.sparse_softmax_cross_entropy_with_logits(logits, labels)
이 경우 state_below 와 U 는 2D 행렬이어야하고 b 는 클래스 수와 동일한 크기의 벡터 여야하며 labels 은 int32 또는 int64 의 2D 행렬이어야합니다. 이 함수는 2 차원 이상의 활성화 텐서도 지원합니다.
Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow