+ 3

Can a neural network learn multiplication?

I saw a neural network code in one of the sololearn's machine learning lessons. That code succeeded in learning addition and subtraction but failed to learn multiplication. By the way I'm a newbie to neural networks. And here's the code.Also, I'm curious to know why this code fails to learn multiplication https://code.sololearn.com/czKhobkSSM6p/?ref=app

22nd Aug 2018, 3:16 PM
Hope
Hope - avatar
11 ответов
+ 4
They can learn any basic maths function even modulo. It depends on the the way you tune it though. Activation functions play a big role. E.g you can't try and make a neural network learn multiplication with a sigmoid activation function, it will just never work out since the output of the neurons will always be between 0 and 1 And michal you'll probably be better lf creating two seperate neural nets.
25th Aug 2018, 7:01 AM
Poet🎭
Poet🎭 - avatar
+ 4
Oh and I forgot.... In that example above there's really no magic you can do its just a simple feedforward net with a single hidden layer of just two neurons and no activation function. The dataset is quite small so your not really exposing it to the full world of multiplication. So no matter how hard you train it, it will sadly never be accurate. I'll create/code one and share with you to show you how exactly you can achieve what you are looking for.
25th Aug 2018, 7:08 AM
Poet🎭
Poet🎭 - avatar
+ 3
Your outputs in the training set are wrong. You're not calculating a*b, you're calculating 2a+2b and your algorithm manages to learn that
23rd Aug 2018, 2:08 AM
Chris
Chris - avatar
+ 3
well, obviously you can't define 2 general weights which are valid for every input. this code doesn't support variable weights
23rd Aug 2018, 8:15 PM
Chris
Chris - avatar
+ 3
That's actually somewhat true. We tell the program that it has to use the dot product and simply want it to calculate the coefficients. We need multiple examples to reduce our problem on a single general equation. Due to the code's nature of using training data and test data, it definetely serves its purpose as a first step into machine learning, but it's difficult to draw a line here whether it's "real" machine learning or not.
24th Aug 2018, 1:28 PM
Chris
Chris - avatar
+ 2
Chris That's right, but how can we then make a neural network that can multiply? And what about a network that can learn from the samples if the result should be sum or multiplication
23rd Aug 2018, 8:28 PM
michal
+ 2
But in the original case (in the lesson), if we know, that the output is a linear combination of 2 inputs, we can just calculate the weights (system of equations) from the sample inputs. So it wouldn't be machine learning either? Why do we use machine learning for that if we can directly calculate the weights?
24th Aug 2018, 1:18 PM
michal
+ 2
https://code.sololearn.com/W6guVlmsZE5T/?ref=app check this out it adds two numbers. I you don't understand then feel free to ask
26th Aug 2018, 1:09 PM
S O U ✌️ I K
S O U ✌️ I K - avatar
+ 1
Thanks for the reply but that's not my code(sorry for the ambiguity). I copied that code from one of the sololearn's machine learning lesson and I tried to see if it learns multiplication by changing the inputs and outputs. Turns out that the output is lacking accuracy and I wanted to know why.
23rd Aug 2018, 1:06 PM
Hope
Hope - avatar
+ 1
I changed the code but still the problem persists.
23rd Aug 2018, 1:06 PM
Hope
Hope - avatar
+ 1
There is a way and I wish I knew it. If you want a code that decides between addition and multiplication, it would depend on whether it knows the output or not. If no, there has to be a + or a * in the equation (otherwise an input of 2 numbers could mean everything). If yes, the program would simply have to multiply and add the numbers to see which one fits. Therefore, neither of it would be machine learning.
23rd Aug 2018, 8:31 PM
Chris
Chris - avatar