
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       ,A__):
												lowercase						     =						parent





							def 			A__				(    self):
												return {}



def 	UpperCamelCase   (							):
					'''simple docstring'''
					lowercase						     =						'''<HTML>

    <HEAD>
    <TITLE>sample document</TITLE>
    </HEAD>

    <BODY BGCOLOR="FFFFFF">
    <HR>
    <a href="http://google.com">Goog</a>
    <H1>This is one header</H1>
    <H2>This is a another Header</H2>
    <P>Travel from
        <P>
        <B>SFO to JFK</B>
        <BR>
        <B><I>on May 2, 2015 at 2:00 pm. For details go to confirm.com </I></B>
        <HR>
        <div style="color:#0000FF">
            <h3>Traveler <b> name </b> is
            <p> John Doe </p>
        </div>'''

					lowercase						     =						'''
    <!DOCTYPE html>
    <html>
    <body>

    <h1>My First Heading</h1>
    <p>My first paragraph.</p>

    </body>
    </html>
    '''

					return [html_string_a, html_string_a]







@require_bsa
class     lowercase		( SCREAMING_SNAKE_CASE__	,  unittest.TestCase		):
							lowercase_	:	List[str]	 =MarkupLMFeatureExtractor if is_bsa_available() else None




							def 			A__				(    self):
												lowercase						     =						MarkupLMFeatureExtractionTester(self)




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





							def 			A__				(    self):
												# Initialize feature_extractor
												lowercase						     =						self.feature_extraction_class()

												# Test not batched input
												lowercase						     =						get_html_strings()[0]
												lowercase						     =						feature_extractor(A__)

												# fmt: off
												lowercase						     =						[['''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''']]
												lowercase						     =						[['''/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       ,A__)
												self.assertEqual(encoding.xpaths       ,A__)

												# Test batched
												lowercase						     =						get_html_strings()
												lowercase						     =						feature_extractor(A__)

												# fmt: off
												lowercase						     =						expected_nodes + [['''My First Heading''', '''My first paragraph.''']]
												lowercase						     =						expected_xpaths + [['''/html/body/h1''', '''/html/body/p''']]

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

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






from __future__ import annotations

import unittest

from transformers import is_tf_available
from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow


if is_tf_available():
							import numpy as np
							import tensorflow as tf

							from transformers import TFXLMRobertaModel







@require_tf
@require_sentencepiece
@require_tokenizers
class     lowercase		( unittest.TestCase		):




							@slow
							def 			A__				(    self):
												lowercase						     =						TFXLMRobertaModel.from_pretrained('''jplu/tf-xlm-roberta-base''')

												lowercase						     =						{
												    '''input_ids''': tf.convert_to_tensor([[0, 2_6_4_6, 1_0_2_6_9, 8_3, 9_9_9_4_2, 2]]       ,dtype=tf.intaa),  # "My dog is cute"
												    '''attention_mask''': tf.convert_to_tensor([[1, 1, 1, 1, 1, 1]]       ,dtype=tf.intaa),
												}

												lowercase						     =						model(A__)['''last_hidden_state''']
												lowercase						     =						tf.TensorShape((1, 6, 7_6_8))
												self.assertEqual(output.shape       ,A__)
												# compare the actual values for a slice.
												lowercase						     =						tf.convert_to_tensor(
												    [
												        [
												            [0.0681762, 0.10894451, 0.06772504],
												            [-0.06423668, 0.02366615, 0.04329344],
												            [-0.06057295, 0.09974135, -0.00070584],
												        ]
												    ]       ,dtype=tf.floataa       ,)

												self.assertTrue(np.allclose(output[:, :3, :3].numpy()       ,expected_slice.numpy()       ,atol=1E-4))




