Answers.Body: <p>Probably the best and most suggestive example of automatic feature extraction comes from <a href="https://en.wikipedia.org/wiki/Restricted_Boltzmann_machine" rel="nofollow noreferrer">Restricted Boltzmann Machines</a> (RBMs). Because of their architecture, composed in its simplest form of one visible layer and one hidden layer of same size, they allow us to visualise the weights learnt during training really easily, i.e. by simply reshaping them in the same size as the input images fed during training.</p>
  <p>Below you can see an example of such weight visualisation, learned on the classic MNIST (hand written digits) dataset. An important thing to understand is that dark and bright pixels are associated with respectively small and big weights. Again, I want to stress out that every image is a set of weights that connect each pixel of an input image to a single hidden node (as shown in the second picture).</p>
  <p>So each image effectively is showing us what the RBM consider important in an image. When we feed an image to the RBM, the first feature map is applied, and we can see that this feature map recall something like a 9 (in black) and a 2 (in white), so the RBM will respond with high activations to images similar to a 2 and very low activations for images similar to a 9.</p>
  <p>How did the RBM decided that these features are important? The answer lies in two main factors:</p>
  <ul>
  <li>the training algorithm</li>
  <li>the data distribution</li>
  </ul>
  <p>In this case the training algorithm is <a href="https://medium.com/datatype/restricted-boltzmann-machine-a-complete-analysis-part-3-contrastive-divergence-algorithm-3d06bbebb10c" rel="nofollow noreferrer">contrastive divergence</a>, an unsupervised energy based algorithm that minimise the energy of the weights when similar training inputs are presented while trying to maximise their energy when different ones are presented. This algorithmic design explain why we see feature maps like the first one. Contrastive divergence is trying to minimise the energy for all inputs images containing 2 while trying also to keep 2 and 9 separated from each other (in terms of nodes activations). Clearly 2 and 9 have similarities like the top curve, so the model need to learn features maps that activate a lot nodes connected to areas belonging to features specific to only one class, like the bottom straight line of 2. Unfortunately, this is almost as far as we can go into the analysis of &quot;why a model is learning something&quot;, without falling into models interpretability discussions (for which there are already good <a href="https://ai.stackexchange.com/questions/12870/which-explainable-artificial-intelligence-techniques-are-there/24138#24138">threads</a> in this community), and surely we'll never know &quot;how exactly&quot;, or if that day will come, then we won't need machine learning anymore.</p>
  <p>Last but not least, a well known bias of the MNIST dataset is the centred position of each digit. Nowhere in the data you will find lines on the edges of an image, and indeed the RBM also never learn to pay attention to the edges. So, regardless of the choice of the training algorithm, the training data distribution will also always impact what a model learn (or in this case not learn).</p>
  <p><a href="https://i.sstatic.net/Pr2cx.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Pr2cx.png" alt="Rbm feature maps learned on the MNIST dataset" /></a>
  <a href="https://i.sstatic.net/Kopye.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Kopye.png" alt="How each feature map is obtained from the trained RBM" /></a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-01T00:20:39.510Z
Answers.LastActivityDate: 2022-02-01T08:22:50.093Z
Answers.LastEditDate: 2022-02-01T08:22:50.093Z
Answers.UserDisplayName: Edoardo Guerriero
Body: <p><strong>I have often heard that Deep Learning Models (i.e. Deep Neural Networks) are automatically performing feature engineering within the network themselves.</strong> This is contrasted with traditional statistical and Machine Learning models where the feature engineering is typically done prior to training the model:</p>
  <p><a href="https://i.sstatic.net/hp8Gd.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/hp8Gd.png" alt="enter image description here" /></a></p>
  <p>Apparently, the operations that Neural Networks perform during the training phase are equivalent to &quot;searching for meaningful combinations of variables that produce better performance results on the training data&quot;. I have heard that this is in some way similar to Principal Component Analysis (PCA) and Kernel Methods, seeing as these methods combine many different existing features into new features that have &quot;more meaningful representation&quot;.</p>
  <p>For instance, in the &quot;Deep Learning Book&quot; (<a href="https://www.deeplearningbook.org/contents/intro.html" rel="nofollow noreferrer">https://www.deeplearningbook.org/contents/intro.html</a>), I read about this ability of Deep Neural Networks to &quot;automatically perform feature engineering&quot; :</p>
  <p>&quot;<em>Deep learning solves this central problem in representation learning by introducing representations that are expressed in terms of other, simpler representations. Deep learning enables the computer to build complex concepts out of simpler concepts.</em>&quot;</p>
  <p>However, in the end - I still do not understand how Neural Networks during the training phase (i.e. gradient descent, weight update, backpropagation) are &quot;automatically performing (some degree of) feature engineering&quot;.</p>
  <p><strong>How exactly are Neural Networks doing this &quot;automatically&quot;?</strong></p>
  <p>Thanks!</p>
  <p><strong>Note:</strong> I have heard that NN's are said to be universal function approximators (i.e. universal approximation theorem). Therefore, for a given data set - there should exist a specific neural network architecture (i.e. specific number/value of weights, layers and choice of activation functions) that will result in your target function being approximated sufficiently well - however, the combinatorial search space is massive and recovering that network can be very difficult for large data because of the time required to train the network using gradient descent. So &quot;automatic feature engineering&quot; is something indirect that might or might not happen because of the universal approximation theorem.</p>
  
Tags: <neural-networks>
Title: Claim: Deep Neural Networks "Automatically" Perform Feature Selection and Feature Engineering?
UserDisplayName: stats_noob
ThreadText: # Claim: Deep Neural Networks "Automatically" Perform Feature Selection and Feature Engineering?
  
  (Asked by: username_0 on 2022-01-31)
  
  **I have often heard that Deep Learning Models (i.e. Deep Neural Networks) are automatically performing feature engineering within the network themselves.** This is contrasted with traditional statistical and Machine Learning models where the feature engineering is typically done prior to training the model:
  
  [![enter image description here](https://i.sstatic.net/hp8Gd.png)](https://i.sstatic.net/hp8Gd.png)
  
  Apparently, the operations that Neural Networks perform during the training phase are equivalent to "searching for meaningful combinations of variables that produce better performance results on the training data". I have heard that this is in some way similar to Principal Component Analysis (PCA) and Kernel Methods, seeing as these methods combine many different existing features into new features that have "more meaningful representation".
  
  For instance, in the "Deep Learning Book" (<https://www.deeplearningbook.org/contents/intro.html>), I read about this ability of Deep Neural Networks to "automatically perform feature engineering" :
  
  "*Deep learning solves this central problem in representation learning by introducing representations that are expressed in terms of other, simpler representations. Deep learning enables the computer to build complex concepts out of simpler concepts.*"
  
  However, in the end - I still do not understand how Neural Networks during the training phase (i.e. gradient descent, weight update, backpropagation) are "automatically performing (some degree of) feature engineering".
  
  **How exactly are Neural Networks doing this "automatically"?**
  
  Thanks!
  
  **Note:** I have heard that NN's are said to be universal function approximators (i.e. universal approximation theorem). Therefore, for a given data set - there should exist a specific neural network architecture (i.e. specific number/value of weights, layers and choice of activation functions) that will result in your target function being approximated sufficiently well - however, the combinatorial search space is massive and recovering that network can be very difficult for large data because of the time required to train the network using gradient descent. So "automatic feature engineering" is something indirect that might or might not happen because of the universal approximation theorem.
  
  **Tags:** neural-networks
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-02-01. Score: 1
  
  Probably the best and most suggestive example of automatic feature extraction comes from [Restricted Boltzmann Machines](https://en.wikipedia.org/wiki/Restricted_Boltzmann_machine) (RBMs). Because of their architecture, composed in its simplest form of one visible layer and one hidden layer of same size, they allow us to visualise the weights learnt during training really easily, i.e. by simply reshaping them in the same size as the input images fed during training.
  
  Below you can see an example of such weight visualisation, learned on the classic MNIST (hand written digits) dataset. An important thing to understand is that dark and bright pixels are associated with respectively small and big weights. Again, I want to stress out that every image is a set of weights that connect each pixel of an input image to a single hidden node (as shown in the second picture).
  
  So each image effectively is showing us what the RBM consider important in an image. When we feed an image to the RBM, the first feature map is applied, and we can see that this feature map recall something like a 9 (in black) and a 2 (in white), so the RBM will respond with high activations to images similar to a 2 and very low activations for images similar to a 9.
  
  How did the RBM decided that these features are important? The answer lies in two main factors:
  
  * the training algorithm
  * the data distribution
  
  In this case the training algorithm is [contrastive divergence](https://medium.com/datatype/restricted-boltzmann-machine-a-complete-analysis-part-3-contrastive-divergence-algorithm-3d06bbebb10c), an unsupervised energy based algorithm that minimise the energy of the weights when similar training inputs are presented while trying to maximise their energy when different ones are presented. This algorithmic design explain why we see feature maps like the first one. Contrastive divergence is trying to minimise the energy for all inputs images containing 2 while trying also to keep 2 and 9 separated from each other (in terms of nodes activations). Clearly 2 and 9 have similarities like the top curve, so the model need to learn features maps that activate a lot nodes connected to areas belonging to features specific to only one class, like the bottom straight line of 2. Unfortunately, this is almost as far as we can go into the analysis of "why a model is learning something", without falling into models interpretability discussions (for which there are already good [threads](https://ai.stackexchange.com/questions/12870/which-explainable-artificial-intelligence-techniques-are-there/24138#24138) in this community), and surely we'll never know "how exactly", or if that day will come, then we won't need machine learning anymore.
  
  Last but not least, a well known bias of the MNIST dataset is the centred position of each digit. Nowhere in the data you will find lines on the edges of an image, and indeed the RBM also never learn to pay attention to the edges. So, regardless of the choice of the training algorithm, the training data distribution will also always impact what a model learn (or in this case not learn).
  
  [![Rbm feature maps learned on the MNIST dataset](https://i.sstatic.net/Pr2cx.png)](https://i.sstatic.net/Pr2cx.png)
  [![How each feature map is obtained from the trained RBM](https://i.sstatic.net/Kopye.png)](https://i.sstatic.net/Kopye.png)
  
  
  ---
  
  