Coder Social home page Coder Social logo

scorch's People

Contributors

gitter-badger avatar koen-dejonghe avatar

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

scorch's Issues

loss explosion after slight overfit

/**linear regression*/
object lrTest {
  import botkop.numsca.Tensor
  import scorch.autograd.Variable
  import scorch.supervised.Linear
  import scorch.optim.{Adam, SGD}
  import botkop.{numsca => ns}
  val f1: Tensor => Tensor = { t: Tensor =>
    t * 3 + 1.0
  }

  def run = {
    val fc1 = Linear(1, 1) // an affine operation: y = Wx + b

    val optimizer = SGD(fc1.parameters, lr = 0.001)
    //todo bug!  overfit to inf
    (1 to 1000) foreach { i =>
      val x = ns.array(i)
      val vx = Variable(x)
      val y = Variable(f1(x))

      val ypred = fc1(vx)

      val loss = scorch.mean((ypred - y) ** 2)

      println(s"loss: ${loss.data}, x: $x, y: ${y.data}, ypred: ${ypred.data}")

      optimizer.zeroGrad()
      loss.backward()
      optimizer.step()
    }
  }
}

after convergence,it gives :
`
loss: 0.00, x: 42.00, y: 127.00, ypred: 127.00
loss: 0.00, x: 43.00, y: 130.00, ypred: 130.02
loss: 0.00, x: 44.00, y: 133.00, ypred: 132.98
loss: 0.01, x: 45.00, y: 136.00, ypred: 136.09
loss: 0.06, x: 46.00, y: 139.00, ypred: 138.75
loss: 0.69, x: 47.00, y: 142.00, ypred: 142.83
loss: 8.30, x: 48.00, y: 145.00, ypred: 142.12
loss: 113.17, x: 49.00, y: 148.00, ypred: 158.64
loss: 1,703.49, x: 50.00, y: 151.00, ypred: 109.73
loss: 28,391.16, x: 51.00, y: 154.00, ypred: 322.50
loss: 521,611.12, x: 52.00, y: 157.00, ypred: -565.23
loss: 10,538,231.00, x: 53.00, y: 160.00, ypred: 3,406.26
loss: 233,496,688.00, x: 54.00, y: 163.00, ypred: -15,117.60
loss: 5,660,134,912.00, x: 55.00, y: 166.00, ypred: 75,399.87
loss: 149,761,097,728.00, x: 56.00, y: 169.00, ypred: -386,820.78

`

Does this really have auto diff?

I saw that for

//============================================
// Loss functions
case class SoftmaxLoss(actual: Variable, target: Variable) extends Function {
  val x: Tensor = actual.data
  val y: Tensor = target.data.T

  val shiftedLogits: Tensor = x - ns.max(x, axis = 1)
  val z: Tensor = ns.sum(ns.exp(shiftedLogits), axis = 1)
  val logProbs: Tensor = shiftedLogits - ns.log(z)
  val n: Int = x.shape.head
  val loss: Double = -ns.sum(logProbs(ns.arange(n), y)) / n

  override def forward(): Variable = Variable(Tensor(loss), Some(this))

  override def backward(gradOutput: Variable /* not used */ ): Unit = {
    val dx = ns.exp(logProbs)
    dx(ns.arange(n), y) -= 1
    dx /= n

    actual.backward(Variable(dx))
  }
}

the backward is manually implemented,which should have been automatically derived

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.