

         # zero the parameter gradients
         optimizer.zero_grad()
         # forward + backward + optimize
         outputs = model(
             input_ids=input_ids,
             attention_mask=attention_mask,
             token_type_ids=token_type_ids,
             labels=labels,
             numeric_values=numeric_values,
             numeric_values_scale=numeric_values_scale,
             float_answer=float_answer,
         )
         loss = outputs.loss
         loss.backward()
         optimizer.step()
``
</pt>
<tf>
You can then fine-tune [TFTapasForQuestionAnswering`] as follows (shown here for the weak supervision for aggregation case):