


'''simple docstring'''
import unittest

from transformers import LiltConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
  import torch

  from transformers import (
      LiltForQuestionAnswering,
      LiltForSequenceClassification,
      LiltForTokenClassification,
      LiltModel,
  )
  from transformers.models.lilt.modeling_lilt import LILT_PRETRAINED_MODEL_ARCHIVE_LIST




class 			lowerCamelCase_   :






      def __init__(					self				:    List[Any]						,						_A				:    Optional[int]						,						_A				:    Any=13						,						_A				:    Dict=7						,						_A				:    List[Any]=True						,						_A				:    Optional[int]=True						,						_A				:    str=True						,						_A				:    Tuple=True						,						_A				:    Any=99						,						_A				:    Union[str, Any]=24						,						_A				:    Any=2						,						_A				:    Optional[int]=6						,						_A				:    str=37						,						_A				:    Dict="gelu"						,						_A				:    List[Any]=0.1						,						_A				:    str=0.1						,						_A				:    List[str]=512						,						_A				:    List[str]=16						,						_A				:    Dict=2						,						_A				:    Optional[int]=0.0_2						,						_A				:    int=3						,						_A				:    Any=None						,						_A				:    Any=1_000						,						):


          '''simple docstring'''


          UpperCAmelCase__			:		Optional[Any]													=				parent
          UpperCAmelCase__			:		Optional[Any]													=				batch_size
          UpperCAmelCase__			:		List[str]													=				seq_length
          UpperCAmelCase__			:		List[Any]													=				is_training
          UpperCAmelCase__			:		Optional[int]													=				use_input_mask
          UpperCAmelCase__			:		Tuple													=				use_token_type_ids
          UpperCAmelCase__			:		List[Any]													=				use_labels
          UpperCAmelCase__			:		Optional[int]													=				vocab_size
          UpperCAmelCase__			:		Optional[int]													=				hidden_size
          UpperCAmelCase__			:		Union[str, Any]													=				num_hidden_layers
          UpperCAmelCase__			:		Optional[Any]													=				num_attention_heads
          UpperCAmelCase__			:		Optional[int]													=				intermediate_size
          UpperCAmelCase__			:		Tuple													=				hidden_act
          UpperCAmelCase__			:		Union[str, Any]													=				hidden_dropout_prob
          UpperCAmelCase__			:		str													=				attention_probs_dropout_prob
          UpperCAmelCase__			:		Union[str, Any]													=				max_position_embeddings
          UpperCAmelCase__			:		Optional[int]													=				type_vocab_size
          UpperCAmelCase__			:		int													=				type_sequence_label_size
          UpperCAmelCase__			:		Optional[int]													=				initializer_range
          UpperCAmelCase__			:		Optional[int]													=				num_labels
          UpperCAmelCase__			:		Optional[Any]													=				scope
          UpperCAmelCase__			:		List[Any]													=				range_bbox






      def lowercase_							(					self				:    Tuple ):


          '''simple docstring'''


          UpperCAmelCase__			:		Optional[int]													=				ids_tensor([self.batch_size, self.seq_length]						,						self.vocab_size )

          UpperCAmelCase__			:		Union[str, Any]													=				ids_tensor([self.batch_size, self.seq_length, 4]						,						self.range_bbox )
          # 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]:
                      UpperCAmelCase__			:		Optional[int]													=				bbox[i, j, 3]
                      UpperCAmelCase__			:		Dict													=				bbox[i, j, 1]
                      UpperCAmelCase__			:		Dict													=				t
                  if bbox[i, j, 2] < bbox[i, j, 0]:
                      UpperCAmelCase__			:		Union[str, Any]													=				bbox[i, j, 2]
                      UpperCAmelCase__			:		List[str]													=				bbox[i, j, 0]
                      UpperCAmelCase__			:		str													=				t

          UpperCAmelCase__			:		Any													=				None
          if self.use_input_mask:
              UpperCAmelCase__			:		Union[str, Any]													=				ids_tensor([self.batch_size, self.seq_length]						,						vocab_size=2 )

          UpperCAmelCase__			:		Dict													=				None
          if self.use_token_type_ids:
              UpperCAmelCase__			:		Any													=				ids_tensor([self.batch_size, self.seq_length]						,						self.type_vocab_size )

          UpperCAmelCase__			:		str													=				None
          UpperCAmelCase__			:		Union[str, Any]													=				None
          if self.use_labels:
              UpperCAmelCase__			:		str													=				ids_tensor([self.batch_size]						,						self.type_sequence_label_size )
              UpperCAmelCase__			:		Dict													=				ids_tensor([self.batch_size, self.seq_length]						,						self.num_labels )

          UpperCAmelCase__			:		Union[str, Any]													=				self.get_config()

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






      def lowercase_							(					self				:    List[str] ):


          '''simple docstring'''


          return LiltConfig(
              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						,						)






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


          '''simple docstring'''


          UpperCAmelCase__			:		Optional[Any]													=				LiltModel(config=_A )
          model.to(_A )
          model.eval()
          UpperCAmelCase__			:		Tuple													=				model(_A						,						bbox=_A						,						attention_mask=_A						,						token_type_ids=_A )
          UpperCAmelCase__			:		List[Any]													=				model(_A						,						bbox=_A						,						token_type_ids=_A )
          UpperCAmelCase__			:		Dict													=				model(_A						,						bbox=_A )

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






      def lowercase_							(					self				:    Optional[Any]						,						_A				:    List[Any]						,						_A				:    Union[str, Any]						,						_A				:    Tuple						,						_A				:    List[str]						,						_A				:    List[str]						,						_A				:    Union[str, Any]						,						_A				:    Any						,						):


          '''simple docstring'''


          UpperCAmelCase__			:		Optional[int]													=				self.num_labels
          UpperCAmelCase__			:		Any													=				LiltForTokenClassification(config=_A )
          model.to(_A )
          model.eval()
          UpperCAmelCase__			:		List[str]													=				model(
              _A						,						bbox=_A						,						attention_mask=_A						,						token_type_ids=_A						,						labels=_A )
          self.parent.assertEqual(result.logits.shape						,						(self.batch_size, self.seq_length, self.num_labels) )






      def lowercase_							(					self				:    int						,						_A				:    str						,						_A				:    Optional[Any]						,						_A				:    List[Any]						,						_A				:    Any						,						_A				:    List[str]						,						_A				:    Dict						,						_A				:    Tuple						,						):


          '''simple docstring'''


          UpperCAmelCase__			:		Dict													=				LiltForQuestionAnswering(config=_A )
          model.to(_A )
          model.eval()
          UpperCAmelCase__			:		Optional[Any]													=				model(
              _A						,						bbox=_A						,						attention_mask=_A						,						token_type_ids=_A						,						start_positions=_A						,						end_positions=_A						,						)
          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 lowercase_							(					self				:    Tuple ):


          '''simple docstring'''


          UpperCAmelCase__			:		List[Any]													=				self.prepare_config_and_inputs()
          (
              (
              UpperCAmelCase__
          )						,						(
              UpperCAmelCase__
          )						,						(
              UpperCAmelCase__
          )						,						(
              UpperCAmelCase__
          )						,						(
              UpperCAmelCase__
          )						,						(
              UpperCAmelCase__
          )						,						(
              UpperCAmelCase__
          )						,						
          )			:		Optional[int]													=				config_and_inputs
          UpperCAmelCase__			:		int													=				{
              '''input_ids''': input_ids,
              '''bbox''': bbox,
              '''token_type_ids''': token_type_ids,
              '''attention_mask''': input_mask,
          }
          return config, inputs_dict




@require_torch
class 			lowerCamelCase_   (	__a     ,       __a     ,       __a     ,       unittest.TestCase      ):
      lowerCAmelCase__		     =     (
          (
              LiltModel,
              LiltForSequenceClassification,
              LiltForTokenClassification,
              LiltForQuestionAnswering,
          )
          if is_torch_available()
          else ()
      )
      lowerCAmelCase__		     =     (
          {
              'feature-extraction': LiltModel,
              'question-answering': LiltForQuestionAnswering,
              'text-classification': LiltForSequenceClassification,
              'token-classification': LiltForTokenClassification,
              'zero-shot': LiltForSequenceClassification,
          }
          if is_torch_available()
          else {}
      )
      lowerCAmelCase__		     =     False
      lowerCAmelCase__		     =     False






      def lowercase_							(					self				:    List[str]						,						_A				:    Any						,						_A				:    Optional[int]						,						_A				:    int						,						_A				:    Tuple						,						_A				:    List[Any] ):


          '''simple docstring'''


          return True






      def lowercase_							(					self				:    Union[str, Any] ):


          '''simple docstring'''


          UpperCAmelCase__			:		List[Any]													=				LiltModelTester(self )
          UpperCAmelCase__			:		Optional[int]													=				ConfigTester(self						,						config_class=_A						,						hidden_size=37 )






      def lowercase_							(					self				:    List[str] ):


          '''simple docstring'''


          self.config_tester.run_common_tests()






      def lowercase_							(					self				:    Union[str, Any] ):


          '''simple docstring'''


          UpperCAmelCase__			:		Optional[int]													=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*_A )






      def lowercase_							(					self				:    Dict ):


          '''simple docstring'''


          UpperCAmelCase__			:		Optional[Any]													=				self.model_tester.prepare_config_and_inputs()
          for type in ["absolute", "relative_key", "relative_key_query"]:
              UpperCAmelCase__			:		Dict													=				type
              self.model_tester.create_and_check_model(*_A )






      def lowercase_							(					self				:    List[Any] ):


          '''simple docstring'''


          UpperCAmelCase__			:		Any													=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_token_classification(*_A )






      def lowercase_							(					self				:    List[str] ):


          '''simple docstring'''


          UpperCAmelCase__			:		Optional[int]													=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_question_answering(*_A )






      @slow
      def lowercase_							(					self				:    List[str] ):


          '''simple docstring'''


          for model_name in LILT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              UpperCAmelCase__			:		Any													=				LiltModel.from_pretrained(_A )
              self.assertIsNotNone(_A )




@require_torch
@slow
class 			lowerCamelCase_   (	unittest.TestCase      ):






      def lowercase_							(					self				:    int ):


          '''simple docstring'''


          UpperCAmelCase__			:		Any													=				LiltModel.from_pretrained('''SCUT-DLVCLab/lilt-roberta-en-base''' ).to(_A )

          UpperCAmelCase__			:		Any													=				torch.tensor([[1, 2]]						,						device=_A )
          UpperCAmelCase__			:		str													=				torch.tensor([[[1, 2, 3, 4], [5, 6, 7, 8]]]						,						device=_A )

          # forward pass
          with torch.no_grad():
              UpperCAmelCase__			:		str													=				model(input_ids=_A						,						bbox=_A )

          UpperCAmelCase__			:		Dict													=				torch.Size([1, 2, 768] )
          UpperCAmelCase__			:		Tuple													=				torch.tensor(
              [[-0.0_6_5_3, 0.0_9_5_0, -0.0_0_6_1], [-0.0_5_4_5, 0.0_9_2_6, -0.0_3_2_4]]						,						device=_A						,						)

          self.assertTrue(outputs.last_hidden_state.shape						,						_A )
          self.assertTrue(torch.allclose(outputs.last_hidden_state[0, :, :3]						,						_A						,						atol=1e-3 ) )




'''simple docstring'''
import pprint

import requests

UpperCamelCase__    					=      '''https://zenquotes.io/api'''





def 					a__       (					)    ->	list:
    return requests.get(API_ENDPOINT_URL + '''/today'''						).json()





def 					a__       (					)    ->	list:
    return requests.get(API_ENDPOINT_URL + '''/random'''						).json()


if __name__ == "__main__":
  UpperCamelCase__    					=      random_quotes()
  pprint.pprint(response)
