title: Mask specific elements in a final layer in PyTorch
body: <p>I am now reproducing the following model which outputs an <code>action</code> and uses <code>filter</code> for filtering inappropriate candidates. 
  <a href="https://arxiv.org/abs/1702.03274" rel="nofollow noreferrer">https://arxiv.org/abs/1702.03274</a></p>
  
  <p>In this model, output is filtered after last softmax layer. Let's assume <code>action_size==3</code>. So the output after dense &amp; asoftmax layer is like below. </p>
  
  <pre><code>output: [0.1, 0.7, 0.2]
  filter: [0, 1, 1]
  output*filter: [0, 0.7, 0.2]
  </code></pre>
  
  <p>But in pytorch, <code>logsoftmax</code> is preferred with <code>NLLLoss</code>. So my output is like below. This doesn't make sense.</p>
  
  <pre><code>output: [-5.4, -0.2, -4.9]
  filter: [0, 1, 1]
  output*filter: [0, -0.2, -4.9]
  </code></pre>
  
  <p>So pytoroch doesn't recommend <code>vanilla Softmax</code>. How should I apply mask to eliminate specific actions?
  Or is there any categorical cross entropy loss functions with vanilla Softmax?</p>
  
  <blockquote>
    <p>This module doesn’t work directly with NLLLoss, which expects the Log to be computed between the Softmax and itself. Use Logsoftmax instead (it’s faster and has better numerical properties).
    <a href="http://pytorch.org/docs/master/nn.html#torch.nn.Softmax" rel="nofollow noreferrer">http://pytorch.org/docs/master/nn.html#torch.nn.Softmax</a></p>
  </blockquote>