0
$\begingroup$

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?

$\endgroup$
3
  • 1
    $\begingroup$ This is a difficult thing to learn stats.stackexchange.com/q/161189 . You'd need better features if you wanted to learn parity, and that's entirely unnecessary since Mod[x,2] already does the job perfectly. $\endgroup$
    – flinty
    Commented Oct 4, 2020 at 13:33
  • $\begingroup$ Thanks but obviously this example is a proxy for more complicated data that shows rapid oscillations. $\endgroup$ Commented Oct 4, 2020 at 15:36
  • 1
    $\begingroup$ Your question did not mention a proxy model. However, the reasoning still applies. You'd still need more features in the data, even if that meant just getting the binary expansions as feature vectors IntegerDigits[#,2,numdigits]->class[#]&/@numbers $\endgroup$
    – flinty
    Commented Oct 4, 2020 at 15:42

1 Answer 1

5
$\begingroup$

This answer is from @GalAster . I simply translate it.

https://www.zhihu.com/question/364113452/answer/996790012


End-to-end double-layer LSTM can

enter image description here

Simple network two-layer LSTM

enter image description here

Automatic loss function, automatic parameter tuning algorithm, cross-validation 10% per round

enter image description here

The test set is a string of numbers below 10^12, the accuracy is 100%, perfect

enter image description here

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"]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.