
Simple example of machine learning in TensorFlow - jostmey
https://github.com/jostmey/NakedTensor?bare
======
dbcurtis
I like these kind of "Hello, world!" examples for TensorFlow. As a TensorFlow
beginner, I need all the references I can get. Here is what I need right now:
"Hello, we meet again!". I can build a neural net model, and train (albeit,
often badly) a model, but saving and restoring the trained weights so that I
can run the model again is giving me fits. I am clearly missing something
fundamental about how to restore a TensorFlow NN model.

For your next tutorial, may I suggest: 1) a list of do's and don'ts for
constructing a savable/restorable model, and 2) a wee bit of example code.

Of course, now that I have discovered Keras I'm moving away from low-level
direct TensorFlow. But I suspect I'm not the only one a bit foggy about the
whole save/restore work flow.

~~~
pmalynin
As a person that uses TensorFlow for his day job:

I find that saving and restoring are of the weirder things with TensorFlow,
you can either go all out an decide to save out all the variables, or only the
ones needed for the model.

You usually don't want to save out gradients (which are also variables) since
they take up a bunch of space and aren't actually that useful to restore. Now
on the other, what are model variables -- do you want to save model variables
+ the moving averages ... or just the averages. But then when you're loading
you'll have to "shadow" the moving averages to the real variables that
actually run in your model.

Good news though, most of the scaffolding code you can write once and re-use
it over and over again.

~~~
minimaxir
In Keras, it's just a simple model.save() [to a hdf5 file] and load_model().
This includes both the weights and the architecture.

Models with a few million parameters result in a file around ~50MB, which is
still reasonable for modern production use cases.

~~~
glial
Keras makes using deep learning for simple-ish use cases sooooo easy.

~~~
matheweis
I second this - I'm really excited about Keras being integrated into the core
of Tensorflow (other than the chance it might lose the Torch compatibility).

------
pred_
That's nifty; I was looking for something like that just a few weeks ago for a
work demonstration! Ended up doing
[https://gist.github.com/fuglede/ad04ce38e80887ddcbeb6b81e97b...](https://gist.github.com/fuglede/ad04ce38e80887ddcbeb6b81e97bbfbc)
instead.

~~~
rhcom2
Thank you to you and OP for both sharing these resources. Really helpful.

------
nemo1618
I wish there were more TensorFlow examples written in Go. I made the mistake
of checking out TensorFlow as my first intro to ML and it flew about 10 miles
over my head. Slowly learning now, but most of the documentation and tutorials
are written in Python.

This blog series was also helpful on a conceptual level:
[https://medium.com/emergent-future/simple-reinforcement-
lear...](https://medium.com/emergent-future/simple-reinforcement-learning-
with-tensorflow-part-0-q-learning-with-tables-and-neural-
networks-d195264329d0#.4znc3ulur)

~~~
make3
as a deep learning professional, the deep learning community is something like
99% Python. You'd probably better learn Python at least well enough to
recreate the corresponding Go code in your mind instantly.

------
calebm
>>> You are one buzzword away from being a professional. Instead of fitting a
line to just eight datapoints, we will now fit a line to 8-million datapoints.
Welcome to big data.

LOL :) (Side-note: 8 million is still not big data)

~~~
mcrad
Big Data is a reference to complexity of the data & underlying system that
data represents, NOT the number of datapoints.

lol

~~~
pyromine
Big data is really just a buzzword that no one knows what it really means,
because everyone's definition is different

lol

~~~
happycube
I always think in terms of Munchkin: "any data that is not Big is small"

------
JonathonCwik
So I'm still wrapping my head around some of the math (I haven't had a math
class in a handful of years)...

I get the output of the model (y_model = m*xs[i]+b), it's the y = mx + b where
we know x (from the dataset) and have y be a variable.

The error is where I start to lose it, so I get the idea of the first part
(ys[i]-y_model). It's basically the difference between the actual y value
(from the dataset). I get that we want this number to be as small as possible
as the closer to zero it is for the entire dataset that means we get closer to
the line going through (or near) all the points and the closest fit will be
when this total_error is nearest to zero.

What I don't get is the squaring of the difference. Is it just to make the
difference a larger number so that it's a little more normalized? How do you
get to the conclusion that it needs to be normalized? Same thing with the
learning rate? I believe these to be correlated but I can't tell you how...

~~~
cowabungabruce
Squaring gets you guaranteed positive numbers. Remember, we are adding all the
errors together to optimize the model: If we get

sum_errors_A = 4 + -3 + -1

sum_errors_B = 1 + 1 + 1

B is obviously the better model, but it has a higher error than A when
comparing. If we squared all the terms and then added, B would be the stronger
model.

~~~
JonathonCwik
Ah, gotcha! Makes a lot more sense now.

------
Kiro
This is awesome!

I currently have a small pet project where I think some simple ML would be
cool but I don't know where to start so these things are great.

Basically my use case is that I have a bunch of 64x64 images (16 colors) which
I manually label as "good", "neutral" or "bad". I want to input this dataset
and train the network to categorize new 64x64 images of the same type.

The closest I've found is this: [https://gist.github.com/sono-
bfio/89a91da65a12175fb1169240cd...](https://gist.github.com/sono-
bfio/89a91da65a12175fb1169240cde3a87b)

But it's still too hard to understand exactly how I can create my own dataset
and how to set it up efficiently (the example is using 32x32 but I also want
to factor in that it's only 16 colors; will that give it some performance
advantages?).

~~~
nl
[https://blog.keras.io/building-powerful-image-
classification...](https://blog.keras.io/building-powerful-image-
classification-models-using-very-little-data.html) is what you want.

------
cosmicexplorer
What is the meaning of the "?bare" query string in the url? I googled around
for the meaning of query strings on the github site but only found rnandom
repos on github (not sure how to narrow the search). The first time I tried
removing it I saw another folder named "to_do", but this is gone now so it
might give a version which is cached for longer somehow?

~~~
cosmicexplorer
OK, found out what a bare repository means and pretty sure that's what it
refers to. Still can't find any documentation for the query string parameter
and don't know how that makes sense for github's repository view page.

------
blauditore
I'm not sure about the rules, but shouldn't posts linking to own, personal
projects be prefixed with "Show HN:"? I've seen a lot such posts lately where
the poster was clearly the author as well.

~~~
pvg
No, Show HN is a different thing with its own (generally stricter) rules. You
don't have to add it to things just because you happen to be the author.

[https://news.ycombinator.com/showhn.html](https://news.ycombinator.com/showhn.html)

------
kyleschiller
I think you meant bare bones.

------
mediocrejoker
I'm guessing english is not your first language, so I just wanted to point out
that "bare bottom" is generally synonymous with "uncovered buttocks" ie. in
the context of changing an infant's diaper.

Perhaps you were meaning to put "bare bones"? Google's definition of the
latter is "reduced to or comprising only the basic or essential elements of
something."

Don't want to detract from your point but I think your title is throwing some
people off. I know I would be hesitant to click something at work that sounds
like it could contain nudity.

~~~
dekhn
I think the last example was a clASSifier, so it makes sense.

------
bencollier49
"Bare bottom"? I'm not clicking on this.

~~~
bencollier49
Downvoted! The title might have changed now, but the original one was
completely indecipherable. As far as I could tell it was genuinely some sort
of image recognition algorithm for naked buttocks.

------
BonoboBoner
Simple example? Before finishing the first paragraph, it says

"The slope and y-intercept of the line are determined using gradient descent."

What on earth does that mean? Maybe they should teach mathematics in english
at universities outside of english speaking countries. German mathematics does
not help here.

I wish there was a 4GL like SQL for machine learning using dynamic programming
for algorithm selection and model synthesis like a dbms query planner.

PREDICT s as revenue LEARN FROM company.sales as s GROUP BY MONTH ORDER BY
company.region

~~~
sampo
> _" The slope and y-intercept of the line are determined using gradient
> descent."_

Slope and intercept are very standard names for the parameters of a linear
regression model. Gradient descent is the name of the algorithm used.

