Answers.Body: <blockquote>
  <p>Does L1/L2 (NAdam weight decay) really make the model &quot;unlearn&quot;?</p>
  </blockquote>
  <p>Sort of. These regularisation methods help to make it &quot;forget&quot;, but are not required. This is something it will do anyway - unless repeatedly shown the same data, neural networks will preferentially match to more recent data to at least some degree. This is often desirable, and allows neural networks to be used in situations that require <em>online learning</em>.</p>
  <blockquote>
  <p>A possible solution I'm thinking is like keeping the weights of the model before and/or after the training I want to make it unlearn and then somehow use it to do the unlearning but not sure.</p>
  </blockquote>
  <p>For a neural network, this is the only workable solution.</p>
  <p>You could, in principle, keep the individual weight step calculations, and reverse them. It would have to be done strictly in order, like an &quot;undo&quot; step in a word processor. However, you cannot calculate what the previous weight step <em>was</em> from the current network plus a set of data. So this will normally keep a data structure the same size as the neural network parameters for each undo step. Keeping a backup copy of the network to restore will use less data than two undo steps, and is less mathematically complicated therefore less prone to error in code.</p>
  <p>Most neural network libraries will let you clone a network, so you use that feature to assign to a variable and/or save to disk. If you need to restore then copy the backup (cloning again, so that the two sets of weights are not shared) over the variable tracking the current learning network.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-02T09:27:03.450Z
Answers.Text: I'm very interested in how this undo will work in practice - are there any reference documents or implementations - but from what I'm reading wouldn't it be the same as saving and loading the model weights (at certain point) - which is not what I ideally want.
Answers.UserDisplayName: AnArrayOfFunctions
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-02T11:30:38.957Z
Answers.Text: @AnArrayOfFunctions: You don't *have* to save or load to disk, most NN libraries will give you a deep clone function. Take a look at DQN or early stopping code if you want to see an example (DQN uses this to stash the "target" NN. You might also see example in your NN library documentation. This is too small a thing for there to be separate reference docs, and what to do will depend strongly on the logic surrounding your try/fail scenarios plus which NN library you are using. Provided you already have the try -> succeed/fail logic written out though, we're only talking a few lines of code.
Answers.UserDisplayName: Neil Slater
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-02T11:33:18.890Z
Answers.Text: Your best bet for a clean example is that someone has written out how to do early stopping logic using your library. However many libraries now have this built in so you automatically get the backed-up copy without needing to do anything, so it is not guaranteed you will see the code you need
Answers.UserDisplayName: Neil Slater
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-02T09:05:42.463Z
Answers.LastActivityDate: 2024-02-02T09:12:50.083Z
Answers.LastEditDate: 2024-02-02T09:12:50.083Z
Answers.UserDisplayName: Neil Slater
Body: <p>Does L1/L2 (NAdam weight decay) really make the model &quot;unlearn&quot;?</p>
  <p>Ok so my question might be dumb but is there any way to &quot;unlearn&quot; a model - and yeah I know there is wieght_decay and L1 and L2 - but I'm thinking like instead having a way to tell a model to forget specific thing it has learned so like untrain it from certain cases.</p>
  <p>And my questions is worded this way because L1/L2 was the only thing I've found close to what I ask but I don't think it's exactly what I'm searching for - instead as I've worded it above I want instead of having a pass which &quot;trains&quot; the model specific outcome to have a &quot;pass&quot; which reverts that training (not train on different outcome).</p>
  <p>So after it has unlearned this training - it predicts with all the other training it has received before.</p>
  <p>Thanks in advance.</p>
  <p><em>A possible solution I'm thinking is like keeping the weights of the model before and/or after the training  I want to make it unlearn and then somehow use it to do the unlearning but not sure.</em></p>
  
Tags: <neural-networks><machine-learning><pytorch><linear-regression>
Title: How to make a model forget specific training it has received?
UserDisplayName: AnArrayOfFunctions
ThreadText: # How to make a model forget specific training it has received?
  
  (Asked by: username_0 on 2024-02-02)
  
  Does L1/L2 (NAdam weight decay) really make the model "unlearn"?
  
  Ok so my question might be dumb but is there any way to "unlearn" a model - and yeah I know there is wieght\_decay and L1 and L2 - but I'm thinking like instead having a way to tell a model to forget specific thing it has learned so like untrain it from certain cases.
  
  And my questions is worded this way because L1/L2 was the only thing I've found close to what I ask but I don't think it's exactly what I'm searching for - instead as I've worded it above I want instead of having a pass which "trains" the model specific outcome to have a "pass" which reverts that training (not train on different outcome).
  
  So after it has unlearned this training - it predicts with all the other training it has received before.
  
  Thanks in advance.
  
  *A possible solution I'm thinking is like keeping the weights of the model before and/or after the training I want to make it unlearn and then somehow use it to do the unlearning but not sure.*
  
  **Tags:** neural-networks, machine-learning, pytorch, linear-regression
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-02-02. Score: 0
  
  > Does L1/L2 (NAdam weight decay) really make the model "unlearn"?
  
  Sort of. These regularisation methods help to make it "forget", but are not required. This is something it will do anyway - unless repeatedly shown the same data, neural networks will preferentially match to more recent data to at least some degree. This is often desirable, and allows neural networks to be used in situations that require *online learning*.
  
  > A possible solution I'm thinking is like keeping the weights of the model before and/or after the training I want to make it unlearn and then somehow use it to do the unlearning but not sure.
  
  For a neural network, this is the only workable solution.
  
  You could, in principle, keep the individual weight step calculations, and reverse them. It would have to be done strictly in order, like an "undo" step in a word processor. However, you cannot calculate what the previous weight step *was* from the current network plus a set of data. So this will normally keep a data structure the same size as the neural network parameters for each undo step. Keeping a backup copy of the network to restore will use less data than two undo steps, and is less mathematically complicated therefore less prone to error in code.
  
  Most neural network libraries will let you clone a network, so you use that feature to assign to a variable and/or save to disk. If you need to restore then copy the backup (cloning again, so that the two sets of weights are not shared) over the variable tracking the current learning network.
  
  > **Comments:**
  > **username_0**: I'm very interested in how this undo will work in practice - are there any reference documents or implementations - but from what I'm reading wouldn't it be the same as saving and loading the model weights (at certain point) - which is not what I ideally want.  
  > **username_1**: @AnArrayOfFunctions: You don't *have* to save or load to disk, most NN libraries will give you a deep clone function. Take a look at DQN or early stopping code if you want to see an example (DQN uses this to stash the "target" NN. You might also see example in your NN library documentation. This is too small a thing for there to be separate reference docs, and what to do will depend strongly on the logic surrounding your try/fail scenarios plus which NN library you are using. Provided you already have the try -> succeed/fail logic written out though, we're only talking a few lines of code.  
  > **username_1**: Your best bet for a clean example is that someone has written out how to do early stopping logic using your library. However many libraries now have this built in so you automatically get the backed-up copy without needing to do anything, so it is not guaranteed you will see the code you need  
  
  ---
  
  