我想產生一個基於標量輸入的數學運算選擇nn模型。該操作是根據由nn產生的softmax結果來選擇的。然後,該操作必須應用於標量輸入以生成最終輸出。到目前爲止,我已經提出了在softmax輸出上應用argmax和onehot,以便生成一個掩碼,然後將其應用於要執行的所有可能操作(如下面的僞代碼所示)的拼接值矩陣中。問題在於argmax和onehot都不是可區分的。我對此很陌生,所以任何人都會受到高度讚賞。提前致謝。如何在TensorFlow中執行可微分操作選擇?
#perform softmax
logits = tf.matmul(current_input, W) + b
softmax = tf.nn.softmax(logits)
#perform all possible operations on the input
op_1_val = tf_op_1(current_input)
op_2_val = tf_op_2(current_input)
op_3_val = tf_op_2(current_input)
values = tf.concat([op_1_val, op_2_val, op_3_val], 1)
#create a mask
argmax = tf.argmax(softmax, 1)
mask = tf.one_hot(argmax, num_of_operations)
#produce the input, by masking out those operation results which have not been selected
output = values * mask
非常感謝您的回答。我已經用softmax本身進行了實驗,並且如果logits之間的差異非常大,它看起來像爲最大值生成值接近1,較小值爲0。用「softmax = tf.nn.softmax(10000 * logits)」來產生我的面具是否合理,以便馬上產生很大的差異,或者我應該訓練nn通過權重來挑選它? – user59271
我認爲你應該訓練nn通過權重選擇它。與1000這樣的大數相乘唯一的問題是它會在訓練過程的早期飽和softmax。對於較大的logit值,softmax的梯度幾乎爲0,因此即使在訓練過程開始時,softmax後面的權重也會得到較少的更新。儘管乘以1000應該會增加梯度,但它可能與softmax中梯度的指數衰減不匹配。 –