SlideShare a Scribd company logo
1 of 15
STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 1
TensorFlow Eager Execution
Speaker: Ehsan Amjadian | Data Scientist | DNA Applied Research
November 27th, 2018
STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 2
Overview
• Introducing TensorFlow Eager
• Implications of Eager Execution
• Implementation Tutorial
• Concluding Remarks
STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 3
Eager Execution Intro
• Dynamic Computation Graph v.s Static Graphs
• Follows the imperative paradigm
• Operations evaluated immediately
• Operations return values vs. constructing graph that runs later
STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 4
Implications
• More Pythonic
• Python’s Data structures
• Python’s Iteration Statements
• Python tools for error reporting
• Python control flow
• Enables Dynamic Models
• No unconventional idiosyncrasies
• Fewer boilerplates (arguably none)
• More intuitive
• Easier to debug
• Great for research and prototyping
STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 5
Implementation Tutorial
• Latest version of TF:
• Flagging Eager Mode:
• Verify:
!pip install -q --upgrade tensorflow==1.11
from __future__ import absolute_import, division, print_function
import tensorflow as tf
tf.enable_eager_execution() #This is the flag
tf.executing_eagerly()
True
STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 6
Implementation Tutorial
x = [[2.]]
m = tf.matmul(x, x)
print("hello, {}".format(m))
• Quick example
• No symbolic handles to nodes in the CG:
• Evaluating or printing does not disrupt the flow of gradients computation
• Verify:
a = tf.constant([[1, 2],
[3, 4]])
print(a)
tf.Tensor( [[1 2] [3 4]], shape=(2, 2), dtype=int32)
STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 7
Broadcasting, Operator Overloading, NumPy
Interoperability
# Broadcasting support
b = tf.add(a, 1)
print(b)
tf.Tensor( [[2 3] [4 5]], shape=(2, 2), dtype=int32)
# Operator overloading is supported
print(a * b)
tf.Tensor( [[ 2 6] [12 20]], shape=(2, 2), dtype=int32)
# Obtain numpy value from a tensor:
print(a.numpy())
# => [[1 2]
# [3 4]]
STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 8
Iterating over Data
• No need to use create an iterator and call iterator.get_next()
initial_value = tf.random_normal([2,3], stddev=0.2)
w = tfe.Variable(initial_value, name=‘weights’)
words = tf.constant([‘cat’, ‘dog’, ‘house’, ‘car’])
dataset = tf.data.Dataset.from_tensor_slices(words)
for x in dataset:
print x
STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 9
Gradients: no tf.gradients
• We us a gradient tape instead
variables = [w1, b1, w2, b2]
optimizer = tf.train.AdamOptimizer()
with tf.GradientTape() as tape:
y_pred = model.predict(x, variables)
loss = model.compute_loss(y_pred, y)
grads = tape.gradient(loss, variables)
optimizer.apply_gradients(zip(grads, variables))
STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 10
Logging
• tf.contrib.summary instead of it.summary
summary_writer = tf.contrib.summary.create_file_writer(‘logs’,
flush_millis=10000)
summary_writer.set_as_default()
global_step = tf.train.get_or_create_global_step()
def log_loss(loss):
with tf.contrib.summary.always_record_summaries:
tf.contrib.summary.scalar(‘loss’, loss)
# In training loop
global_step.assign_add(1)
loss = some value
log_loss(loss )
STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 11
Saving & Checkpointing
• tfe.Saver instead of tf.train.Saver
• Instead of saving an entire session now you save only the values of the variables that you
desire.
variables = [w1, b1, w2, b2]
saver = tfe.Saver(variables)
# Training
# saving
saver.save(‘checkpoints/values.ckpt’, global_step=step)
# loading
checkpoint_path = tf.train.latest_checkpoint(‘checkpoints’)
saver.restore(checkpoint_path)
STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 12
Quick Way to Model
• You can inherit your layers from tf.keras.layers.Layer, simply use any python objects to represent a
layer, or
• Build method helps you depend the shape of variables on input
• Leaves the specifics of the input shape to the user not the developer (variable length)
# Costum Model
class MySimpleLayer(tf.keras.layers.Layer):
def __init__(self, output_units):
super(MySimpleLayer, self).__init__()
self.output_units = output_units
def build(self, input_shape):
self.kernel = self.add_variable(
"kernel", [input_shape[-1], self.output_units])
def call(self, input):
# Override call()
return tf.matmul(input, self.kernel)
STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 13
Stacking Keras Layers
model = tf.keras.Sequential([
tf.keras.layers.Dense(10, input_shape=(784,)), # must declare input shape
tf.keras.layers.Dense(10)
])
• You can employ tf.keras.Sequential
STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 14
Organize models in classes
class MNISTModel(tf.keras.Model):
def __init__(self):
super(MNISTModel, self).__init__()
self.dense1 = tf.keras.layers.Dense(units=10)
self.dense2 = tf.keras.layers.Dense(units=10)
def call(self, input):
"""Run the model."""
result = self.dense1(input)
result = self.dense2(result)
result = self.dense2(result) # reuse variables from dense2 layer
return result
model = MNISTModel()
• Inherit from tf.keras.Model
STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 15
Thank You!

More Related Content

What's hot

Enabling Ad-hoc Business Process Adaptations through Event-driven Task Decoup...
Enabling Ad-hoc Business Process Adaptations through Event-driven Task Decoup...Enabling Ad-hoc Business Process Adaptations through Event-driven Task Decoup...
Enabling Ad-hoc Business Process Adaptations through Event-driven Task Decoup...Malinda Kapuruge
 
Analytical Models of Parallel Programs
Analytical Models of Parallel ProgramsAnalytical Models of Parallel Programs
Analytical Models of Parallel ProgramsDr Shashikant Athawale
 
Partition Configuration RTNS 2013 Presentation
Partition Configuration RTNS 2013 PresentationPartition Configuration RTNS 2013 Presentation
Partition Configuration RTNS 2013 PresentationJoseph Porter
 
Chapter 3 principles of parallel algorithm design
Chapter 3   principles of parallel algorithm designChapter 3   principles of parallel algorithm design
Chapter 3 principles of parallel algorithm designDenisAkbar1
 
Optimized Assignment of Independent Task for Improving Resources Performance ...
Optimized Assignment of Independent Task for Improving Resources Performance ...Optimized Assignment of Independent Task for Improving Resources Performance ...
Optimized Assignment of Independent Task for Improving Resources Performance ...ijgca
 

What's hot (6)

Enabling Ad-hoc Business Process Adaptations through Event-driven Task Decoup...
Enabling Ad-hoc Business Process Adaptations through Event-driven Task Decoup...Enabling Ad-hoc Business Process Adaptations through Event-driven Task Decoup...
Enabling Ad-hoc Business Process Adaptations through Event-driven Task Decoup...
 
Analytical Models of Parallel Programs
Analytical Models of Parallel ProgramsAnalytical Models of Parallel Programs
Analytical Models of Parallel Programs
 
Chap12 slides
Chap12 slidesChap12 slides
Chap12 slides
 
Partition Configuration RTNS 2013 Presentation
Partition Configuration RTNS 2013 PresentationPartition Configuration RTNS 2013 Presentation
Partition Configuration RTNS 2013 Presentation
 
Chapter 3 principles of parallel algorithm design
Chapter 3   principles of parallel algorithm designChapter 3   principles of parallel algorithm design
Chapter 3 principles of parallel algorithm design
 
Optimized Assignment of Independent Task for Improving Resources Performance ...
Optimized Assignment of Independent Task for Improving Resources Performance ...Optimized Assignment of Independent Task for Improving Resources Performance ...
Optimized Assignment of Independent Task for Improving Resources Performance ...
 

Similar to Tensorflow User Group Toronto - Ehsan Amjadian - TF Gager

When Apache Spark Meets TiDB with Xiaoyu Ma
When Apache Spark Meets TiDB with Xiaoyu MaWhen Apache Spark Meets TiDB with Xiaoyu Ma
When Apache Spark Meets TiDB with Xiaoyu MaDatabricks
 
Processing 50,000 Events Per Second with Cassandra and Spark (Ben Slater, Ins...
Processing 50,000 Events Per Second with Cassandra and Spark (Ben Slater, Ins...Processing 50,000 Events Per Second with Cassandra and Spark (Ben Slater, Ins...
Processing 50,000 Events Per Second with Cassandra and Spark (Ben Slater, Ins...DataStax
 
Processing 50,000 events per second with Cassandra and Spark
Processing 50,000 events per second with Cassandra and SparkProcessing 50,000 events per second with Cassandra and Spark
Processing 50,000 events per second with Cassandra and SparkBen Slater
 
Processing 50,000 events per second with Cassandra and Spark
Processing 50,000 events per second with Cassandra and SparkProcessing 50,000 events per second with Cassandra and Spark
Processing 50,000 events per second with Cassandra and SparkInstaclustr
 
Apache Pinot Meetup Sept02, 2020
Apache Pinot Meetup Sept02, 2020Apache Pinot Meetup Sept02, 2020
Apache Pinot Meetup Sept02, 2020Mayank Shrivastava
 
Deep Learning Introduction - WeCloudData
Deep Learning Introduction - WeCloudDataDeep Learning Introduction - WeCloudData
Deep Learning Introduction - WeCloudDataWeCloudData
 
InfluxDB 101 – Concepts and Architecture by Michael DeSa, Software Engineer |...
InfluxDB 101 – Concepts and Architecture by Michael DeSa, Software Engineer |...InfluxDB 101 – Concepts and Architecture by Michael DeSa, Software Engineer |...
InfluxDB 101 – Concepts and Architecture by Michael DeSa, Software Engineer |...InfluxData
 
Big Data, Bigger Analytics
Big Data, Bigger AnalyticsBig Data, Bigger Analytics
Big Data, Bigger AnalyticsItzhak Kameli
 
22-4_PerformanceTuningUsingtheAdvisorFramework.pdf
22-4_PerformanceTuningUsingtheAdvisorFramework.pdf22-4_PerformanceTuningUsingtheAdvisorFramework.pdf
22-4_PerformanceTuningUsingtheAdvisorFramework.pdfyishengxi
 
Neo4j: What's Under the Hood & How Knowing This Can Help You
Neo4j: What's Under the Hood & How Knowing This Can Help You Neo4j: What's Under the Hood & How Knowing This Can Help You
Neo4j: What's Under the Hood & How Knowing This Can Help You Neo4j
 
Metrics-Based Process Mapping
Metrics-Based Process MappingMetrics-Based Process Mapping
Metrics-Based Process MappingTKMG, Inc.
 
AWS re:Invent 2016| DAT318 | Migrating from RDBMS to NoSQL: How Sony Moved fr...
AWS re:Invent 2016| DAT318 | Migrating from RDBMS to NoSQL: How Sony Moved fr...AWS re:Invent 2016| DAT318 | Migrating from RDBMS to NoSQL: How Sony Moved fr...
AWS re:Invent 2016| DAT318 | Migrating from RDBMS to NoSQL: How Sony Moved fr...Amazon Web Services
 
Reduce SRE Stress: Minimizing Service Downtime with Grafana, InfluxDB and Tel...
Reduce SRE Stress: Minimizing Service Downtime with Grafana, InfluxDB and Tel...Reduce SRE Stress: Minimizing Service Downtime with Grafana, InfluxDB and Tel...
Reduce SRE Stress: Minimizing Service Downtime with Grafana, InfluxDB and Tel...InfluxData
 
[JSS2015] In memory and operational analytics
[JSS2015] In memory and operational analytics[JSS2015] In memory and operational analytics
[JSS2015] In memory and operational analyticsGUSS
 
Jss 2015 in memory and operational analytics
Jss 2015   in memory and operational analyticsJss 2015   in memory and operational analytics
Jss 2015 in memory and operational analyticsDavid Barbarin
 
Evolution of Real-time User Engagement Event Consumption at Pinterest
Evolution of Real-time User Engagement Event Consumption at PinterestEvolution of Real-time User Engagement Event Consumption at Pinterest
Evolution of Real-time User Engagement Event Consumption at PinterestHostedbyConfluent
 
How We Reduced Performance Tuning Time by Orders of Magnitude with Database O...
How We Reduced Performance Tuning Time by Orders of Magnitude with Database O...How We Reduced Performance Tuning Time by Orders of Magnitude with Database O...
How We Reduced Performance Tuning Time by Orders of Magnitude with Database O...ScyllaDB
 
Best Practices: How to Analyze IoT Sensor Data with InfluxDB
Best Practices: How to Analyze IoT Sensor Data with InfluxDBBest Practices: How to Analyze IoT Sensor Data with InfluxDB
Best Practices: How to Analyze IoT Sensor Data with InfluxDBInfluxData
 

Similar to Tensorflow User Group Toronto - Ehsan Amjadian - TF Gager (20)

Shaik Niyas Ahamed M Resume
Shaik Niyas Ahamed M ResumeShaik Niyas Ahamed M Resume
Shaik Niyas Ahamed M Resume
 
When Apache Spark Meets TiDB with Xiaoyu Ma
When Apache Spark Meets TiDB with Xiaoyu MaWhen Apache Spark Meets TiDB with Xiaoyu Ma
When Apache Spark Meets TiDB with Xiaoyu Ma
 
Processing 50,000 Events Per Second with Cassandra and Spark (Ben Slater, Ins...
Processing 50,000 Events Per Second with Cassandra and Spark (Ben Slater, Ins...Processing 50,000 Events Per Second with Cassandra and Spark (Ben Slater, Ins...
Processing 50,000 Events Per Second with Cassandra and Spark (Ben Slater, Ins...
 
Processing 50,000 events per second with Cassandra and Spark
Processing 50,000 events per second with Cassandra and SparkProcessing 50,000 events per second with Cassandra and Spark
Processing 50,000 events per second with Cassandra and Spark
 
Processing 50,000 events per second with Cassandra and Spark
Processing 50,000 events per second with Cassandra and SparkProcessing 50,000 events per second with Cassandra and Spark
Processing 50,000 events per second with Cassandra and Spark
 
Apache Pinot Meetup Sept02, 2020
Apache Pinot Meetup Sept02, 2020Apache Pinot Meetup Sept02, 2020
Apache Pinot Meetup Sept02, 2020
 
Deep Learning Introduction - WeCloudData
Deep Learning Introduction - WeCloudDataDeep Learning Introduction - WeCloudData
Deep Learning Introduction - WeCloudData
 
InfluxDB 101 – Concepts and Architecture by Michael DeSa, Software Engineer |...
InfluxDB 101 – Concepts and Architecture by Michael DeSa, Software Engineer |...InfluxDB 101 – Concepts and Architecture by Michael DeSa, Software Engineer |...
InfluxDB 101 – Concepts and Architecture by Michael DeSa, Software Engineer |...
 
Big Data, Bigger Analytics
Big Data, Bigger AnalyticsBig Data, Bigger Analytics
Big Data, Bigger Analytics
 
22-4_PerformanceTuningUsingtheAdvisorFramework.pdf
22-4_PerformanceTuningUsingtheAdvisorFramework.pdf22-4_PerformanceTuningUsingtheAdvisorFramework.pdf
22-4_PerformanceTuningUsingtheAdvisorFramework.pdf
 
Neo4j: What's Under the Hood & How Knowing This Can Help You
Neo4j: What's Under the Hood & How Knowing This Can Help You Neo4j: What's Under the Hood & How Knowing This Can Help You
Neo4j: What's Under the Hood & How Knowing This Can Help You
 
Metrics-Based Process Mapping
Metrics-Based Process MappingMetrics-Based Process Mapping
Metrics-Based Process Mapping
 
R- Introduction
R- IntroductionR- Introduction
R- Introduction
 
AWS re:Invent 2016| DAT318 | Migrating from RDBMS to NoSQL: How Sony Moved fr...
AWS re:Invent 2016| DAT318 | Migrating from RDBMS to NoSQL: How Sony Moved fr...AWS re:Invent 2016| DAT318 | Migrating from RDBMS to NoSQL: How Sony Moved fr...
AWS re:Invent 2016| DAT318 | Migrating from RDBMS to NoSQL: How Sony Moved fr...
 
Reduce SRE Stress: Minimizing Service Downtime with Grafana, InfluxDB and Tel...
Reduce SRE Stress: Minimizing Service Downtime with Grafana, InfluxDB and Tel...Reduce SRE Stress: Minimizing Service Downtime with Grafana, InfluxDB and Tel...
Reduce SRE Stress: Minimizing Service Downtime with Grafana, InfluxDB and Tel...
 
[JSS2015] In memory and operational analytics
[JSS2015] In memory and operational analytics[JSS2015] In memory and operational analytics
[JSS2015] In memory and operational analytics
 
Jss 2015 in memory and operational analytics
Jss 2015   in memory and operational analyticsJss 2015   in memory and operational analytics
Jss 2015 in memory and operational analytics
 
Evolution of Real-time User Engagement Event Consumption at Pinterest
Evolution of Real-time User Engagement Event Consumption at PinterestEvolution of Real-time User Engagement Event Consumption at Pinterest
Evolution of Real-time User Engagement Event Consumption at Pinterest
 
How We Reduced Performance Tuning Time by Orders of Magnitude with Database O...
How We Reduced Performance Tuning Time by Orders of Magnitude with Database O...How We Reduced Performance Tuning Time by Orders of Magnitude with Database O...
How We Reduced Performance Tuning Time by Orders of Magnitude with Database O...
 
Best Practices: How to Analyze IoT Sensor Data with InfluxDB
Best Practices: How to Analyze IoT Sensor Data with InfluxDBBest Practices: How to Analyze IoT Sensor Data with InfluxDB
Best Practices: How to Analyze IoT Sensor Data with InfluxDB
 

More from Devatanu Banerjee

TensorFlow 2.0 Autographs - For TFUG - Vik Pant
TensorFlow 2.0 Autographs - For TFUG - Vik PantTensorFlow 2.0 Autographs - For TFUG - Vik Pant
TensorFlow 2.0 Autographs - For TFUG - Vik PantDevatanu Banerjee
 
TensorFlow 2.0 Overview - For TensorFlow User Group - Ehsan Amjadian
TensorFlow 2.0 Overview - For TensorFlow User Group - Ehsan AmjadianTensorFlow 2.0 Overview - For TensorFlow User Group - Ehsan Amjadian
TensorFlow 2.0 Overview - For TensorFlow User Group - Ehsan AmjadianDevatanu Banerjee
 
Font classification with 5 deep learning models using tensor flow
Font classification with 5 deep learning models using tensor flowFont classification with 5 deep learning models using tensor flow
Font classification with 5 deep learning models using tensor flowDevatanu Banerjee
 
Application of NLG in e commerce
Application of NLG in e commerceApplication of NLG in e commerce
Application of NLG in e commerceDevatanu Banerjee
 
Dave D'Silva - Emerging Technology Framework to Unite Society
Dave D'Silva - Emerging Technology Framework to Unite SocietyDave D'Silva - Emerging Technology Framework to Unite Society
Dave D'Silva - Emerging Technology Framework to Unite SocietyDevatanu Banerjee
 
Sandeep Chaudhury - AI & Prosperity
Sandeep Chaudhury - AI & ProsperitySandeep Chaudhury - AI & Prosperity
Sandeep Chaudhury - AI & ProsperityDevatanu Banerjee
 
Monitoring Trends (Seminar Slides)
Monitoring Trends (Seminar Slides)Monitoring Trends (Seminar Slides)
Monitoring Trends (Seminar Slides)Devatanu Banerjee
 

More from Devatanu Banerjee (7)

TensorFlow 2.0 Autographs - For TFUG - Vik Pant
TensorFlow 2.0 Autographs - For TFUG - Vik PantTensorFlow 2.0 Autographs - For TFUG - Vik Pant
TensorFlow 2.0 Autographs - For TFUG - Vik Pant
 
TensorFlow 2.0 Overview - For TensorFlow User Group - Ehsan Amjadian
TensorFlow 2.0 Overview - For TensorFlow User Group - Ehsan AmjadianTensorFlow 2.0 Overview - For TensorFlow User Group - Ehsan Amjadian
TensorFlow 2.0 Overview - For TensorFlow User Group - Ehsan Amjadian
 
Font classification with 5 deep learning models using tensor flow
Font classification with 5 deep learning models using tensor flowFont classification with 5 deep learning models using tensor flow
Font classification with 5 deep learning models using tensor flow
 
Application of NLG in e commerce
Application of NLG in e commerceApplication of NLG in e commerce
Application of NLG in e commerce
 
Dave D'Silva - Emerging Technology Framework to Unite Society
Dave D'Silva - Emerging Technology Framework to Unite SocietyDave D'Silva - Emerging Technology Framework to Unite Society
Dave D'Silva - Emerging Technology Framework to Unite Society
 
Sandeep Chaudhury - AI & Prosperity
Sandeep Chaudhury - AI & ProsperitySandeep Chaudhury - AI & Prosperity
Sandeep Chaudhury - AI & Prosperity
 
Monitoring Trends (Seminar Slides)
Monitoring Trends (Seminar Slides)Monitoring Trends (Seminar Slides)
Monitoring Trends (Seminar Slides)
 

Recently uploaded

Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxFIDO Alliance
 
الأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهلهالأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهلهMohamed Sweelam
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxFIDO Alliance
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuidePixlogix Infotech
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityVictorSzoltysek
 
Navigating the Large Language Model choices_Ravi Daparthi
Navigating the Large Language Model choices_Ravi DaparthiNavigating the Large Language Model choices_Ravi Daparthi
Navigating the Large Language Model choices_Ravi DaparthiRaviKumarDaparthi
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...panagenda
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfalexjohnson7307
 
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdfMuhammad Subhan
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxMarkSteadman7
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024Lorenzo Miniero
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch TuesdayIvanti
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...ScyllaDB
 
Microsoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdfMicrosoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdfOverkill Security
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptxFIDO Alliance
 
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 Ontologyjohnbeverley2021
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...FIDO Alliance
 
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdfFrisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdfAnubhavMangla3
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsLeah Henrickson
 

Recently uploaded (20)

Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
الأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهلهالأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهله
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
Navigating the Large Language Model choices_Ravi Daparthi
Navigating the Large Language Model choices_Ravi DaparthiNavigating the Large Language Model choices_Ravi Daparthi
Navigating the Large Language Model choices_Ravi Daparthi
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdf
 
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
Microsoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdfMicrosoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdf
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
 
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
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdfFrisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 

Tensorflow User Group Toronto - Ehsan Amjadian - TF Gager

  • 1. STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 1 TensorFlow Eager Execution Speaker: Ehsan Amjadian | Data Scientist | DNA Applied Research November 27th, 2018
  • 2. STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 2 Overview • Introducing TensorFlow Eager • Implications of Eager Execution • Implementation Tutorial • Concluding Remarks
  • 3. STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 3 Eager Execution Intro • Dynamic Computation Graph v.s Static Graphs • Follows the imperative paradigm • Operations evaluated immediately • Operations return values vs. constructing graph that runs later
  • 4. STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 4 Implications • More Pythonic • Python’s Data structures • Python’s Iteration Statements • Python tools for error reporting • Python control flow • Enables Dynamic Models • No unconventional idiosyncrasies • Fewer boilerplates (arguably none) • More intuitive • Easier to debug • Great for research and prototyping
  • 5. STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 5 Implementation Tutorial • Latest version of TF: • Flagging Eager Mode: • Verify: !pip install -q --upgrade tensorflow==1.11 from __future__ import absolute_import, division, print_function import tensorflow as tf tf.enable_eager_execution() #This is the flag tf.executing_eagerly() True
  • 6. STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 6 Implementation Tutorial x = [[2.]] m = tf.matmul(x, x) print("hello, {}".format(m)) • Quick example • No symbolic handles to nodes in the CG: • Evaluating or printing does not disrupt the flow of gradients computation • Verify: a = tf.constant([[1, 2], [3, 4]]) print(a) tf.Tensor( [[1 2] [3 4]], shape=(2, 2), dtype=int32)
  • 7. STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 7 Broadcasting, Operator Overloading, NumPy Interoperability # Broadcasting support b = tf.add(a, 1) print(b) tf.Tensor( [[2 3] [4 5]], shape=(2, 2), dtype=int32) # Operator overloading is supported print(a * b) tf.Tensor( [[ 2 6] [12 20]], shape=(2, 2), dtype=int32) # Obtain numpy value from a tensor: print(a.numpy()) # => [[1 2] # [3 4]]
  • 8. STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 8 Iterating over Data • No need to use create an iterator and call iterator.get_next() initial_value = tf.random_normal([2,3], stddev=0.2) w = tfe.Variable(initial_value, name=‘weights’) words = tf.constant([‘cat’, ‘dog’, ‘house’, ‘car’]) dataset = tf.data.Dataset.from_tensor_slices(words) for x in dataset: print x
  • 9. STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 9 Gradients: no tf.gradients • We us a gradient tape instead variables = [w1, b1, w2, b2] optimizer = tf.train.AdamOptimizer() with tf.GradientTape() as tape: y_pred = model.predict(x, variables) loss = model.compute_loss(y_pred, y) grads = tape.gradient(loss, variables) optimizer.apply_gradients(zip(grads, variables))
  • 10. STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 10 Logging • tf.contrib.summary instead of it.summary summary_writer = tf.contrib.summary.create_file_writer(‘logs’, flush_millis=10000) summary_writer.set_as_default() global_step = tf.train.get_or_create_global_step() def log_loss(loss): with tf.contrib.summary.always_record_summaries: tf.contrib.summary.scalar(‘loss’, loss) # In training loop global_step.assign_add(1) loss = some value log_loss(loss )
  • 11. STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 11 Saving & Checkpointing • tfe.Saver instead of tf.train.Saver • Instead of saving an entire session now you save only the values of the variables that you desire. variables = [w1, b1, w2, b2] saver = tfe.Saver(variables) # Training # saving saver.save(‘checkpoints/values.ckpt’, global_step=step) # loading checkpoint_path = tf.train.latest_checkpoint(‘checkpoints’) saver.restore(checkpoint_path)
  • 12. STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 12 Quick Way to Model • You can inherit your layers from tf.keras.layers.Layer, simply use any python objects to represent a layer, or • Build method helps you depend the shape of variables on input • Leaves the specifics of the input shape to the user not the developer (variable length) # Costum Model class MySimpleLayer(tf.keras.layers.Layer): def __init__(self, output_units): super(MySimpleLayer, self).__init__() self.output_units = output_units def build(self, input_shape): self.kernel = self.add_variable( "kernel", [input_shape[-1], self.output_units]) def call(self, input): # Override call() return tf.matmul(input, self.kernel)
  • 13. STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 13 Stacking Keras Layers model = tf.keras.Sequential([ tf.keras.layers.Dense(10, input_shape=(784,)), # must declare input shape tf.keras.layers.Dense(10) ]) • You can employ tf.keras.Sequential
  • 14. STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 14 Organize models in classes class MNISTModel(tf.keras.Model): def __init__(self): super(MNISTModel, self).__init__() self.dense1 = tf.keras.layers.Dense(units=10) self.dense2 = tf.keras.layers.Dense(units=10) def call(self, input): """Run the model.""" result = self.dense1(input) result = self.dense2(result) result = self.dense2(result) # reuse variables from dense2 layer return result model = MNISTModel() • Inherit from tf.keras.Model
  • 15. STRICTLY PRIVATE & CONFIDENTIAL | RBC Royal Bank of Canada | December 12, 2018 | 15 Thank You!