Skip to content

Instantly share code, notes, and snippets.

@tastyminerals
Created January 30, 2018 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tastyminerals/83cf2b6e951146771518d55a77fe30f0 to your computer and use it in GitHub Desktop.
Save tastyminerals/83cf2b6e951146771518d55a77fe30f0 to your computer and use it in GitHub Desktop.
demoNet
class NetworkInit(vocabSize: Int) {
private val embeddingWidth = DatasetTools.getTomlConfTable("romain").getLong("inputsize").toInt
private val hiddenSize = DatasetTools.getTomlConfTable("romain").getLong("hiddensize").toInt
private val numberOfFeats = DatasetTools.getTomlConfTable("romain").getLong("feats").toInt
private val numberOfClasses = DatasetTools.getTomlConfTable("romain").getLong("classes").toInt
val config: ComputationGraphConfiguration = new NeuralNetConfiguration.Builder()
.learningRate(DatasetTools.getTomlConfTable("romain").getDouble("minlr"))
.graphBuilder()
.addInputs("wordIndeces")
.addInputs("features")
.addLayer("wordVectorizer",
new EmbeddingLayer.Builder()
.nIn(vocabSize)
.nOut(embeddingWidth)
.build(),
"wordIndeces")
.addLayer("linear1",
new DenseLayer.Builder()
.nIn(numberOfFeats)
.nOut(embeddingWidth)
.build(),
"features")
.addVertex("sum", new ElementWiseVertex(ElementWiseVertex.Op.Add), "wordVectorizer", "linear1")
.addLayer("hidden",
new GravesLSTM.Builder()
.activation(Activation.TANH)
.nIn(hiddenSize)
.nOut(hiddenSize)
.build(),
"sum")
.addLayer("linear2",
new DenseLayer.Builder()
.activation(Activation.SIGMOID) // only if numberOfClasses == 1
//.activation(Activation.SOFTMAX) // use if numberOfClasses > 1
.nIn(hiddenSize)
.nOut(numberOfClasses)
.build(),
"hidden")
.setOutputs("linear2")
.build()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment