Изменения
→Рекуррентные нейронные сети
(exp_x - exp_nx) / (exp_x + exp_nx)
}
'''def '''charRNN(x: INDArray, y: INDArray, hprev: INDArrayLayer): ('''Double'''LayerDoubleLayer, INDArrayLayer, INDArrayLayer) = {
'''val '''hnext = tanh(wxh.dot(x) + whh.dot(hprev) + bh)
'''val '''yraw = why.dot(hnext) + by
type Batch = IndexedSeq[(Char, Char)]
type Losses = Vector['''Double''']
'''def '''singleBatch(batch: WithHiddenLayer[Batch]): WithHiddenLayer['''Double'''LayerDoubleLayer] = {
batch '''match '''{
'''case '''(batchseq, hprev) => batchseq.foldLeft(('''Double'''LayerDoubleLayer(0.0.forward), hprev)) { (bstate: WithHiddenLayer['''Double'''LayerDoubleLayer], xy: (Char, Char)) =>
(bstate, xy) '''match '''{
'''case '''((tot, localhprev), (x, y)) => {
'''case '''(bloss, hnext) => bloss.train.map {
(blossval: '''Double''') => {
'''val '''nloss = prevloss.last * 0.999 + bloss'''val '''blossval * 0.001 '''val '''loss_seq = prevloss :+ prevloss.last * 0.999 + bloss'''val '''blossval * 0.001
(loss_seq, hnext)
}