由於遞歸性質,我可以通過一次輸入一個項目來激活一個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++;
}
}
非常感謝!我很高興我並不孤單,發現突觸問題!我嘗試修復它,甚至聯繫了沒有太多幫助的作者,但非常感謝! – wordSmith