"""simple docstring"""




import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow


if is_torch_available():
					import torch

					from transformers import XLMRobertaModel
@require_sentencepiece
@require_tokenizers
@require_torch
class     UpperCamelCase__(			unittest.TestCase ):





						@slow
						def 				snake_case__	(       self     )					->				int:
													A__	     =							XLMRobertaModel.from_pretrained('xlm-roberta-base'     )
													A__	     =							torch.tensor([[0, 5_81, 1_02_69, 83, 9_99_42, 1_36, 6_07_42, 23, 70, 8_05_83, 1_82_76, 2]]     )
													# The dog is cute and lives in the garden house

													A__	     =							torch.Size((1, 12, 7_68)     )  # batch_size, sequence_length, embedding_vector_dim
													A__	     =							torch.tensor(
													    [[-0.0_1_0_1, 0.1_2_1_8, -0.0_8_0_3, 0.0_8_0_1, 0.1_3_2_7, 0.0_7_7_6, -0.1_2_1_5, 0.2_3_8_3, 0.3_3_3_8, 0.3_1_0_6, 0.0_3_0_0, 0.0_2_5_2]]     )
													#  xlmr = torch.hub.load('pytorch/fairseq', 'xlmr.base')
													#  xlmr.eval()
													#  expected_output_values_last_dim = xlmr.extract_features(input_ids[0])[:, :, -1]
													with torch.no_grad():
																				A__	     =							model(_UpperCamelCase     )["""last_hidden_state"""].detach()
													self.assertEqual(output.shape		,_UpperCamelCase     )
													# compare the actual values for a slice of last dim
													self.assertTrue(torch.allclose(output[:, :, -1]		,_UpperCamelCase		,atol=1e-3     )     )





						@slow
						def 				snake_case__	(       self     )					->				Optional[Any]:
													A__	     =							XLMRobertaModel.from_pretrained('xlm-roberta-large'     )
													A__	     =							torch.tensor([[0, 5_81, 1_02_69, 83, 9_99_42, 1_36, 6_07_42, 23, 70, 8_05_83, 1_82_76, 2]]     )
													# The dog is cute and lives in the garden house

													A__	     =							torch.Size((1, 12, 10_24)     )  # batch_size, sequence_length, embedding_vector_dim
													A__	     =							torch.tensor(
													    [[-0.0_6_9_9, -0.0_3_1_8, 0.0_7_0_5, -0.1_2_4_1, 0.0_9_9_9, -0.0_5_2_0, 0.1_0_0_4, -0.1_8_3_8, -0.4_7_0_4, 0.1_4_3_7, 0.0_8_2_1, 0.0_1_2_6]]     )
													#  xlmr = torch.hub.load('pytorch/fairseq', 'xlmr.large')
													#  xlmr.eval()
													#  expected_output_values_last_dim = xlmr.extract_features(input_ids[0])[:, :, -1]
													with torch.no_grad():
																				A__	     =							model(_UpperCamelCase     )["""last_hidden_state"""].detach()
													self.assertEqual(output.shape		,_UpperCamelCase     )
													# compare the actual values for a slice of last dim
													self.assertTrue(torch.allclose(output[:, :, -1]		,_UpperCamelCase		,atol=1e-3     )     )






"""simple docstring"""




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     UpperCamelCase__(			unittest.TestCase ):





						def __init__(       self		,__UpperCAmelCase     )					->				str:
													A__	     =							parent





						def 				snake_case__	(       self     )					->				int:
													return {}






def   UpperCAmelCase					(	):






							"""simple docstring"""





							A__	     =							'<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>'

							A__	     =							'\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     UpperCamelCase__(			__A		,						unittest.TestCase ):
						lowerCAmelCase__  :						Dict													=		MarkupLMFeatureExtractor if is_bsa_available() else None





						def 				snake_case__	(       self     )					->				Dict:
													A__	     =							MarkupLMFeatureExtractionTester(self     )





						@property
						def 				snake_case__	(       self     )					->				Optional[Any]:
													return self.feature_extract_tester.prepare_feat_extract_dict()





						def 				snake_case__	(       self     )					->				Any:
													# Initialize feature_extractor
													A__	     =							self.feature_extraction_class()

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

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

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

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

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

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





