





'''simple docstring'''







from sklearn.metrics import fa_score, matthews_corrcoef

import datasets

from .record_evaluation import evaluate as evaluate_record


snake_case_     :       Tuple						=  "\\n@article{wang2019superglue,\n  title={SuperGLUE: A Stickier Benchmark for General-Purpose Language Understanding Systems},\n  author={Wang, Alex and Pruksachatkun, Yada and Nangia, Nikita and Singh, Amanpreet and Michael, Julian and Hill, Felix and Levy, Omer and Bowman, Samuel R},\n  journal={arXiv preprint arXiv:1905.00537},\n  year={2019}\n}\n"

snake_case_     :       Optional[Any]						=  "\\nSuperGLUE (https://super.gluebenchmark.com/) is a new benchmark styled after\nGLUE with a new set of more difficult language understanding tasks, improved\nresources, and a new public leaderboard.\n"

snake_case_     :       str						=  "\nCompute SuperGLUE evaluation metric associated to each SuperGLUE dataset.\nArgs:\n    predictions: list of predictions to score. Depending on the SuperGlUE subset:\n        - for 'record': list of question-answer dictionaries with the following keys:\n            - 'idx': index of the question as specified by the dataset\n            - 'prediction_text': the predicted answer text\n        - for 'multirc': list of question-answer dictionaries with the following keys:\n            - 'idx': index of the question-answer pair as specified by the dataset\n            - 'prediction': the predicted answer label\n        - otherwise: list of predicted labels\n    references: list of reference labels. Depending on the SuperGLUE subset:\n        - for 'record': list of question-answers dictionaries with the following keys:\n            - 'idx': index of the question as specified by the dataset\n            - 'answers': list of possible answers\n        - otherwise: list of reference labels\nReturns: depending on the SuperGLUE subset:\n    - for 'record':\n        - 'exact_match': Exact match between answer and gold answer\n        - 'f1': F1 score\n    - for 'multirc':\n        - 'exact_match': Exact match between answer and gold answer\n        - 'f1_m': Per-question macro-F1 score\n        - 'f1_a': Average F1 score over all answers\n    - for 'axb':\n        'matthews_correlation': Matthew Correlation\n    - for 'cb':\n        - 'accuracy': Accuracy\n        - 'f1': F1 score\n    - for all others:\n        - 'accuracy': Accuracy\nExamples:\n\n    >>> super_glue_metric = datasets.load_metric('super_glue', 'copa')  # any of [\"copa\", \"rte\", \"wic\", \"wsc\", \"wsc.fixed\", \"boolq\", \"axg\"]\n    >>> predictions = [0, 1]\n    >>> references = [0, 1]\n    >>> results = super_glue_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {'accuracy': 1.0}\n\n    >>> super_glue_metric = datasets.load_metric('super_glue', 'cb')\n    >>> predictions = [0, 1]\n    >>> references = [0, 1]\n    >>> results = super_glue_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {'accuracy': 1.0, 'f1': 1.0}\n\n    >>> super_glue_metric = datasets.load_metric('super_glue', 'record')\n    >>> predictions = [{'idx': {'passage': 0, 'query': 0}, 'prediction_text': 'answer'}]\n    >>> references = [{'idx': {'passage': 0, 'query': 0}, 'answers': ['answer', 'another_answer']}]\n    >>> results = super_glue_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {'exact_match': 1.0, 'f1': 1.0}\n\n    >>> super_glue_metric = datasets.load_metric('super_glue', 'multirc')\n    >>> predictions = [{'idx': {'answer': 0, 'paragraph': 0, 'question': 0}, 'prediction': 0}, {'idx': {'answer': 1, 'paragraph': 2, 'question': 3}, 'prediction': 1}]\n    >>> references = [0, 1]\n    >>> results = super_glue_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {'exact_match': 1.0, 'f1_m': 1.0, 'f1_a': 1.0}\n\n    >>> super_glue_metric = datasets.load_metric('super_glue', 'axb')\n    >>> references = [0, 1]\n    >>> predictions = [0, 1]\n    >>> results = super_glue_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {'matthews_correlation': 1.0}\n"





def        lowerCamelCase_      (  SCREAMING_SNAKE_CASE__      :			List[Any],			SCREAMING_SNAKE_CASE__      :			Optional[Any]   ) ->	Optional[Any]:
      return float((preds == labels).mean()   )





def        lowerCamelCase_      (  SCREAMING_SNAKE_CASE__      :			Union[str, Any],			SCREAMING_SNAKE_CASE__      :			Optional[int],			SCREAMING_SNAKE_CASE__      :			Optional[Any]="binary"   ) ->	Optional[Any]:
      UpperCAmelCase_			:      Optional[Any]     						=  simple_accuracy(_lowerCamelCase,			_lowerCamelCase   )
      UpperCAmelCase_			:      Union[str, Any]     						=  float(fa_score(y_true=_lowerCamelCase,			y_pred=_lowerCamelCase,			average=_lowerCamelCase   )   )
      return {
          "accuracy": acc,
          "f1": fa,
      }





def        lowerCamelCase_      (  SCREAMING_SNAKE_CASE__      :			List[str],			SCREAMING_SNAKE_CASE__      :			Union[str, Any]   ) ->	Tuple:
      UpperCAmelCase_			:      Dict     						=  {}
      for id_pred, label in zip(_lowerCamelCase,			_lowerCamelCase   ):
            UpperCAmelCase_			:      Dict     						=  F"""{id_pred["idx"]["paragraph"]}-{id_pred["idx"]["question"]}"""
            UpperCAmelCase_			:      List[Any]     						=  id_pred["""prediction"""]
            if question_id in question_map:
                  question_map[question_id].append((pred, label)   )
            else:
                  UpperCAmelCase_			:      Optional[int]     						=  [(pred, label)]
      UpperCAmelCase_			:      Optional[int]     						=  [], []
      for question, preds_labels in question_map.items():
            UpperCAmelCase_			:      Dict     						=  zip(*_lowerCamelCase   )
            UpperCAmelCase_			:      str     						=  fa_score(y_true=_lowerCamelCase,			y_pred=_lowerCamelCase,			average='''macro'''   )
            fas.append(_lowerCamelCase   )
            UpperCAmelCase_			:      str     						=  int(sum(pred == label for pred, label in preds_labels   ) == len(_lowerCamelCase   )   )
            ems.append(_lowerCamelCase   )
      UpperCAmelCase_			:      Dict     						=  float(sum(_lowerCamelCase   ) / len(_lowerCamelCase   )   )
      UpperCAmelCase_			:      Union[str, Any]     						=  sum(_lowerCamelCase   ) / len(_lowerCamelCase   )
      UpperCAmelCase_			:      List[Any]     						=  float(fa_score(y_true=_lowerCamelCase,			y_pred=[id_pred['''prediction'''] for id_pred in ids_preds]   )   )
      return {"exact_match": em, "f1_m": fa_m, "f1_a": fa_a}


@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION       ,		_KWARGS_DESCRIPTION     )
class 					__a      (datasets.Metric     ):

       def     UpperCAmelCase__	(							self							:     Optional[Any]   )					->       str:







             """simple docstring"""

             if self.config_name not in [
                 "boolq",
                 "cb",
                 "copa",
                 "multirc",
                 "record",
                 "rte",
                 "wic",
                 "wsc",
                 "wsc.fixed",
                 "axb",
                 "axg",
             ]:
                   raise KeyError(
                       '''You should supply a configuration name selected in '''
                       '''[\"boolq\", \"cb\", \"copa\", \"multirc\", \"record\", \"rte\", \"wic\", \"wsc\", \"wsc.fixed\", \"axb\", \"axg\",]'''   )
             return datasets.MetricInfo(
                 description=_DESCRIPTION       ,     citation=_CITATION       ,     inputs_description=_KWARGS_DESCRIPTION       ,     features=datasets.Features(self._get_feature_types()   )       ,     codebase_urls=[]       ,     reference_urls=[]       ,     format='''numpy''' if not self.config_name == '''record''' and not self.config_name == '''multirc''' else None       ,     )

       def     UpperCAmelCase__	(							self							:     List[str]   )					->       Tuple:







             """simple docstring"""

             if self.config_name == "record":
                   return {
                       "predictions": {
                           "idx": {
                               "passage": datasets.Value('''int64'''   ),
                               "query": datasets.Value('''int64'''   ),
                           },
                           "prediction_text": datasets.Value('''string'''   ),
                       },
                       "references": {
                           "idx": {
                               "passage": datasets.Value('''int64'''   ),
                               "query": datasets.Value('''int64'''   ),
                           },
                           "answers": datasets.Sequence(datasets.Value('''string'''   )   ),
                       },
                   }
             elif self.config_name == "multirc":
                   return {
                       "predictions": {
                           "idx": {
                               "answer": datasets.Value('''int64'''   ),
                               "paragraph": datasets.Value('''int64'''   ),
                               "question": datasets.Value('''int64'''   ),
                           },
                           "prediction": datasets.Value('''int64'''   ),
                       },
                       "references": datasets.Value('''int64'''   ),
                   }
             else:
                   return {
                       "predictions": datasets.Value('''int64'''   ),
                       "references": datasets.Value('''int64'''   ),
                   }



       def     UpperCAmelCase__	(							self							:     List[str]       ,     __magic_name__							:     int       ,     __magic_name__							:     Optional[int]   )					->       Dict:







             """simple docstring"""

             if self.config_name == "axb":
                   return {"matthews_correlation": matthews_corrcoef(_lowercase       ,     _lowercase   )}
             elif self.config_name == "cb":
                   return acc_and_fa(_lowercase       ,     _lowercase       ,     fa_avg='''macro'''   )
             elif self.config_name == "record":
                   UpperCAmelCase_			:      List[str]     						=  [
                       {
                           """qas""": [
                               {"""id""": ref["""idx"""]["""query"""], """answers""": [{"""text""": ans} for ans in ref["""answers"""]]}
                               for ref in references
                           ]
                       }
                   ]
                   UpperCAmelCase_			:      List[Any]     						=  {pred["""idx"""]["""query"""]: pred["""prediction_text"""] for pred in predictions}
                   return evaluate_record(_lowercase       ,     _lowercase   )[0]
             elif self.config_name == "multirc":
                   return evaluate_multirc(_lowercase       ,     _lowercase   )
             elif self.config_name in ["copa", "rte", "wic", "wsc", "wsc.fixed", "boolq", "axg"]:
                   return {"accuracy": simple_accuracy(_lowercase       ,     _lowercase   )}
             else:
                   raise KeyError(
                       '''You should supply a configuration name selected in '''
                       '''[\"boolq\", \"cb\", \"copa\", \"multirc\", \"record\", \"rte\", \"wic\", \"wsc\", \"wsc.fixed\", \"axb\", \"axg\",]'''   )












'''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 					__a      :

							def __init__(							self							:     int       ,     __magic_name__							:     Optional[Any]       ,     __magic_name__							:     Any=13       ,     __magic_name__							:     Any=7       ,     __magic_name__							:     Union[str, Any]=True       ,     __magic_name__							:     Union[str, Any]=True       ,     __magic_name__							:     str=True       ,     __magic_name__							:     Optional[int]=True       ,     __magic_name__							:     List[Any]=99       ,     __magic_name__							:     int=24       ,     __magic_name__							:     Optional[int]=2       ,     __magic_name__							:     Tuple=6       ,     __magic_name__							:     Union[str, Any]=37       ,     __magic_name__							:     Optional[Any]="gelu"       ,     __magic_name__							:     Any=0.1       ,     __magic_name__							:     str=0.1       ,     __magic_name__							:     Tuple=5_12       ,     __magic_name__							:     Union[str, Any]=16       ,     __magic_name__							:     Tuple=2       ,     __magic_name__							:     Tuple=0.0_2       ,     __magic_name__							:     Optional[Any]=3       ,     __magic_name__							:     Optional[int]=None       ,     __magic_name__							:     Any=10_00       ,     )					->       str:







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

							def     UpperCAmelCase__	(							self							:     Optional[int]   )					->       List[Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      Optional[int]     						=  ids_tensor([self.batch_size, self.seq_length]       ,     self.vocab_size   )

													UpperCAmelCase_			:      List[str]     						=  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_			:      List[str]     						=  bbox[i, j, 3]
																															UpperCAmelCase_			:      Dict     						=  bbox[i, j, 1]
																															UpperCAmelCase_			:      Optional[Any]     						=  t
																									if bbox[i, j, 2] < bbox[i, j, 0]:
																															UpperCAmelCase_			:      List[str]     						=  bbox[i, j, 2]
																															UpperCAmelCase_			:      Tuple     						=  bbox[i, j, 0]
																															UpperCAmelCase_			:      Union[str, Any]     						=  t

													UpperCAmelCase_			:      int     						=  None
													if self.use_input_mask:
																			UpperCAmelCase_			:      Optional[int]     						=  ids_tensor([self.batch_size, self.seq_length]       ,     vocab_size=2   )

													UpperCAmelCase_			:      Optional[int]     						=  None
													if self.use_token_type_ids:
																			UpperCAmelCase_			:      str     						=  ids_tensor([self.batch_size, self.seq_length]       ,     self.type_vocab_size   )

													UpperCAmelCase_			:      Dict     						=  None
													UpperCAmelCase_			:      Tuple     						=  None
													if self.use_labels:
																			UpperCAmelCase_			:      Any     						=  ids_tensor([self.batch_size]       ,     self.type_sequence_label_size   )
																			UpperCAmelCase_			:      Dict     						=  ids_tensor([self.batch_size, self.seq_length]       ,     self.num_labels   )

													UpperCAmelCase_			:      int     						=  self.get_config()

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

							def     UpperCAmelCase__	(							self							:     Any   )					->       List[Any]:







													"""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     UpperCAmelCase__	(							self							:     List[Any]       ,     __magic_name__							:     str       ,     __magic_name__							:     Optional[Any]       ,     __magic_name__							:     int       ,     __magic_name__							:     Optional[Any]       ,     __magic_name__							:     int       ,     __magic_name__							:     Optional[Any]       ,     __magic_name__							:     int       ,     )					->       Optional[int]:







													"""simple docstring"""
													UpperCAmelCase_			:      Any     						=  LiltModel(config=__magic_name__   )
													model.to(__magic_name__   )
													model.eval()
													UpperCAmelCase_			:      Optional[Any]     						=  model(__magic_name__       ,     bbox=__magic_name__       ,     attention_mask=__magic_name__       ,     token_type_ids=__magic_name__   )
													UpperCAmelCase_			:      List[Any]     						=  model(__magic_name__       ,     bbox=__magic_name__       ,     token_type_ids=__magic_name__   )
													UpperCAmelCase_			:      Optional[int]     						=  model(__magic_name__       ,     bbox=__magic_name__   )

													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     UpperCAmelCase__	(							self							:     int       ,     __magic_name__							:     Optional[Any]       ,     __magic_name__							:     List[str]       ,     __magic_name__							:     Any       ,     __magic_name__							:     Optional[int]       ,     __magic_name__							:     str       ,     __magic_name__							:     Optional[int]       ,     __magic_name__							:     List[Any]       ,     )					->       Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      Any     						=  self.num_labels
													UpperCAmelCase_			:      List[Any]     						=  LiltForTokenClassification(config=__magic_name__   )
													model.to(__magic_name__   )
													model.eval()
													UpperCAmelCase_			:      List[Any]     						=  model(
													    __magic_name__       ,     bbox=__magic_name__       ,     attention_mask=__magic_name__       ,     token_type_ids=__magic_name__       ,     labels=__magic_name__   )
													self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.seq_length, self.num_labels)   )

							def     UpperCAmelCase__	(							self							:     Any       ,     __magic_name__							:     Optional[Any]       ,     __magic_name__							:     Dict       ,     __magic_name__							:     Any       ,     __magic_name__							:     Optional[int]       ,     __magic_name__							:     int       ,     __magic_name__							:     Tuple       ,     __magic_name__							:     Any       ,     )					->       Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      str     						=  LiltForQuestionAnswering(config=__magic_name__   )
													model.to(__magic_name__   )
													model.eval()
													UpperCAmelCase_			:      Optional[Any]     						=  model(
													    __magic_name__       ,     bbox=__magic_name__       ,     attention_mask=__magic_name__       ,     token_type_ids=__magic_name__       ,     start_positions=__magic_name__       ,     end_positions=__magic_name__       ,     )
													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     UpperCAmelCase__	(							self							:     List[Any]   )					->       List[Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      Tuple     						=  self.prepare_config_and_inputs()
													(
													    (
													    UpperCAmelCase_
													)						,       (
													    UpperCAmelCase_
													)						,       (
													    UpperCAmelCase_
													)						,       (
													    UpperCAmelCase_
													)						,       (
													    UpperCAmelCase_
													)						,       (
													    UpperCAmelCase_
													)						,       (
													    UpperCAmelCase_
													)						,       
													)			:      Optional[int]     						=  config_and_inputs
													UpperCAmelCase_			:      Tuple     						=  {
													    '''input_ids''': input_ids,
													    '''bbox''': bbox,
													    '''token_type_ids''': token_type_ids,
													    '''attention_mask''': input_mask,
													}
													return config, inputs_dict





@require_torch
class 					__a      (lowerCamelCase       ,		lowerCamelCase       ,		lowerCamelCase       ,		unittest.TestCase     ):
							__a					:   Tuple									=       (
							    (
							        LiltModel,
							        LiltForSequenceClassification,
							        LiltForTokenClassification,
							        LiltForQuestionAnswering,
							    )
							    if is_torch_available()
							    else ()
							)
							__a					:   Any									=       (
							    {
							        "feature-extraction": LiltModel,
							        "question-answering": LiltForQuestionAnswering,
							        "text-classification": LiltForSequenceClassification,
							        "token-classification": LiltForTokenClassification,
							        "zero-shot": LiltForSequenceClassification,
							    }
							    if is_torch_available()
							    else {}
							)
							__a					:   Union[str, Any]									=       False
							__a					:   int									=       False

							def     UpperCAmelCase__	(							self							:     List[str]       ,     __magic_name__							:     Dict       ,     __magic_name__							:     List[Any]       ,     __magic_name__							:     Optional[int]       ,     __magic_name__							:     Optional[Any]       ,     __magic_name__							:     int   )					->       str:







													"""simple docstring"""
													return True

							def     UpperCAmelCase__	(							self							:     str   )					->       List[Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      List[Any]     						=  LiltModelTester(self   )
													UpperCAmelCase_			:      List[Any]     						=  ConfigTester(self       ,     config_class=__magic_name__       ,     hidden_size=37   )

							def     UpperCAmelCase__	(							self							:     Union[str, Any]   )					->       str:







													"""simple docstring"""
													self.config_tester.run_common_tests()

							def     UpperCAmelCase__	(							self							:     str   )					->       Union[str, Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      int     						=  self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_model(*__magic_name__   )

							def     UpperCAmelCase__	(							self							:     str   )					->       str:







													"""simple docstring"""
													UpperCAmelCase_			:      Any     						=  self.model_tester.prepare_config_and_inputs()
													for type in ["absolute", "relative_key", "relative_key_query"]:
																			UpperCAmelCase_			:      Tuple     						=  type
																			self.model_tester.create_and_check_model(*__magic_name__   )

							def     UpperCAmelCase__	(							self							:     Union[str, Any]   )					->       int:







													"""simple docstring"""
													UpperCAmelCase_			:      Any     						=  self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_token_classification(*__magic_name__   )

							def     UpperCAmelCase__	(							self							:     str   )					->       List[Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      Optional[Any]     						=  self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_question_answering(*__magic_name__   )



							@slow
							def     UpperCAmelCase__	(							self							:     int   )					->       Union[str, Any]:







													"""simple docstring"""
													for model_name in LILT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																			UpperCAmelCase_			:      Optional[int]     						=  LiltModel.from_pretrained(__magic_name__   )
																			self.assertIsNotNone(__magic_name__   )





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

							def     UpperCAmelCase__	(							self							:     Tuple   )					->       Tuple:







													"""simple docstring"""
													UpperCAmelCase_			:      str     						=  LiltModel.from_pretrained('''SCUT-DLVCLab/lilt-roberta-en-base'''   ).to(__magic_name__   )

													UpperCAmelCase_			:      Any     						=  torch.tensor([[1, 2]]       ,     device=__magic_name__   )
													UpperCAmelCase_			:      int     						=  torch.tensor([[[1, 2, 3, 4], [5, 6, 7, 8]]]       ,     device=__magic_name__   )

													# forward pass
													with torch.no_grad():
																			UpperCAmelCase_			:      Optional[int]     						=  model(input_ids=__magic_name__       ,     bbox=__magic_name__   )

													UpperCAmelCase_			:      int     						=  torch.Size([1, 2, 7_68]   )
													UpperCAmelCase_			:      List[str]     						=  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=__magic_name__       ,     )

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





