Giter VIP home page Giter VIP logo

thoughtworksinc / deeplearning.scala Goto Github PK

View Code? Open in Web Editor NEW
765.0 76.0 87.0 8.18 MB

A simple library for creating complex neural networks

Home Page: http://deeplearning.thoughtworks.school/

License: Apache License 2.0

Scala 100.00%
automatic-differentiation deep-neural-networks deep-learning scala neural-network functional-programming symbolic-computation dsl domain-specific-language machine-learning

deeplearning.scala's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deeplearning.scala's Issues

Website

  • website template
  • CI
  • Homepage
  • Documentation
    • Tutorials in Jupyter Notebook format
    • Contribution Guideline
    • Scaladoc
      • Directory Structure and import guidelines
      • Each concept: Batch, Layer, Symbolic, Poly, XxxOps
      • Utility methods: train, predict, compose,withOutputDataHook
      • translate

https://thoughtworksinc.github.io/DeepLearning.scala

TryT

Use TryT instead of EitherT in RAII.scala

  • remove RAIITask

  • ResourceFactoryT

  • ResourceFactoryTSpec

  • remove sde-raii & sde-raii-Spec

  • Shared

  • SharedSpec

Type inference error

下面可以编译通过且正确运行:

package testPackage

import com.thoughtworks.deeplearning.DifferentiableINDArray._
import com.thoughtworks.deeplearning.DifferentiableAny._
import com.thoughtworks.deeplearning.Lift._
import com.thoughtworks.deeplearning.Poly.MathFunctions._
import com.thoughtworks.deeplearning.Poly.MathOps
import org.nd4j.linalg.api.ndarray.INDArray
import org.nd4s.Implicits._
import shapeless._

object Bug extends App {
  def layer(implicit x: From[INDArray] ##T): To[INDArray] ##T = {
    val result: To[INDArray] ##T = exp(x).withOutputDataHook { x: INDArray =>
      println(x)
    }
    result / result.sum(1)
  }

  layer.train(
    Array(Array(1, 2, 3, 4),
          Array(1, 2, 3, 4),
          Array(1, 2, 3, 4),
          Array(1, 2, 3, 4)).toNDArray)
}

result后面的类型去掉后会报错:

Error:(17, 21) value sum is not a member of com.thoughtworks.deeplearning.Layer.Aux[com.thoughtworks.deeplearning.Layer.Batch{type Data <: org.nd4j.linalg.api.ndarray.INDArray; type Delta >: org.nd4j.linalg.api.ndarray.INDArray},com.thoughtworks.deeplearning.Layer.Batch.Aux[this.Data,com.thoughtworks.deeplearning.DifferentiableINDArray.INDArrayPlaceholder.Delta]]
    result / result.sum(1)

Package structure

  • deeplearning

    • package
      • implicit cases
    • Tape
    • Lift
    • tapefactories
    • math
    • logs
    • differentiable
      • package
        • type Float
        • type Double = Do[_ <: Tape.Aux[scala.Double, scala.Double]] / type Double = Do[Tape.Aux[scala.Double, scala.Double]]
        • type Any = Do[_ <: Tape.Aux[scala.Any, scala.Nothing]]
      • Any
        • AnyOps
          • predict
          • train
      • Float
      • Double
      • INDArray
  • raii

    • resourcet
      • ResourceT
      • Releasable
    • sharedops
      • SharedOps
    • future
      • Do
    • sde
      • raii
      • do
  • tryt

remove CovariantT
remove EitherTNondeterminism
remove FreeTParallelApplicative
remvoe KleisliParallelApplicative

Do

  • DoInstance
  • DoExtractor
  • Implicit methods

isTrainable should be avoided

backward, forceBackward and rawBackward seems too messy.

We should remove forceBackward and isTrainable from public API.

compile error in scala version 2.12

    def toLayerTest(implicit from: From[Double]##T) = {
      1.0.toLayer
      Seq(1.0).toLayer
      Seq(1.0.toLayer).toLayer
      Seq(1.toLayer).toLayer
      Seq(1).toLayer
    }

error:

[error] DeepLearning.scala/src/test/scala/com/thoughtworks/deeplearning/SeqSpec.scala:38: value toLayer is not a member of Double
[error]       1.0.toLayer
[error]           ^
[error] DeepLearning.scala/src/test/scala/com/thoughtworks/deeplearning/SeqSpec.scala:39: value toLayer is not a member of Seq[Double]
[error]       Seq(1.0).toLayer
[error]                ^
[error] DeepLearning.scala/src/test/scala/com/thoughtworks/deeplearning/SeqSpec.scala:40: value toLayer is not a member of Double
[error]       Seq(1.0.toLayer).toLayer
[error]               ^
[error] DeepLearning.scala/src/test/scala/com/thoughtworks/deeplearning/SeqSpec.scala:41: value toLayer is not a member of Int
[error]       Seq(1.toLayer).toLayer
[error]             ^
[error] DeepLearning.scala/src/test/scala/com/thoughtworks/deeplearning/SeqSpec.scala:42: value toLayer is not a member of Seq[Int]
[error]       Seq(1).toLayer
[error]              ^
[error] 5 errors found

Abstract GPU AST

At the moment, DslExpression and DslType only works for OpenCL. We should create abstract types in order to support other compute platform, e.g. CUDA

Compile neural networks to OpenCL

  • Generate non-differentiable OpenCL code for a minimal AST
  • Utilities to release OpenCL contexts, command queues and buffers
  • Utilities to create OpenCL contexts and command queues
  • Create a OpenCL version of neural network for a AST (#9), which creates a buffer and it does not reference to other buffers
  • Create a OpenCL version of neural network for a AST that references to other buffers

Use `Do` instead of `RAIITask`

  • Tape

  • ToTapeTask

  • TapeTaskFactory

  • TapeTask

  • differentiable-float

  • differentiable-float-Spec

  • DifferentiableKernel

  • DifferentiableKernelSpec

Type infer error at implement of Poly1 in differentiable-indarray

That should compile

    implicit def optimizer: Optimizer = new LearningRate {
      def currentLearningRate() = 1
    }

    val weight: Do[Borrowing[Tape.Aux[INDArray, INDArray]]]   = (Nd4j.ones(4, 4) * 10).toWeight

    def myNetwork(input: INDArray) : Do[Borrowing[Tape.Aux[INDArray, INDArray]]] = {
      abs(weight)
    }

but actually not:

Error:(429, 11) type mismatch;
 found   : weight.type (with underlying type com.thoughtworks.raii.asynchronous.Do[com.thoughtworks.raii.ownership.Borrowing[com.thoughtworks.deeplearning.Tape.Aux[org.nd4j.linalg.api.ndarray.INDArray,org.nd4j.linalg.api.ndarray.INDArray]]])
 required: com.thoughtworks.deeplearning.PolyFunctions.abs.ProductCase.Aux[shapeless.HNil,?]
    (which expands to)  shapeless.poly.Case[com.thoughtworks.deeplearning.PolyFunctions.abs.type,shapeless.HNil]{type Result = ?}
      abs(weight)

a workaround:

    implicit def optimizer: Optimizer = new LearningRate {
      def currentLearningRate() = 1
    }

    val weight: Do[Borrowing[Tape.Aux[INDArray, INDArray]]]   = (Nd4j.ones(4, 4) * 10).toWeight

    def myNetwork(input: INDArray)  = {
      abs(weight)
    }

or :

    implicit def optimizer: Optimizer = new LearningRate {
      def currentLearningRate() = 1
    }

    val weight: Do[Borrowing[Tape.Aux[INDArray, INDArray]]]   = (Nd4j.ones(4, 4) * 10).toWeight

    def myNetwork(input: INDArray) : Do[Borrowing[Tape.Aux[INDArray, INDArray]]] = {
      val result = abs(weight)
      result
    }

possible solution:

add

def abs(a: AnyRef)(implicit c: abs.Case[a.type]): c.Result = c[a.type](a)

to PolyFunctions, and make Do be a type Do[A] <:AnyRef

General LA, Data Flow and Reactive Programming

For what you are implementing for deep learning with a bit more flexibility perhaps you can make this a such that it can also be used to code application logic in LA / Data Flow / Reactive paradigms. Is it possible to give this flexibility?

Optimizers for OpenCL buffer

  • PendingBuffer should borrow OpenCL.Buffer and OpenCL.Event
  • Weight should store OpenCL.Buffer and OpenCL.Event, not PendingBuffer
  • Weight.data should duplicate OpenCL.Buffer and OpenCL.Event
  • A simple optimizer

Support RAII

So that we can avoid too many try/finally statements when constructing a complicated layer.

DifferentiableNDArray

  • Weight
  • Optimizer
  • Ops
  • PolyMethods & PolyFunctions
  • convolutionOps
  • Test
  • SemigroupTapeTaskFactory

More than async

We are implementing asynchronous computing in DeepLearning.scala 2.0.
However, in order to maximize the throughput, we need on-device computing graph instead of CPU driven asynchronous computing.

In DeepLearning.scala 3.0, we will implement applicative-based computing graph, avoiding flatMap or map. We will keep a proper number of kernel for an on-device command queue, e.g. 3 kernels. Most of the on-CPU Futures await for command queue available, instead of awaiting for result.

  • Counting the load of command queue
  • Make tuples of Buffer and Event

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.