import requests

__lowerCamelCase      :			Optional[int]							       =		'''https://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey='''



def      __SCREAMING_SNAKE_CASE  ( __UpperCamelCase   :	str     )							-> None:







  """simple docstring"""





  SCREAMING_SNAKE_CASE__      							=				requests.get(_NEWS_API + bbc_news_api_key     ).json()
  # each article in the list is a dict
  for i, article in enumerate(bbc_news_page["""articles"""]			,					1     ):
    print(f"""{i}.) {article['title']}"""     )


if __name__ == "__main__":
   fetch_bbc_news(bbc_news_api_key='''<Your BBC News API key goes here>''')

from __future__ import annotations

import copy
import inspect
import unittest

import numpy as np

from transformers import is_tf_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_tf, slow
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
   import tensorflow as tf

   from transformers import (
       TF_LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST,
       TF_MODEL_FOR_MULTIPLE_CHOICE_MAPPING,
       TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING,
       TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
       TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
       LayoutLMvaConfig,
       TFLayoutLMvaForQuestionAnswering,
       TFLayoutLMvaForSequenceClassification,
       TFLayoutLMvaForTokenClassification,
       TFLayoutLMvaModel,
   )

if is_vision_available():
   from PIL import Image

   from transformers import LayoutLMvaImageProcessor







class __snake_case    :




   def __init__(   self      :    Any	,     _lowercase      :    Tuple	,     _lowercase      :    str=2	,     _lowercase      :    List[Any]=3	,     _lowercase      :    Optional[Any]=4	,     _lowercase      :    Optional[Any]=2	,     _lowercase      :    str=7	,     _lowercase      :    Dict=True	,     _lowercase      :    List[str]=True	,     _lowercase      :    Union[str, Any]=True	,     _lowercase      :    Optional[int]=True	,     _lowercase      :    Dict=99	,     _lowercase      :    Dict=36	,     _lowercase      :    Tuple=2	,     _lowercase      :    Optional[int]=4	,     _lowercase      :    int=37	,     _lowercase      :    Tuple="gelu"	,     _lowercase      :    Optional[Any]=0.1	,     _lowercase      :    Tuple=0.1	,     _lowercase      :    str=5_12	,     _lowercase      :    Dict=16	,     _lowercase      :    int=2	,     _lowercase      :    int=0.02	,     _lowercase      :    Any=6	,     _lowercase      :    List[Any]=6	,     _lowercase      :    List[Any]=3	,     _lowercase      :    List[Any]=4	,     _lowercase      :    int=None	,     _lowercase      :    Optional[int]=10_00	,     ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				parent
     SCREAMING_SNAKE_CASE__      							=				batch_size
     SCREAMING_SNAKE_CASE__      							=				num_channels
     SCREAMING_SNAKE_CASE__      							=				image_size
     SCREAMING_SNAKE_CASE__      							=				patch_size
     SCREAMING_SNAKE_CASE__      							=				is_training
     SCREAMING_SNAKE_CASE__      							=				use_input_mask
     SCREAMING_SNAKE_CASE__      							=				use_token_type_ids
     SCREAMING_SNAKE_CASE__      							=				use_labels
     SCREAMING_SNAKE_CASE__      							=				vocab_size
     SCREAMING_SNAKE_CASE__      							=				hidden_size
     SCREAMING_SNAKE_CASE__      							=				num_hidden_layers
     SCREAMING_SNAKE_CASE__      							=				num_attention_heads
     SCREAMING_SNAKE_CASE__      							=				intermediate_size
     SCREAMING_SNAKE_CASE__      							=				hidden_act
     SCREAMING_SNAKE_CASE__      							=				hidden_dropout_prob
     SCREAMING_SNAKE_CASE__      							=				attention_probs_dropout_prob
     SCREAMING_SNAKE_CASE__      							=				max_position_embeddings
     SCREAMING_SNAKE_CASE__      							=				type_vocab_size
     SCREAMING_SNAKE_CASE__      							=				type_sequence_label_size
     SCREAMING_SNAKE_CASE__      							=				initializer_range
     SCREAMING_SNAKE_CASE__      							=				coordinate_size
     SCREAMING_SNAKE_CASE__      							=				shape_size
     SCREAMING_SNAKE_CASE__      							=				num_labels
     SCREAMING_SNAKE_CASE__      							=				num_choices
     SCREAMING_SNAKE_CASE__      							=				scope
     SCREAMING_SNAKE_CASE__      							=				range_bbox

     # LayoutLMv3's sequence length equals the number of text tokens + number of patches + 1 (we add 1 for the CLS token)
     SCREAMING_SNAKE_CASE__      							=				text_seq_length
     SCREAMING_SNAKE_CASE__      							=				(image_size // patch_size) ** 2 + 1
     SCREAMING_SNAKE_CASE__      							=				self.text_seq_length + self.image_seq_length




   def      __a						(   self      :    List[str]				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				ids_tensor([self.batch_size, self.text_seq_length]	,     self.vocab_size				)

     SCREAMING_SNAKE_CASE__      							=				ids_tensor([self.batch_size, self.text_seq_length, 4]	,     self.range_bbox				)
     SCREAMING_SNAKE_CASE__      							=				bbox.numpy()
     # Ensure that bbox is legal
     for i in range(bbox.shape[0]				):
       for j in range(bbox.shape[1]				):
         if bbox[i, j, 3] < bbox[i, j, 1]:
           SCREAMING_SNAKE_CASE__      							=				bbox[i, j, 3]
           SCREAMING_SNAKE_CASE__      							=				bbox[i, j, 1]
           SCREAMING_SNAKE_CASE__      							=				tmp_coordinate
         if bbox[i, j, 2] < bbox[i, j, 0]:
           SCREAMING_SNAKE_CASE__      							=				bbox[i, j, 2]
           SCREAMING_SNAKE_CASE__      							=				bbox[i, j, 0]
           SCREAMING_SNAKE_CASE__      							=				tmp_coordinate
     SCREAMING_SNAKE_CASE__      							=				tf.constant(_lowercase				)

     SCREAMING_SNAKE_CASE__      							=				floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]				)

     SCREAMING_SNAKE_CASE__      							=				None
     if self.use_input_mask:
       SCREAMING_SNAKE_CASE__      							=				random_attention_mask([self.batch_size, self.text_seq_length]				)

     SCREAMING_SNAKE_CASE__      							=				None
     if self.use_token_type_ids:
       SCREAMING_SNAKE_CASE__      							=				ids_tensor([self.batch_size, self.text_seq_length]	,     self.type_vocab_size				)

     SCREAMING_SNAKE_CASE__      							=				None
     SCREAMING_SNAKE_CASE__      							=				None
     if self.use_labels:
       SCREAMING_SNAKE_CASE__      							=				ids_tensor([self.batch_size]	,     self.type_sequence_label_size				)
       SCREAMING_SNAKE_CASE__      							=				ids_tensor([self.batch_size, self.text_seq_length]	,     self.num_labels				)

     SCREAMING_SNAKE_CASE__      							=				LayoutLMvaConfig(
         vocab_size=self.vocab_size	,     hidden_size=self.hidden_size	,     num_hidden_layers=self.num_hidden_layers	,     num_attention_heads=self.num_attention_heads	,     intermediate_size=self.intermediate_size	,     hidden_act=self.hidden_act	,     hidden_dropout_prob=self.hidden_dropout_prob	,     attention_probs_dropout_prob=self.attention_probs_dropout_prob	,     max_position_embeddings=self.max_position_embeddings	,     type_vocab_size=self.type_vocab_size	,     initializer_range=self.initializer_range	,     coordinate_size=self.coordinate_size	,     shape_size=self.shape_size	,     input_size=self.image_size	,     patch_size=self.patch_size	,     )

     return config, input_ids, bbox, pixel_values, token_type_ids, input_mask, sequence_labels, token_labels




   def      __a						(   self      :    List[str]	,     _lowercase      :    Dict	,     _lowercase      :    List[Any]	,     _lowercase      :    str	,     _lowercase      :    Optional[int]	,     _lowercase      :    Union[str, Any]	,     _lowercase      :    Tuple				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				TFLayoutLMvaModel(config=_lowercase				)

     # text + image
     SCREAMING_SNAKE_CASE__      							=				model(_lowercase	,     pixel_values=_lowercase	,     training=_lowercase				)
     SCREAMING_SNAKE_CASE__      							=				model(
         _lowercase	,     bbox=_lowercase	,     pixel_values=_lowercase	,     attention_mask=_lowercase	,     token_type_ids=_lowercase	,     training=_lowercase	,     )
     SCREAMING_SNAKE_CASE__      							=				model(_lowercase	,     bbox=_lowercase	,     pixel_values=_lowercase	,     training=_lowercase				)

     self.parent.assertEqual(result.last_hidden_state.shape	,     (self.batch_size, self.seq_length, self.hidden_size)				)

     # text only
     SCREAMING_SNAKE_CASE__      							=				model(_lowercase	,     training=_lowercase				)
     self.parent.assertEqual(
         result.last_hidden_state.shape	,     (self.batch_size, self.text_seq_length, self.hidden_size)				)

     # image only
     SCREAMING_SNAKE_CASE__      							=				model({"""pixel_values""": pixel_values}	,     training=_lowercase				)
     self.parent.assertEqual(
         result.last_hidden_state.shape	,     (self.batch_size, self.image_seq_length, self.hidden_size)				)




   def      __a						(   self      :    int	,     _lowercase      :    int	,     _lowercase      :    Optional[int]	,     _lowercase      :    Optional[Any]	,     _lowercase      :    Optional[int]	,     _lowercase      :    Tuple	,     _lowercase      :    List[Any]	,     _lowercase      :    Tuple				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				self.num_labels
     SCREAMING_SNAKE_CASE__      							=				TFLayoutLMvaForSequenceClassification(config=_lowercase				)
     SCREAMING_SNAKE_CASE__      							=				model(
         _lowercase	,     bbox=_lowercase	,     pixel_values=_lowercase	,     attention_mask=_lowercase	,     token_type_ids=_lowercase	,     labels=_lowercase	,     training=_lowercase	,     )
     self.parent.assertEqual(result.logits.shape	,     (self.batch_size, self.num_labels)				)




   def      __a						(   self      :    Any	,     _lowercase      :    Dict	,     _lowercase      :    Tuple	,     _lowercase      :    int	,     _lowercase      :    Optional[int]	,     _lowercase      :    Optional[int]	,     _lowercase      :    Union[str, Any]	,     _lowercase      :    Tuple				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				self.num_labels
     SCREAMING_SNAKE_CASE__      							=				TFLayoutLMvaForTokenClassification(config=_lowercase				)
     SCREAMING_SNAKE_CASE__      							=				model(
         _lowercase	,     bbox=_lowercase	,     pixel_values=_lowercase	,     attention_mask=_lowercase	,     token_type_ids=_lowercase	,     labels=_lowercase	,     training=_lowercase	,     )
     self.parent.assertEqual(result.logits.shape	,     (self.batch_size, self.text_seq_length, self.num_labels)				)




   def      __a						(   self      :    str	,     _lowercase      :    int	,     _lowercase      :    List[str]	,     _lowercase      :    str	,     _lowercase      :    str	,     _lowercase      :    List[str]	,     _lowercase      :    List[str]	,     _lowercase      :    Union[str, Any]				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				2
     SCREAMING_SNAKE_CASE__      							=				TFLayoutLMvaForQuestionAnswering(config=_lowercase				)
     SCREAMING_SNAKE_CASE__      							=				model(
         _lowercase	,     bbox=_lowercase	,     pixel_values=_lowercase	,     attention_mask=_lowercase	,     token_type_ids=_lowercase	,     start_positions=_lowercase	,     end_positions=_lowercase	,     training=_lowercase	,     )
     self.parent.assertEqual(result.start_logits.shape	,     (self.batch_size, self.seq_length)				)
     self.parent.assertEqual(result.end_logits.shape	,     (self.batch_size, self.seq_length)				)




   def      __a						(   self      :    List[Any]				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				self.prepare_config_and_inputs()
     ((SCREAMING_SNAKE_CASE__)							,					(SCREAMING_SNAKE_CASE__)							,					(SCREAMING_SNAKE_CASE__)							,					(SCREAMING_SNAKE_CASE__)							,					(SCREAMING_SNAKE_CASE__)							,					(SCREAMING_SNAKE_CASE__)							,					(SCREAMING_SNAKE_CASE__)							,					(SCREAMING_SNAKE_CASE__))      							=				config_and_inputs
     SCREAMING_SNAKE_CASE__      							=				{
         """input_ids""": input_ids,
         """bbox""": bbox,
         """pixel_values""": pixel_values,
         """token_type_ids""": token_type_ids,
         """attention_mask""": input_mask,
     }
     return config, inputs_dict







@require_tf
class __snake_case    (						lowerCamelCase_       ,		lowerCamelCase_       ,		unittest.TestCase		):
   lowerCAmelCase_														=							(
       (
           TFLayoutLMvaModel,
           TFLayoutLMvaForQuestionAnswering,
           TFLayoutLMvaForSequenceClassification,
           TFLayoutLMvaForTokenClassification,
       )
       if is_tf_available()
       else ()
   )
   lowerCAmelCase_														=							(
       {"document-question-answering": TFLayoutLMvaForQuestionAnswering, "feature-extraction": TFLayoutLMvaModel}
       if is_tf_available()
       else {}
   )

   lowerCAmelCase_														=							False
   lowerCAmelCase_														=							False
   lowerCAmelCase_														=							False




   def      __a						(   self      :    Union[str, Any]	,     _lowercase      :    Optional[int]	,     _lowercase      :    List[str]	,     _lowercase      :    Optional[Any]	,     _lowercase      :    Optional[int]	,     _lowercase      :    List[Any]				):



     """simple docstring"""






     return True




   def      __a						(   self      :    List[str]	,     _lowercase      :    List[Any]	,     _lowercase      :    str	,     _lowercase      :    str=False				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				copy.deepcopy(_lowercase				)

     if model_class in get_values(_lowercase				):
       SCREAMING_SNAKE_CASE__      							=				{
           k: tf.tile(tf.expand_dims(_lowercase	,     1				)	,     (1, self.model_tester.num_choices) + (1,) * (v.ndim - 1)				)
           if isinstance(_lowercase	,     tf.Tensor				) and v.ndim > 0
           else v
           for k, v in inputs_dict.items()
       }

     if return_labels:
       if model_class in get_values(_lowercase				):
         SCREAMING_SNAKE_CASE__      							=				tf.ones(self.model_tester.batch_size	,     dtype=tf.intaa				)
       elif model_class in get_values(_lowercase				):
         SCREAMING_SNAKE_CASE__      							=				tf.zeros(self.model_tester.batch_size	,     dtype=tf.intaa				)
         SCREAMING_SNAKE_CASE__      							=				tf.zeros(self.model_tester.batch_size	,     dtype=tf.intaa				)
       elif model_class in get_values(_lowercase				):
         SCREAMING_SNAKE_CASE__      							=				tf.zeros(self.model_tester.batch_size	,     dtype=tf.intaa				)
       elif model_class in get_values(_lowercase				):
         SCREAMING_SNAKE_CASE__      							=				tf.zeros(
             (self.model_tester.batch_size, self.model_tester.text_seq_length)	,     dtype=tf.intaa				)

     return inputs_dict




   def      __a						(   self      :    Tuple				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				TFLayoutLMvaModelTester(self				)
     SCREAMING_SNAKE_CASE__      							=				ConfigTester(self	,     config_class=_lowercase	,     hidden_size=37				)




   def      __a						(   self      :    Any				):



     """simple docstring"""






     self.config_tester.run_common_tests()




   def      __a						(   self      :    Dict				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__							,					SCREAMING_SNAKE_CASE__      							=				self.model_tester.prepare_config_and_inputs_for_common()
     for model_class in self.all_model_classes:
       SCREAMING_SNAKE_CASE__      							=				model_class(_lowercase				)
       if getattr(_lowercase	,     """hf_compute_loss"""	,     _lowercase				):
         # The number of elements in the loss should be the same as the number of elements in the label
         SCREAMING_SNAKE_CASE__      							=				self._prepare_for_class(inputs_dict.copy()	,     _lowercase	,     return_labels=_lowercase				)
         SCREAMING_SNAKE_CASE__      							=				prepared_for_class[
             sorted(prepared_for_class.keys() - inputs_dict.keys()	,     reverse=_lowercase				)[0]
         ]
         SCREAMING_SNAKE_CASE__      							=				added_label.shape.as_list()[:1]

         # Test that model correctly compute the loss with kwargs
         SCREAMING_SNAKE_CASE__      							=				self._prepare_for_class(inputs_dict.copy()	,     _lowercase	,     return_labels=_lowercase				)
         SCREAMING_SNAKE_CASE__      							=				prepared_for_class.pop("""input_ids"""				)

         SCREAMING_SNAKE_CASE__      							=				model(_lowercase	,     **_lowercase				)[0]
         self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]				)

         # Test that model correctly compute the loss when we mask some positions
         SCREAMING_SNAKE_CASE__      							=				self._prepare_for_class(inputs_dict.copy()	,     _lowercase	,     return_labels=_lowercase				)
         SCREAMING_SNAKE_CASE__      							=				prepared_for_class.pop("""input_ids"""				)
         if "labels" in prepared_for_class:
           SCREAMING_SNAKE_CASE__      							=				prepared_for_class["""labels"""].numpy()
           if len(labels.shape				) > 1 and labels.shape[1] != 1:
             SCREAMING_SNAKE_CASE__      							=				-1_00
             SCREAMING_SNAKE_CASE__      							=				tf.convert_to_tensor(_lowercase				)
             SCREAMING_SNAKE_CASE__      							=				model(_lowercase	,     **_lowercase				)[0]
             self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]				)
             self.assertTrue(not np.any(np.isnan(loss.numpy()				)				)				)

                # Test that model correctly compute the loss with a dict
         SCREAMING_SNAKE_CASE__      							=				self._prepare_for_class(inputs_dict.copy()	,     _lowercase	,     return_labels=_lowercase				)
         SCREAMING_SNAKE_CASE__      							=				model(_lowercase				)[0]
         self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]				)

         # Test that model correctly compute the loss with a tuple
         SCREAMING_SNAKE_CASE__      							=				self._prepare_for_class(inputs_dict.copy()	,     _lowercase	,     return_labels=_lowercase				)

         # Get keys that were added with the _prepare_for_class function
         SCREAMING_SNAKE_CASE__      							=				prepared_for_class.keys() - inputs_dict.keys()
         SCREAMING_SNAKE_CASE__      							=				inspect.signature(model.call				).parameters
         SCREAMING_SNAKE_CASE__      							=				list(signature.keys()				)

         # Create a dictionary holding the location of the tensors in the tuple
         SCREAMING_SNAKE_CASE__      							=				{0: """input_ids"""}
         for label_key in label_keys:
           SCREAMING_SNAKE_CASE__      							=				signature_names.index(_lowercase				)
           SCREAMING_SNAKE_CASE__      							=				label_key
         SCREAMING_SNAKE_CASE__      							=				sorted(tuple_index_mapping.items()				)
         # Initialize a list with their default values, update the values and convert to a tuple
         SCREAMING_SNAKE_CASE__      							=				[]

         for name in signature_names:
           if name != "kwargs":
             list_input.append(signature[name].default				)

         for index, value in sorted_tuple_index_mapping:
           SCREAMING_SNAKE_CASE__      							=				prepared_for_class[value]

         SCREAMING_SNAKE_CASE__      							=				tuple(_lowercase				)

         # Send to model
         SCREAMING_SNAKE_CASE__      							=				model(tuple_input[:-1]				)[0]

         self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]				)




   def      __a						(   self      :    Optional[int]				):



     """simple docstring"""






     (
         (
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					
     )      							=				self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(_lowercase	,     _lowercase	,     _lowercase	,     _lowercase	,     _lowercase	,     _lowercase				)




   def      __a						(   self      :    int				):



     """simple docstring"""






     (
         (
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					
     )      							=				self.model_tester.prepare_config_and_inputs()
     for type in ["absolute", "relative_key", "relative_key_query"]:
       SCREAMING_SNAKE_CASE__      							=				type
       self.model_tester.create_and_check_model(_lowercase	,     _lowercase	,     _lowercase	,     _lowercase	,     _lowercase	,     _lowercase				)




   def      __a						(   self      :    int				):



     """simple docstring"""






     (
         (
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					
     )      							=				self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_sequence_classification(
         _lowercase	,     _lowercase	,     _lowercase	,     _lowercase	,     _lowercase	,     _lowercase	,     _lowercase				)




   def      __a						(   self      :    str				):



     """simple docstring"""






     (
         (
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					
     )      							=				self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_token_classification(
         _lowercase	,     _lowercase	,     _lowercase	,     _lowercase	,     _lowercase	,     _lowercase	,     _lowercase				)




   def      __a						(   self      :    List[str]				):



     """simple docstring"""






     (
         (
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					(
         SCREAMING_SNAKE_CASE__
     )							,					
     )      							=				self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_question_answering(
         _lowercase	,     _lowercase	,     _lowercase	,     _lowercase	,     _lowercase	,     _lowercase	,     _lowercase				)




   @slow
   def      __a						(   self      :    Tuple				):



     """simple docstring"""






     for model_name in TF_LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       SCREAMING_SNAKE_CASE__      							=				TFLayoutLMvaModel.from_pretrained(_lowercase				)
       self.assertIsNotNone(_lowercase				)





def      __SCREAMING_SNAKE_CASE  ( )							-> List[Any]:







  """simple docstring"""





  SCREAMING_SNAKE_CASE__      							=				Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""     )
  return image







@require_tf
class __snake_case    (						unittest.TestCase		):




   @cached_property
   def      __a						(   self      :    Optional[int]				):



     """simple docstring"""






     return LayoutLMvaImageProcessor(apply_ocr=_lowercase				) if is_vision_available() else None




   @slow
   def      __a						(   self      :    Tuple				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				TFLayoutLMvaModel.from_pretrained("""microsoft/layoutlmv3-base"""				)

     SCREAMING_SNAKE_CASE__      							=				self.default_image_processor
     SCREAMING_SNAKE_CASE__      							=				prepare_img()
     SCREAMING_SNAKE_CASE__      							=				image_processor(images=_lowercase	,     return_tensors="""tf"""				).pixel_values

     SCREAMING_SNAKE_CASE__      							=				tf.constant([[1, 2]]				)
     SCREAMING_SNAKE_CASE__      							=				tf.expand_dims(tf.constant([[1, 2, 3, 4], [5, 6, 7, 8]]				)	,     axis=0				)

     # forward pass
     SCREAMING_SNAKE_CASE__      							=				model(input_ids=_lowercase	,     bbox=_lowercase	,     pixel_values=_lowercase	,     training=_lowercase				)

     # verify the logits
     SCREAMING_SNAKE_CASE__      							=				(1, 1_99, 7_68)
     self.assertEqual(outputs.last_hidden_state.shape	,     _lowercase				)

     SCREAMING_SNAKE_CASE__      							=				tf.constant(
         [[-0.05_29, 0.36_18, 0.16_32], [-0.15_87, -0.16_67, -0.04_00], [-0.15_57, -0.16_71, -0.05_05]]				)

     self.assertTrue(np.allclose(outputs.last_hidden_state[0, :3, :3]	,     _lowercase	,     atol=1E-4				)				)
