TensorFlow Example: Fit a straight line
github.com
github.com
(Grumble grumble something about dynamic and/or implicit type systems.)
"TensorFlow™ is an open source software library for numerical computation using data flow graphs. Nodes in the graph represent mathematical operations, while the graph edges represent the multidimensional data arrays (tensors) communicated between them." [https://www.tensorflow.org/]
In retrospect the name "Tensor Flow" makes a lot more sense now - I had only ever seen it in the context of machine learning, and assumed it was pretty specific to that domain.
The tensorflow example is able to predict the result of this function for any x, without knowing the function itself only by knowing some example points (points for which the model knows both x and y).
This is a "Hello World" in the area of AI, adapted for the tensorflow library.
Learning to use TensorFlow/Theano/ect isn't like learning another programming language or package. I think it is more like learning a new skill.
I always find it easier to use and understand the higher level tools (like TensorFlow) once you've written your own rudimentary implementation from scratch. Most of my work is done Julia, and sometimes that code is fast enough that I don't have to use anything else.
Yet minimal code examples like this let me see straight away what TensorFlow programs look like, without having to distinguish between fundamental aspects and snippet-specific ones.
My only remark would be to put a comment at the top something like "Fit a straight line, of the form y=m*x+b".
I guessed that the "m" and "b" variables were referring to these common usages, but was wary of this assumption until line 14.
For all I know, "m" and "b" could be common parameter names for some TensorFlow config or something :)
Also, it's best practice and common tensorflow idiom to do:
init = tf.initialize_all_variables()
...
with tf.Session() as session:
session.run(init)
Not just for style, but because creating new graph nodes after creating the session requires tearing down and then re-setting-up some of the internal session stuff. It's much faster to move the initialize_all_variables() creation outside of the session.Btw - you know what also is learning by example? This example.