El objetivo de la charla es contar una breve introducción a Machine Learning para situarnos, como funciona, en qué consiste y qué uso podemos darle en nuestras aplicaciones.
Analizaremos con un ejemplo real muy visual cómo construir una aplicación con Inteligencia artificial, viendo lo fácil que es aprovechar el potencial de TensorFlow (plataforma Open Source de Google), interactuando desde FireBase e implementando la lógica con Cloud Functions.
1. “Construir una App
con AI nunca fue tan fácil”
con frameworks y servicios que nos acercan la
potencia de la inteligencia artificial y el machine
learning
Rubén Chavarri Elduayen
Software Engineer en Kairos
@pekewake
David Chavarri Elduayen
Software Architect en BBVA
@dvdchavarri
MAD · NOV 24-25 · 2017
2. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
Introduction to Artificial Intelligence
In the next years, fullstack will
not be full stack without
AI skills
‘‘
’’
3. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
4. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
Type of
MachineLearning
algorithms
5. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
Type of
MachineLearning
algorithms
6. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
Type of
MachineLearning
algorithms
7. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
Type of
MachineLearning
algorithms
8. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
● Neurons
● Activation Functions
● Cost Functions
● Gradient Descent and Backpropagation
How Machine Learning works
9. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
● Neurons in ML called Perceptrons
How Machine Learning works
10. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
● Neurons in ML called Perceptrons
How Machine Learning works
11. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
● Activation Functions: method which calculate the output
How Machine Learning works
ReLUTanhLinear Sigmoid
12. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
● Cost Functions: Method to evaluate the performance of
a neuron based on how far off we are for expected value.
○ Quadratic Cost
○ Cross Entropy
How Machine Learning works
13. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
● Gradient Descent: Optimization
algorithm to minimize cost function.
● Backpropagation: Calculates the error
contribution of each neuron
How Machine Learning works
14. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
http://playground.tensorflow.org
15. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
How MachineLearning can make our Apps smart?
16. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
How MachineLearning can make our Apps smart?
Pinterest
Spam moderation
Content discovery
Advertising monetization
Reducing churn of email
17. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
How MachineLearning can make our Apps smart?
Facebook
Chatbot Army
Filter out spam
Poor-quality content
Computer vision
18. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
How MachineLearning can make our Apps smart?
Twitter
Curated Timelines.
Real time and “scores”.
Decisions based on your
individual preferences.
Deep learning models.
19. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
How MachineLearning can make our Apps smart?
Spotify
Discovery Weekly
+ Collaborative Filtering
+ Natural Language Processing
+ Audio models
20. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
How MachineLearning can make our Apps smart?
Shazam
Fingerprint for recording
Generative models
21. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
How MachineLearning can make our Apps smart?
Google
DeepMind network,
the “machine that dreams”.
Natural language Processing.
Speech translation.
22. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
Where to start?
ML as a services vs My Neuronal Network
23. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
Best MLaaS? Source link
Amazon ML Google Cloud ML IBM Watson MS Azure
Overview Large automated platform that
applies ML algorithms to data
stored in AWS
State-of-the-art of Google algorithms
and other industry-leading apps.
Focused on production models
through REST API connectors
Long list of predefined algorithms but less
automated.
Interface Amazon ML Console
Amazon cmd line Interface
Google Cloud cmd line interface
integrated with TensorFlow
IBM graphical analysis
API connectors enable users to
build 3rd data science apps
Azure ML Studio drag-and-drop env.
R & Python packages
Algorithms Regression, Classification, multi
class classification
Video, Image & Text Analysis, Speech
recognitions, Translation
Links to Apache Spark’s MLib
IBM Data Science workbench
Scale boosted decision tree
Bayesian recommendation sys.
Multicass & binary classification
Regression clustering
Suggestions Yes Yes No No
Pricing $0.42/h Data analysis y model
$0,10 per thousand predictions
$0.49/h Model Training
$0.10 per thousand predictions
Free tier for 5k predictions & 5h
$0.45 computer hour
$0.50 per thousands predics
Limited free tier for devs
$0.99 user/month
$1.00 Studio experiment hour
Extras Data Storage extra fees Google account required IBM SPSS Modeler or Data
Science experience required.
Bluemix account required
Azure or Microsoft account required
Others Automatic data transf. tool Little abstraction. Steep learning curve Focus on Backend ML with API Visual interface, limited insight
24. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
Machine Learning hands on - FiendlyChat
https://codelabs.developers.google.com/codelabs/firebase-cloud-functions/
Google Codelab
Cloud function & AI Moderation
+
25. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
Machine Learning hands on - FiendlyChat diagram
Safe
Detection
Blur image
when violent
Write
Location
Push
26. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
https://cloud.google.com/vision/docs/drag-and-drop
27. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
Show me the Code - ML Api Call
exports.blurOffensiveImages = functions.storage.object().onChange(event => {
const object = event.data;
const image = { source: {imageUri: `gs://${object.bucket}/${object.name}`} };
// Check the image content using the Cloud Vision API.
return vision.safeSearchDetection(image).then(batchAnnotateImagesResponse => {
const safeSearchResult = batchAnnotateImagesResponse[0].safeSearchAnnotation;
const Likelihood = Vision.types.Likelihood;
if (Likelihood[safeSearchResult.adult] >= Likelihood.LIKELY ||
Likelihood[safeSearchResult.violence] >= Likelihood.LIKELY) {
console.log('The image', object.name, 'has been detected as inappropriate.');
return blurImage(object.name, object.bucket);
} else {
console.log('The image', object.name,'has been detected as OK.');
}
});
});
28. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
Machine Learning hands on - FiendlyChat Code
29. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
Where to start?
ML as a services vs My Neuronal Network
30. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
(2015-2016)
31. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
My first neuronal network - TensorDraw
Repo: https://github.com/Twiinlab/codemotion2017 inspired by: https://quickdraw.withgoogle.com/
Main Tools
TensorFlow & App Engine
+
32. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
Python data science libraries
Numpy: Numerical processing
Pandas: Data Analysis
MatPlotLib: Visualization
SciKit: Processing machine learning data sets
33. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
pre-processing training evaluate
load / split / images CNN network check accuracy
model
TensorFlow
Training
save
bucle
Data source: https://quickdraw.withgoogle.com/data
34. Show me the Code - Training
# Imports libraries
# layers configuration
...
# Optimizer
...
# Loss Function
...
# image helper
fileList = ['smile','car','pencil','burger','moon','hand','tornado','scissors','mug','sock']
class SketchImageHelper():
# init training images
def set_up_images(self):
sampleSize = self.pos_end - self.pos_begin
for i in range(len(self.fileList)):
partialImages = np.array(np.load(fileList[i])[self.pos_begin:self.pos_end])
self.images.append( partialImages / 255)
self.labels.append(np.full((sampleSize,10), one_hot_encode(i)))
def next_batch(self, batch_size):
for i in range(len(self.fileList)):
x = np.array((self.images[i])[self.position:self.position+batch_size])
y = np.array((self.labels[i])[self.position:self.position+batch_size])
self.position = (self.position + batch_size)
return x, y
35. Show me the Code - Training
...
# init test images
sih = SketchImageHelper()
sih.set_up_images()
saver = tf.train.Saver()
with tf.Session() as sess:
steps = 3000
sess.run(init)
for j in range(steps):
batch_x , batch_y = sih.next_batch(100)
sess.run(train,feed_dict={x:batch_x,y_true:batch_y,hold_prob:0.5})
if j%50 == 0:
# Validate the Train Model
matches = tf.equal(tf.argmax(y_pred,1),tf.argmax(y_true,1))
acc = tf.reduce_mean(tf.cast(matches,tf.float32))
print(sess.run(acc,feed_dict={x:test_x,y_true:test_y,hold_prob:1.0}))
saver.save(sess, savefile)
36. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
Show me the Code - Network configuration
37. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
pre-processing
/prediction
restore
model
TensorFlow
Prediction
result : [ prob1,
prob2,
…
prob10]
APP
ENGINE
prediction
grey scale
resize image
39. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
try here: https://tensorweb-af554.firebaseapp.com/
40. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
The Future of MachineLearning
What’s next in machine learning trends?
Machines That Learn More Effectively
Automation of Cyberattack Countermeasures
Convincing Generative Models
Better Machine Learning Training
41. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
Thanks!
Any question?
Rubén Chavarri Elduayen
@pekewake
David Chavarri elduayen
@dvdchavarri
42. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
Special Thanks to
Jorge del Val Juantomas García Gema Parreño Codemotion
43. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
The Future of MachineLearning
What’s next in machine learning trends?
Machines That Learn More Effectively
Automation of Cyberattack Countermeasures
Convincing Generative Models
Better Machine Learning Training
44. Rubén y David · Contruir una App con AI nunca fue tan facil · @pekewake @dvdchavarri
RESOURCES:
Código fuente:
Demo: ML as a service
https://codelabs.developers.google.com/codelabs/firebase-web/
Demo: my neuronal network
https://github.com/Twiinlab/codemotion2017
Recomended course:
https://www.tensorflow.org/tutorials/
https://www.udemy.com/complete-guide-to-tensorflow-for-deep-learning-with-python/
AI - ML - DeepLearning
https://www.datascience.com/blog/machine-learning-and-deep-learning-what-is-the-difference
https://blogs.nvidia.com/blog/2016/07/29/whats-difference-artificial-intelligence-machine-learning-deep-learning-ai/
Real apps
http://www.wordstream.com/blog/ws/2017/07/28/machine-learning-applications
https://blog.twitter.com/engineering/en_us/topics/insights/2017/using-deep-learning-at-scale-in-twitters-timelines.html
https://hackernoon.com/spotifys-discover-weekly-how-machine-learning-finds-your-new-music-19a41ab76efe
https://www.toptal.com/algorithms/shazam-reconocimiento-de-algoritmos-de-m%C3%BAsica-huellas-dactilares-y-procesamiento/es
Machine Learning framework comparison
https://blog.paperspace.com/which-ml-framework-should-i-use/
https://project.inria.fr/deeplearning/files/2016/05/DLFrameworks.pdf