Tensorgo?
Using Wistfully looking at
Tensorflow in GO
ME
Background
Test, Test Automation,
Support, Development,
Release Engineering,
Management and now
back to development
with teamwork.com
No Data Science?
Nope. Just someone
who is interested in all
the amazing things
happening in this space
Tensorflow experience
About 7 days… yeah honestly you’ll soon see
Deep Neural Network - In diagram form
Definition
Input Layer - Source of data. No transforms just pass it on
Bias Nodes - Always on. Always set to 1. Think of it as b in y = ax + b. Shifts a
function by allowing flexibility.
Hidden Layer - > 1 layer here makes it a deep network. This is where
calculations are applied and result past to next layer. Hidden because values
not in training set. S
Output Layer - Result from the model. During training this is compared to
expected and used to change weights to improve model
https://ujjwalkarn.me/2016/08/09/quick-intro-neural-networks/
Some good intro resources
https://stevenmiller888.github.io/mind-how-to-build-a-neural-network/
https://www.quora.com/ELI5-What-are-neural-networks is a nice example and talks about how you would get a computer to learn
a ‘square’ function
https://stats.stackexchange.com/questions/63152/what-does-the-hidden-layer-in-a-neural-network-compute
Talks about hidden layers and classifying pictures of a bus. You might look for wheels. For a box. Checking the size etc and if all
3 hit you’re confident this is a bus…
http://ufldl.stanford.edu/tutorial/supervised/MultiLayerNeuralNetworks/
https://stackoverflow.com/questions/38248657/why-does-simple-2-layer-neural-network-cannot-learn-0-0-sequence#38253140
https://stackoverflow.com/questions/1697243/perceptron-learning-algorithm-not-converging-to-0
OK but what’s tensorflow
Collection of API’s to allow you to create, train and
consume the models we are talking about.
Machine learning toolkit in other words
https://www.tensorflow.org/get_started/ - official docs
Colab notebooks are COOL but a bit slow
Other good introductions
https://eu.udacity.com/course/deep-learning--ud730 - Free course from Google
https://developers.google.com/machine-learning/crash-course/ml-intro -
amazing google course
https://developers.google.com/machine-learning/glossary/ -Glossary
https://medium.com/all-of-us-are-belong-to-machines/the-gentlest-introduction-
to-tensorflow-248dc871a224
https://dzone.com/refcardz/introduction-to-tensorflow?chapter=1 - focused on
worked examples in python
https://www.youtube.com/watch?v=MotG3XI2qSs
https://www.youtube.com/watch?v=5DknTFbcGVM
TensorFlow & Go
Just GO?
Java and C supported as well it seems.
Swift and JS just announced and the original C++ and
Python so it may soon become ubiquitous
Getting setup
https://www.tensorflow.org/install/install_go
Hello Gopher Version
Let’s review the hello world version
https://gist.github.com/PatrickWalker/78e7cbaf3bcb791150
5990409a33dfa6
^ added some comments
We can create a graph, setup a session to execute the
graph and scoop out the results. Nice.
It’s exactly the same as the python version...
What’s different?
Tensortflow was initially for C++ and Python. Go is a relative newcomer with it and it’s not
fully featured yet
It is not officially designated to support creation and training of models. Yep that’s right. You
shouldn’t train a model with go…
Ok so it’s not ideal but don’t leave yet.
You can in theory train your model in Go, but the API isn’t stable, but the suggested
‘idiomatic’ way is to train it in python and consume it in go so not all is lost
The idiotmatic way
THE PATRICK WAY
Let some other brainboxes do that bit. It’s the hardest bit.
We’ll just profit on other peoples work.
We will re-use work from other people. GENIUS. If only
there was a common shared place that gave you
confidence...
Tensorflow Hub
https://www.tensorflow.org/hub/
Recently launched.
TensorFlow Hub is a library to foster the publication, discovery, and
consumption of reusable parts of machine learning models. A module is a
self-contained piece of a TensorFlow graph, along with its weights and assets,
that can be reused across different tasks in a process known as transfer
learning.
Other new stuff?
● Tensorflow lite (mobile)
● Tensorflow JS
● Probability API
● Community Focus
More here
https://medium.com/tensorflow/highlights-from-tensorflow-
developer-summit-2018-cd86615714b2
https://www.youtube.com/tensorflow
Twitter Sentiment
Why?
Interested in doing a competitor analysis for a project we are about to
undertake for work.
What I would love to do is get a stream of tweets using a search term. Push
them through a SPECIAL MACHINE (our tensorflow model in this case) and
know if they are positive or negative statements.
Then try and work out common words/themes that show up in both category to
know what is loved and what isn’t loved
Isn’t this overkill
Well there is an api essentially to do it but that probably wouldn’t have been
too interesting for a tensorflow meetup :D
There are ready made github libraries but I struggled to
get actual results from them. Everything was deemed
neutral or positive even if I searched for overwhelmingly
negative things like “Internet Explorer” or “James
Corden” or “middle aged men crowbarring gifs into tech
presentations”
So I started to think about making my
own naive bayes classification system...
How?
Went to lift a fully featured trained twitter sentiment model from the hub…
Doesn’t exist because these are building blocks. It’s more of a library. So there
are text helpers and one even looks at semantic similarity between sentences
but would take a fair amount of building and actual brain power to make the full
thing. That’s not me.
So off to github and scouring blogs I went.
How?
Followed this blog and made an amazing model which would allow us to check
sentiment of strings. AMAZING. Thought porting to go would be easy.
<voiceover> it was not easy </voiceover>
Training the model in Python was pretty straightforward but time consuming
and resource hungry.
Had to change the exported model format after the 2nd go as it had seperated
weights and model which made parsing them again hard.
This left with me with a trained model (github) and now it was time to interact
with it in Go
Go Code
Followed this blog and made an amazing model which would allow us to check
sentiment of strings. AMAZING. Thought porting to go would be easy.
<voiceover> it was not easy </voiceover>
Training the model in Python was pretty straightforward but time consuming
and resource hungry.
Had to change the exported model format after the 2nd go as it had separated
weights and model which made parsing them again hard.
This left with me with a trained model and now it was time to interact with it in
Go...
Go Code
That’s when you realise that unless you define some sort of contract on the
model it can be quite hard to parse and understand the format of the input
tensor etc to get the model going again in another context (go in this case).
Imagine trying to talk to an undocumented api in a language that had no json
helper...
Also don’t have* wonderous helpers like numpy and others to help make the
tensors so it’s a bit hokey in Go atm.
I mean I forked python code which allowed me to do this out of the box so I’m
unsure why you would want to redo half of it in another language.
Summary
● Really interesting area
● If you’re familiar with Go or organizationally invested in
Go you can still get involved in Tensorflow
● It probably isn’t the right thing to do imo. Python is.
● Javascript seems like the priority now for other
languages so not sure when Go will get the love
As of today Go isn’t really the language of ML
The End?
The End

Tensorflow go

  • 1.
  • 2.
    ME Background Test, Test Automation, Support,Development, Release Engineering, Management and now back to development with teamwork.com No Data Science? Nope. Just someone who is interested in all the amazing things happening in this space Tensorflow experience About 7 days… yeah honestly you’ll soon see
  • 3.
    Deep Neural Network- In diagram form
  • 4.
    Definition Input Layer -Source of data. No transforms just pass it on Bias Nodes - Always on. Always set to 1. Think of it as b in y = ax + b. Shifts a function by allowing flexibility. Hidden Layer - > 1 layer here makes it a deep network. This is where calculations are applied and result past to next layer. Hidden because values not in training set. S Output Layer - Result from the model. During training this is compared to expected and used to change weights to improve model https://ujjwalkarn.me/2016/08/09/quick-intro-neural-networks/
  • 5.
    Some good introresources https://stevenmiller888.github.io/mind-how-to-build-a-neural-network/ https://www.quora.com/ELI5-What-are-neural-networks is a nice example and talks about how you would get a computer to learn a ‘square’ function https://stats.stackexchange.com/questions/63152/what-does-the-hidden-layer-in-a-neural-network-compute Talks about hidden layers and classifying pictures of a bus. You might look for wheels. For a box. Checking the size etc and if all 3 hit you’re confident this is a bus… http://ufldl.stanford.edu/tutorial/supervised/MultiLayerNeuralNetworks/ https://stackoverflow.com/questions/38248657/why-does-simple-2-layer-neural-network-cannot-learn-0-0-sequence#38253140 https://stackoverflow.com/questions/1697243/perceptron-learning-algorithm-not-converging-to-0
  • 6.
    OK but what’stensorflow Collection of API’s to allow you to create, train and consume the models we are talking about. Machine learning toolkit in other words https://www.tensorflow.org/get_started/ - official docs Colab notebooks are COOL but a bit slow
  • 7.
    Other good introductions https://eu.udacity.com/course/deep-learning--ud730- Free course from Google https://developers.google.com/machine-learning/crash-course/ml-intro - amazing google course https://developers.google.com/machine-learning/glossary/ -Glossary https://medium.com/all-of-us-are-belong-to-machines/the-gentlest-introduction- to-tensorflow-248dc871a224 https://dzone.com/refcardz/introduction-to-tensorflow?chapter=1 - focused on worked examples in python https://www.youtube.com/watch?v=MotG3XI2qSs https://www.youtube.com/watch?v=5DknTFbcGVM
  • 8.
  • 9.
    Just GO? Java andC supported as well it seems. Swift and JS just announced and the original C++ and Python so it may soon become ubiquitous
  • 10.
  • 11.
    Hello Gopher Version Let’sreview the hello world version https://gist.github.com/PatrickWalker/78e7cbaf3bcb791150 5990409a33dfa6 ^ added some comments We can create a graph, setup a session to execute the graph and scoop out the results. Nice. It’s exactly the same as the python version...
  • 12.
    What’s different? Tensortflow wasinitially for C++ and Python. Go is a relative newcomer with it and it’s not fully featured yet It is not officially designated to support creation and training of models. Yep that’s right. You shouldn’t train a model with go… Ok so it’s not ideal but don’t leave yet. You can in theory train your model in Go, but the API isn’t stable, but the suggested ‘idiomatic’ way is to train it in python and consume it in go so not all is lost
  • 13.
    The idiotmatic way THEPATRICK WAY Let some other brainboxes do that bit. It’s the hardest bit. We’ll just profit on other peoples work. We will re-use work from other people. GENIUS. If only there was a common shared place that gave you confidence...
  • 14.
    Tensorflow Hub https://www.tensorflow.org/hub/ Recently launched. TensorFlowHub is a library to foster the publication, discovery, and consumption of reusable parts of machine learning models. A module is a self-contained piece of a TensorFlow graph, along with its weights and assets, that can be reused across different tasks in a process known as transfer learning.
  • 15.
    Other new stuff? ●Tensorflow lite (mobile) ● Tensorflow JS ● Probability API ● Community Focus More here https://medium.com/tensorflow/highlights-from-tensorflow- developer-summit-2018-cd86615714b2 https://www.youtube.com/tensorflow
  • 16.
  • 17.
    Why? Interested in doinga competitor analysis for a project we are about to undertake for work. What I would love to do is get a stream of tweets using a search term. Push them through a SPECIAL MACHINE (our tensorflow model in this case) and know if they are positive or negative statements. Then try and work out common words/themes that show up in both category to know what is loved and what isn’t loved
  • 18.
    Isn’t this overkill Wellthere is an api essentially to do it but that probably wouldn’t have been too interesting for a tensorflow meetup :D There are ready made github libraries but I struggled to get actual results from them. Everything was deemed neutral or positive even if I searched for overwhelmingly negative things like “Internet Explorer” or “James Corden” or “middle aged men crowbarring gifs into tech presentations” So I started to think about making my own naive bayes classification system...
  • 19.
    How? Went to lifta fully featured trained twitter sentiment model from the hub… Doesn’t exist because these are building blocks. It’s more of a library. So there are text helpers and one even looks at semantic similarity between sentences but would take a fair amount of building and actual brain power to make the full thing. That’s not me. So off to github and scouring blogs I went.
  • 20.
    How? Followed this blogand made an amazing model which would allow us to check sentiment of strings. AMAZING. Thought porting to go would be easy. <voiceover> it was not easy </voiceover> Training the model in Python was pretty straightforward but time consuming and resource hungry. Had to change the exported model format after the 2nd go as it had seperated weights and model which made parsing them again hard. This left with me with a trained model (github) and now it was time to interact with it in Go
  • 21.
    Go Code Followed thisblog and made an amazing model which would allow us to check sentiment of strings. AMAZING. Thought porting to go would be easy. <voiceover> it was not easy </voiceover> Training the model in Python was pretty straightforward but time consuming and resource hungry. Had to change the exported model format after the 2nd go as it had separated weights and model which made parsing them again hard. This left with me with a trained model and now it was time to interact with it in Go...
  • 22.
    Go Code That’s whenyou realise that unless you define some sort of contract on the model it can be quite hard to parse and understand the format of the input tensor etc to get the model going again in another context (go in this case). Imagine trying to talk to an undocumented api in a language that had no json helper... Also don’t have* wonderous helpers like numpy and others to help make the tensors so it’s a bit hokey in Go atm. I mean I forked python code which allowed me to do this out of the box so I’m unsure why you would want to redo half of it in another language.
  • 23.
    Summary ● Really interestingarea ● If you’re familiar with Go or organizationally invested in Go you can still get involved in Tensorflow ● It probably isn’t the right thing to do imo. Python is. ● Javascript seems like the priority now for other languages so not sure when Go will get the love As of today Go isn’t really the language of ML
  • 24.
  • 25.

Editor's Notes

  • #14 https://godoc.org/github.com/tensorflow/tensorflow/tensorflow/go#example-PartialRun This approach is actually used in the go doc and referenced in tensorflow getting started
  • #23 There’s been some attempts but you’ll find most of the tutorials on this roll their own tensors