Answers.Body: <p>No, Neural Networks do not have such a guarantee. In fact, I don't believe <strong>any</strong> kind of classifier in the entire field of Machine Learning has such a guarantee, though some may be slipping my mind...</p>
  
  <p>For an easy counterexample, consider what happens if you have two instances with precisely identical inputs, but different output labels. If your classifier is deterministic (in the sense that there is no stochasticity in the procedure going from input to output <strong>after training</strong>), which a Neural Network is (unless, for example, you mess up a Dropout implementation and accidentally also apply dropout after training), it cannot possibly generate the correct output for both of those instances, even if they were presented as examples thousands of times during training.</p>
  
  <p>Of course the above is an extreme example, but similar intuition applies to more realistic cases. There can be cases where getting the correct prediction on one instance would reduce the quality of predictions on many other instances if they have somewhat similar inputs. Normally, the training procedure would then prefer getting better predictions on the larger number of instances, and settle for failure on another instance.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-12T14:02:31.603Z
Answers.Text: I would be tempted to edit this answer to just highlight the 'equal inputs with opposite labels' section, since that is a very clear and elegant verbal proof.
Answers.UserDisplayName: DrMcCleod
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-17T17:25:23.840Z
Answers.Text: In principle, a rule-based or exact classifier could always be right. For instance, if you store the images that you've seen during training or testing/validation in a database, then, when a new image arrives, compare it with all other images in the database, you can simply return the correct label (if such an image exists in the dataset). So, I suppose that you're excluding this type of "classifier" when you say "ML classifier". In any case, the key idea is: most ML models typically **approximate** the desired function, so there's a chance that they may be wrong.
Answers.UserDisplayName: nbro
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-12T10:13:39.297Z
Answers.LastActivityDate: 2019-01-12T10:13:39.297Z
Answers.UserDisplayName: Dennis Soemers
Answers.Body: <p>After training, all standard models are deterministic (the process each input goes thru is set). </p>
  
  <p>In essence, during training the model attempts to learn the distribution of the training dataset. Whether it is able to depends on the size of the model, if it is big enough, it can simply "memorize" all the training samples and result in perfect accuracy on the training set.</p>
  
  <p>Normally this is considered to be terrible (called overfitting) and many regularization techniques attempt to prevent it. Eventually when training a model, you are giving it the training distribution as an example but you hope that it will be able to estimate the real distribution out of it.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-12T08:51:16.587Z
Answers.LastActivityDate: 2019-01-12T08:51:16.587Z
Answers.UserDisplayName: Mark.F
Body: <p>If I'm performing a text classification task using a model built in Keras, and, for example, I am attempting to predict the appropriate tag for a given Stack Overflow question:</p>
  <blockquote>
  <p>How do I subtract 1 from an integer?</p>
  </blockquote>
  <p>And the ground-truth tag for this question is:</p>
  <blockquote>
  <p><a href="/questions/tagged/objective-c" class="post-tag" title="show questions tagged &#39;objective-c&#39;" rel="tag">objective-c</a></p>
  </blockquote>
  <p>But my model is predicting:</p>
  <blockquote>
  <p><a href="/questions/tagged/c%23" class="post-tag" title="show questions tagged &#39;c#&#39;" rel="tag">c#</a></p>
  </blockquote>
  <p>If I were to retrain my model, but this time add the above question and tag in both the training and testing data, would the model be guaranteed to predict the correct tag for this question in the test data?</p>
  <p>I suppose the tl;dr is: Are neural networks deterministic if they encounter identical data during training and testing?</p>
  <p>I'm aware it's not a good idea to use the same data in both training and testing, but I'm interested from a hypothetical perspective, and for gaining more insight into how neural networks actually learn. My intuition for this question is &quot;no&quot;, but I'd really be interested in being pointed to some relevant literature that expands/explains that intuition.</p>
  
Tags: <neural-networks><deep-learning><classification><keras><computational-learning-theory>
Title: Will a neural network always predict the correct label if it sees the exact same input during training and testing?
UserDisplayName: thx1138
ThreadText: # Will a neural network always predict the correct label if it sees the exact same input during training and testing?
  
  (Asked by: username_0 on 2019-01-11)
  
  If I'm performing a text classification task using a model built in Keras, and, for example, I am attempting to predict the appropriate tag for a given Stack Overflow question:
  
  > How do I subtract 1 from an integer?
  
  And the ground-truth tag for this question is:
  
  > [objective-c](/questions/tagged/objective-c "show questions tagged 'objective-c'")
  
  But my model is predicting:
  
  > [c#](/questions/tagged/c%23 "show questions tagged 'c#'")
  
  If I were to retrain my model, but this time add the above question and tag in both the training and testing data, would the model be guaranteed to predict the correct tag for this question in the test data?
  
  I suppose the tl;dr is: Are neural networks deterministic if they encounter identical data during training and testing?
  
  I'm aware it's not a good idea to use the same data in both training and testing, but I'm interested from a hypothetical perspective, and for gaining more insight into how neural networks actually learn. My intuition for this question is "no", but I'd really be interested in being pointed to some relevant literature that expands/explains that intuition.
  
  **Tags:** neural-networks, deep-learning, classification, keras, computational-learning-theory
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2019-01-12. Score: 3
  
  No, Neural Networks do not have such a guarantee. In fact, I don't believe **any** kind of classifier in the entire field of Machine Learning has such a guarantee, though some may be slipping my mind...
  
  For an easy counterexample, consider what happens if you have two instances with precisely identical inputs, but different output labels. If your classifier is deterministic (in the sense that there is no stochasticity in the procedure going from input to output **after training**), which a Neural Network is (unless, for example, you mess up a Dropout implementation and accidentally also apply dropout after training), it cannot possibly generate the correct output for both of those instances, even if they were presented as examples thousands of times during training.
  
  Of course the above is an extreme example, but similar intuition applies to more realistic cases. There can be cases where getting the correct prediction on one instance would reduce the quality of predictions on many other instances if they have somewhat similar inputs. Normally, the training procedure would then prefer getting better predictions on the larger number of instances, and settle for failure on another instance.
  
  > **Comments:**
  > **username_2**: I would be tempted to edit this answer to just highlight the 'equal inputs with opposite labels' section, since that is a very clear and elegant verbal proof.  
  > **username_3**: In principle, a rule-based or exact classifier could always be right. For instance, if you store the images that you've seen during training or testing/validation in a database, then, when a new image arrives, compare it with all other images in the database, you can simply return the correct label (if such an image exists in the dataset). So, I suppose that you're excluding this type of "classifier" when you say "ML classifier". In any case, the key idea is: most ML models typically **approximate** the desired function, so there's a chance that they may be wrong.  
  
  ---
  
  ### Answer by username_4 on 2019-01-12. Score: 1
  
  After training, all standard models are deterministic (the process each input goes thru is set).
  
  In essence, during training the model attempts to learn the distribution of the training dataset. Whether it is able to depends on the size of the model, if it is big enough, it can simply "memorize" all the training samples and result in perfect accuracy on the training set.
  
  Normally this is considered to be terrible (called overfitting) and many regularization techniques attempt to prevent it. Eventually when training a model, you are giving it the training distribution as an example but you hope that it will be able to estimate the real distribution out of it.
  
  
  ---
  
  