|
{ |
|
"cells": [ |
|
{ |
|
"cell_type": "markdown", |
|
"metadata": {}, |
|
"source": [ |
|
"## L2Regularization\n", |
|
"\n", |
|
"L2Regularization applies L2 regularization during back propagation. Note that it only modifies `delta`, so the loss value user obtained is the \"raw\" loss value without L2 regularization applied." |
|
] |
|
}, |
|
{ |
|
"cell_type": "markdown", |
|
"metadata": {}, |
|
"source": [ |
|
"### Dependencies for use in Ammonite REPL" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"metadata": { |
|
"collapsed": true |
|
}, |
|
"outputs": [], |
|
"source": [ |
|
"import $ivy.`com.thoughtworks.deeplearning::plugins-builtins:2.0.0`\n", |
|
"\n", |
|
"import scala.concurrent.ExecutionContext.Implicits.global\n", |
|
"import org.nd4j.linalg.factory.Nd4j\n", |
|
"import org.nd4j.linalg.api.ndarray.INDArray\n", |
|
"import com.thoughtworks.feature.Factory\n", |
|
"import com.thoughtworks.deeplearning.plugins.INDArrayWeights\n", |
|
"import com.thoughtworks.deeplearning.plugins.Builtins" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"metadata": { |
|
"collapsed": true |
|
}, |
|
"outputs": [], |
|
"source": [ |
|
"interp.load(scala.io.Source.fromURL(new java.net.URL(\"https://gist.githubusercontent.com/TerrorJack/a60ff752270c40a6485ee787837390aa/raw/1539ffb15b4c70c3314c54e9ddc26af8198621ab/L2Regularization.sc\")).mkString)" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"metadata": { |
|
"collapsed": true |
|
}, |
|
"outputs": [], |
|
"source": [ |
|
"interp.load(\"\"\"\n", |
|
" val hyperparameters = Factory[Builtins with L2Regularization].newInstance(l2Regularization = 0.001)\n", |
|
"\"\"\")" |
|
] |
|
}, |
|
{ |
|
"cell_type": "markdown", |
|
"metadata": {}, |
|
"source": [ |
|
"### For sbt projects" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"metadata": { |
|
"collapsed": true |
|
}, |
|
"outputs": [], |
|
"source": [ |
|
"// build.sbt\n", |
|
"libraryDependencies += \"com.thoughtworks.deeplearning\" %% \"plugins-builtins\" % \"latest.release\"\n", |
|
"\n", |
|
"addCompilerPlugin(\"com.thoughtworks.import\" %% \"import\" % \"latest.release\")\n", |
|
"\n", |
|
"// XXX.scala\n", |
|
"import $exec.`https://gist.githubusercontent.com/TerrorJack/a60ff752270c40a6485ee787837390aa/raw/1539ffb15b4c70c3314c54e9ddc26af8198621ab/L2Regularization.sc`\n", |
|
" \n", |
|
"import scala.concurrent.ExecutionContext.Implicits.global\n", |
|
"import org.nd4j.linalg.factory.Nd4j\n", |
|
"import org.nd4j.linalg.api.ndarray.INDArray\n", |
|
"import com.thoughtworks.feature.Factory\n", |
|
"import com.thoughtworks.deeplearning.plugins.INDArrayWeights\n", |
|
"import com.thoughtworks.deeplearning.plugins.Builtins\n", |
|
" \n", |
|
"val hyperparameters = Factory[Builtins with L2Regularization].newInstance(l2Regularization = 0.001)" |
|
] |
|
} |
|
], |
|
"metadata": { |
|
"kernelspec": { |
|
"display_name": "Scala", |
|
"language": "scala", |
|
"name": "scala" |
|
}, |
|
"language_info": { |
|
"codemirror_mode": "text/x-scala", |
|
"file_extension": ".scala", |
|
"mimetype": "text/x-scala", |
|
"name": "scala211", |
|
"nbconvert_exporter": "script", |
|
"pygments_lexer": "scala", |
|
"version": "2.11.11" |
|
} |
|
}, |
|
"nbformat": 4, |
|
"nbformat_minor": 2 |
|
} |