






import unittest

import numpy as np
import torch

from .utils_summarization import build_mask, compute_token_type_ids, process_story, truncate_or_pad


class    __lowercase   (						unittest.TestCase	):







     '''simple docstring'''




     def 		lowerCAmelCase_  (					self							:      List[Any]					):


         """simple docstring"""



         __A       =						10




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


         """simple docstring"""



         __A       =						[1, 2, 3, 4]
         __A       =						[1, 2, 3, 4, 0, 0, 0, 0, 0, 0]
         self.assertEqual(truncate_or_pad(UpperCamelCase_			,						self.block_size			,						0					)			,						UpperCamelCase_					)




     def 		lowerCAmelCase_  (					self							:      Any					):


         """simple docstring"""



         __A       =						[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
         __A       =						[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
         self.assertEqual(truncate_or_pad(UpperCamelCase_			,						self.block_size			,						0					)			,						UpperCamelCase_					)




     def 		lowerCAmelCase_  (					self							:      Tuple					):


         """simple docstring"""



         __A       =						[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
         __A       =						[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
         self.assertEqual(truncate_or_pad(UpperCamelCase_			,						self.block_size			,						0					)			,						UpperCamelCase_					)




     def 		lowerCAmelCase_  (					self							:      List[str]					):


         """simple docstring"""



         __A       =						"""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."""
         __A     ,						__A       =						process_story(UpperCamelCase_					)
         self.assertEqual(UpperCamelCase_			,						[]					)




     def 		lowerCAmelCase_  (					self							:      Optional[Any]					):


         """simple docstring"""



         __A       =						""""""
         __A     ,						__A       =						process_story(UpperCamelCase_					)
         self.assertEqual(UpperCamelCase_			,						[]					)
         self.assertEqual(UpperCamelCase_			,						[]					)




     def 		lowerCAmelCase_  (					self							:      List[Any]					):


         """simple docstring"""



         __A       =						(
             """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"""
         )
         __A     ,						__A       =						process_story(UpperCamelCase_					)

         __A       =						[
             """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(UpperCamelCase_			,						UpperCamelCase_					)

         __A       =						["""It was the best of times."""]
         self.assertEqual(UpperCamelCase_			,						UpperCamelCase_					)




     def 		lowerCAmelCase_  (					self							:      str					):


         """simple docstring"""



         __A       =						torch.tensor([1, 2, 3, 4]					)
         __A       =						torch.tensor([1, 1, 1, 1]					)
         np.testing.assert_array_equal(build_mask(UpperCamelCase_			,						0					).numpy()			,						expected.numpy()					)




     def 		lowerCAmelCase_  (					self							:      Any					):


         """simple docstring"""



         __A       =						torch.tensor([1, 2, 3, 4, 23, 23, 23]					)
         __A       =						torch.tensor([1, 1, 1, 1, 0, 0, 0]					)
         np.testing.assert_array_equal(build_mask(UpperCamelCase_			,						23					).numpy()			,						expected.numpy()					)




     def 		lowerCAmelCase_  (					self							:      str					):


         """simple docstring"""



         __A       =						torch.tensor([8, 2, 3, 4, 1, 1, 1]					)
         __A       =						torch.tensor([1, 1, 1, 1, 0, 0, 0]					)
         np.testing.assert_array_equal(build_mask(UpperCamelCase_			,						1					).numpy()			,						expected.numpy()					)





     def 		lowerCAmelCase_  (					self							:      str					):


         """simple docstring"""



         __A       =						101
         __A       =						torch.tensor([[1, 2, 3, 4, 5, 6], [1, 2, 3, 101, 5, 6], [1, 101, 3, 4, 101, 6]]					)
         __A       =						torch.tensor([[1, 1, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 1]]					)

         __A       =						compute_token_type_ids(UpperCamelCase_			,						UpperCamelCase_					)
         np.testing.assert_array_equal(UpperCamelCase_			,						UpperCamelCase_					)












from ...configuration_utils import PretrainedConfig
from ...utils import logging


__a   :							Optional[Any]						= logging.get_logger(__name__)

__a   :							Dict						= {
    "google/realm-cc-news-pretrained-embedder": (
        "https://huggingface.co/google/realm-cc-news-pretrained-embedder/resolve/main/config.json"
    ),
    "google/realm-cc-news-pretrained-encoder": (
        "https://huggingface.co/google/realm-cc-news-pretrained-encoder/resolve/main/config.json"
    ),
    "google/realm-cc-news-pretrained-scorer": (
        "https://huggingface.co/google/realm-cc-news-pretrained-scorer/resolve/main/config.json"
    ),
    "google/realm-cc-news-pretrained-openqa": (
        "https://huggingface.co/google/realm-cc-news-pretrained-openqa/aresolve/main/config.json"
    ),
    "google/realm-orqa-nq-openqa": "https://huggingface.co/google/realm-orqa-nq-openqa/resolve/main/config.json",
    "google/realm-orqa-nq-reader": "https://huggingface.co/google/realm-orqa-nq-reader/resolve/main/config.json",
    "google/realm-orqa-wq-openqa": "https://huggingface.co/google/realm-orqa-wq-openqa/resolve/main/config.json",
    "google/realm-orqa-wq-reader": "https://huggingface.co/google/realm-orqa-wq-reader/resolve/main/config.json",
    # See all REALM models at https://huggingface.co/models?filter=realm
}


class    __lowercase   (						lowercase_	):







     '''simple docstring'''
     SCREAMING_SNAKE_CASE     =					"realm"




     def __init__(					self							:      str			,						UpperCamelCase_							:      List[Any]=30_522			,						UpperCamelCase_							:      Dict=768			,						UpperCamelCase_							:      Union[str, Any]=128			,						UpperCamelCase_							:      Tuple=12			,						UpperCamelCase_							:      Optional[Any]=12			,						UpperCamelCase_							:      Optional[int]=8			,						UpperCamelCase_							:      str=3_072			,						UpperCamelCase_							:      List[str]="gelu_new"			,						UpperCamelCase_							:      Optional[int]=0.1			,						UpperCamelCase_							:      Optional[int]=0.1			,						UpperCamelCase_							:      str=512			,						UpperCamelCase_							:      int=2			,						UpperCamelCase_							:      str=0.02			,						UpperCamelCase_							:      List[Any]=1e-12			,						UpperCamelCase_							:      str=256			,						UpperCamelCase_							:      List[str]=10			,						UpperCamelCase_							:      int=1e-3			,						UpperCamelCase_							:      List[str]=5			,						UpperCamelCase_							:      Tuple=320			,						UpperCamelCase_							:      List[str]=13_353_718			,						UpperCamelCase_							:      Tuple=5_000			,						UpperCamelCase_							:      Optional[int]=1			,						UpperCamelCase_							:      List[str]=0			,						UpperCamelCase_							:      Union[str, Any]=2			,						**UpperCamelCase_							:      List[Any]			,						):


         """simple docstring"""



         super().__init__(pad_token_id=UpperCamelCase_			,						bos_token_id=UpperCamelCase_			,						eos_token_id=UpperCamelCase_			,						**UpperCamelCase_					)

         # Common config
         __A       =						vocab_size
         __A       =						max_position_embeddings
         __A       =						hidden_size
         __A       =						retriever_proj_size
         __A       =						num_hidden_layers
         __A       =						num_attention_heads
         __A       =						num_candidates
         __A       =						intermediate_size
         __A       =						hidden_act
         __A       =						hidden_dropout_prob
         __A       =						attention_probs_dropout_prob
         __A       =						initializer_range
         __A       =						type_vocab_size
         __A       =						layer_norm_eps

         # Reader config
         __A       =						span_hidden_size
         __A       =						max_span_width
         __A       =						reader_layer_norm_eps
         __A       =						reader_beam_size
         __A       =						reader_seq_len

         # Retrieval config
         __A       =						num_block_records
         __A       =						searcher_beam_size




