I tried training this model: All even integers map to T and all odd ones map to F. I used 100 million training examples with Support Vector Machine as the method yet I got garbage for the test cases. Same with all other methods. What am I doing wrong?
1 Answer
$\begingroup$
$\endgroup$
This answer is from @GalAster . I simply translate it.
https://www.zhihu.com/question/364113452/answer/996790012
End-to-end double-layer LSTM can
Simple network two-layer LSTM
Automatic loss function, automatic parameter tuning algorithm, cross-validation 10% per round
The test set is a string of numbers below 10^12, the accuracy is 100%, perfect
makeRule[i_] := IntegerString[i] -> If[OddQ@i, "Odd", "Even"];
trainingData = Flatten@Table[makeRule[i], {i, 0, 10000}];
net = NetChain[
{
UnitVectorLayer[],
LongShortTermMemoryLayer[40],
LongShortTermMemoryLayer[20],
SequenceLastLayer[],
LinearLayer[2],
SoftmaxLayer[]
},
"Input" -> NetEncoder[{"Characters", {DigitCharacter}}],
"Output" -> NetDecoder[{"Class", {"Odd", "Even"}}]
]
trained = NetTrain[
net, trainingData, All,
MaxTrainingRounds -> 25,
ValidationSet -> Scaled[0.1],
TargetDevice -> "GPU"
]
eval = trained["TrainedNet"];
eval["123456789101112131415"]
eval["20200202"]
eval["114514"]
eval["19260817"]
testingData = Table[makeRule[i], {i, RandomInteger[10^12, 10^4]}];
NetMeasurements[trained["TrainedNet"], testingData, "Accuracy"]
IntegerDigits[#,2,numdigits]->class[#]&/@numbers
$\endgroup$