code: def test_small_model_pt(self):
      dqa_pipeline = pipeline(
          "document-question-answering",
          model="hf-internal-testing/tiny-random-layoutlmv2",
      )
      image = INVOICE_URL
      question = "How many cats are there?"
  
      expected_output = [
          {
              "score": 0.0001,
              "answer": "oy 2312/2019",
              "start": 38,
              "end": 39,
          },
          {
              "score": 0.0001,
              "answer": "oy 2312/2019 DUE",
              "start": 38,
              "end": 40,
          },
      ]
      outputs = dqa_pipeline(image=image, question=question, top_k=2)
      self.assertEqual(
          nested_simplify(outputs, decimals=4), expected_output
      )
  
      outputs = dqa_pipeline(
          {"image": image, "question": question}, top_k=2
      )
      self.assertEqual(
          nested_simplify(outputs, decimals=4), expected_output
      )
  
      # This image does not detect ANY text in it, meaning layoutlmv2 should fail.
      # Empty answer probably
      image = "./tests/fixtures/tests_samples/COCO/000000039769.png"
      outputs = dqa_pipeline(image=image, question=question, top_k=2)
      self.assertEqual(outputs, [])
  
      # We can optionnally pass directly the words and bounding boxes
      image = "./tests/fixtures/tests_samples/COCO/000000039769.png"
      words = []
      boxes = []
      outputs = dqa_pipeline(
          image=image,
          question=question,
          words=words,
          boxes=boxes,
          top_k=2,
      )
      self.assertEqual(outputs, [])
  
file_path: transformers/tests/pipelines/test_pipelines_document_question_answering.py
imports: import unittest
  from transformers import MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING, AutoTokenizer, is_vision_available
  from transformers.pipelines import pipeline
  from transformers.pipelines.document_question_answering import apply_tesseract
  from transformers.testing_utils import is_pipeline_test, nested_simplify, require_detectron2, require_pytesseract, require_tf, require_torch, require_vision, slow
  from .test_pipelines_common import ANY
label_desc: Use image node_id 3 for calling the DocumentQuestionAnsweringPipelineTests obj's underlying member method code with example usage: obj.test_small_model_pt() without return types