SlideShare a Scribd company logo
BUILDING
INTERPRETABLE &
SECURE AI
SYSTEMS USING
PYTORCH
GEETA CHAUHAN
AI PARTNER ENGINEERING
FACEBOOK AI
AGENDA 01
INTERPRETABLE AI
02
SECURE & PRIVACY PRESERVING AI
03
REFERENCES
I N T E R P R E T A B I L I T Y
WHAT IS MODEL INTERPRETABILIT Y ?
“THE ABILIT Y TO DESCRIBE AI MODEL INTERNALS AND PREDICTIONS IN HUMAN
UNDERSTANDABLE TERMS*”
* LH Gilpin, et. al., Explaining explanations: An overview of interpretability of machine learning in IEEE 5th International Conference on data science and advanced analytics (DSAA), 2018
I N C R E A S E D
T R A N S P A R E N C Y
D E B U G G I N GB E T T E R
U N D E R S TA N D I N G
MODEL INTERPRETABILIT Y
Screenshot of the tool
Attributing to dog
Attribution Magnitudes
MODEL INTERPRETABILIT Y LIBRARY FOR PY TORCH
M U LT I M O D A L E A S Y T O U S EE X T E N S I B L E
class MyAttribution(Attribution):
def attribute(self, input, ...):
attributions = self._compute_attrs(input, ... )
# <Add any logic necessary for attribution>
return attributions
visualize_image_attr(attr_algo.attribute(input), ...)
captum.ai
GradientSHAP
DeepLiftSHAP
SHAP Methods Integrated Gradients
Saliency
GuidedGradCam
Attribute model output (or internal neurons) to input
features
LayerGradientSHAP
LayerDeepLiftSHAP
SHAP Methods
LayerConductance
InternalInfluence
GradCam
Attribute model output to the layers of the model
DeepLift
NoiseTunnel (Smoothgrad, Vargrad, Smoothgrad Square)
LayerActivation
LayerGradientXActivationLayerDeepLiftFeatureAblation /
FeaturePermutation
GuidedBackprop /
Deconvolution
AT TRIBUTION ALGORITHMS
Input * Gradient LayerFeatureAblation
LayerIntegratedGradients
Occlusion
Shapely Value Sampling
Gradient
Perturbation
Other
attributions = Attribution(forward_func, ...).attribute(inputs, ...)*
* Check out our Getting Started docs and API:
https://github.com/pytorch/captum
https://captum.ai/api/
GradientAttribution PerturbationAttribution
IntegratedGradients FeatureAblation
... ...
attributions = Attribution(forward_func, ...).attribute(inputs, ...)*
* Check out our Getting Started docs and API:
https://github.com/pytorch/captum
https://captum.ai/api/
the importance of
inputs to forward_func
model's forward function or
any modification of it
EXPL AINING WITH
INTEGRATED GRADIENTS
FEATURE 0
FEATURE 1
FEATURE 2
TARGET 0
TARGET 1
from captum.attr import IntegratedGradients
attr_algo = IntegratedGradients(model)
input = torch.rand(1, 3)
attributions = attr_algo.attribute(input, target=0)
EXPL AINING WITH
INTEGRATED GRADIENTS
from captum.attr import IntegratedGradients
attr_algo = IntegratedGradients(model)
input = torch.rand(1, 3)
attributions = attr_algo.attribute(input, target=0)
FEATURE 0
FEATURE 1
FEATURE 2
TARGET 0
TARGET 1
EXPL AINING WITH
INTEGRATED GRADIENTS
from captum.attr import IntegratedGradients
attr_algo = IntegratedGradients(model)
input = torch.rand(1, 3)
attributions = attr_algo.attribute(input, target=0)
FEATURE 0
FEATURE 1
FEATURE 2
TARGET 0
TARGET 1
OUTPUT
attributions: tensor([[-0.41, 0.54, 0.88]])
EXPL AINING WITH
INTEGRATED GRADIENTS
from captum.attr import IntegratedGradients
attr_algo = IntegratedGradients(model)
input = torch.rand(1, 3)
attributions, delta = attr_algo.attribute(input,
target=0,
return_convergence_delta=True)
FEATURE 0
FEATURE 1
FEATURE 2
TARGET 0
TARGET 1
OUTPUT
attributions: tensor([[-0.41, 0.54, 0.88]])
delta: 0.0190
EXPL AINING WITH
INTEGRATED GRADIENTS
from captum.attr import IntegratedGradients
attr_algo = IntegratedGradients(model)
input = torch.rand(1, 3)
baseline = torch.rand(1, 3)
attributions, delta = attr_algo.attribute(input,
target=0,
return_convergence_delta=True,
n_steps=5000,
baselines=baselines)
FEATURE 0
FEATURE 1
FEATURE 2
TARGET 0
TARGET 1
OUTPUT
attributions: tensor([[0.0, 0.88, -2.45]])
convergence delta: 1.5497e-06
ORIGINAL IMAGE ATTRIBUTING* TO DOG ATTRIBUTING* TO CAT
* MATTHEW D ZEILER, ROB FERGUS, OCCLUSION: VISUALIZING AND UNDERSTANDING CONVOLUTIONAL NETWORKS, IN SPRINGER INTERNATIONAL PUBLISHING SWITZERLAND, 2014
VISUALIZATIONS USING RESNET152 MODEL
VISUALIZING
EXPL ANATIONS OF
A TEXT CL ASSIFICATION
MODEL USING IMDB
DATASET
WITH
CAPTUM INSIGHTS
VISUALIZING
EXPL ANATIONS OF
MULTIMODAL VQA
MODELS
WITH
CAPTUM INSIGHTS
VISUALIZING
EXPL ANATIONS OF
A 3-L AYER MLP MODEL
USING TITANIC DATASET
WITH
CAPTUM INSIGHTS
CASE STUDY FOR BERT MODELS
EXPL AINING BERT MODELS
+ Fine-tuning BERT model for Question Answering on SQUAD dataset
+ Evaluating on Dev Set
Exact Match: 78%
F1-Score: 86%
+ Understanding the importance of different types of word tokens, layers and neurons
+ Already existing research in understanding and visualizing attention heads
+ What Does BERT Look At? An Analysis of BERT's Attention, Clark, et. al. 2019, BlackBoxNLP@ACL
+ ExBERT: A Visual Analysis Tool to Explore Learned Representations in Transformers Models, Hoover, et. al., 2019,
EXPL AINING BERT MODELS FOR QUESTION ANSWERING
text = 'It is important to us to include, empower and support humans of all kinds.'
question = 'What is important to us?'
[CLS]
tokens
what [SEP]to isimportant ?is us it important to us
to include em, and support humans of all kinds .##power
P(Start Position) = 0.72 P(End Position) = 0.73
[SEP]
# explaining layers
for i in range(model.config.num_hidden_layers):
lc = LayerConductance(squad_pos_forward_func,
model.bert.encoder.layer[i])
layer_attributions_start = lc.attribute(
input_embed, baselines=ref_emb, ..., 0))
layer_attributions_end = lc.attribute(
input_embed, baselines=ref_emb, ..., 1))
EXPL AINING BERT MODELS FOR
QUESTION ANSWERING
AT TRIBUTION HEAT MAP OF ALL TOKENS ACROSS ALL 12 BERT L AYERS FOR START POSITION
PREDICTION
AT TRIBUTION HEAT MAP OF ALL TOKENS ACROSS ALL 12 BERT L AYERS FOR END POSITION
PREDICTION
THE LIMITATIONS OF AT TRIBUTIONS
+ Attributions do not capture feature correlations and interactions
+ Finding good baselines is challenging
+ They are difficult to evaluate
+ Attributions do not explain the model globally
FUTURE DIRECTIONS
+ captum.robust
+ adversarial robustness and attacks
+ studying the connections between
model robustness and interpretability
+ captum.metrics
+ model interpretability, sensitivity, trust, infidelity
and robustness related metrics
+ captum.benchmarks
+ benchmarks for different datasets and methodologies
+ sanity checks
+ captum.optim
+ optimization-based visualizations
...
S E C U R E & P R I V A C Y
P R E S E R V I N G A I
IS IT POSSIBLE TO:
answer questions using
data we cannot see?
What do handwritten

digits look like?
◆ Step 1: Download data
◆ Step 2: Download SOTA training script
◆ Step 3: Run script.
Source: Wikipedia Commons
What do tumors
look like in humans?
◆ Step -1: Persuade a VC.
◆ Step 0: Buy a dataset from a hospital.
◆ Step 1: Download millions of tumor images.
Getting access to
private data is HARD!
We SOLVE tasks which
are accessible:
✓ ImageNet
✓ MNIST
✓ CIFAR-10
✓ Librispeech
✓ WikiText-103
✓ WMT
◆ Cancer
◆ Alzheimers
◆ Dementia
◆ Depression
◆ Anxiety
◆ … Covid-19 Cure?
… but what about?
TOOLS
+ Remote Execution
+ OpenMined PySyft
+ Search and Example Data
+ OpenMined PyGrid
+ Differential Privacy
+ OpenMined PyDP
+ Secure Multi-Party Communication
+ CrypTen.ai
INTRODUCING
CRYPTEN import crypten
import torch
crypten.init() # sets up communication
x = torch.tensor([1.0, 2.0, 3.0])
x_enc = crypten.cryptensor(x) # encrypts tensor
x_dec = x_enc.get_plain_text() # decrypts tensor
assert torch.all_close(x_dec, x) # this passes!
y_enc = crypten.cryptensor([2.0, 3.0, 4.0])
xy_enc = x_enc + y_enc # adds encrypted tensors
xy_dec = xy_enc.get_plain_text()
assert torch.all_close(xy_dec, x + y) # this passes!
z = torch.tensor([4.0, 5.0, 6.0])
xz_enc = x_enc + z # adds FloatTensor to CrypTensor
xz_dec = xz_enc.get_plain_text()
assert torch.all_close(xz_dec, x + z) # this passes!
K E Y F E AT U R E S :
• Tensors and CrypTensors coexist and can be mixed
and matched
• Uses standard eager execution — No compilers! Easy
debugging and learning
• Support for Secure multi-party computation (MPC)
A platform for research in machine learning using
secure-computation techniques
B
HELLO
CRYPTENSOR
1. CrypTensor wraps an implementation that does:
1. Arithmetic secret sharing.
2. XOR secret sharing.
3. Conversions between both secret sharings.
4. A large number of operations.
2. CrypTensor exposes these via a PyTorch-like API.
PyTorch LongTensor
Binary (XOR) Sharing
CrypTensor
Arithmetic Sharing
Trusted Party
Numerical Library
Secure Computation Primitives
Secure Computation Protocol
Protocol-Independent Layer
uses
abstracts
uses
AutogradCrypTensor
MPCTensor
B2A/A2B
Conversion
uses
Automatic di erentiation
User-level code Neural networks, etc.
uses
Parties
1. Make a CrypTen Model.
2. Encrypt Data
3. Train!
ENCRYPTED TRAINING
import crypten
crypten.init() # sets up communication
class LogisticRegression(crypten.nn.Module):
def __init__(self):
super().__init__()
self.linear = crypten.nn.Linear(28 * 28, 10)
def forward(self, x):
return self.linear(x)
model = LogisticRegression().encrypt() # encrypts tensor
1. Join Encrypted Data
2. Encrypt Model
3. Train!
Training Across Par ties
import crypten
crypten.init() # sets up communication
alice_images_enc = crypten.load("/tmp/data/alice_images.pth", src=ALICE)
bob_labels_enc = crypten.load("/tmp/data/bob_labels.pth", src=BOB)
model = LogisticRegression().encrypt()
train_model(model, alice_images_enc, bob_labels_enc)
1. Create a PyTorch or ONNX model.
2. Import model into CrypTen.
3. All computations are now encrypted.
PY TORCH / ONNX
INTEGRATION
import torchvision.datasets as datasets
import torchvision.models as models
# download and set up ImageNet dataset:
transform = transforms.ToTensor()
dataset = datasets.ImageNet(
imagenet_folder,
transform=transform,
)
# download pre-trained ResNet-18 model and encrypt it:
model = models.resnet18(pretrained=True)
encrypted_model = crypten.nn.from_pytorch(
model, dataset[0],
)
# do inference on encrypted images with encrypted model:
encrypted_image = crypten.cryptensor(dataset[1])
encrypted_output = encrypted_model(encrypted_image)
output = encrypted_output.get_plain_text() # this works
USE CASES
+ COVID-19 Sols
+ Cancer Research
+ Integrity (eg PhotoDNA project)
+ Federated AI across Enterprise Silos
+ What problems will you solve?
• Captum: https://captum.ai/
• Captum Blog: https://bit.ly/2vHBxJI
• Captum Algorithms Matrix: https://captum.ai/docs/algorithms_comparison_matrix
• Interpreting MultiModal models: https://captum.ai/tutorials/Multimodal_VQA_Interpret
• Interpretable ML Book: https://christophm.github.io/interpretable-ml-book/
• Crypten: https://crypten.ai/
• CrypTen Tutorials: https://github.com/facebookresearch/CrypTen#how-crypten-works
• OpenMined: https://www.openmined.org/
• OpenMined for Covid-19 Apps: https://blog.openmined.org/providing-opensource-privacy-for-covid19/
• Udacity Course: https://www.udacity.com/course/secure-and-private-ai--ud185
• Active Federated Learning Paper: https://arxiv.org/pdf/1909.12641.pdf
• Microsoft PhotoDNA Project: https://www.microsoft.com/en-us/photodna
REFERENCES
QUESTIONS?
Contact:
Email: gchauhan@fb.com
Linkedin: https://www.linkedin.com/in/geetachauhan/

More Related Content

PDF
Báo cáo thực tập công nghệ thông tin.
DOCX
Danh Sách 200 Đề Tài Báo Cáo Thực Tập Khoa Học Máy Tính Chọn Lọc
PDF
Đề tài: Tìm hiểu ngôn ngữ C# và viết một ứng dụng minh họa, HAY
PDF
Đề tài: Quản lý cửa hàng vật liệu xây dựng, HAY, 9đ
PDF
Đề thi Kỹ thuật lập trình có lời giải
PDF
Đề tài: Nhận dạng đối tượng sử dụng thuật toán AdaBoost, HOT
PDF
Intepretability / Explainable AI for Deep Neural Networks
ODP
Neo4j
Báo cáo thực tập công nghệ thông tin.
Danh Sách 200 Đề Tài Báo Cáo Thực Tập Khoa Học Máy Tính Chọn Lọc
Đề tài: Tìm hiểu ngôn ngữ C# và viết một ứng dụng minh họa, HAY
Đề tài: Quản lý cửa hàng vật liệu xây dựng, HAY, 9đ
Đề thi Kỹ thuật lập trình có lời giải
Đề tài: Nhận dạng đối tượng sử dụng thuật toán AdaBoost, HOT
Intepretability / Explainable AI for Deep Neural Networks
Neo4j

What's hot (20)

DOC
Bao cao thuc tap nghành điều khiển tự động k44ddk
DOCX
Danh sách 200 đề tài luận văn thạc sĩ khoa học máy tính, 9 điểm
PDF
Machine Learning Interpretability / Explainability
PDF
Đề cương xử lý ảnh
PDF
Thực trạng dạy và học môn vật lý trong trường thcs hiện nay, nguyên nhân và g...
DOC
luan van thac si giam sat nhiet do am va dieu khien thiet bi dien qua internet
PDF
Khóa luận nghiên cứu bài toán phân tích cảm xúc của người hùng 9166421
PDF
Luận văn: Nhận dạng và phân loại hoa quả trong ảnh màu, HAY
PDF
phân tích thiết kế hệ thống thông tin
PPT
Chg4 tham lam
PDF
Đề tài: Thiết kế mạch tự động đóng mở cửa tự động, HAY
PDF
Bài Giảng Vi Xử Lý PIT
PPTX
Thuyet trinh vat li
DOCX
Đề Tài Tốt Nghiệp Nghiên Cứu Các Kỹ Thuật Của Iot Và Các Ứng Dụng Của Nó Cho ...
PDF
Chuong 04 mach logic
DOCX
KHO DỮ LIỆU VÀ KHAI PHÁ DỮ LIỆU PTIT
PDF
Luận văn: Phương pháp tấn công chữ ký số: Rsa,Elgamal,Dss
PPTX
Introduction to Interpretable Machine Learning
PPT
Slide đồ án tốt nghiệp
PDF
Xử lý ảnh PTIT
Bao cao thuc tap nghành điều khiển tự động k44ddk
Danh sách 200 đề tài luận văn thạc sĩ khoa học máy tính, 9 điểm
Machine Learning Interpretability / Explainability
Đề cương xử lý ảnh
Thực trạng dạy và học môn vật lý trong trường thcs hiện nay, nguyên nhân và g...
luan van thac si giam sat nhiet do am va dieu khien thiet bi dien qua internet
Khóa luận nghiên cứu bài toán phân tích cảm xúc của người hùng 9166421
Luận văn: Nhận dạng và phân loại hoa quả trong ảnh màu, HAY
phân tích thiết kế hệ thống thông tin
Chg4 tham lam
Đề tài: Thiết kế mạch tự động đóng mở cửa tự động, HAY
Bài Giảng Vi Xử Lý PIT
Thuyet trinh vat li
Đề Tài Tốt Nghiệp Nghiên Cứu Các Kỹ Thuật Của Iot Và Các Ứng Dụng Của Nó Cho ...
Chuong 04 mach logic
KHO DỮ LIỆU VÀ KHAI PHÁ DỮ LIỆU PTIT
Luận văn: Phương pháp tấn công chữ ký số: Rsa,Elgamal,Dss
Introduction to Interpretable Machine Learning
Slide đồ án tốt nghiệp
Xử lý ảnh PTIT
Ad

Similar to Building Interpretable & Secure AI Systems using PyTorch (20)

PDF
Pycon tati gabru
PDF
OpenPOWER Workshop in Silicon Valley
PDF
Getting Started with Keras and TensorFlow - StampedeCon AI Summit 2017
PPTX
Demystifying-AI-Frameworks-TensorFlow-PyTorch-JAX-and-More (1).pptx
PDF
Pytorch meetup
PDF
TensorFlow example for AI Ukraine2016
PDF
Deep-Learning-with-PydddddddddddddTorch.pdf
PDF
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...
PDF
Pytorch A Detailed Overview Agladze Mikhail
PDF
機械学習モデルの判断根拠の説明
PDF
Icpp power ai-workshop 2018
PDF
Deep Learning Tutorial | Deep Learning Tutorial for Beginners | Neural Networ...
PPTX
Soumith Chintala - Increasing the Impact of AI Through Better Software
PPTX
Introduction to Deep Learning, Keras, and Tensorflow
PDF
Introduction to Deep Learning, Keras, and TensorFlow
PDF
Intro to TensorFlow and PyTorch Workshop at Tubular Labs
PPTX
TensorFlow in Your Browser
PDF
Tensorflow 2.0 and Coral Edge TPU
PDF
pytorch-cheatsheet.pdf for ML study with pythroch
PPTX
Deep Learning in Your Browser
Pycon tati gabru
OpenPOWER Workshop in Silicon Valley
Getting Started with Keras and TensorFlow - StampedeCon AI Summit 2017
Demystifying-AI-Frameworks-TensorFlow-PyTorch-JAX-and-More (1).pptx
Pytorch meetup
TensorFlow example for AI Ukraine2016
Deep-Learning-with-PydddddddddddddTorch.pdf
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...
Pytorch A Detailed Overview Agladze Mikhail
機械学習モデルの判断根拠の説明
Icpp power ai-workshop 2018
Deep Learning Tutorial | Deep Learning Tutorial for Beginners | Neural Networ...
Soumith Chintala - Increasing the Impact of AI Through Better Software
Introduction to Deep Learning, Keras, and Tensorflow
Introduction to Deep Learning, Keras, and TensorFlow
Intro to TensorFlow and PyTorch Workshop at Tubular Labs
TensorFlow in Your Browser
Tensorflow 2.0 and Coral Edge TPU
pytorch-cheatsheet.pdf for ML study with pythroch
Deep Learning in Your Browser
Ad

More from geetachauhan (20)

PDF
Profiling PyTorch for Efficiency & Sustainability
PDF
Building AI with Security Privacy in Mind
PDF
Building AI with Security and Privacy in mind
PDF
Scaling AI in production using PyTorch
PDF
Future is private intel dev fest
PDF
Decentralized AI Draper
PDF
Decentralized AI: Convergence of AI + Blockchain
PDF
Decentralized AI: Convergence of Blockchain + AI
PDF
Decentralized AI: Convergence of Blockchain + AI
PDF
Deep learning for medical imaging
PDF
Deep learning for FinTech
PDF
NIPS - Deep learning @ Edge using Intel's NCS
PDF
Best Practices for On-Demand HPC in Enterprises
PDF
Deep learning @ Edge using Intel's Neural Compute Stick
PDF
Distributed deep learning optimizations for Finance
PDF
Distributed deep learning optimizations - AI WithTheBest
PDF
Distributed deep learning optimizations
PDF
Tensorflow IoT - 1 Wk coding challenge
PDF
Intel optimized tensorflow, distributed deep learning
PDF
Transfer learning for IoT
Profiling PyTorch for Efficiency & Sustainability
Building AI with Security Privacy in Mind
Building AI with Security and Privacy in mind
Scaling AI in production using PyTorch
Future is private intel dev fest
Decentralized AI Draper
Decentralized AI: Convergence of AI + Blockchain
Decentralized AI: Convergence of Blockchain + AI
Decentralized AI: Convergence of Blockchain + AI
Deep learning for medical imaging
Deep learning for FinTech
NIPS - Deep learning @ Edge using Intel's NCS
Best Practices for On-Demand HPC in Enterprises
Deep learning @ Edge using Intel's Neural Compute Stick
Distributed deep learning optimizations for Finance
Distributed deep learning optimizations - AI WithTheBest
Distributed deep learning optimizations
Tensorflow IoT - 1 Wk coding challenge
Intel optimized tensorflow, distributed deep learning
Transfer learning for IoT

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Encapsulation theory and applications.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPT
Teaching material agriculture food technology
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Machine learning based COVID-19 study performance prediction
PDF
Modernizing your data center with Dell and AMD
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Big Data Technologies - Introduction.pptx
Network Security Unit 5.pdf for BCA BBA.
Encapsulation theory and applications.pdf
Review of recent advances in non-invasive hemoglobin estimation
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Teaching material agriculture food technology
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Machine learning based COVID-19 study performance prediction
Modernizing your data center with Dell and AMD
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
NewMind AI Monthly Chronicles - July 2025
Understanding_Digital_Forensics_Presentation.pptx
Spectral efficient network and resource selection model in 5G networks
Encapsulation_ Review paper, used for researhc scholars
NewMind AI Weekly Chronicles - August'25 Week I
Per capita expenditure prediction using model stacking based on satellite ima...
“AI and Expert System Decision Support & Business Intelligence Systems”
Big Data Technologies - Introduction.pptx

Building Interpretable & Secure AI Systems using PyTorch

  • 1. BUILDING INTERPRETABLE & SECURE AI SYSTEMS USING PYTORCH GEETA CHAUHAN AI PARTNER ENGINEERING FACEBOOK AI
  • 2. AGENDA 01 INTERPRETABLE AI 02 SECURE & PRIVACY PRESERVING AI 03 REFERENCES
  • 3. I N T E R P R E T A B I L I T Y
  • 4. WHAT IS MODEL INTERPRETABILIT Y ? “THE ABILIT Y TO DESCRIBE AI MODEL INTERNALS AND PREDICTIONS IN HUMAN UNDERSTANDABLE TERMS*” * LH Gilpin, et. al., Explaining explanations: An overview of interpretability of machine learning in IEEE 5th International Conference on data science and advanced analytics (DSAA), 2018
  • 5. I N C R E A S E D T R A N S P A R E N C Y D E B U G G I N GB E T T E R U N D E R S TA N D I N G MODEL INTERPRETABILIT Y Screenshot of the tool Attributing to dog Attribution Magnitudes
  • 6. MODEL INTERPRETABILIT Y LIBRARY FOR PY TORCH M U LT I M O D A L E A S Y T O U S EE X T E N S I B L E class MyAttribution(Attribution): def attribute(self, input, ...): attributions = self._compute_attrs(input, ... ) # <Add any logic necessary for attribution> return attributions visualize_image_attr(attr_algo.attribute(input), ...) captum.ai
  • 7. GradientSHAP DeepLiftSHAP SHAP Methods Integrated Gradients Saliency GuidedGradCam Attribute model output (or internal neurons) to input features LayerGradientSHAP LayerDeepLiftSHAP SHAP Methods LayerConductance InternalInfluence GradCam Attribute model output to the layers of the model DeepLift NoiseTunnel (Smoothgrad, Vargrad, Smoothgrad Square) LayerActivation LayerGradientXActivationLayerDeepLiftFeatureAblation / FeaturePermutation GuidedBackprop / Deconvolution AT TRIBUTION ALGORITHMS Input * Gradient LayerFeatureAblation LayerIntegratedGradients Occlusion Shapely Value Sampling Gradient Perturbation Other
  • 8. attributions = Attribution(forward_func, ...).attribute(inputs, ...)* * Check out our Getting Started docs and API: https://github.com/pytorch/captum https://captum.ai/api/ GradientAttribution PerturbationAttribution IntegratedGradients FeatureAblation ... ...
  • 9. attributions = Attribution(forward_func, ...).attribute(inputs, ...)* * Check out our Getting Started docs and API: https://github.com/pytorch/captum https://captum.ai/api/ the importance of inputs to forward_func model's forward function or any modification of it
  • 10. EXPL AINING WITH INTEGRATED GRADIENTS FEATURE 0 FEATURE 1 FEATURE 2 TARGET 0 TARGET 1 from captum.attr import IntegratedGradients attr_algo = IntegratedGradients(model) input = torch.rand(1, 3) attributions = attr_algo.attribute(input, target=0)
  • 11. EXPL AINING WITH INTEGRATED GRADIENTS from captum.attr import IntegratedGradients attr_algo = IntegratedGradients(model) input = torch.rand(1, 3) attributions = attr_algo.attribute(input, target=0) FEATURE 0 FEATURE 1 FEATURE 2 TARGET 0 TARGET 1
  • 12. EXPL AINING WITH INTEGRATED GRADIENTS from captum.attr import IntegratedGradients attr_algo = IntegratedGradients(model) input = torch.rand(1, 3) attributions = attr_algo.attribute(input, target=0) FEATURE 0 FEATURE 1 FEATURE 2 TARGET 0 TARGET 1 OUTPUT attributions: tensor([[-0.41, 0.54, 0.88]])
  • 13. EXPL AINING WITH INTEGRATED GRADIENTS from captum.attr import IntegratedGradients attr_algo = IntegratedGradients(model) input = torch.rand(1, 3) attributions, delta = attr_algo.attribute(input, target=0, return_convergence_delta=True) FEATURE 0 FEATURE 1 FEATURE 2 TARGET 0 TARGET 1 OUTPUT attributions: tensor([[-0.41, 0.54, 0.88]]) delta: 0.0190
  • 14. EXPL AINING WITH INTEGRATED GRADIENTS from captum.attr import IntegratedGradients attr_algo = IntegratedGradients(model) input = torch.rand(1, 3) baseline = torch.rand(1, 3) attributions, delta = attr_algo.attribute(input, target=0, return_convergence_delta=True, n_steps=5000, baselines=baselines) FEATURE 0 FEATURE 1 FEATURE 2 TARGET 0 TARGET 1 OUTPUT attributions: tensor([[0.0, 0.88, -2.45]]) convergence delta: 1.5497e-06
  • 15. ORIGINAL IMAGE ATTRIBUTING* TO DOG ATTRIBUTING* TO CAT * MATTHEW D ZEILER, ROB FERGUS, OCCLUSION: VISUALIZING AND UNDERSTANDING CONVOLUTIONAL NETWORKS, IN SPRINGER INTERNATIONAL PUBLISHING SWITZERLAND, 2014 VISUALIZATIONS USING RESNET152 MODEL
  • 16. VISUALIZING EXPL ANATIONS OF A TEXT CL ASSIFICATION MODEL USING IMDB DATASET WITH CAPTUM INSIGHTS
  • 17. VISUALIZING EXPL ANATIONS OF MULTIMODAL VQA MODELS WITH CAPTUM INSIGHTS
  • 18. VISUALIZING EXPL ANATIONS OF A 3-L AYER MLP MODEL USING TITANIC DATASET WITH CAPTUM INSIGHTS
  • 19. CASE STUDY FOR BERT MODELS
  • 20. EXPL AINING BERT MODELS + Fine-tuning BERT model for Question Answering on SQUAD dataset + Evaluating on Dev Set Exact Match: 78% F1-Score: 86% + Understanding the importance of different types of word tokens, layers and neurons + Already existing research in understanding and visualizing attention heads + What Does BERT Look At? An Analysis of BERT's Attention, Clark, et. al. 2019, BlackBoxNLP@ACL + ExBERT: A Visual Analysis Tool to Explore Learned Representations in Transformers Models, Hoover, et. al., 2019,
  • 21. EXPL AINING BERT MODELS FOR QUESTION ANSWERING text = 'It is important to us to include, empower and support humans of all kinds.' question = 'What is important to us?' [CLS] tokens what [SEP]to isimportant ?is us it important to us to include em, and support humans of all kinds .##power P(Start Position) = 0.72 P(End Position) = 0.73 [SEP]
  • 22. # explaining layers for i in range(model.config.num_hidden_layers): lc = LayerConductance(squad_pos_forward_func, model.bert.encoder.layer[i]) layer_attributions_start = lc.attribute( input_embed, baselines=ref_emb, ..., 0)) layer_attributions_end = lc.attribute( input_embed, baselines=ref_emb, ..., 1)) EXPL AINING BERT MODELS FOR QUESTION ANSWERING
  • 23. AT TRIBUTION HEAT MAP OF ALL TOKENS ACROSS ALL 12 BERT L AYERS FOR START POSITION PREDICTION
  • 24. AT TRIBUTION HEAT MAP OF ALL TOKENS ACROSS ALL 12 BERT L AYERS FOR END POSITION PREDICTION
  • 25. THE LIMITATIONS OF AT TRIBUTIONS + Attributions do not capture feature correlations and interactions + Finding good baselines is challenging + They are difficult to evaluate + Attributions do not explain the model globally
  • 26. FUTURE DIRECTIONS + captum.robust + adversarial robustness and attacks + studying the connections between model robustness and interpretability + captum.metrics + model interpretability, sensitivity, trust, infidelity and robustness related metrics + captum.benchmarks + benchmarks for different datasets and methodologies + sanity checks + captum.optim + optimization-based visualizations ...
  • 27. S E C U R E & P R I V A C Y P R E S E R V I N G A I
  • 28. IS IT POSSIBLE TO: answer questions using data we cannot see?
  • 29. What do handwritten
 digits look like? ◆ Step 1: Download data ◆ Step 2: Download SOTA training script ◆ Step 3: Run script.
  • 30. Source: Wikipedia Commons What do tumors look like in humans? ◆ Step -1: Persuade a VC. ◆ Step 0: Buy a dataset from a hospital. ◆ Step 1: Download millions of tumor images.
  • 31. Getting access to private data is HARD!
  • 32. We SOLVE tasks which are accessible: ✓ ImageNet ✓ MNIST ✓ CIFAR-10 ✓ Librispeech ✓ WikiText-103 ✓ WMT ◆ Cancer ◆ Alzheimers ◆ Dementia ◆ Depression ◆ Anxiety ◆ … Covid-19 Cure? … but what about?
  • 33. TOOLS + Remote Execution + OpenMined PySyft + Search and Example Data + OpenMined PyGrid + Differential Privacy + OpenMined PyDP + Secure Multi-Party Communication + CrypTen.ai
  • 35. CRYPTEN import crypten import torch crypten.init() # sets up communication x = torch.tensor([1.0, 2.0, 3.0]) x_enc = crypten.cryptensor(x) # encrypts tensor x_dec = x_enc.get_plain_text() # decrypts tensor assert torch.all_close(x_dec, x) # this passes! y_enc = crypten.cryptensor([2.0, 3.0, 4.0]) xy_enc = x_enc + y_enc # adds encrypted tensors xy_dec = xy_enc.get_plain_text() assert torch.all_close(xy_dec, x + y) # this passes! z = torch.tensor([4.0, 5.0, 6.0]) xz_enc = x_enc + z # adds FloatTensor to CrypTensor xz_dec = xz_enc.get_plain_text() assert torch.all_close(xz_dec, x + z) # this passes! K E Y F E AT U R E S : • Tensors and CrypTensors coexist and can be mixed and matched • Uses standard eager execution — No compilers! Easy debugging and learning • Support for Secure multi-party computation (MPC) A platform for research in machine learning using secure-computation techniques
  • 36. B
  • 37. HELLO CRYPTENSOR 1. CrypTensor wraps an implementation that does: 1. Arithmetic secret sharing. 2. XOR secret sharing. 3. Conversions between both secret sharings. 4. A large number of operations. 2. CrypTensor exposes these via a PyTorch-like API. PyTorch LongTensor Binary (XOR) Sharing CrypTensor Arithmetic Sharing Trusted Party Numerical Library Secure Computation Primitives Secure Computation Protocol Protocol-Independent Layer uses abstracts uses AutogradCrypTensor MPCTensor B2A/A2B Conversion uses Automatic di erentiation User-level code Neural networks, etc. uses Parties
  • 38. 1. Make a CrypTen Model. 2. Encrypt Data 3. Train! ENCRYPTED TRAINING import crypten crypten.init() # sets up communication class LogisticRegression(crypten.nn.Module): def __init__(self): super().__init__() self.linear = crypten.nn.Linear(28 * 28, 10) def forward(self, x): return self.linear(x) model = LogisticRegression().encrypt() # encrypts tensor
  • 39. 1. Join Encrypted Data 2. Encrypt Model 3. Train! Training Across Par ties import crypten crypten.init() # sets up communication alice_images_enc = crypten.load("/tmp/data/alice_images.pth", src=ALICE) bob_labels_enc = crypten.load("/tmp/data/bob_labels.pth", src=BOB) model = LogisticRegression().encrypt() train_model(model, alice_images_enc, bob_labels_enc)
  • 40. 1. Create a PyTorch or ONNX model. 2. Import model into CrypTen. 3. All computations are now encrypted. PY TORCH / ONNX INTEGRATION import torchvision.datasets as datasets import torchvision.models as models # download and set up ImageNet dataset: transform = transforms.ToTensor() dataset = datasets.ImageNet( imagenet_folder, transform=transform, ) # download pre-trained ResNet-18 model and encrypt it: model = models.resnet18(pretrained=True) encrypted_model = crypten.nn.from_pytorch( model, dataset[0], ) # do inference on encrypted images with encrypted model: encrypted_image = crypten.cryptensor(dataset[1]) encrypted_output = encrypted_model(encrypted_image) output = encrypted_output.get_plain_text() # this works
  • 41. USE CASES + COVID-19 Sols + Cancer Research + Integrity (eg PhotoDNA project) + Federated AI across Enterprise Silos + What problems will you solve?
  • 42. • Captum: https://captum.ai/ • Captum Blog: https://bit.ly/2vHBxJI • Captum Algorithms Matrix: https://captum.ai/docs/algorithms_comparison_matrix • Interpreting MultiModal models: https://captum.ai/tutorials/Multimodal_VQA_Interpret • Interpretable ML Book: https://christophm.github.io/interpretable-ml-book/ • Crypten: https://crypten.ai/ • CrypTen Tutorials: https://github.com/facebookresearch/CrypTen#how-crypten-works • OpenMined: https://www.openmined.org/ • OpenMined for Covid-19 Apps: https://blog.openmined.org/providing-opensource-privacy-for-covid19/ • Udacity Course: https://www.udacity.com/course/secure-and-private-ai--ud185 • Active Federated Learning Paper: https://arxiv.org/pdf/1909.12641.pdf • Microsoft PhotoDNA Project: https://www.microsoft.com/en-us/photodna REFERENCES