

'''simple docstring'''

import unittest

import numpy as np
import torch

from .utils_summarization import build_mask, compute_token_type_ids, process_story, truncate_or_pad




class 	A_			(    unittest.TestCase							):






     '''simple docstring'''



     def        UpperCAmelCase_	(		self			:					str	)						->     Tuple:
      UpperCAmelCase	:     Optional[int]						 =			10


     def        UpperCAmelCase_	(		self			:					List[Any]	)						->     Dict:
      UpperCAmelCase	:     int						 =			[1, 2, 3, 4]
      UpperCAmelCase	:     Union[str, Any]						 =			[1, 2, 3, 4, 0, 0, 0, 0, 0, 0]
      self.assertEqual(truncate_or_pad(_a					,      self.block_size					,      0	)					,      _a	)


     def        UpperCAmelCase_	(		self			:					Optional[int]	)						->     Any:
      UpperCAmelCase	:     Optional[int]						 =			[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
      UpperCAmelCase	:     Dict						 =			[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
      self.assertEqual(truncate_or_pad(_a					,      self.block_size					,      0	)					,      _a	)


     def        UpperCAmelCase_	(		self			:					Any	)						->     Optional[Any]:
      UpperCAmelCase	:     Union[str, Any]						 =			[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
      UpperCAmelCase	:     List[Any]						 =			[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
      self.assertEqual(truncate_or_pad(_a					,      self.block_size					,      0	)					,      _a	)


     def        UpperCAmelCase_	(		self			:					Optional[Any]	)						->     int:
      UpperCAmelCase	:     int						 =			'It was the year of Our Lord one thousand seven hundred and\n        seventy-five.\n\nSpiritual revelations were conceded to England at that\n        favoured period, as at this.'
      UpperCAmelCase ,			UpperCAmelCase	:     List[Any]						 =			process_story(_a	)
      self.assertEqual(_a					,      []	)


     def        UpperCAmelCase_	(		self			:					Optional[int]	)						->     Union[str, Any]:
      UpperCAmelCase	:     Tuple						 =			''
      UpperCAmelCase ,			UpperCAmelCase	:     int						 =			process_story(_a	)
      self.assertEqual(_a					,      []	)
      self.assertEqual(_a					,      []	)


     def        UpperCAmelCase_	(		self			:					List[Any]	)						->     Dict:
      UpperCAmelCase	:     Union[str, Any]						 =			(
          'It was the year of Our Lord one thousand seven hundred and '
          'seventy-five\n\nSpiritual revelations were conceded to England '
          'at that favoured period, as at this.\n@highlight\n\nIt was the best of times'
      )
      UpperCAmelCase ,			UpperCAmelCase	:     List[Any]						 =			process_story(_a	)

      UpperCAmelCase	:     List[Any]						 =			[
          'It was the year of Our Lord one thousand seven hundred and seventy-five.',
          'Spiritual revelations were conceded to England at that favoured period, as at this.',
      ]
      self.assertEqual(_a					,      _a	)

      UpperCAmelCase	:     List[str]						 =			['It was the best of times.']
      self.assertEqual(_a					,      _a	)


     def        UpperCAmelCase_	(		self			:					Union[str, Any]	)						->     int:
      UpperCAmelCase	:     Tuple						 =			torch.tensor([1, 2, 3, 4]	)
      UpperCAmelCase	:     Union[str, Any]						 =			torch.tensor([1, 1, 1, 1]	)
      np.testing.assert_array_equal(build_mask(_a					,      0	).numpy()					,      expected.numpy()	)


     def        UpperCAmelCase_	(		self			:					Union[str, Any]	)						->     Optional[int]:
      UpperCAmelCase	:     List[str]						 =			torch.tensor([1, 2, 3, 4, 23, 23, 23]	)
      UpperCAmelCase	:     Optional[Any]						 =			torch.tensor([1, 1, 1, 1, 0, 0, 0]	)
      np.testing.assert_array_equal(build_mask(_a					,      23	).numpy()					,      expected.numpy()	)


     def        UpperCAmelCase_	(		self			:					str	)						->     Any:
      UpperCAmelCase	:     Tuple						 =			torch.tensor([8, 2, 3, 4, 1, 1, 1]	)
      UpperCAmelCase	:     List[Any]						 =			torch.tensor([1, 1, 1, 1, 0, 0, 0]	)
      np.testing.assert_array_equal(build_mask(_a					,      1	).numpy()					,      expected.numpy()	)




     def        UpperCAmelCase_	(		self			:					Any	)						->     Tuple:
      UpperCAmelCase	:     str						 =			101
      UpperCAmelCase	:     Union[str, Any]						 =			torch.tensor([[1, 2, 3, 4, 5, 6], [1, 2, 3, 101, 5, 6], [1, 101, 3, 4, 101, 6]]	)
      UpperCAmelCase	:     Tuple						 =			torch.tensor([[1, 1, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 1]]	)

      UpperCAmelCase	:     Optional[int]						 =			compute_token_type_ids(_a					,      _a	)
      np.testing.assert_array_equal(_a					,      _a	)







'''simple docstring'''

from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


lowercase__         =      {
    "configuration_xlm": ["XLM_PRETRAINED_CONFIG_ARCHIVE_MAP", "XLMConfig", "XLMOnnxConfig"],
    "tokenization_xlm": ["XLMTokenizer"],
}

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowercase__         =      [
     "XLM_PRETRAINED_MODEL_ARCHIVE_LIST",
     "XLMForMultipleChoice",
     "XLMForQuestionAnswering",
     "XLMForQuestionAnsweringSimple",
     "XLMForSequenceClassification",
     "XLMForTokenClassification",
     "XLMModel",
     "XLMPreTrainedModel",
     "XLMWithLMHeadModel",
 ]

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowercase__         =      [
     "TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST",
     "TFXLMForMultipleChoice",
     "TFXLMForQuestionAnsweringSimple",
     "TFXLMForSequenceClassification",
     "TFXLMForTokenClassification",
     "TFXLMMainLayer",
     "TFXLMModel",
     "TFXLMPreTrainedModel",
     "TFXLMWithLMHeadModel",
 ]


if TYPE_CHECKING:
 from .configuration_xlm import XLM_PRETRAINED_CONFIG_ARCHIVE_MAP, XLMConfig, XLMOnnxConfig
 from .tokenization_xlm import XLMTokenizer

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_xlm import (
      XLM_PRETRAINED_MODEL_ARCHIVE_LIST,
      XLMForMultipleChoice,
      XLMForQuestionAnswering,
      XLMForQuestionAnsweringSimple,
      XLMForSequenceClassification,
      XLMForTokenClassification,
      XLMModel,
      XLMPreTrainedModel,
      XLMWithLMHeadModel,
  )

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_xlm import (
      TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST,
      TFXLMForMultipleChoice,
      TFXLMForQuestionAnsweringSimple,
      TFXLMForSequenceClassification,
      TFXLMForTokenClassification,
      TFXLMMainLayer,
      TFXLMModel,
      TFXLMPreTrainedModel,
      TFXLMWithLMHeadModel,
  )

else:
 import sys

 lowercase__         =      _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)




