# How can I train a simple model to understand the relation of math addition? \[Flux\]

**URL:** https://discourse.julialang.org/t/how-can-i-train-a-simple-model-to-understand-the-relation-of-math-addition-flux/34294
**Category:** Machine Learning
**Created:** [February 7, 2020, 11:37am UTC](https://discourse.julialang.org/t/how-can-i-train-a-simple-model-to-understand-the-relation-of-math-addition-flux/34294 "2020-02-07T11:37:07Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![TheOnlyArtz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theonlyartz/32/12685_2.png) [@TheOnlyArtz](https://discourse.julialang.org/u/TheOnlyArtz)
#### Post date: [February 7, 2020, 11:37am UTC](https://discourse.julialang.org/t/how-can-i-train-a-simple-model-to-understand-the-relation-of-math-addition-flux/34294/1 "2020-02-07T11:37:07Z")

</div>

So as the title suggests, I want to get started with Flux and I can’t really understand that much from the docs, I want to train a simple model which will take 2 numbers in the input layer and output a single number (the addition of the 2 numbers), I don’t have the understanding on how to add the output,hidden,input layers to the model nor how to write a data set (I’m used to something like [firstnum,secndnum,result]) from other languages I’ve been doing ML in.

Thank you.

---

<div class="post-metadata">

### Author: ![orialb](https://avatars.discourse-cdn.com/v4/letter/o/65b543/32.png) [@orialb](https://discourse.julialang.org/u/orialb)
#### Post date: [February 7, 2020, 12:50pm UTC](https://discourse.julialang.org/t/how-can-i-train-a-simple-model-to-understand-the-relation-of-math-addition-flux/34294/2 "2020-02-07T12:50:23Z")

</div>

Did you go through the [model building basics](https://fluxml.ai/Flux.jl/stable/models/basics/) and [training](https://fluxml.ai/Flux.jl/stable/training/training/) sections of the docs? Those questions are addressed there. Or is there something specific from there which you find unclear?

---

<div class="post-metadata">

### Author: ![TheOnlyArtz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theonlyartz/32/12685_2.png) [@TheOnlyArtz](https://discourse.julialang.org/u/TheOnlyArtz)
#### Post date: [February 7, 2020, 12:52pm UTC](https://discourse.julialang.org/t/how-can-i-train-a-simple-model-to-understand-the-relation-of-math-addition-flux/34294/3 "2020-02-07T12:52:35Z")

</div>

I did go through, I didn’t manage to understand 70% of the things there, it’s not straight forward or newbie friendly at all.

---

<div class="post-metadata">

### Author: ![TheOnlyArtz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theonlyartz/32/12685_2.png) [@TheOnlyArtz](https://discourse.julialang.org/u/TheOnlyArtz)
#### Post date: [February 7, 2020, 1:01pm UTC](https://discourse.julialang.org/t/how-can-i-train-a-simple-model-to-understand-the-relation-of-math-addition-flux/34294/4 "2020-02-07T13:01:55Z")

</div>

@orialb I didn’t understand how can I create a Dense layer which consists of 2 input values and 1 output value when Dense gets 3 values which the first 2 of them are Integers and not arrays.

How can I add a dataset which looks like  
`[(1, 1, 2), (5, 5, 10), (20, 20, 40)]` where the first two values of each element is the input and the third is the target

---

<div class="post-metadata">

### Author: ![orialb](https://avatars.discourse-cdn.com/v4/letter/o/65b543/32.png) [@orialb](https://discourse.julialang.org/u/orialb)
#### Post date: [February 7, 2020, 1:12pm UTC](https://discourse.julialang.org/t/how-can-i-train-a-simple-model-to-understand-the-relation-of-math-addition-flux/34294/5 "2020-02-07T13:12:55Z")

</div>

Let me preface this by saying that I’m not a regular Flux user (or even ML practitioner). The following code will create a model which is just one dense layer with input size 2 and output size 1:

```julia
 model = Dense(2,1)

```

The last optional argument for `Dense` allows you to specify the activation function (by default it is just the identity).

As for the data set, it is basically a list of tuples of the form (x,y) , so for your example it should be:

```julia
data = [([1, 1], 2), ([5, 5], 10), ([20, 20], 40)]

```

---

<div class="post-metadata">

### Author: ![dmolina](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmolina/32/5246_2.png) [@dmolina](https://discourse.julialang.org/u/dmolina)
#### Post date: [February 7, 2020, 2:07pm UTC](https://discourse.julialang.org/t/how-can-i-train-a-simple-model-to-understand-the-relation-of-math-addition-flux/34294/6 "2020-02-07T14:07:27Z")

</div>

I recommend  
[Deep Learning with Flux.jl | JuliaAcademy](https://juliaacademy.com/p/deep-learning-with-flux-jl) because it is a lot more intuitive. I am not sure if it is updated to version 0.10 but in my opinion is a lot more undestandable than official documentation.
