# Why isn't Flux Descent learning?

**URL:** <https://discourse.julialang.org/t/why-isnt-flux-descent-learning/32605>\
**Category:** New to Julia\
**Created:** [December 23, 2019, 6:06am UTC](https://discourse.julialang.org/t/why-isnt-flux-descent-learning/32605 "2019-12-23T06:06:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yuxi.liu](https://avatars.discourse-cdn.com/v4/letter/y/839c29/32.png) [@yuxi.liu](https://discourse.julialang.org/u/yuxi.liu)\
**Post date:** [December 23, 2019, 6:06am UTC](https://discourse.julialang.org/t/why-isnt-flux-descent-learning/32605/1 "2019-12-23T06:06:42Z")

</div>

The following code doesn’t cause nearly as much learning as it should.

Basically, I create two groups 0 and 1, each having two points, and want them separated by a sigmoid function, using mean square error as loss.

During training, the loss function isn’t decreasing, as reported by the callback:

```julia
using Flux
xs_test = [[0.5, 0.25],[0.5, 0.25],[0.5, 0.5],[0.5, 0.5]]
ys_test = [0, 0, 1, 1]

model = Dense(2, 1, σ)
model.W .= ones(1, 2)
model.b .= ones(1)

loss(x, y) = Flux.mse(model(x), y)

ps = params(model)
data = zip(xs_test, ys_test)
opt = Descent(0.1)

plot(loss.(xs_test, ys_test), label="before training")
Flux.train!(loss, ps, data, opt; cb = () -> println("Current loss: ", sum(loss.(xs_test, ys_test))))

plot!(loss.(xs_test, ys_test), label="after training")

```

But after training, there is no improvement in separation:

```julia
contour(0:.1:1, 0:.1:1, (x, y) -> model([x,y])[1], fill=true)
scatter!(first.(xs_test[1:2]), last.(xs_test[1:2]), label="group 0")
scatter!(first.(xs_test[3:4]), last.(xs_test[3:4]), label="group 1")

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/b/7b03bb4921e346f7f9059ac400c0e6ed15af95ed.png)

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [December 23, 2019, 6:17am UTC](https://discourse.julialang.org/t/why-isnt-flux-descent-learning/32605/2 "2019-12-23T06:17:29Z")

</div>

It does learn, it’s just that you only run a single epoch. Try

```julia
 Flux.@epochs 100 Flux.train!(loss, ps, data, opt; cb = () -> println("Current loss: ", sum(loss.(xs_test, ys_test))))

```
