SlideShare une entreprise Scribd logo
1  sur  55
Télécharger pour lire hors ligne
R interface for Tensorflow
#sdss2019
Kevin Kuo @kevinykuo
Artificial
intelligence?
Artificial
Intelligence?
Getty Images
Getty Images
Artificial
Intelligence?
Rule #1 of AI:
Rule #1 of AI:
Someone talk to you about AI
with a straight face? They
tryna hustle ya.
ELI5
TensorFlow?
ELI5 a stats
undergrad
TensorFlow
What’s a tensor?
What’s a tensor?
What’s flowing?
Tensors & Ops
Tensors are just
multidimensional
arrays
Tensors & Ops
Tensors are just
multidimensional
arrays
You apply Ops
(transformations
) to Tensors to
get more Tensors
Deep Learning?
Neural networks?
Find a function F
such that Y ≈ f(x)
Find a function F
such that Y ≈ f(x)
(at least some of the
time)
Find a function F
such that Y ≈ f(x)
(at least some of the
time, hopefully)
Really just
straightforward
matrix algebra
Resources
tensorflow
https://www.tensorflow.org/guide/extend/ar
chitecture
tensorflow
tf.keras
tensorflow
tf.keras
library(keras)
library(tfdatasets)
library(tfprobability)
library(tensorflow)
GLM is a neural net!
We’re doing AI!
Proof (by example).
library(keras)
library(tfprobability)
model <- keras_model_sequential() %>%
layer_dense(units = 1, input_shape = 1,
name = "parameters") %>%
layer_lambda(f = k_exp) %>%
layer_distribution_lambda(tfd_poisson)
library(keras)
library(tfprobability)
model <- keras_model_sequential() %>%
layer_dense(units = 1, input_shape = 1,
name = "parameters") %>%
layer_lambda(f = k_exp) %>%
layer_distribution_lambda(tfd_poisson)
neg_loglik <- function(y_true, y_pred) {
- tfd_log_prob(y_pred, y_true)
}
model %>%
compile(optimizer = optimizer_sgd(lr = 0.1),
loss = neg_loglik)
model <- keras_model_sequential() %>%
layer_dense(units = 1, input_shape = 1,
name = "parameters") %>%
layer_lambda(f = k_exp) %>%
layer_distribution_lambda(tfd_poisson)
neg_loglik <- function(y_true, y_pred) {
- tfd_log_prob(y_pred, y_true)
}
model %>%
compile(optimizer = optimizer_sgd(lr = 0.1),
loss = neg_loglik)
model %>%
fit(x, y, epochs = 15)
> parameters <- model %>%
+ get_layer("parameters") %>%
+ (function(x) x$get_weights())
> parameters
[[1]]
[,1]
[1,] 1.985788
[[2]]
[1] 1.090006
> glm(y ~ x, family = poisson())
Call: glm(formula = y ~ x, family = poisson())
Coefficients:
(Intercept) x
1.090 1.986
Degrees of Freedom: 99 Total (i.e. Null); 98 Residual
Null Deviance: 359
Residual Deviance: 90.1 AIC: 484.2
> parameters <- model %>%
+ get_layer("parameters") %>%
+ (function(x) x$get_weights())
> parameters
[[1]]
[,1]
[1,] 1.985788
[[2]]
[1] 1.090006
model <- keras_model_sequential() %>%
layer_dense(units = 8675309, input_shape = 1,
name = "parameters") %>%
layer_dense(units = 8675309) %>%
layer_lambda(f = k_exp) %>%
layer_distribution_lambda(tfd_poisson)
NOW YOU HAVE A DEEP NEURAL NET
model <- keras_model_sequential() %>%
layer_dense(units = 8675309, input_shape = 1,
name = "parameters") %>%
layer_dense_variational(
units = 1,
make_posterior_fn = posterior_mean_field,
make_prior_fn = prior_trainable,
kl_weight = 1 / n_rows,
activation = "linear"
) %>%
layer_lambda(f = k_exp) %>%
layer_distribution_lambda(tfd_poisson)
NOW YOUR MODEL IS A RANDOM
VARIABLE ZOMG
model <- keras_model_sequential() %>%
layer_dense(units = 8675309, input_shape = 1,
name = "parameters") %>%
layer_dense_variational(
units = 2,
make_posterior_fn = posterior_mean_field,
make_prior_fn = prior_trainable,
kl_weight = 1 / n_rows,
activation = "linear"
) %>%
layer_distribution_lambda(function(t) {
tfd_normal(t[,1], k_softplus(t[,2]))
})
HETEROSCEDASTIC ERRORS OMGWTFBBQ
model <- keras_model_sequential() %>%
____ %>%
____ %>%
____
model %>%
compile(optimizer = ____,
loss = ____)
THE POSSIBILITIES ARE ENDLESS
model <- keras_model_sequential() %>%
____ %>%
____ %>%
____
model %>%
compile(optimizer = ____,
loss = ____)
THE POSSIBILITIES ARE ENDLESS
Why should I give a
___ about deep
learning?
Enabling new
applications?
1.123%
Percentage of data scientists who
work with image data on the job
Things neural nets can help with
- Images (yeah, sometimes we get them)
- Natural language / Time series
- High dimensional categorical predictors
- Multi-task learning, i.e. when we want to predict
multiple outputs with a single model
- Combining different types of inputs into the same model
- Making predictions on devices without docker containers
(e.g. your phone)
Resources
● https://tensorflow.rstudio.com/
● https://keras.rstudio.com/
● https://blogs.rstudio.com/tensorflow/
● https://github.com/rstudio/tfprobability

Contenu connexe

Tendances

Data Structure
Data StructureData Structure
Data Structure
sheraz1
 
Lec 25 - arrays-strings
Lec 25 - arrays-stringsLec 25 - arrays-strings
Lec 25 - arrays-strings
Princess Sam
 

Tendances (20)

07slide
07slide07slide
07slide
 
Arrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | EdurekaArrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | Edureka
 
Preparation Data Structures 10 trees
Preparation Data Structures 10 treesPreparation Data Structures 10 trees
Preparation Data Structures 10 trees
 
Introduction To Generative Adversarial Networks GANs
Introduction To Generative Adversarial Networks GANsIntroduction To Generative Adversarial Networks GANs
Introduction To Generative Adversarial Networks GANs
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
 
Arrays in Java | Edureka
Arrays in Java | EdurekaArrays in Java | Edureka
Arrays in Java | Edureka
 
06slide
06slide06slide
06slide
 
Preparation Data Structures 11 graphs
Preparation Data Structures 11 graphsPreparation Data Structures 11 graphs
Preparation Data Structures 11 graphs
 
Albumentations: fast and flexible image augmentations
Albumentations: fast and flexible image augmentationsAlbumentations: fast and flexible image augmentations
Albumentations: fast and flexible image augmentations
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
 
Arrays C#
Arrays C#Arrays C#
Arrays C#
 
Natural Language Processing (NLP)
Natural Language Processing (NLP)Natural Language Processing (NLP)
Natural Language Processing (NLP)
 
Machine learning with scikit-learn
Machine learning with scikit-learnMachine learning with scikit-learn
Machine learning with scikit-learn
 
Data Structure
Data StructureData Structure
Data Structure
 
Lec 25 - arrays-strings
Lec 25 - arrays-stringsLec 25 - arrays-strings
Lec 25 - arrays-strings
 
C# Arrays
C# ArraysC# Arrays
C# Arrays
 
Chapter 5 ds
Chapter 5 dsChapter 5 ds
Chapter 5 ds
 
Transfer Learning
Transfer LearningTransfer Learning
Transfer Learning
 
Arrays in java language
Arrays in java languageArrays in java language
Arrays in java language
 
Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]
 

Similaire à R Interface for TensorFlow

Lec 1 Ds
Lec 1 DsLec 1 Ds
Lec 1 Ds
Qundeel
 
Lec 1 Ds
Lec 1 DsLec 1 Ds
Lec 1 Ds
Qundeel
 

Similaire à R Interface for TensorFlow (20)

Neuroevolution in Elixir
Neuroevolution in ElixirNeuroevolution in Elixir
Neuroevolution in Elixir
 
Fuel Up JavaScript with Functional Programming
Fuel Up JavaScript with Functional ProgrammingFuel Up JavaScript with Functional Programming
Fuel Up JavaScript with Functional Programming
 
Functions In Scala
Functions In Scala Functions In Scala
Functions In Scala
 
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...
 
Artificial Intelligence and Optimization with Parallelism
Artificial Intelligence and Optimization with ParallelismArtificial Intelligence and Optimization with Parallelism
Artificial Intelligence and Optimization with Parallelism
 
Getting Started with Keras and TensorFlow - StampedeCon AI Summit 2017
Getting Started with Keras and TensorFlow - StampedeCon AI Summit 2017Getting Started with Keras and TensorFlow - StampedeCon AI Summit 2017
Getting Started with Keras and TensorFlow - StampedeCon AI Summit 2017
 
Scaling Deep Learning with MXNet
Scaling Deep Learning with MXNetScaling Deep Learning with MXNet
Scaling Deep Learning with MXNet
 
From Tensorflow Graph to Tensorflow Eager
From Tensorflow Graph to Tensorflow EagerFrom Tensorflow Graph to Tensorflow Eager
From Tensorflow Graph to Tensorflow Eager
 
Mat lab workshop
Mat lab workshopMat lab workshop
Mat lab workshop
 
Natural language processing open seminar For Tensorflow usage
Natural language processing open seminar For Tensorflow usageNatural language processing open seminar For Tensorflow usage
Natural language processing open seminar For Tensorflow usage
 
Lec 1 Ds
Lec 1 DsLec 1 Ds
Lec 1 Ds
 
Lec 1 Ds
Lec 1 DsLec 1 Ds
Lec 1 Ds
 
The Fuss about || Haskell | Scala | F# ||
The Fuss about || Haskell | Scala | F# ||The Fuss about || Haskell | Scala | F# ||
The Fuss about || Haskell | Scala | F# ||
 
TensorFlow for IITians
TensorFlow for IITiansTensorFlow for IITians
TensorFlow for IITians
 
30 分鐘學會實作 Python Feature Selection
30 分鐘學會實作 Python Feature Selection30 分鐘學會實作 Python Feature Selection
30 分鐘學會實作 Python Feature Selection
 
Chtp405
Chtp405Chtp405
Chtp405
 
Pydiomatic
PydiomaticPydiomatic
Pydiomatic
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomatico
 
30 分鐘學會實作 Python Feature Selection
30 分鐘學會實作 Python Feature Selection30 分鐘學會實作 Python Feature Selection
30 分鐘學會實作 Python Feature Selection
 
The SAM Pattern: State Machines and Computation
The SAM Pattern: State Machines and ComputationThe SAM Pattern: State Machines and Computation
The SAM Pattern: State Machines and Computation
 

Dernier

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

R Interface for TensorFlow