SlideShare ist ein Scribd-Unternehmen logo
1 von 59
Downloaden Sie, um offline zu lesen
Machine learning with Go? Go!
Diana Ortega
Diana ORTEGA
dicaormu@gmail.com
@dicaormu
2
Background
3
Objective
http://www.paperfreeinvoice.com/h
andwritten-and-typewritten-invoice
s-old-scho/
4
Objective
Optical Handwritten Character
Recognition using Deep Learning
http://www.paperfreeinvoice.com/h
andwritten-and-typewritten-invoice
s-old-scho/
5
What is machine learning?
6
Or the ability of an AI system to acquire their own
knowledge
7
What is machine learning?
8
Limited variability:
Limited set of rules to code
1
2
3
4
The computer learns the rules
from examples
Data scienceLarge variability:
A lot of rules to code
9
10
?Inputs Outputs
p
a
r
a
m
s
11
F(x)Inputs Outputs
p
a
r
a
m
s
Example machine learning: linear regression
12
Time walking
(mins) Distance (Kms)
110 7.3
360 17
540 25
180 11
125 7.9
245 17.5
190 12.3
123 7
100 4.75
249 12
60 3
90 5
100 5.8
129 6
65 4.3
Example machine learning: linear regression
13
Time walking
(mins) Distance (Kms)
110 7.3
360 17
540 25
180 11
125 7.9
245 17.5
190 12.3
123 7
100 4.75
249 12
60 3
90 5
100 5.8
129 6
65 4.3
Example machine learning: linear regression
14
How much time for a 6km walk
aprox?
1. 200 mins
2. 10 mins
3. 120 mins
How do you do a real machine learning project?
15
Steps of a data science project
16
Gather Data
Profile Data
Clean/
Manipulate Data
Prepare
Training and
Test Data
Define Model(s)
Train Model(s)
Test Model(s)
Export/Compile
Model(s)
Deploy Model
Inference
Deploy
Online/Prod
Model Training
Automation,
Monitoring and
Updating
Identify the
problem
Explore,
select data
Train and
test
model(s)
Deploy
and use
model(s)
Machine learning project code
17
https://papers.nips.cc/paper/5656-hidden-technical-debt-in-machine-learning-systems.pdf
Only a small fraction of real-world ML systems is composed of the ML code.
Detailed
view of the
solution
18
19
Gather Data
Profile Data
Clean/
Manipulate Data
Prepare
Training and
Test Data
Define Model(s)
Train Model(s)
Test Model(s)
Export/Compile
Model(s)
Deploy Model
Inference
Deploy
Online/Prod
Model Training
Automation,
Monitoring and
Updating
Identify the
problem
Explore,
select data
Train and
test
model(s)
Deploy
and use
model(s)
http://www.fki.inf.unibe.ch/databases/iam-handwriting-database
● Well annotated
● Controlled image variability
● All text is inside the image
20
IAM Database
Gonum and Dataframe
annotations := dataframe.ReadCSV(file)
...
labels := annotations.Col("Labels").Float()
vectorLabels := mat.NewVecDense(len(labels), labels)
transposed := vectorLabels.T()
21
Jupyter and Go
22
23
Gather Data
Profile Data
Clean/
Manipulate Data
Prepare
Training and
Test Data
Define Model(s)
Train Model(s)
Test Model(s)
Export/Compile
Model(s)
Deploy Model
Inference
Deploy
Online/Prod
Model Training
Automation,
Monitoring and
Updating
Identify the
problem
Explore,
select data
Train and
test
model(s)
Deploy
and use
model(s)
24
Inputs Outputs
{“text”: “a move to stop” }
25
Inputs Outputs
{“text”: “a move to stop” }
Deng, Y., Kanervisto, A.,
Image-to-Markup Generation with
Coarse-to-Fine Attention. In
International Conference on Machine
Learning (pp. 980-989)
26
Inputs Outputs
{“text”: “a move to stop” }
Convolutional
Neural Network
(CNN)
Encoder:
Recurrent Neural
Network (RNN)
Decoder:
Recurrent Neural
Network (RNN)
TensorFlow
● Library for ML
● Use a graph based flow
● Maybe the most popular
framework
27
op1
Tensor1
op2
op3
op4
op5Tensor2
Tensor3
Tensor4
Session
1.
2.
From the TensorFlow’s web site:
“These APIs are particularly well-suited to loading models
created in Python and executing them within a Go
application”
TensorFlow official bindings
28
TensorFlow with mod
29
Trying to implement a CNN in Go-TensorFlow
conv1 := op.Conv2D(root.SubScope("conv1"), inputLayer, filterTensor, []int64{5, 5, 1, 1}, "VALID")
pool1 := op.MaxPool(root.SubScope("pool1"), conv1, []int64{2, 2, 1, 1}, []int64{2, 2, 1, 1}, "VALID")
…
conv2_no_heigh := op.Reshape(root, pool2, op.Shape(root, pool2))
loss, backprop := op.SoftmaxCrossEntropyWithLogits(root, conv2_no_heigh, labels)
….
30
Only one optimizer: Stochastic Dual Coordinate Ascent
(SDCA).
Convolution and
sampling for a layer
in my CNN
Calculating the difference
between what I got and
what I expected
Model development and
testing
● You can create a graph with the Go
bindings, but it is complicated
● There are some elements like “session”
and “scope”. Not very intuitive from Go
point of view
● We don’t have all functions and I’ll have
to implement them from scratch
31
op1
Tensor1
op2
op3
op4
op5Tensor2
Tensor3
Tensor4
32
If we have to develop from scratch, why not to use a
native Go library?
33
Gorgonia
● It is similar to theano (Python)
● Works with graphs (as Tensorflow does)
● Support many Go versions (including the most recent)
34
The CNN with Gorgonia
g := gorgonia.NewGraph()
x := gorgonia.NewTensor(g, dt, 4, gorgonia.WithShape(bs, 3 , 32, maxImageLenght),
gorgonia.WithName("x"))
y := gorgonia.NewMatrix(g, dt, gorgonia.WithShape(bs, 10), gorgonia.WithName("y"))
Also tensor
Multidimensional array
(more accurate to ml
operations)
35
Graph initialization
Creating a layer Gorgonia vs TensorFlow
if c0, err = gorgonia.Conv2d(x, m.w0, tensor.Shape{3, 3},
[]int{1, 1}, []int{1, 1}); err != nil {
return errors.Wrap(err, "Layer 0 Convolution failed")
}
if a0, err = gorgonia.Rectify(c0); err != nil {
return errors.Wrap(err, "Layer 0 activation failed")
}
if p0, err = gorgonia.MaxPool2D(a0, tensor.Shape{2, 2},
[]int{0, 0}, []int{2, 2}); err != nil {
return errors.Wrap(err, "Layer 0 Maxpooling failed")
}
conv1 = tf.layers.conv2d(
inputs=input_layer,
filters=16,
kernel_size=[5, 5],
padding="VALID",
activation=tf.nn.relu,
name="conv1")
pool1 = tf.layers.max_pooling2d(inputs=conv1,
pool_size=[2, 2],
strides=strides,
padding="VALID",
name="pool1")
Convolution
Activation
Pooling
36
37
Inputs Outputs
{“text”: “a move to stop” }
Convolutional
Neural Network
(CNN)
Encoder:
Recurrent
Neural
Network (RNN)
Decoder:
Recurrent
Neural
Network (RNN)
The encoder in TensorFlow
38
lstm_cell_list_fw = [tf.contrib.rnn.LSTMCell(num_units=num_hidden,
forget_bias=1.0,
state_is_tuple=True,
activation=tf.nn.relu6) for i in range(num_layers)]
lstm_cell_list_bw = ….
multi_rnn_cell_fw = tf.contrib.rnn.MultiRNNCell(lstm_cell_list_fw, state_is_tuple=True)
multi_rnn_cell_bw = ….
outputs, output_state = tf.nn.bidirectional_dynamic_rnn(multi_rnn_cell_fw,
multi_rnn_cell_bw,
inputs=input_layer,
dtype=tf.float32,
sequence_length=sequence_lengths_placeholder,
time_major=False,
scope="encoder_rnn_bidir")
Basic Cell creation
RNN creation
Bidirectional RNN
creation
The encoder in Go
39
https://github.com/owulveryck/min-char-rnn
https://github.com/owulveryck/lstm
https://github.com/gorgonia/gorgonia/tree/master/examples/charRNN
Only do under the consent of a responsible data scientist
40
Inputs Outputs
{“text”: “a move to stop” }
Convolutional
Neural Network
(CNN)
Encoder:
Recurrent
Neural
Network (RNN)
Decoder:
Recurrent
Neural
Network (RNN)
you have to create them from scratch
Implications
41
● If I want to create a neural network in go, I
have to do it from scratch
● For other machine learning models, we can
use gorgonia and gonum
42
Gather Data
Profile Data
Clean/
Manipulate Data
Prepare
Training and
Test Data
Define Model(s)
Train Model(s)
Test Model(s)
Export/Compile
Model(s)
Deploy Model
Inference
Deploy
Online/Prod
Model Training
Automation,
Monitoring and
Updating
Identify the
problem
Explore,
select data
Train and
test
model(s)
Deploy
and use
model(s)
43Deep learning frameworks. Source: den Bakker 2017
Open Neural Network
Exchange (ONNX)
Frameworks interoperability
En création par Olivier Wulveryck
https://github.com/owulveryck/onnx-go
Session
Run
44
op1
Tensor1
op2
op3
op4
op5Tensor2
Tensor3
Tensor4
Model building Running
Saving the model TF (1.X) using Python
builder = tf.saved_model.builder.SavedModelBuilder("ocrModel")
builder.add_meta_graph_and_variables(sess, ["serve"])
builder.save()
45
Creates a folder
“ocrModel”
Saves the graph
and variables
Loading and running a model in Go
model := tf.LoadSavedModel(modelPath, []string{"serve"}, nil) // load model from file
...
tensors := map[tf.Output]*tf.Tensor{
graph.Operation(input_layer").Output(0): tensor,
}
outputs := []tf.Output{
graph.Operation("decoder/decoder_prediction/kernel/Adam_1").Output(0),
}
result, runErr := model.Session.Run(
tensors,
outputs,
nil,
)
46
Load model in
modelPath
Tensor with name
“input_layer” in my graph
Output for the operation
“decoder/decoder_prediction
/kernel/Adam_1”
Run the model
Running the model: TensorBoard to identify tensors
names
47
Tensors’
names
Some problems
● Errors of type:
● The response of my model was one-hot encoded
○ I had to transform it by hand because, there is no Go library to do that
48
panic: nil-Operation. If the Output was created with a Scope
object, see Scope.Err() for details.
49
Results
50
Real Predicted
Minsk -
Move Move
asked askied
easier cosce
households hanehalds
substantiated substinctived
could coult
Other tools
51
Gather Data
Profile Data
Clean/
Manipulate Data
Prepare
Training and
Test Data
Define Model(s)
Train Model(s)
Test Model(s)
Export/Compile
Model(s)
Deploy Model
Inference
Deploy
Online/Prod
Model Training
Automation,
Monitoring and
Updating
Identify the
problem
Explore,
select data
Train and
test
model(s)
Deploy
and use
model(s)
Event driving
Monitoring:
What I really, really want!
52
53
Takeaways
and
conclusions
54
55
Go tools for Data Science
● Gonum libraries
● http://github.com/kniren/gota/dataframe
● Notebook jupyter
● Gorgonia
● ONNX for Go
● Official tensorflow bindings for Go
● Pachyderm
Conclusions
● If you are using existing Tensorflow models
○ You are good to go, you can use the official bindings or tfgo
● If you want to develop from scratch
○ You can use Gorgonia and Gonum
○ If you want to have it easy and have the support and the knowledge of a community, use
Python
● If you are creating a model (not neural network)
○ You can use Go libraries (but most are still in development)
○ Things are getting better though :D
56
57From tweet of AmyCharlotte Kean
“Tastes better than it
looks”
Merci!
58
Questions?
59

Weitere ähnliche Inhalte

Was ist angesagt?

Bartosz Milewski, “Re-discovering Monads in C++”
Bartosz Milewski, “Re-discovering Monads in C++”Bartosz Milewski, “Re-discovering Monads in C++”
Bartosz Milewski, “Re-discovering Monads in C++”Platonov Sergey
 
Computer Graphics Lab
Computer Graphics LabComputer Graphics Lab
Computer Graphics LabNeil Mathew
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manualAnkit Kumar
 
The Ring programming language version 1.9 book - Part 38 of 210
The Ring programming language version 1.9 book - Part 38 of 210The Ring programming language version 1.9 book - Part 38 of 210
The Ring programming language version 1.9 book - Part 38 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 40 of 196
The Ring programming language version 1.7 book - Part 40 of 196The Ring programming language version 1.7 book - Part 40 of 196
The Ring programming language version 1.7 book - Part 40 of 196Mahmoud Samir Fayed
 
Gremlin's Graph Traversal Machinery
Gremlin's Graph Traversal MachineryGremlin's Graph Traversal Machinery
Gremlin's Graph Traversal MachineryMarko Rodriguez
 
openFrameworks 007 - 3D
openFrameworks 007 - 3DopenFrameworks 007 - 3D
openFrameworks 007 - 3Droxlu
 
SE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of PuneSE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of PuneBhavesh Shah
 
The Ring programming language version 1.5.3 book - Part 10 of 184
The Ring programming language version 1.5.3 book - Part 10 of 184The Ring programming language version 1.5.3 book - Part 10 of 184
The Ring programming language version 1.5.3 book - Part 10 of 184Mahmoud Samir Fayed
 
PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...Andrey Karpov
 
Computer graphics practical(jainam)
Computer graphics practical(jainam)Computer graphics practical(jainam)
Computer graphics practical(jainam)JAINAM KAPADIYA
 
Tomato Classification using Computer Vision
Tomato Classification using Computer VisionTomato Classification using Computer Vision
Tomato Classification using Computer VisionRaman Pandey
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Platonov Sergey
 
Swift for tensorflow
Swift for tensorflowSwift for tensorflow
Swift for tensorflow규영 허
 
The Ring programming language version 1.5.4 book - Part 10 of 185
The Ring programming language version 1.5.4 book - Part 10 of 185The Ring programming language version 1.5.4 book - Part 10 of 185
The Ring programming language version 1.5.4 book - Part 10 of 185Mahmoud Samir Fayed
 

Was ist angesagt? (20)

Scala taxonomy
Scala taxonomyScala taxonomy
Scala taxonomy
 
Advance java
Advance javaAdvance java
Advance java
 
Bartosz Milewski, “Re-discovering Monads in C++”
Bartosz Milewski, “Re-discovering Monads in C++”Bartosz Milewski, “Re-discovering Monads in C++”
Bartosz Milewski, “Re-discovering Monads in C++”
 
Computer Graphics Lab
Computer Graphics LabComputer Graphics Lab
Computer Graphics Lab
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
The Ring programming language version 1.9 book - Part 38 of 210
The Ring programming language version 1.9 book - Part 38 of 210The Ring programming language version 1.9 book - Part 38 of 210
The Ring programming language version 1.9 book - Part 38 of 210
 
The Ring programming language version 1.7 book - Part 40 of 196
The Ring programming language version 1.7 book - Part 40 of 196The Ring programming language version 1.7 book - Part 40 of 196
The Ring programming language version 1.7 book - Part 40 of 196
 
Gremlin's Graph Traversal Machinery
Gremlin's Graph Traversal MachineryGremlin's Graph Traversal Machinery
Gremlin's Graph Traversal Machinery
 
openFrameworks 007 - 3D
openFrameworks 007 - 3DopenFrameworks 007 - 3D
openFrameworks 007 - 3D
 
SE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of PuneSE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of Pune
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
The Ring programming language version 1.5.3 book - Part 10 of 184
The Ring programming language version 1.5.3 book - Part 10 of 184The Ring programming language version 1.5.3 book - Part 10 of 184
The Ring programming language version 1.5.3 book - Part 10 of 184
 
PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...
 
Computer graphics practical(jainam)
Computer graphics practical(jainam)Computer graphics practical(jainam)
Computer graphics practical(jainam)
 
Tomato Classification using Computer Vision
Tomato Classification using Computer VisionTomato Classification using Computer Vision
Tomato Classification using Computer Vision
 
Cgm Lab Manual
Cgm Lab ManualCgm Lab Manual
Cgm Lab Manual
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”
 
Swift for tensorflow
Swift for tensorflowSwift for tensorflow
Swift for tensorflow
 
The Ring programming language version 1.5.4 book - Part 10 of 185
The Ring programming language version 1.5.4 book - Part 10 of 185The Ring programming language version 1.5.4 book - Part 10 of 185
The Ring programming language version 1.5.4 book - Part 10 of 185
 
662305 10
662305 10662305 10
662305 10
 

Ähnlich wie Machine learning with Go? Go for it

A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...Databricks
 
maxbox starter60 machine learning
maxbox starter60 machine learningmaxbox starter60 machine learning
maxbox starter60 machine learningMax Kleiner
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Raffi Khatchadourian
 
Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...
Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...
Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...Raffi Khatchadourian
 
slide-keras-tf.pptx
slide-keras-tf.pptxslide-keras-tf.pptx
slide-keras-tf.pptxRithikRaj25
 
Google Big Data Expo
Google Big Data ExpoGoogle Big Data Expo
Google Big Data ExpoBigDataExpo
 
Deep Learning, Scala, and Spark
Deep Learning, Scala, and SparkDeep Learning, Scala, and Spark
Deep Learning, Scala, and SparkOswald Campesato
 
Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117Ganesan Narayanasamy
 
MATLAB for Technical Computing
MATLAB for Technical ComputingMATLAB for Technical Computing
MATLAB for Technical ComputingNaveed Rehman
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manualsameer farooq
 
TensorFlow example for AI Ukraine2016
TensorFlow example  for AI Ukraine2016TensorFlow example  for AI Ukraine2016
TensorFlow example for AI Ukraine2016Andrii Babii
 
Diving into Deep Learning (Silicon Valley Code Camp 2017)
Diving into Deep Learning (Silicon Valley Code Camp 2017)Diving into Deep Learning (Silicon Valley Code Camp 2017)
Diving into Deep Learning (Silicon Valley Code Camp 2017)Oswald Campesato
 
Pytorch for tf_developers
Pytorch for tf_developersPytorch for tf_developers
Pytorch for tf_developersAbdul Muneer
 
Introduction to Deep Learning and Tensorflow
Introduction to Deep Learning and TensorflowIntroduction to Deep Learning and Tensorflow
Introduction to Deep Learning and TensorflowOswald Campesato
 
Language translation with Deep Learning (RNN) with TensorFlow
Language translation with Deep Learning (RNN) with TensorFlowLanguage translation with Deep Learning (RNN) with TensorFlow
Language translation with Deep Learning (RNN) with TensorFlowS N
 
AIML4 CNN lab256 1hr (111-1).pdf
AIML4 CNN lab256 1hr (111-1).pdfAIML4 CNN lab256 1hr (111-1).pdf
AIML4 CNN lab256 1hr (111-1).pdfssuserb4d806
 
Introducton to Convolutional Nerural Network with TensorFlow
Introducton to Convolutional Nerural Network with TensorFlowIntroducton to Convolutional Nerural Network with TensorFlow
Introducton to Convolutional Nerural Network with TensorFlowEtsuji Nakai
 

Ähnlich wie Machine learning with Go? Go for it (20)

A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...
 
maxbox starter60 machine learning
maxbox starter60 machine learningmaxbox starter60 machine learning
maxbox starter60 machine learning
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
 
Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...
Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...
Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...
 
slide-keras-tf.pptx
slide-keras-tf.pptxslide-keras-tf.pptx
slide-keras-tf.pptx
 
Google Big Data Expo
Google Big Data ExpoGoogle Big Data Expo
Google Big Data Expo
 
Deep Learning, Scala, and Spark
Deep Learning, Scala, and SparkDeep Learning, Scala, and Spark
Deep Learning, Scala, and Spark
 
Angular and Deep Learning
Angular and Deep LearningAngular and Deep Learning
Angular and Deep Learning
 
Android and Deep Learning
Android and Deep LearningAndroid and Deep Learning
Android and Deep Learning
 
Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117
 
Deep Learning for Computer Vision: Software Frameworks (UPC 2016)
Deep Learning for Computer Vision: Software Frameworks (UPC 2016)Deep Learning for Computer Vision: Software Frameworks (UPC 2016)
Deep Learning for Computer Vision: Software Frameworks (UPC 2016)
 
MATLAB for Technical Computing
MATLAB for Technical ComputingMATLAB for Technical Computing
MATLAB for Technical Computing
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
 
TensorFlow example for AI Ukraine2016
TensorFlow example  for AI Ukraine2016TensorFlow example  for AI Ukraine2016
TensorFlow example for AI Ukraine2016
 
Diving into Deep Learning (Silicon Valley Code Camp 2017)
Diving into Deep Learning (Silicon Valley Code Camp 2017)Diving into Deep Learning (Silicon Valley Code Camp 2017)
Diving into Deep Learning (Silicon Valley Code Camp 2017)
 
Pytorch for tf_developers
Pytorch for tf_developersPytorch for tf_developers
Pytorch for tf_developers
 
Introduction to Deep Learning and Tensorflow
Introduction to Deep Learning and TensorflowIntroduction to Deep Learning and Tensorflow
Introduction to Deep Learning and Tensorflow
 
Language translation with Deep Learning (RNN) with TensorFlow
Language translation with Deep Learning (RNN) with TensorFlowLanguage translation with Deep Learning (RNN) with TensorFlow
Language translation with Deep Learning (RNN) with TensorFlow
 
AIML4 CNN lab256 1hr (111-1).pdf
AIML4 CNN lab256 1hr (111-1).pdfAIML4 CNN lab256 1hr (111-1).pdf
AIML4 CNN lab256 1hr (111-1).pdf
 
Introducton to Convolutional Nerural Network with TensorFlow
Introducton to Convolutional Nerural Network with TensorFlowIntroducton to Convolutional Nerural Network with TensorFlow
Introducton to Convolutional Nerural Network with TensorFlow
 

Kürzlich hochgeladen

James Joyce, Dubliners and Ulysses.ppt !
James Joyce, Dubliners and Ulysses.ppt !James Joyce, Dubliners and Ulysses.ppt !
James Joyce, Dubliners and Ulysses.ppt !risocarla2016
 
Genshin Impact PPT Template by EaTemp.pptx
Genshin Impact PPT Template by EaTemp.pptxGenshin Impact PPT Template by EaTemp.pptx
Genshin Impact PPT Template by EaTemp.pptxJohnree4
 
Mathan flower ppt.pptx slide orchids ✨🌸
Mathan flower ppt.pptx slide orchids ✨🌸Mathan flower ppt.pptx slide orchids ✨🌸
Mathan flower ppt.pptx slide orchids ✨🌸mathanramanathan2005
 
SaaStr Workshop Wednesday w/ Kyle Norton, Owner.com
SaaStr Workshop Wednesday w/ Kyle Norton, Owner.comSaaStr Workshop Wednesday w/ Kyle Norton, Owner.com
SaaStr Workshop Wednesday w/ Kyle Norton, Owner.comsaastr
 
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...marjmae69
 
Work Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxWork Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxmavinoikein
 
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...Krijn Poppe
 
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxGenesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxFamilyWorshipCenterD
 
miladyskindiseases-200705210221 2.!!pptx
miladyskindiseases-200705210221 2.!!pptxmiladyskindiseases-200705210221 2.!!pptx
miladyskindiseases-200705210221 2.!!pptxCarrieButtitta
 
The Ten Facts About People With Autism Presentation
The Ten Facts About People With Autism PresentationThe Ten Facts About People With Autism Presentation
The Ten Facts About People With Autism PresentationNathan Young
 
Simulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with AerialistSimulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with AerialistSebastiano Panichella
 
SBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSebastiano Panichella
 
Dutch Power - 26 maart 2024 - Henk Kras - Circular Plastics
Dutch Power - 26 maart 2024 - Henk Kras - Circular PlasticsDutch Power - 26 maart 2024 - Henk Kras - Circular Plastics
Dutch Power - 26 maart 2024 - Henk Kras - Circular PlasticsDutch Power
 
Call Girls In Aerocity 🤳 Call Us +919599264170
Call Girls In Aerocity 🤳 Call Us +919599264170Call Girls In Aerocity 🤳 Call Us +919599264170
Call Girls In Aerocity 🤳 Call Us +919599264170Escort Service
 
THE COUNTRY WHO SOLVED THE WORLD_HOW CHINA LAUNCHED THE CIVILIZATION REVOLUTI...
THE COUNTRY WHO SOLVED THE WORLD_HOW CHINA LAUNCHED THE CIVILIZATION REVOLUTI...THE COUNTRY WHO SOLVED THE WORLD_HOW CHINA LAUNCHED THE CIVILIZATION REVOLUTI...
THE COUNTRY WHO SOLVED THE WORLD_HOW CHINA LAUNCHED THE CIVILIZATION REVOLUTI...漢銘 謝
 
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
PHYSICS PROJECT BY MSC - NANOTECHNOLOGY
PHYSICS PROJECT BY MSC  - NANOTECHNOLOGYPHYSICS PROJECT BY MSC  - NANOTECHNOLOGY
PHYSICS PROJECT BY MSC - NANOTECHNOLOGYpruthirajnayak525
 
The 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringThe 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringSebastiano Panichella
 
call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@vikas rana
 
Anne Frank A Beacon of Hope amidst darkness ppt.pptx
Anne Frank A Beacon of Hope amidst darkness ppt.pptxAnne Frank A Beacon of Hope amidst darkness ppt.pptx
Anne Frank A Beacon of Hope amidst darkness ppt.pptxnoorehahmad
 

Kürzlich hochgeladen (20)

James Joyce, Dubliners and Ulysses.ppt !
James Joyce, Dubliners and Ulysses.ppt !James Joyce, Dubliners and Ulysses.ppt !
James Joyce, Dubliners and Ulysses.ppt !
 
Genshin Impact PPT Template by EaTemp.pptx
Genshin Impact PPT Template by EaTemp.pptxGenshin Impact PPT Template by EaTemp.pptx
Genshin Impact PPT Template by EaTemp.pptx
 
Mathan flower ppt.pptx slide orchids ✨🌸
Mathan flower ppt.pptx slide orchids ✨🌸Mathan flower ppt.pptx slide orchids ✨🌸
Mathan flower ppt.pptx slide orchids ✨🌸
 
SaaStr Workshop Wednesday w/ Kyle Norton, Owner.com
SaaStr Workshop Wednesday w/ Kyle Norton, Owner.comSaaStr Workshop Wednesday w/ Kyle Norton, Owner.com
SaaStr Workshop Wednesday w/ Kyle Norton, Owner.com
 
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
 
Work Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxWork Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptx
 
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
 
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxGenesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
 
miladyskindiseases-200705210221 2.!!pptx
miladyskindiseases-200705210221 2.!!pptxmiladyskindiseases-200705210221 2.!!pptx
miladyskindiseases-200705210221 2.!!pptx
 
The Ten Facts About People With Autism Presentation
The Ten Facts About People With Autism PresentationThe Ten Facts About People With Autism Presentation
The Ten Facts About People With Autism Presentation
 
Simulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with AerialistSimulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with Aerialist
 
SBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation Track
 
Dutch Power - 26 maart 2024 - Henk Kras - Circular Plastics
Dutch Power - 26 maart 2024 - Henk Kras - Circular PlasticsDutch Power - 26 maart 2024 - Henk Kras - Circular Plastics
Dutch Power - 26 maart 2024 - Henk Kras - Circular Plastics
 
Call Girls In Aerocity 🤳 Call Us +919599264170
Call Girls In Aerocity 🤳 Call Us +919599264170Call Girls In Aerocity 🤳 Call Us +919599264170
Call Girls In Aerocity 🤳 Call Us +919599264170
 
THE COUNTRY WHO SOLVED THE WORLD_HOW CHINA LAUNCHED THE CIVILIZATION REVOLUTI...
THE COUNTRY WHO SOLVED THE WORLD_HOW CHINA LAUNCHED THE CIVILIZATION REVOLUTI...THE COUNTRY WHO SOLVED THE WORLD_HOW CHINA LAUNCHED THE CIVILIZATION REVOLUTI...
THE COUNTRY WHO SOLVED THE WORLD_HOW CHINA LAUNCHED THE CIVILIZATION REVOLUTI...
 
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
 
PHYSICS PROJECT BY MSC - NANOTECHNOLOGY
PHYSICS PROJECT BY MSC  - NANOTECHNOLOGYPHYSICS PROJECT BY MSC  - NANOTECHNOLOGY
PHYSICS PROJECT BY MSC - NANOTECHNOLOGY
 
The 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringThe 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software Engineering
 
call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@
 
Anne Frank A Beacon of Hope amidst darkness ppt.pptx
Anne Frank A Beacon of Hope amidst darkness ppt.pptxAnne Frank A Beacon of Hope amidst darkness ppt.pptx
Anne Frank A Beacon of Hope amidst darkness ppt.pptx
 

Machine learning with Go? Go for it

  • 1. Machine learning with Go? Go! Diana Ortega
  • 5. Objective Optical Handwritten Character Recognition using Deep Learning http://www.paperfreeinvoice.com/h andwritten-and-typewritten-invoice s-old-scho/ 5
  • 6. What is machine learning? 6 Or the ability of an AI system to acquire their own knowledge
  • 7. 7 What is machine learning?
  • 8. 8 Limited variability: Limited set of rules to code 1 2 3 4
  • 9. The computer learns the rules from examples Data scienceLarge variability: A lot of rules to code 9
  • 12. Example machine learning: linear regression 12 Time walking (mins) Distance (Kms) 110 7.3 360 17 540 25 180 11 125 7.9 245 17.5 190 12.3 123 7 100 4.75 249 12 60 3 90 5 100 5.8 129 6 65 4.3
  • 13. Example machine learning: linear regression 13 Time walking (mins) Distance (Kms) 110 7.3 360 17 540 25 180 11 125 7.9 245 17.5 190 12.3 123 7 100 4.75 249 12 60 3 90 5 100 5.8 129 6 65 4.3
  • 14. Example machine learning: linear regression 14 How much time for a 6km walk aprox? 1. 200 mins 2. 10 mins 3. 120 mins
  • 15. How do you do a real machine learning project? 15
  • 16. Steps of a data science project 16 Gather Data Profile Data Clean/ Manipulate Data Prepare Training and Test Data Define Model(s) Train Model(s) Test Model(s) Export/Compile Model(s) Deploy Model Inference Deploy Online/Prod Model Training Automation, Monitoring and Updating Identify the problem Explore, select data Train and test model(s) Deploy and use model(s)
  • 17. Machine learning project code 17 https://papers.nips.cc/paper/5656-hidden-technical-debt-in-machine-learning-systems.pdf Only a small fraction of real-world ML systems is composed of the ML code.
  • 19. 19 Gather Data Profile Data Clean/ Manipulate Data Prepare Training and Test Data Define Model(s) Train Model(s) Test Model(s) Export/Compile Model(s) Deploy Model Inference Deploy Online/Prod Model Training Automation, Monitoring and Updating Identify the problem Explore, select data Train and test model(s) Deploy and use model(s)
  • 20. http://www.fki.inf.unibe.ch/databases/iam-handwriting-database ● Well annotated ● Controlled image variability ● All text is inside the image 20 IAM Database
  • 21. Gonum and Dataframe annotations := dataframe.ReadCSV(file) ... labels := annotations.Col("Labels").Float() vectorLabels := mat.NewVecDense(len(labels), labels) transposed := vectorLabels.T() 21
  • 23. 23 Gather Data Profile Data Clean/ Manipulate Data Prepare Training and Test Data Define Model(s) Train Model(s) Test Model(s) Export/Compile Model(s) Deploy Model Inference Deploy Online/Prod Model Training Automation, Monitoring and Updating Identify the problem Explore, select data Train and test model(s) Deploy and use model(s)
  • 25. 25 Inputs Outputs {“text”: “a move to stop” } Deng, Y., Kanervisto, A., Image-to-Markup Generation with Coarse-to-Fine Attention. In International Conference on Machine Learning (pp. 980-989)
  • 26. 26 Inputs Outputs {“text”: “a move to stop” } Convolutional Neural Network (CNN) Encoder: Recurrent Neural Network (RNN) Decoder: Recurrent Neural Network (RNN)
  • 27. TensorFlow ● Library for ML ● Use a graph based flow ● Maybe the most popular framework 27 op1 Tensor1 op2 op3 op4 op5Tensor2 Tensor3 Tensor4 Session 1. 2.
  • 28. From the TensorFlow’s web site: “These APIs are particularly well-suited to loading models created in Python and executing them within a Go application” TensorFlow official bindings 28
  • 30. Trying to implement a CNN in Go-TensorFlow conv1 := op.Conv2D(root.SubScope("conv1"), inputLayer, filterTensor, []int64{5, 5, 1, 1}, "VALID") pool1 := op.MaxPool(root.SubScope("pool1"), conv1, []int64{2, 2, 1, 1}, []int64{2, 2, 1, 1}, "VALID") … conv2_no_heigh := op.Reshape(root, pool2, op.Shape(root, pool2)) loss, backprop := op.SoftmaxCrossEntropyWithLogits(root, conv2_no_heigh, labels) …. 30 Only one optimizer: Stochastic Dual Coordinate Ascent (SDCA). Convolution and sampling for a layer in my CNN Calculating the difference between what I got and what I expected
  • 31. Model development and testing ● You can create a graph with the Go bindings, but it is complicated ● There are some elements like “session” and “scope”. Not very intuitive from Go point of view ● We don’t have all functions and I’ll have to implement them from scratch 31 op1 Tensor1 op2 op3 op4 op5Tensor2 Tensor3 Tensor4
  • 32. 32
  • 33. If we have to develop from scratch, why not to use a native Go library? 33
  • 34. Gorgonia ● It is similar to theano (Python) ● Works with graphs (as Tensorflow does) ● Support many Go versions (including the most recent) 34
  • 35. The CNN with Gorgonia g := gorgonia.NewGraph() x := gorgonia.NewTensor(g, dt, 4, gorgonia.WithShape(bs, 3 , 32, maxImageLenght), gorgonia.WithName("x")) y := gorgonia.NewMatrix(g, dt, gorgonia.WithShape(bs, 10), gorgonia.WithName("y")) Also tensor Multidimensional array (more accurate to ml operations) 35 Graph initialization
  • 36. Creating a layer Gorgonia vs TensorFlow if c0, err = gorgonia.Conv2d(x, m.w0, tensor.Shape{3, 3}, []int{1, 1}, []int{1, 1}); err != nil { return errors.Wrap(err, "Layer 0 Convolution failed") } if a0, err = gorgonia.Rectify(c0); err != nil { return errors.Wrap(err, "Layer 0 activation failed") } if p0, err = gorgonia.MaxPool2D(a0, tensor.Shape{2, 2}, []int{0, 0}, []int{2, 2}); err != nil { return errors.Wrap(err, "Layer 0 Maxpooling failed") } conv1 = tf.layers.conv2d( inputs=input_layer, filters=16, kernel_size=[5, 5], padding="VALID", activation=tf.nn.relu, name="conv1") pool1 = tf.layers.max_pooling2d(inputs=conv1, pool_size=[2, 2], strides=strides, padding="VALID", name="pool1") Convolution Activation Pooling 36
  • 37. 37 Inputs Outputs {“text”: “a move to stop” } Convolutional Neural Network (CNN) Encoder: Recurrent Neural Network (RNN) Decoder: Recurrent Neural Network (RNN)
  • 38. The encoder in TensorFlow 38 lstm_cell_list_fw = [tf.contrib.rnn.LSTMCell(num_units=num_hidden, forget_bias=1.0, state_is_tuple=True, activation=tf.nn.relu6) for i in range(num_layers)] lstm_cell_list_bw = …. multi_rnn_cell_fw = tf.contrib.rnn.MultiRNNCell(lstm_cell_list_fw, state_is_tuple=True) multi_rnn_cell_bw = …. outputs, output_state = tf.nn.bidirectional_dynamic_rnn(multi_rnn_cell_fw, multi_rnn_cell_bw, inputs=input_layer, dtype=tf.float32, sequence_length=sequence_lengths_placeholder, time_major=False, scope="encoder_rnn_bidir") Basic Cell creation RNN creation Bidirectional RNN creation
  • 39. The encoder in Go 39 https://github.com/owulveryck/min-char-rnn https://github.com/owulveryck/lstm https://github.com/gorgonia/gorgonia/tree/master/examples/charRNN Only do under the consent of a responsible data scientist
  • 40. 40 Inputs Outputs {“text”: “a move to stop” } Convolutional Neural Network (CNN) Encoder: Recurrent Neural Network (RNN) Decoder: Recurrent Neural Network (RNN) you have to create them from scratch
  • 41. Implications 41 ● If I want to create a neural network in go, I have to do it from scratch ● For other machine learning models, we can use gorgonia and gonum
  • 42. 42 Gather Data Profile Data Clean/ Manipulate Data Prepare Training and Test Data Define Model(s) Train Model(s) Test Model(s) Export/Compile Model(s) Deploy Model Inference Deploy Online/Prod Model Training Automation, Monitoring and Updating Identify the problem Explore, select data Train and test model(s) Deploy and use model(s)
  • 43. 43Deep learning frameworks. Source: den Bakker 2017 Open Neural Network Exchange (ONNX) Frameworks interoperability En création par Olivier Wulveryck https://github.com/owulveryck/onnx-go
  • 45. Saving the model TF (1.X) using Python builder = tf.saved_model.builder.SavedModelBuilder("ocrModel") builder.add_meta_graph_and_variables(sess, ["serve"]) builder.save() 45 Creates a folder “ocrModel” Saves the graph and variables
  • 46. Loading and running a model in Go model := tf.LoadSavedModel(modelPath, []string{"serve"}, nil) // load model from file ... tensors := map[tf.Output]*tf.Tensor{ graph.Operation(input_layer").Output(0): tensor, } outputs := []tf.Output{ graph.Operation("decoder/decoder_prediction/kernel/Adam_1").Output(0), } result, runErr := model.Session.Run( tensors, outputs, nil, ) 46 Load model in modelPath Tensor with name “input_layer” in my graph Output for the operation “decoder/decoder_prediction /kernel/Adam_1” Run the model
  • 47. Running the model: TensorBoard to identify tensors names 47 Tensors’ names
  • 48. Some problems ● Errors of type: ● The response of my model was one-hot encoded ○ I had to transform it by hand because, there is no Go library to do that 48 panic: nil-Operation. If the Output was created with a Scope object, see Scope.Err() for details.
  • 49. 49
  • 50. Results 50 Real Predicted Minsk - Move Move asked askied easier cosce households hanehalds substantiated substinctived could coult
  • 51. Other tools 51 Gather Data Profile Data Clean/ Manipulate Data Prepare Training and Test Data Define Model(s) Train Model(s) Test Model(s) Export/Compile Model(s) Deploy Model Inference Deploy Online/Prod Model Training Automation, Monitoring and Updating Identify the problem Explore, select data Train and test model(s) Deploy and use model(s) Event driving
  • 52. Monitoring: What I really, really want! 52
  • 53. 53
  • 55. 55 Go tools for Data Science ● Gonum libraries ● http://github.com/kniren/gota/dataframe ● Notebook jupyter ● Gorgonia ● ONNX for Go ● Official tensorflow bindings for Go ● Pachyderm
  • 56. Conclusions ● If you are using existing Tensorflow models ○ You are good to go, you can use the official bindings or tfgo ● If you want to develop from scratch ○ You can use Gorgonia and Gonum ○ If you want to have it easy and have the support and the knowledge of a community, use Python ● If you are creating a model (not neural network) ○ You can use Go libraries (but most are still in development) ○ Things are getting better though :D 56
  • 57. 57From tweet of AmyCharlotte Kean “Tastes better than it looks”