The Wayback Machine - https://web.archive.org/web/20240910222748/https://www.geeksforgeeks.org/differential-privacy-and-deep-learning/
Open In App

Differential Privacy and Deep Learning

Last Updated : 02 Mar, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Differential privacy is a new topic in the field of deep learning. It is about ensuring that when our neural networks are learning from sensitive data, they’re only learning what they’re supposed to learn from the data.

Differential privacy is a concept in privacy-preserving data analysis that aims to protect the privacy of individuals while still allowing useful insights to be gleaned from the data. It is particularly relevant in the context of deep learning, where large amounts of sensitive data may be used to train models. Here are some ways that differential privacy can be used in deep learning:

Adding noise to data: One common approach to achieving differential privacy in deep learning is to add noise to the data during training. This can help ensure that the model does not overfit to specific individuals or sensitive information in the data. Various techniques, such as the Laplace mechanism or the Gaussian mechanism, can be used to add noise to the training data.

Using private aggregation of teacher ensembles (PATE): PATE is a framework for training machine learning models with differential privacy, which is particularly useful in the context of deep learning. PATE involves training multiple “teacher” models on disjoint subsets of the data, and then using these models to generate “noisy labels” for the training data. A final “student” model is then trained on the noisy labels, which helps ensure differential privacy.

Federated learning: Federated learning is an approach to deep learning where the training data remains on the user’s device, and only the model parameters are sent to a central server for aggregation. This can help protect user privacy, as the raw data never leaves the user’s device. Differential privacy can be used to add an additional layer of protection to federated learning, by ensuring that the aggregation of model updates does not leak sensitive information about the user’s data.

Some potential advantages of using differential privacy in deep learning include improved privacy, increased trust in the model, and increased fairness. However, there are also some potential disadvantages, such as increased computational complexity and decreased accuracy. It is important to carefully consider the trade-offs and design appropriate differential privacy mechanisms for specific use cases
Robust definition of privacy proposed by Cynthia Dwork (from her book Algorithmic Foundations):

“Differential Privacy” describes a promise, made by a data holder, or curator, to a data subject, and the promise is like this: “You will not be affected, adversely or otherwise, by allowing your data to be used in any study or analysis, no matter what other studies, data sets, or information sources, are available.”

The general goal of differential privacy is to ensure that different kind of statistical analysis doesn’t compromise privacy and privacy is preserved if, after the analysis, the analyzer doesn’t know anything about the features in data-set, that means Information which has been made public elsewhere isn’t harmful to an individual. 
To define privacy in the context of a simple database, we’re performing some queries against the database and if we remove a person from the database and the query doesn’t change then that person’s privacy would be fully protected.

Let us Understand With An Example 

Given a database, which contains some numbers ‘1’ and ‘0’ which is some sensitive data like if an individual has some kind of disease or not (maybe patients don’t want to reveal this data). 

  db = [1, 0, 1, 1, 0, 1, 0, 1, 0, 0]

And now, you have your databases with one of each entry removed, which are called parallel DBS. so there are ‘n’ number of parallel DBS if the length of original DB is ‘n’, in our case it’s 10. Now, we consider one of parallel DBS, let’s take the first one in which the first individual is removed and what do we get?

pdbs[0] = [0, 1, 1, 0, 1, 0, 1, 0, 0]

So you see that now this database has length ‘n-1’. So to calculate sensitivity we need a query function so, we assume the simplest ‘sum’. So we now focus on two results:  

 sum(db) = 5
 sum(pdbs[0]) = 4

And the difference between the above two is ‘1’ and we know that we need to find the maximum of all these differences, since this DB only contains ‘1’ and ‘0’ all those differences will either be ‘1’ (when similar like above, when 1 is removed) or ‘0’ (when 0 is removed). 
Therefore, we get our sensitivity for this example as ‘1’ and this is really high value and therefore differencing attacks can be easily done using this ‘sum’ query. 

The sensitivity should be below so that it gives a quantitative idea of what level of differencing attacks can reveal info/leak privacy.

Implementing the code for Differential Privacy in Python:

Python3




import torch
 
# the number of entries in our database
num_entries = 5000
 
db = torch.rand(num_entries) > 0.5
 
# generating parallel databases
 
 
def get_parallel_db(db, remove_index):
 
    return torch.cat((db[0:remove_index],
                      db[remove_index+1:]))
 
 
get_parallel_db(db, 52352)
 
 
def get_parallel_dbs(db):
 
    parallel_dbs = list()
 
    for i in range(len(db)):
        pdb = get_parallel_db(db, i)
        parallel_dbs.append(pdb)
 
    return parallel_dbs
 
 
pdbs = get_parallel_dbs(db)
 
# Creating linear and parallel databases
 
 
def create_db_and_parallels(num_entries):
 
    db = torch.rand(num_entries) > 0.5
    pdbs = get_parallel_dbs(db)
 
    return db, pdbs
 
 
db, pdbs = create_db_and_parallels(2000)
 
# Creating sensitivity function
 
 
def sensitivity(query, n_entries=1000):
 
    db, pdbs = create_db_and_parallels(n_entries)
 
    full_db_result = query(db)
 
    max_distance = 0
    for pdb in pdbs:
        pdb_result = query(pdb)
 
        db_distance = torch.abs(pdb_result - full_db_result)
 
        if(db_distance > max_distance):
            max_distance = db_distance
 
    return max_distance
 
# query our database and evaluate whether or not the result of the
# query is leaking "private" information
 
 
def query(db):
    return db.float().mean()
 
 
sensitivity(query)


Input : A randomly generated database(with the help of torch library) 
Output : tensor(0.0005)

Explanation: First of all, we create a random database with the help of the torch library then we defined two functions get_parallel_db and get_parallel_dbs for linear and parallel databases. Now we defined the sensitivity function then we measured the difference between each parallel DB’s query result and the query result for the entire database and then calculated the max value (which was 1). This value is called “sensitivity”.



Similar Reads

Deep Belief Network (DBN) in Deep Learning
Discover data creation with Deep Belief Networks (DBNs), cutting-edge generative models that make use of deep architecture. This article walks you through the concepts of DBNs, how they work, and how to implement them using practical coding. What is a Deep Belief Network?Deep Belief Networks (DBNs) are sophisticated artificial neural networks used
9 min read
Deep Boltzmann Machines (DBMs) in Deep Learning
In this article, we will discuss the Deep Boltzmann Machines concepts and their applications in the real-world scenario. What are Deep Boltzmann Machines (DBMs)?Deep Boltzmann Machines (DBMs) are a kind of artificial neural network that belongs to the family of generative models. They are designed to discover intricate structures within large datas
10 min read
Unveiling the Power of Fastai: A Deep Dive into the Versatile Deep Learning Library
Fastai is a powerful deep-learning library designed for researchers and practitioners. It offers high-level abstractions, PyTorch integration, and application-specific APIs, making it both adaptable and accessible for a wide range of deep learning tasks. In this article, we'll delve into the intricacies of Fastai, a powerful deep-learning library.
9 min read
Need of Data Structures and Algorithms for Deep Learning and Machine Learning
Deep Learning is a field that is heavily based on Mathematics and you need to have a good understanding of Data Structures and Algorithms to solve the mathematical problems optimally. Data Structures and Algorithms can be used to determine how a problem is represented internally or how the actual storage pattern works & what is happening under
6 min read
Partial differential equations (PDEs) in Deep Larning
Partial Differential Equations (PDEs) are fundamental in modeling various phenomena in science and engineering, ranging from fluid dynamics to heat transfer and quantum mechanics. Traditional numerical methods for solving PDEs, such as the finite difference method, finite element method, and finite volume method, have been effective but often compu
8 min read
Difference Between Machine Learning and Deep Learning
If you are interested in building your career in the IT industry then you must have come across the term Data Science which is a booming field in terms of technologies and job availability as well. In this article, we will explore the Difference between Machine Learning and Deep Learning, two major fields within Data Science. Understanding these di
8 min read
Introduction to Multi-Task Learning(MTL) for Deep Learning
Multi-Task Learning (MTL) is a type of machine learning technique where a model is trained to perform multiple tasks simultaneously. In deep learning, MTL refers to training a neural network to perform multiple tasks by sharing some of the network's layers and parameters across tasks. In MTL, the goal is to improve the generalization performance of
6 min read
Artificial intelligence vs Machine Learning vs Deep Learning
Nowadays many misconceptions are there related to the words machine learning, deep learning, and artificial intelligence (AI), most people think all these things are the same whenever they hear the word AI, they directly relate that word to machine learning or vice versa, well yes, these things are related to each other but not the same. Let's see
4 min read
Difference Between Artificial Intelligence vs Machine Learning vs Deep Learning
Artificial Intelligence is basically the mechanism to incorporate human intelligence into machines through a set of rules(algorithm). AI is a combination of two words: "Artificial" meaning something made by humans or non-natural things and "Intelligence" meaning the ability to understand or think accordingly. Another definition could be that "AI is
14 min read
Role of Differential calculus in Machine Learning
A subset of artificial intelligence called machine learning has completely changed how we handle challenging issues in a variety of industries. The idea of optimization, which is crucial for building models that can correctly predict events, is at the core of this revolution. This optimization method relies heavily on differential calculus, which e
10 min read
Black and white image colorization with OpenCV and Deep Learning
In this article, we'll create a program to convert a black & white image i.e grayscale image to a colour image. We're going to use the Caffe colourization model for this program. And you should be familiar with basic OpenCV functions and uses like reading an image or how to load a pre-trained model using dnn module etc. Now let's discuss the pr
3 min read
Avengers Endgame and Deep learning | Image Caption Generation using the Avengers EndGames Characters
Behold, Marvel Fans. Avengers are out there to save the Multiverse, so are we, ready to do whatever it takes to support them. In this article, we will use Deep Learning and computer vision for the caption generation of Avengers Endgame characters. We will start will the basics, explaining concepts and use a pre-trained model to implement the projec
14 min read
Difference between a Neural Network and a Deep Learning System
Since their inception in the late 1950s, Artificial Intelligence and Machine Learning have come a long way. These technologies have gotten quite complex and advanced in recent years. While technological advancements in the Data Science domain are commendable, they have resulted in a flood of terminologies that are beyond the understanding of the av
7 min read
Fashion MNIST with Python Keras and Deep Learning
Deep learning is a subfield of machine learning related to artificial neural networks. The word deep means bigger neural networks with a lot of hidden units. Deep learning's CNN's have proved to be the state-of-the-art technique for image recognition tasks. Keras is a deep learning library in Python which provides an interface for creating an artif
6 min read
Advantages and Disadvantages of Deep Learning
Deep learning is a subset of machine learning that uses artificial neural networks (ANNs) to model and solve complex problems. It is based on the idea of building artificial neural networks with multiple layers, called deep neural networks, that can learn hierarchical representations of the data. Deep learning algorithms use a layered architecture,
7 min read
What is the relationship between the accuracy and the loss in deep learning?
Answer: In deep learning, as loss decreases (indicating better model performance on the training data), accuracy typically increases, reflecting improved model predictions on the evaluated data.In deep learning, accuracy and loss are two primary metrics used to evaluate the performance of a model, but they measure different aspects. MetricDescripti
2 min read
Holistically-Nested Edge Detection with OpenCV and Deep Learning
Holistically-nested edge detection (HED) is a deep learning model that uses fully convolutional neural networks and deeply-supervised nets to do image-to-image prediction. HED develops rich hierarchical representations automatically (directed by deep supervision on side replies) that are critical for resolving ambiguity in edge and object boundary
3 min read
Difference between Traditional Computer Vision Techniques and Deep Learning-based Approaches
Computer vision enables machines to interpret and understand the visual world. Over the years, two main approaches have dominated the field: traditional computer vision techniques and deep learning-based approaches. This article delves into the fundamental differences between these two methodologies and how can be answered in the interview. Traditi
5 min read
Architecture and Working of Transformers in Deep Learning
Transformers are a type of deep learning model that utilizes self-attention mechanisms to process and generate sequences of data efficiently, capturing long-range dependencies and contextual relationships. The article aims to discuss the architecture and working of the transformers model in deep learning. Table of Content Transformer Architecture:
9 min read
Vanishing and Exploding Gradients Problems in Deep Learning
In the realm of deep learning, the optimization process plays a crucial role in training neural networks. Gradient descent, a fundamental optimization algorithm, can sometimes encounter two common issues: vanishing gradients and exploding gradients. In this article, we will delve into these challenges, providing insights into what they are, why the
14 min read
Ethics in Data Science and Proper Privacy and Usage of Data
As we know, these days Data Science has become more popular and it is one of the emerging technologies. According to the latest estimation 328.77 million terabytes are generated every day so just think of how large the volume is. , this data may also consist of your data such as your Identity cards or your Banking information or it may be any other
8 min read
ML | Natural Language Processing using Deep Learning
Machine Comprehension is a very interesting but challenging task in both Natural Language Processing (NLP) and artificial intelligence (AI) research. There are several approaches to natural language processing tasks. With recent breakthroughs in deep learning algorithms, hardware, and user-friendly APIs like TensorFlow, some tasks have become feasi
9 min read
Deep Learning with PyTorch | An Introduction
PyTorch in a lot of ways behaves like the arrays we love from Numpy. These Numpy arrays, after all, are just tensors. PyTorch takes these tensors and makes it simple to move them to GPUs for the faster processing needed when training neural networks. It also provides a module that automatically calculates gradients (for backpropagation) and another
7 min read
Prediction of Wine type using Deep Learning
We use deep learning for the large data sets but to understand the concept of deep learning, we use the small data set of wine quality. You can find the wine quality data set from the UCI Machine Learning Repository which is available for free. The aim of this article is to get started with the libraries of deep learning such as Keras, etc and to b
4 min read
Deep Q-Learning
Q-Learning is required as a pre-requisite as it is a process of Q-Learning creates an exact matrix for the working agent which it can "refer to" to maximize its reward in the long run. Although this approach is not wrong in itself, this is only practical for very small environments and quickly loses it's feasibility when the number of states and ac
4 min read
Implementing Deep Q-Learning using Tensorflow
Prerequisites: Deep Q-Learning This article will demonstrate how to do reinforcement learning on a larger environment than previously demonstrated. We will be implementing Deep Q-Learning technique using Tensorflow. Note: A graphics rendering library is required for the following demonstration. For Windows operating system, PyOpenGl is suggested wh
4 min read
Human Activity Recognition - Using Deep Learning Model
Human activity recognition using smartphone sensors like accelerometer is one of the hectic topics of research. HAR is one of the time series classification problem. In this project various machine learning and deep learning models have been worked out to get the best final result. In the same sequence, we can use LSTM (long short term memory) mode
6 min read
Residual Networks (ResNet) - Deep Learning
After the first CNN-based architecture (AlexNet) that win the ImageNet 2012 competition, Every subsequent winning architecture uses more layers in a deep neural network to reduce the error rate. This works for less number of layers, but when we increase the number of layers, there is a common problem in deep learning associated with that called the
10 min read
ML - Saving a Deep Learning model in Keras
Training a neural network/deep learning model usually takes a lot of time, particularly if the hardware capacity of the system doesn't match up to the requirement. Once the training is done, we save the model to a file. To reuse the model at a later point of time to make predictions, we load the saved model. Through Keras, models can be saved in th
2 min read
DLSS - Deep Learning Super Sampling
Super Sampling is also known as Super Sampling Anti Aliasing(SSAA) is a spatial anti-aliasing method i.e. a method to remove aliasing (jagged and pixelated edges also known as "jaggies") from a video, rendered images or another software that produces computer graphics. Aliasing is not often dealt-with in higher resolutions but if the user does not
4 min read