2015-05-21 77 views
0

由于递归性质,我可以通过一次输入一个项目来激活一个lstm,它只有一个输入神经元,带有一个序列。训练带有序列的神经网络(目前不收敛)

但是,当我尝试用相同的技术训练网络时,它从不会收敛。培训永远持续下去。

下面是我正在做的,我将一个自然语言字符串转换为二进制,然后将一个数字作为时间。我转换成二进制的原因是因为网络只取0和1之间的值。

我知道训练的工作原理,因为当我训练输入神经元的数值为1时, :[0],它收敛并训练良好。

我想我可以单独传递每个数字,但它会有一个单独的每个数字的理想输出。当数字再次出现在另一个训练集的另一个理想输出中时,它将不会收敛,因为例如0可能是0级还是1级? 请告诉我,如果我错了这个假设。

我该如何训练这个lstm的序列,以便类似的序列在激活时被类似地分类?

Here is my whole trainer-file: https://github.com/theirf/synaptic/blob/master/src/trainer.js

这里是列车上的工作人员的网络代码:

workerTrain: function(set, callback, options) { 

    var that = this; 
    var error = 1; 
    var iterations = bucketSize = 0; 
    var input, output, target, currentRate; 
    var length = set.length; 

    var start = Date.now(); 

    if (options) { 
     if (options.shuffle) { 
      function shuffle(o) { //v1.0 
       for (var j, x, i = o.length; i; j = Math.floor(Math.random() * 
      i), x = o[--i], o[i] = o[j], o[j] = x); 
       return o; 
      }; 
      } 
      if(options.iterations) this.iterations = options.iterations; 
      if(options.error) this.error = options.error; 
      if(options.rate) this.rate = options.rate; 
      if(options.cost) this.cost = options.cost; 
      if(options.schedule) this.schedule = options.schedule; 
      if (options.customLog){ 
      // for backward compatibility with code that used customLog 
      console.log('Deprecated: use schedule instead of customLog') 
      this.schedule = options.customLog; 
      } 
    } 

    // dynamic learning rate 
    currentRate = this.rate; 
    if(Array.isArray(this.rate)) { 
     bucketSize = Math.floor(this.iterations/this.rate.length); 
    } 

    // create a worker 
    var worker = this.network.worker(); 

    // activate the network 
    function activateWorker(input) 
     { 
      worker.postMessage({ 
       action: "activate", 
       input: input, 
       memoryBuffer: that.network.optimized.memory 
      }, [that.network.optimized.memory.buffer]); 
     } 

     // backpropagate the network 
     function propagateWorker(target){ 
      if(bucketSize > 0) { 
        var currentBucket = Math.floor(iterations/bucketSize); 
        currentRate = this.rate[currentBucket]; 
      } 
      worker.postMessage({ 
       action: "propagate", 
       target: target, 
       rate: currentRate, 
       memoryBuffer: that.network.optimized.memory 
      }, [that.network.optimized.memory.buffer]); 
     } 

     // train the worker 
     worker.onmessage = function(e){ 
      // give control of the memory back to the network 
      that.network.optimized.ownership(e.data.memoryBuffer); 

      if(e.data.action == "propagate"){ 
       if(index >= length){ 
        index = 0; 
        iterations++; 
        error /= set.length; 

        // log 
        if(options){ 
         if(this.schedule && this.schedule.every && iterations % this.schedule.every == 0) 
         abort_training = this.schedule.do({ 
          error: error, 
          iterations: iterations 
         }); 
         else if(options.log && iterations % options.log == 0){ 
          console.log('iterations', iterations, 'error', error); 
         }; 
         if(options.shuffle) shuffle(set); 
        } 

        if(!abort_training && iterations < that.iterations && error > that.error){ 
         activateWorker(set[index].input); 
        } 
        else{ 
         // callback 
         callback({ 
          error: error, 
          iterations: iterations, 
          time: Date.now() - start 
         }) 
        } 
        error = 0; 
       } 
       else{ 
        activateWorker(set[index].input); 
       } 
     } 

     if(e.data.action == "activate"){ 
      error += that.cost(set[index].output, e.data.output); 
      propagateWorker(set[index].output); 
      index++; 
     } 
    } 

回答

1

不应将自然语言字符串转换为二进制以进行标准化。用一位热码编码来代替:

enter image description here

此外,我建议你看一看Neataptic,而不是突触。它修复了Synaptic中的很多错误,并且有更多的功能供您使用。它在训练期间有一个特殊选项,称为clear。这告诉网络在每次训练迭代中重置上下文,所以它知道它从一开始就开始。

+0

非常感谢!我很高兴我并不孤单,发现突触问题!我尝试修复它,甚至联系了没有太多帮助的作者,但非常感谢! – wordSmith

0

为什么你的网络中只有1个二进制输入?网络投入应该是有道理的。神经网络是强大的,但你给他们一个非常艰巨的任务。

相反,您应该有多个输入,每个字母一个。或者更理想的是,每个单词一个。

+0

因为它是一个rnn,所以它一次只需要部分序列并记住序列 – wordSmith