diff options
author | cloudygoose <[email protected]> | 2015-06-04 12:47:18 +0800 |
---|---|---|
committer | cloudygoose <[email protected]> | 2015-06-04 12:47:18 +0800 |
commit | 2301cba19914f35a8c34c3d27d98deb43ddaaf1d (patch) | |
tree | a2a58889ad90c684a00512037f4f3d3d566c3f60 /layer/softmax_ce.lua | |
parent | 88a2c29f347df2ef75b9891235bc176676e5dafd (diff) | |
parent | ea6f2990f99dd9ded6a0e74d75a3ec84900a2518 (diff) |
...
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'layer/softmax_ce.lua')
-rw-r--r-- | layer/softmax_ce.lua | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/layer/softmax_ce.lua b/layer/softmax_ce.lua index 09eb3a9..cf98c45 100644 --- a/layer/softmax_ce.lua +++ b/layer/softmax_ce.lua @@ -5,6 +5,10 @@ function SoftmaxCELayer:__init(id, global_conf, layer_conf) self.gconf = global_conf self.dim_in = layer_conf.dim_in self.dim_out = layer_conf.dim_out + self.compressed = layer_conf.compressed + if self.compressed == nil then + self.compressed = false + end self:check_dim_len(2, -1) -- two inputs: nn output and label end @@ -26,15 +30,21 @@ function SoftmaxCELayer:propagate(input, output) soutput:softmax(input[1]) local ce = soutput:create() ce:log_elem(soutput) - ce:mul_elem(ce, input[2]) --- print(input[1][0]) --- print(soutput[1][0]) - -- add total ce + local label = input[2] + if self.compressed then + label = label:decompress(input[1]:ncol()) + end + ce:mul_elem(ce, label) + -- add total ce self.total_ce = self.total_ce - ce:rowsum():colsum()[0] self.total_frames = self.total_frames + soutput:nrow() end function SoftmaxCELayer:back_propagate(next_bp_err, bp_err, input, output) -- softmax output - label - next_bp_err[1]:add(self.soutput, input[2], 1.0, -1.0) + local label = input[2] + if self.compressed then + label = label:decompress(input[1]:ncol()) + end + next_bp_err[1]:add(self.soutput, label, 1.0, -1.0) end |