Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't ignore MNIST training test in MNISTSpec #90

Open
kostaleonard opened this issue Mar 14, 2023 · 0 comments
Open

Don't ignore MNIST training test in MNISTSpec #90

kostaleonard opened this issue Mar 14, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@kostaleonard
Copy link
Owner

As a machine learning engineer, I want the library to work on MNIST so that I know it can at least get good results on the Hello World of machine learning.

The MNIST training test in MNISTSpec (which also appears in the new main README) is too slow and for that reason we have ignored it. That test needs to work for the first release. Here is the test in question, for reference.

  // We ignore this test because it is too slow to converge, but we keep it as
  // our goal for the initial release.
  ignore should "be easy to train a model on MNIST" in {
    val xTrain = dataset._1.reshape(Array(60000, 28 * 28)).toFloat / 255
    val yTrain = dataset._2.toCategorical().toFloat
    assert(xTrain.flatten().forall(pixel => pixel >= 0 && pixel <= 1))
    assert(yTrain.flatten().forall(label => label == 0 || label == 1))
    val input = Input[Float]("X", Array(None, Some(28 * 28)))
    val inputLayer = InputLayer(input)
    val dense1 = Dense.withRandomWeights(inputLayer, 128)
    val activation1 = Sigmoid(dense1)
    val dense2 = Dense.withRandomWeights(activation1, 10)
    val activation2 = Sigmoid(dense2)
    val model = Model(activation2)
    val inputs = Map(input -> xTrain)
    val lossFunctionBefore = Mean(
      Square(Subtract(model.outputLayer.getComputationGraph, Constant(yTrain)))
    )
    val lossBefore = lossFunctionBefore.compute(inputs).flatten().head
    val fittedModel = model.fit(inputs, yTrain, 10)
    val lossFunctionAfter = Mean(
      Square(
        Subtract(fittedModel.outputLayer.getComputationGraph, Constant(yTrain))
      )
    )
    val lossAfter = lossFunctionAfter.compute(inputs).flatten().head
    assert(lossAfter < lossBefore)
  }
@kostaleonard kostaleonard added the enhancement New feature or request label Mar 14, 2023
@kostaleonard kostaleonard added this to the First release milestone Mar 14, 2023
@kostaleonard kostaleonard self-assigned this Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant