code: def test_training_question_answering_head_weak_supervision(self):
      # note that google/tapas-base-finetuned-wtq should correspond to tapas_wtq_wikisql_sqa_inter_masklm_base_reset
      model = TapasForQuestionAnswering.from_pretrained(
          "google/tapas-base-finetuned-wtq"
      ).to(torch_device)
      model.to(torch_device)
      # normally we should put the model in training mode but it's a pain to do this with the TF 1 implementation
  
      tokenizer = self.default_tokenizer
      # let's test on a batch
      (
          table,
          queries,
          answer_coordinates,
          answer_text,
          float_answer,
      ) = prepare_tapas_batch_inputs_for_training()
      inputs = tokenizer(
          table=table,
          queries=queries,
          answer_coordinates=answer_coordinates,
          answer_text=answer_text,
          padding="longest",
          return_tensors="pt",
      )
  
      # prepare data (created by the tokenizer) and move to torch_device
      input_ids = inputs["input_ids"].to(torch_device)
      attention_mask = inputs["attention_mask"].to(torch_device)
      token_type_ids = inputs["token_type_ids"].to(torch_device)
      labels = inputs["labels"].to(torch_device)
      numeric_values = inputs["numeric_values"].to(torch_device)
      numeric_values_scale = inputs["numeric_values_scale"].to(
          torch_device
      )
  
      # the answer should be prepared by the user
      float_answer = torch.FloatTensor(float_answer).to(torch_device)
  
      # forward pass to get loss + logits:
      with torch.no_grad():
          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,
          )
  
      # test the loss
      loss = outputs.loss
      expected_loss = torch.tensor(
          3.3527612686157227e-08, device=torch_device
      )
      self.assertTrue(torch.allclose(loss, expected_loss, atol=1e-6))
  
      # test the logits on the first example
      logits = outputs.logits
      expected_shape = torch.Size((2, 29))
      self.assertEqual(logits.shape, expected_shape)
      expected_slice = torch.tensor(
          [
              -160.0156,
              -160.0156,
              -160.0156,
              -160.0156,
              -160.0156,
              -10072.2266,
              -10070.8896,
              -10092.6006,
              -10092.6006,
          ],
          device=torch_device,
      )
  
      self.assertTrue(
          torch.allclose(logits[0, -9:], expected_slice, atol=1e-6)
      )
  
      # test the aggregation logits on the second example
      logits_aggregation = outputs.logits_aggregation
      expected_shape = torch.Size((2, 4))
      self.assertEqual(logits_aggregation.shape, expected_shape)
      expected_slice = torch.tensor(
          [-4.0538, 40.0304, -5.3554, 23.3965], device=torch_device
      )
  
      self.assertTrue(
          torch.allclose(
              logits_aggregation[1, -4:], expected_slice, atol=1e-4
          )
      )
  
imports: import copy
  import unittest
  import numpy
  import pandas
  from transformers import MODEL_FOR_CAUSAL_LM_MAPPING, MODEL_FOR_MASKED_LM_MAPPING, MODEL_FOR_MULTIPLE_CHOICE_MAPPING, MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING, MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING, MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING, MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING, MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING, TapasConfig, is_torch_available
  from transformers.models.auto import get_values
  from transformers.testing_utils import require_scatter, require_tensorflow_probability, require_torch, slow, torch_device
  from transformers.utils import cached_property
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
label_desc: Use image node_id 7 for calling the TapasModelIntegrationTest obj's underlying member method code with example usage: obj.test_training_question_answering_head_weak_supervision() without return types