kostaleonard / great-model-theory

A deep learning library for Scala.
MIT License
2 stars 0 forks source link

Great model theory

A deep learning library for Scala.

Usage

The package follows conventions commonly found in deep learning libraries like TensorFlow.

import applications.MNIST
import autodifferentiation.Input
import layers.{Dense, InputLayer, Sigmoid}
import model.Model

val dataset = MNIST.getDataset
val xTrain = dataset._1.reshape(Array(60000, 28 * 28)).toFloat / 255
val yTrain = dataset._2.toCategorical().toFloat
val xTest = dataset._3.reshape(Array(10000, 28 * 28)).toFloat / 255
val yTest = dataset._4.toCategorical().toFloat
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 neuralNetwork = Model(activation2)
val lossBefore = neuralNetwork.evaluate(Map("X" -> xTest), yTest)
val fittedNeuralNetwork = neuralNetwork.fit(Map("X" -> xTrain), yTrain, 10)
val lossAfter = fittedNeuralNetwork.evaluate(Map("X" -> xTest), yTest)
println(s"Loss before: $lossBefore")
println(s"Loss after: $lossAfter")

API docs

The full Scala docs are available on GitHub Pages.

Design goals