Here is a part of my code
** the Optimizer is defined outside this block of code **

for epoch in range(num_epochs):
         print("epoch no. ", epoch + 1)    # training loop
         train_loss = 0
         self.model.train()
         New_data=[]
         for batch_ndx, sample in enumerate(TrainLoader):
            
             self.optimizer.zero_grad()
             data = Variable(sample[0], requires_grad=True)
             self.data = nn.Parameter(data)
             self.optimizer.add_param_group({"params": data})
             labels = sample[1].type(torch.LongTensor)-1
             logits, probas = self.model(data.float())
             loss = self.criterion(logits, labels) + self.regularizer
             loss.backward(retain_graph=True)
             self.optimizer.step()
             if epoch + 1 == num_epochs:
                 data_optimised = list(self.parameters())[0].clone()
                 New_data.append(data_optimised.detach().numpy())     
             train_loss += loss.item()

etc

The purpose of “New_data” is to return the optimized input data so that I can compare to the original data before optimization. There are 2 for loops; one over epochs and one over data batches, and I only append the optimised data at the last epochs of training.  ***** Does this seem logical?? *****
What i observed is that the difference between input data and the optimised data is so small and it did not affect the result of logistic regression remarkably. Consequently, I want to make sure:
1- If my implementation is correct in the way of how I add data to the optimizer and optimise them?
2- If data optimization can not so much affect the results of regression, what is the utility of this step in general? I remarked some people trying to do the same but not a lot.
********** Another important question **************
In the code above it was easy to add (requires_grad=True) to the data tensor. This data is produced through cross correlating word vectors (i.e., word_vectors_1 * word_vector_2 = data) . This process of cross correlation is coded outside the training phase. Can I include word_vectors_1 & word_vector_2 in the optimization process as well? I wont be able to add them to the optimizer as they are not included in the training file, where is the optimizer is first defined.
So how can I add them to the optimizer while they are defined in other files in the program?
Thanks for help

Thanks