HuwCampbell / grenade

Deep Learning in Haskell
BSD 2-Clause "Simplified" License
1.45k stars 84 forks source link

Recurrent — cannot deduce typeclasses #67

Closed almays closed 6 years ago

almays commented 6 years ago

Whatever I do, I cannot get working recurrent nets.

It keeps giving me two errors:

[ghcmod]
• Could not deduce (Grenade.Recurrent.Core.Network.CreatableRecurrent
                      MyLayers MyShapes)
    arising from a use of ‘randomRecurrent’
[ghcmod]
• No instance for (Num (RecurrentInputs MyLayers))
    arising from a use of ‘trainRecurrent’

where

type RR = Recurrent

type FF i o = RecurrentNetwork
  '[ RR (LSTM i o)]
  '[ 'D1 i, 'D1 o]

type MyLayers = '[ FF 3 6, FF 6 4, FF 4 1]
type MyShapes = '[ 'D1 3, 'D1 6, 'D1 4, 'D1 1]
almays commented 6 years ago

Solved by removing that FF thing.

type MyNet = RecurrentNetwork MyLayers MyShapes

type MyLayers = '[ RR (LSTM 3 6), RR (LSTM 6 4), RR (LSTM 4 1)]
type MyShapes = '[ 'D1 3, 'D1 6, 'D1 4, 'D1 1]

is the remedy.

HuwCampbell commented 6 years ago

The other solution, which still allows for network composition (as networks "are" layers as well), is to annotate the FF.

type RR = Recurrent

type FF i o = RecurrentNetwork
  '[ RR (LSTM i o)]
  '[ 'D1 i, 'D1 o]

type MyLayers = '[ RR (FF 3 6), RR (FF 6 4), RR( FF 4 1)]
type MyShapes = '[ 'D1 3, 'D1 6, 'D1 4, 'D1 1]
almays commented 6 years ago

Oh. Clear. Thank you.