





import unittest

from transformers.testing_utils import require_bsa
from transformers.utils import is_bsa_available

from ...test_feature_extraction_common import FeatureExtractionSavingTestMixin


if is_bsa_available():
      from transformers import MarkupLMFeatureExtractor





class      lowercase__    (							unittest.TestCase  ):







  def __init__(	self    ,						_lowercase						):
       lowerCAmelCase_					:       Any    =		parent







  def 	UpperCAmelCase__		(	self						):
       return {}






def 							_lowerCAmelCase (  )	->			List[Any]:
     lowerCAmelCase_					:       Optional[int]    =		"""<HTML>\n\n    <HEAD>\n    <TITLE>sample document</TITLE>\n    </HEAD>\n\n    <BODY BGCOLOR=\"FFFFFF\">\n    <HR>\n    <a href=\"http://google.com\">Goog</a>\n    <H1>This is one header</H1>\n    <H2>This is a another Header</H2>\n    <P>Travel from\n        <P>\n        <B>SFO to JFK</B>\n        <BR>\n        <B><I>on May 2, 2015 at 2:00 pm. For details go to confirm.com </I></B>\n        <HR>\n        <div style=\"color:#0000FF\">\n            <h3>Traveler <b> name </b> is\n            <p> John Doe </p>\n        </div>"""

     lowerCAmelCase_					:       Optional[int]    =		"""\n    <!DOCTYPE html>\n    <html>\n    <body>\n\n    <h1>My First Heading</h1>\n    <p>My first paragraph.</p>\n\n    </body>\n    </html>\n    """

     return [html_string_a, html_string_a]







@require_bsa
class      lowercase__    (							__A     ,					unittest.TestCase  ):
  __UpperCamelCase	     =  MarkupLMFeatureExtractor if is_bsa_available() else None







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







  @property
  def 	UpperCAmelCase__		(	self						):
       return self.feature_extract_tester.prepare_feat_extract_dict()







  def 	UpperCAmelCase__		(	self						):
       lowerCAmelCase_					:       List[Any]    =		self.feature_extraction_class()

       # Test not batched input
       lowerCAmelCase_					:       Optional[int]    =		get_html_strings()[0]
       lowerCAmelCase_					:       Dict    =		feature_extractor(lowercase_						)

       # fmt: off
       lowerCAmelCase_					:       Dict    =		[["""sample document""", """Goog""", """This is one header""", """This is a another Header""", """Travel from""", """SFO to JFK""", """on May 2, 2015 at 2:00 pm. For details go to confirm.com""", """Traveler""", """name""", """is""", """John Doe"""]]
       lowerCAmelCase_					:       Optional[int]    =		[["""/html/head/title""", """/html/body/a""", """/html/body/h1""", """/html/body/h2""", """/html/body/p""", """/html/body/p/p/b[1]""", """/html/body/p/p/b[2]/i""", """/html/body/p/p/div/h3""", """/html/body/p/p/div/h3/b""", """/html/body/p/p/div/h3""", """/html/body/p/p/div/h3/p"""]]
       # fmt: on

       self.assertEqual(encoding.nodes    ,						lowercase_						)
       self.assertEqual(encoding.xpaths    ,						lowercase_						)

       # Test batched
       lowerCAmelCase_					:       List[str]    =		get_html_strings()
       lowerCAmelCase_					:       int    =		feature_extractor(lowercase_						)

       # fmt: off
       lowerCAmelCase_					:       Optional[Any]    =		expected_nodes + [["""My First Heading""", """My first paragraph."""]]
       lowerCAmelCase_					:       Dict    =		expected_xpaths + [["""/html/body/h1""", """/html/body/p"""]]

       self.assertEqual(len(encoding.nodes						)    ,						2						)
       self.assertEqual(len(encoding.xpaths						)    ,						2						)

       self.assertEqual(encoding.nodes    ,						lowercase_						)
       self.assertEqual(encoding.xpaths    ,						lowercase_						)







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


UpperCAmelCase_					:   Tuple 							=						logging.get_logger(__name__)

UpperCAmelCase_					:   List[str] 							=						{
    """google/fnet-base""": """https://huggingface.co/google/fnet-base/resolve/main/config.json""",
    """google/fnet-large""": """https://huggingface.co/google/fnet-large/resolve/main/config.json"""
    # See all FNet models at https://huggingface.co/models?filter=fnet
}





class      lowercase__    (							__A  ):
  __UpperCamelCase	     =  """fnet"""







  def __init__(	self    ,						_lowercase=32_000    ,						_lowercase=768    ,						_lowercase=12    ,						_lowercase=3_072    ,						_lowercase="gelu_new"    ,						_lowercase=0.1    ,						_lowercase=512    ,						_lowercase=4    ,						_lowercase=0.02    ,						_lowercase=1e-12    ,						_lowercase=False    ,						_lowercase=512    ,						_lowercase=3    ,						_lowercase=1    ,						_lowercase=2    ,						**_lowercase    ,						):
       super().__init__(pad_token_id=_lowercase    ,						bos_token_id=_lowercase    ,						eos_token_id=_lowercase    ,						**_lowercase						)

       lowerCAmelCase_					:       Optional[Any]    =		vocab_size
       lowerCAmelCase_					:       List[str]    =		max_position_embeddings
       lowerCAmelCase_					:       str    =		hidden_size
       lowerCAmelCase_					:       Any    =		num_hidden_layers
       lowerCAmelCase_					:       Optional[int]    =		intermediate_size
       lowerCAmelCase_					:       int    =		hidden_act
       lowerCAmelCase_					:       List[str]    =		hidden_dropout_prob
       lowerCAmelCase_					:       Tuple    =		initializer_range
       lowerCAmelCase_					:       int    =		type_vocab_size
       lowerCAmelCase_					:       str    =		layer_norm_eps
       lowerCAmelCase_					:       Optional[Any]    =		use_tpu_fourier_optimizations
       lowerCAmelCase_					:       Union[str, Any]    =		tpu_short_seq_length
