I am attempting to use the new recurrent network functionality in Mathematica 11.1 Home Edition. I created a network that will attempt to predict future bytes in a raw audio file (using very small sequence length here for initial testing).
net = NetChain[{LongShortTermMemoryLayer[128],
LongShortTermMemoryLayer[128], BasicRecurrentLayer[1]},
"Input" -> NetEncoder["Scalar"], "Output" -> NetDecoder["Scalar"]];
initialized = NetInitialize[net];
This net works with a sequence as expected:
initialized[{1, 2, 3, 4, 5}]
{-0.0164315, -0.0766496, -0.212674, -0.439926, -0.697567}
I read the bytes from the file, and create input values:
bytes = BinaryReadList["C:\\Temp\\ParkerAudio.raw"];
values = N[bytes / 256];
RandomSample[values, 10]
{0.550781, 0.488281, 0.417969, 0.605469, 0.691406, 0.46875, 0.464844, \
0.445313, 0.542969, 0.640625}
I define generator function:
GetOneTrainRecord[unrolllen0_] := Module[
{unrolllen = unrolllen0, startpos, leftside, rightside, rule},
startpos = RandomInteger[{1, Length[values] - unrolllen - 1}];
leftside = Take[values, {startpos, startpos + unrolllen - 1}];
rightside = Take[values, {startpos + 1, startpos + unrolllen}];
rule = leftside -> rightside;
rule
]
generator[assoc0_] := Module[
{assoc = assoc0, batchsize},
batchsize = assoc["BatchSize"];
Table[GetOneTrainRecord[10], batchsize]
]
Generator works as expected:
generator[<|"BatchSize" -> 5|>]
{{0.523438, 0.523438, 0.527344, 0.527344, 0.519531, 0.527344, 0.53125,
0.523438, 0.523438, 0.535156} -> {0.523438, 0.527344, 0.527344,
0.519531, 0.527344, 0.53125, 0.523438, 0.523438, 0.535156,
0.542969}, {0.539063, 0.542969, 0.542969, 0.546875, 0.546875,
0.546875, 0.550781, 0.550781, 0.546875, 0.546875} -> {0.542969,
0.542969, 0.546875, 0.546875, 0.546875, 0.550781, 0.550781,
0.546875, 0.546875, 0.542969}, {0.503906, 0.460938, 0.480469,
0.433594, 0.527344, 0.484375, 0.433594, 0.523438, 0.507813,
0.46875} -> {0.460938, 0.480469, 0.433594, 0.527344, 0.484375,
0.433594, 0.523438, 0.507813, 0.46875, 0.46875}, {0.734375,
0.667969, 0.417969, 0.386719, 0.519531, 0.613281, 0.5, 0.335938,
0.390625, 0.53125} -> {0.667969, 0.417969, 0.386719, 0.519531,
0.613281, 0.5, 0.335938, 0.390625, 0.53125, 0.570313}, {0.523438,
0.550781, 0.554688, 0.527344, 0.523438, 0.554688, 0.542969,
0.511719, 0.523438, 0.546875} -> {0.550781, 0.554688, 0.527344,
0.523438, 0.554688, 0.542969, 0.511719, 0.523438, 0.546875,
0.546875}}
I generate some data with the generator, and successfully train with it:
trained = NetTrain[net, generator[<|"BatchSize" -> 100|>]]
However, when I attempt to train using the generator function itself, I get an error:
trained = NetTrain[net, generator]
NetTrain::interr: An internal error occurred. Please contact Wolfram Research.
Am I doing something stupid here, or is this a bug?