-
-
Save Atry/843f606fc89bd4594ffcd03853c6edc6 to your computer and use it in GitHub Desktop.
Revisions
-
Atry revised this gist
Jul 31, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -66,7 +66,7 @@ ] }, { "cell_type": "markdown", "execution_count": null, "metadata": { "collapsed": true -
Atry revised this gist
Jul 31, 2017 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -73,6 +73,7 @@ }, "outputs": [], "source": [ "``` scala\n", "// build.sbt\n", "libraryDependencies += \"com.thoughtworks.deeplearning\" %% \"plugins-builtins\" % \"latest.release\"\n", "\n", @@ -90,7 +91,8 @@ "import com.thoughtworks.feature.Factory\n", "import com.thoughtworks.deeplearning.plugins.Builtins\n", "\n", "val hyperparameters = Factory[Builtins with L1Regularization].newInstance(l1Regularization = 0.001)", "```\n" ] } ], -
Atry revised this gist
Jul 31, 2017 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -77,7 +77,8 @@ "libraryDependencies += \"com.thoughtworks.deeplearning\" %% \"plugins-builtins\" % \"latest.release\"\n", "\n", "addCompilerPlugin(\"com.thoughtworks.import\" %% \"import\" % \"latest.release\")\n", "```\n", "``` scala\n", "// XXX.scala\n", "\n", "import $exec.`https://gist.github.com/Atry/843f606fc89bd4594ffcd03853c6edc6/raw/63e0f02bfbbb01caf66632ceae5a66b9dd7f444d/L1Regularization.sc`\n", -
Atry revised this gist
Jul 27, 2017 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -42,7 +42,7 @@ }, "outputs": [], "source": [ "interp.load(scala.io.Source.fromURL(new java.net.URL(\"https://gist.github.com/Atry/843f606fc89bd4594ffcd03853c6edc6/raw/63e0f02bfbbb01caf66632ceae5a66b9dd7f444d/L1Regularization.sc\")).mkString)" ] }, { @@ -80,7 +80,7 @@ "\n", "// XXX.scala\n", "\n", "import $exec.`https://gist.github.com/Atry/843f606fc89bd4594ffcd03853c6edc6/raw/63e0f02bfbbb01caf66632ceae5a66b9dd7f444d/L1Regularization.sc`\n", "\n", "import scala.concurrent.ExecutionContext.Implicits.global\n", "import org.nd4j.linalg.api.ndarray.INDArray\n", -
Atry revised this gist
Jul 27, 2017 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,7 @@ trait L1Regularization extends INDArrayWeights { this: INDArrayOptimizer => abstract override def delta: INDArray = { import org.nd4s.Implicits._ import org.nd4j.linalg.ops.transforms.Transforms super.delta + Transforms.sign(weight.data) * l1Regularization } } -
TerrorJack revised this gist
Jul 26, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ }, "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.api.ndarray.INDArray\n", -
TerrorJack revised this gist
Jul 26, 2017 . 1 changed file with 10 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,7 +19,9 @@ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import $ivy.`com.thoughtworks.deeplearning::plugins-builtins:2.0.0-RC7`\n", @@ -35,7 +37,9 @@ { "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/8154015cc0ac5cfba8e351b642ef12b3/raw/35080210cdd83f3fc0f2bb218f04549a57d2b960/L1Regularization.sc\")).mkString)" @@ -73,7 +77,10 @@ "libraryDependencies += \"com.thoughtworks.deeplearning\" %% \"plugins-builtins\" % \"latest.release\"\n", "\n", "addCompilerPlugin(\"com.thoughtworks.import\" %% \"import\" % \"latest.release\")\n", "\n", "// XXX.scala\n", "\n", "import $exec.`https://gist.githubusercontent.com/TerrorJack/8154015cc0ac5cfba8e351b642ef12b3/raw/35080210cdd83f3fc0f2bb218f04549a57d2b960/L1Regularization.sc`\n", "\n", "import scala.concurrent.ExecutionContext.Implicits.global\n", "import org.nd4j.linalg.api.ndarray.INDArray\n", -
TerrorJack revised this gist
Jul 26, 2017 . 1 changed file with 59 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ "### Dependencies for use in Ammonite REPL" ] }, { @@ -22,11 +22,67 @@ "metadata": {}, "outputs": [], "source": [ "import $ivy.`com.thoughtworks.deeplearning::plugins-builtins:2.0.0-RC7`\n", "\n", "import scala.concurrent.ExecutionContext.Implicits.global\n", "import org.nd4j.linalg.api.ndarray.INDArray\n", "import org.nd4j.linalg.ops.transforms.Transforms\n", "import com.thoughtworks.deeplearning.plugins.INDArrayWeights\n", "import com.thoughtworks.feature.Factory\n", "import com.thoughtworks.deeplearning.plugins.Builtins" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "interp.load(scala.io.Source.fromURL(new java.net.URL(\"https://gist.githubusercontent.com/TerrorJack/8154015cc0ac5cfba8e351b642ef12b3/raw/35080210cdd83f3fc0f2bb218f04549a57d2b960/L1Regularization.sc\")).mkString)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "interp.load(\"\"\"\n", " val hyperparameters = Factory[Builtins with L1Regularization].newInstance(l1Regularization = 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", "import $url.{`https://gist.githubusercontent.com/TerrorJack/8154015cc0ac5cfba8e351b642ef12b3/raw/35080210cdd83f3fc0f2bb218f04549a57d2b960/L1Regularization.sc` => L1Regularization}\n", "\n", "import scala.concurrent.ExecutionContext.Implicits.global\n", "import org.nd4j.linalg.api.ndarray.INDArray\n", "import org.nd4j.linalg.ops.transforms.Transforms\n", "import com.thoughtworks.deeplearning.plugins.INDArrayWeights\n", "import com.thoughtworks.feature.Factory\n", "import com.thoughtworks.deeplearning.plugins.Builtins\n", "\n", "val hyperparameters = Factory[Builtins with L1Regularization].newInstance(l1Regularization = 0.001)" ] } ], -
TerrorJack revised this gist
Jul 24, 2017 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ trait L1Regularization extends INDArrayWeights { val l1Regularization: Double trait INDArrayOptimizerApi extends super.INDArrayOptimizerApi { this: INDArrayOptimizer => This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,7 +22,7 @@ "metadata": {}, "outputs": [], "source": [ "import $ivy.`com.thoughtworks.deeplearning::plugins-builtins:2.0.0-RC6`\n", "\n", "import org.nd4j.linalg.api.ndarray.INDArray\n", "import org.nd4j.linalg.ops.transforms.Transforms\n", -
TerrorJack revised this gist
Jul 20, 2017 . 1 changed file with 9 additions and 63 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,82 +6,28 @@ "source": [ "## L1Regularization\n", "\n", "L1Regularization applies L1 regularization during back propagation. Note that it only modifies `delta`, so the loss value user obtained is the \"raw\" loss value without L1 regularization applied." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Dependencies" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import $ivy.`com.thoughtworks.deeplearning::plugins-builtins:2.0.0-RC5`\n", "\n", "import org.nd4j.linalg.api.ndarray.INDArray\n", "import org.nd4j.linalg.ops.transforms.Transforms\n", "import com.thoughtworks.deeplearning.plugins.INDArrayWeights" ] } ], "metadata": { -
TerrorJack revised this gist
Jul 20, 2017 . 1 changed file with 105 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,105 @@ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## L1Regularization\n", "\n", "L1Regularization applies L1 regularization during back propagation. Note that it only modifies `delta`, so the loss value user obtained is the \"raw\" loss value without L1 regularization applied.\n", "\n", "## D" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\u001b[32mimport \u001b[39m\u001b[36m$ivy.$ \n", "\n", "\u001b[39m\n", "\u001b[32mimport \u001b[39m\u001b[36morg.nd4j.linalg.api.ndarray.INDArray\n", "\u001b[39m\n", "\u001b[32mimport \u001b[39m\u001b[36morg.nd4j.linalg.ops.transforms.Transforms\n", "\u001b[39m\n", "\u001b[32mimport \u001b[39m\u001b[36mcom.thoughtworks.deeplearning.plugins.INDArrayWeights\u001b[39m" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import $ivy.`com.thoughtworks.deeplearning::plugins-builtins:2.0.0-RC5`\n", "\n", "import org.nd4j.linalg.api.ndarray.INDArray\n", "import org.nd4j.linalg.ops.transforms.Transforms\n", "import com.thoughtworks.deeplearning.plugins.INDArrayWeights" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "defined \u001b[32mtrait\u001b[39m \u001b[36mL1Regularization\u001b[39m" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "trait L1Regularization extends INDArrayWeights {\n", " def l1Regularization: INDArray\n", "\n", " trait INDArrayOptimizerApi extends super.INDArrayOptimizerApi {\n", " this: INDArrayOptimizer =>\n", " abstract override def delta: INDArray = {\n", " import org.nd4s.Implicits._\n", " super.delta + Transforms.sign(weight.data) * l1Regularization\n", " }\n", " }\n", "\n", " override type INDArrayOptimizer <: INDArrayOptimizerApi with Optimizer\n", "}" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "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 } -
TerrorJack revised this gist
Jul 20, 2017 . 1 changed file with 21 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ MIT License Copyright (c) 2017 ThoughtWorks Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -
TerrorJack created this gist
Jul 20, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ trait L1Regularization extends INDArrayWeights { def l1Regularization: INDArray trait INDArrayOptimizerApi extends super.INDArrayOptimizerApi { this: INDArrayOptimizer => abstract override def delta: INDArray = { import org.nd4s.Implicits._ super.delta + Transforms.sign(weight.data) * l1Regularization } } override type INDArrayOptimizer <: INDArrayOptimizerApi with Optimizer }