Issue
I'm following coursera tensorflow course and I can not understand below code can you explain itusing simple english please..
here is code
model = tf.keras.models.Sequential([tf.keras.layers.Flatten(),
tf.keras.layers.Dense(128, activation=tf.nn.relu),
tf.keras.layers.Dense(10, activation=tf.nn.softmax)])
I want to know what do tf.nn.softmax in a course description have below description but it is not clear to me.
Sequential: That defines a SEQUENCE of layers in the neural network
Flatten: Remember earlier where our images were a square, when you printed them out? Flatten just takes that square and turns it into a 1 dimensional set.
Dense: Adds a layer of neurons
Each layer of neurons need an activation function to tell them what to do. There's lots of options, but just use these for now.
Relu effectively means "If X>0 return X, else return 0" -- so what it does it it only passes values 0 or greater to the next layer in the network.
Softmax takes a set of values, and effectively picks the biggest one, so, for example, if the output of the last layer looks like [0.1, 0.1, 0.05, 0.1, 9.5, 0.1, 0.05, 0.05, 0.05]
, it saves you from fishing through it looking for the biggest value, and turns it into [0,0,0,0,1,0,0,0,0]
-- The goal is to save a lot of coding!
Solution
Here's the docs: https://www.tensorflow.org/api_docs/python/tf/nn/softmax
Basically, softmax is good for classification. It will take any number and map it to an output of either 0 or 1 (for example) because we say that if Softmax(X) <0.5 then set it equal to zero and if Softmax(X)>=0.5 then set it equal to 1.
Take a look at this article here, which also describes the sigmoid and softmax function. The graphs are important. Also a google image search will give some graphs of the function.
http://dataaspirant.com/2017/03/07/difference-between-softmax-function-and-sigmoid-function/
Answered By - Monty
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.