
import inspect
import unittest

import numpy as np

from tests.test_modeling_common import floats_tensor
from transformers import MaskaFormerConfig, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
    import torch

    from transformers import MaskaFormerForUniversalSegmentation, MaskaFormerModel

    if is_vision_available():
        from transformers import MaskaFormerImageProcessor

if is_vision_available():
    from PIL import Image




class 			UpperCAmelCase_     :


  '''simple docstring'''







  def __init__(					self     :					List[str]     ,				UpperCamelCase__     :					Tuple     ,				UpperCamelCase__     :					Optional[int]=2     ,				UpperCamelCase__     :					str=True     ,				UpperCamelCase__     :					Union[str, Any]=False     ,				UpperCamelCase__     :					Optional[int]=10     ,				UpperCamelCase__     :					List[str]=3     ,				UpperCamelCase__     :					str=32 * 8     ,				UpperCamelCase__     :					Tuple=32 * 8     ,				UpperCamelCase__     :					str=4     ,				UpperCamelCase__     :					int=64     ,				)     ->      Dict:







    """simple docstring"""






    __magic_name__								=			parent
    __magic_name__								=			batch_size
    __magic_name__								=			is_training
    __magic_name__								=			use_auxiliary_loss
    __magic_name__								=			num_queries
    __magic_name__								=			num_channels
    __magic_name__								=			min_size
    __magic_name__								=			max_size
    __magic_name__								=			num_labels
    __magic_name__								=			hidden_dim
    __magic_name__								=			hidden_dim
  def 				_lowercase				(					self     :					Tuple       )     ->      Any:







    """simple docstring"""






    __magic_name__								=			floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]       ).to(
        UpperCamelCase__       )

    __magic_name__								=			torch.ones([self.batch_size, self.min_size, self.max_size]     ,				device=UpperCamelCase__       )

    __magic_name__								=			(
        torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size]     ,				device=UpperCamelCase__       ) > 0.5
    ).float()
    __magic_name__								=			(torch.rand((self.batch_size, self.num_labels)     ,				device=UpperCamelCase__       ) > 0.5).long()

    __magic_name__								=			self.get_config()
    return config, pixel_values, pixel_mask, mask_labels, class_labels
  def 				_lowercase				(					self     :					List[Any]       )     ->      int:







    """simple docstring"""






    __magic_name__								=			MaskaFormerConfig(
        hidden_size=self.hidden_dim     ,				)
    __magic_name__								=			self.num_queries
    __magic_name__								=			self.num_labels

    __magic_name__								=			[1, 1, 1, 1]
    __magic_name__								=			self.num_channels

    __magic_name__								=			64
    __magic_name__								=			128
    __magic_name__								=			self.hidden_dim
    __magic_name__								=			self.hidden_dim
    __magic_name__								=			self.hidden_dim
    return config
  def 				_lowercase				(					self     :					Union[str, Any]       )     ->      int:







    """simple docstring"""






    __magic_name__	,       __magic_name__	,       __magic_name__	,       __magic_name__	,       __magic_name__								=			self.prepare_config_and_inputs()
    __magic_name__								=			{"""pixel_values""": pixel_values, """pixel_mask""": pixel_mask}
    return config, inputs_dict
  def 				_lowercase				(					self     :					List[Any]     ,				UpperCamelCase__     :					Optional[int]     ,				UpperCamelCase__     :					List[str]       )     ->      Union[str, Any]:







    """simple docstring"""






    __magic_name__								=			output.encoder_hidden_states
    __magic_name__								=			output.pixel_decoder_hidden_states
    __magic_name__								=			output.transformer_decoder_hidden_states

    self.parent.assertTrue(len(UpperCamelCase__       )     ,				len(config.backbone_config.depths       )       )
    self.parent.assertTrue(len(UpperCamelCase__       )     ,				len(config.backbone_config.depths       )       )
    self.parent.assertTrue(len(UpperCamelCase__       )     ,				config.decoder_layers       )
  def 				_lowercase				(					self     :					Optional[Any]     ,				UpperCamelCase__     :					Optional[Any]     ,				UpperCamelCase__     :					int     ,				UpperCamelCase__     :					str     ,				UpperCamelCase__     :					Union[str, Any]=False       )     ->      Tuple:







    """simple docstring"""






    with torch.no_grad():
      __magic_name__								=			MaskaFormerModel(config=UpperCamelCase__       )
      model.to(UpperCamelCase__       )
      model.eval()

      __magic_name__								=			model(pixel_values=UpperCamelCase__     ,				pixel_mask=UpperCamelCase__       )
      __magic_name__								=			model(UpperCamelCase__     ,				output_hidden_states=UpperCamelCase__       )

    self.parent.assertEqual(
        output.transformer_decoder_last_hidden_state.shape     ,				(self.batch_size, self.num_queries, self.hidden_dim)     ,				)
    # let's ensure the other two hidden state exists
    self.parent.assertTrue(output.pixel_decoder_last_hidden_state is not None       )
    self.parent.assertTrue(output.encoder_last_hidden_state is not None       )

    if output_hidden_states:
      self.check_output_hidden_state(UpperCamelCase__     ,				UpperCamelCase__       )





  def 				_lowercase				(					self     :					Any     ,				UpperCamelCase__     :					Optional[int]     ,				UpperCamelCase__     :					str     ,				UpperCamelCase__     :					Union[str, Any]     ,				UpperCamelCase__     :					Union[str, Any]     ,				UpperCamelCase__     :					Any       )     ->      str:







    """simple docstring"""






    __magic_name__								=			MaskaFormerForUniversalSegmentation(config=UpperCamelCase__       )
    model.to(UpperCamelCase__       )
    model.eval()

    def comm_check_on_output(UpperCamelCase__     :					Union[str, Any]       ):
      # let's still check that all the required stuff is there
      self.parent.assertTrue(result.transformer_decoder_last_hidden_state is not None       )
      self.parent.assertTrue(result.pixel_decoder_last_hidden_state is not None       )
      self.parent.assertTrue(result.encoder_last_hidden_state is not None       )
      # okay, now we need to check the logits shape
      # due to the encoder compression, masks have a //4 spatial size
      self.parent.assertEqual(
          result.masks_queries_logits.shape     ,				(self.batch_size, self.num_queries, self.min_size // 4, self.max_size // 4)     ,				)
      # + 1 for null class
      self.parent.assertEqual(
          result.class_queries_logits.shape     ,				(self.batch_size, self.num_queries, self.num_labels + 1)       )

    with torch.no_grad():
      __magic_name__								=			model(pixel_values=UpperCamelCase__     ,				pixel_mask=UpperCamelCase__       )
      __magic_name__								=			model(UpperCamelCase__       )

      comm_check_on_output(UpperCamelCase__       )

      __magic_name__								=			model(
          pixel_values=UpperCamelCase__     ,				pixel_mask=UpperCamelCase__     ,				mask_labels=UpperCamelCase__     ,				class_labels=UpperCamelCase__       )

    comm_check_on_output(UpperCamelCase__       )

    self.parent.assertTrue(result.loss is not None       )
    self.parent.assertEqual(result.loss.shape     ,				torch.Size([1]       )       )







@require_torch
class 			UpperCAmelCase_     (					_A    ,			_A    ,			unittest.TestCase	):


  '''simple docstring'''







  a__       			=						(MaskaFormerModel, MaskaFormerForUniversalSegmentation) if is_torch_available() else ()
  a__       			=						{"""feature-extraction""": MaskaFormerModel} if is_torch_available() else {}

  a__       			=						False
  a__       			=						False
  a__       			=						False
  a__       			=						False
  def 				_lowercase				(					self     :					Tuple       )     ->      int:







    """simple docstring"""






    __magic_name__								=			MaskaFormerModelTester(self       )
    __magic_name__								=			ConfigTester(self     ,				config_class=UpperCamelCase__     ,				has_text_modality=UpperCamelCase__       )
  def 				_lowercase				(					self     :					Optional[Any]       )     ->      str:







    """simple docstring"""






    self.config_tester.run_common_tests()
  def 				_lowercase				(					self     :					Union[str, Any]       )     ->      Optional[int]:







    """simple docstring"""






    __magic_name__	,       __magic_name__								=			self.model_tester.prepare_config_and_inputs_for_common()
    self.model_tester.create_and_check_maskaformer_model(UpperCamelCase__     ,				**UpperCamelCase__     ,				output_hidden_states=UpperCamelCase__       )
  def 				_lowercase				(					self     :					Union[str, Any]       )     ->      str:







    """simple docstring"""






    __magic_name__								=			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_maskaformer_instance_segmentation_head_model(*UpperCamelCase__       )
  @unittest.skip(reason="""Mask2Former does not use inputs_embeds"""       )
  def 				_lowercase				(					self     :					Optional[Any]       )     ->      Dict:







    """simple docstring"""






    pass
  @unittest.skip(reason="""Mask2Former does not have a get_input_embeddings method"""       )
  def 				_lowercase				(					self     :					Any       )     ->      str:







    """simple docstring"""






    pass
  @unittest.skip(reason="""Mask2Former is not a generative model"""       )
  def 				_lowercase				(					self     :					List[str]       )     ->      List[str]:







    """simple docstring"""






    pass
  @unittest.skip(reason="""Mask2Former does not use token embeddings"""       )
  def 				_lowercase				(					self     :					Tuple       )     ->      Tuple:







    """simple docstring"""






    pass
  @require_torch_multi_gpu
  @unittest.skip(
      reason="""Mask2Former has some layers using `add_module` which doesn't work well with `nn.DataParallel`"""       )
  def 				_lowercase				(					self     :					int       )     ->      Tuple:







    """simple docstring"""






    pass
  @unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests."""       )
  def 				_lowercase				(					self     :					int       )     ->      List[Any]:







    """simple docstring"""






    pass
  def 				_lowercase				(					self     :					Optional[Any]       )     ->      Tuple:







    """simple docstring"""






    __magic_name__	,       __magic_name__								=			self.model_tester.prepare_config_and_inputs_for_common()

    for model_class in self.all_model_classes:
      __magic_name__								=			model_class(UpperCamelCase__       )
      __magic_name__								=			inspect.signature(model.forward       )
      # signature.parameters is an OrderedDict => so arg_names order is deterministic
      __magic_name__								=			[*signature.parameters.keys()]

      __magic_name__								=			["""pixel_values"""]
      self.assertListEqual(arg_names[:1]     ,				UpperCamelCase__       )
  @slow
  def 				_lowercase				(					self     :					Any       )     ->      str:







    """simple docstring"""






    for model_name in ["facebook/mask2former-swin-small-coco-instance"]:
      __magic_name__								=			MaskaFormerModel.from_pretrained(UpperCamelCase__       )
      self.assertIsNotNone(UpperCamelCase__       )
  def 				_lowercase				(					self     :					int       )     ->      Optional[int]:







    """simple docstring"""






    __magic_name__								=			(self.model_tester.min_size,) * 2
    __magic_name__								=			{
        """pixel_values""": torch.randn((2, 3, *size)     ,				device=UpperCamelCase__       ),
        """mask_labels""": torch.randn((2, 10, *size)     ,				device=UpperCamelCase__       ),
        """class_labels""": torch.zeros(2     ,				10     ,				device=UpperCamelCase__       ).long(),
    }
    __magic_name__								=			self.model_tester.get_config()

    __magic_name__								=			MaskaFormerForUniversalSegmentation(UpperCamelCase__       ).to(UpperCamelCase__       )
    __magic_name__								=			model(**UpperCamelCase__       )
    self.assertTrue(outputs.loss is not None       )
  def 				_lowercase				(					self     :					List[str]       )     ->      Optional[int]:







    """simple docstring"""






    __magic_name__	,       __magic_name__								=			self.model_tester.prepare_config_and_inputs_for_common()
    self.model_tester.create_and_check_maskaformer_model(UpperCamelCase__     ,				**UpperCamelCase__     ,				output_hidden_states=UpperCamelCase__       )
  def 				_lowercase				(					self     :					int       )     ->      Union[str, Any]:







    """simple docstring"""






    __magic_name__	,       __magic_name__								=			self.model_tester.prepare_config_and_inputs_for_common()

    for model_class in self.all_model_classes:
      __magic_name__								=			model_class(UpperCamelCase__       ).to(UpperCamelCase__       )
      __magic_name__								=			model(**UpperCamelCase__     ,				output_attentions=UpperCamelCase__       )
      self.assertTrue(outputs.attentions is not None       )
  def 				_lowercase				(					self     :					Optional[int]       )     ->      Tuple:







    """simple docstring"""






    if not self.model_tester.is_training:
      return

    __magic_name__								=			self.all_model_classes[1]
    __magic_name__	,       __magic_name__	,       __magic_name__	,       __magic_name__	,       __magic_name__								=			self.model_tester.prepare_config_and_inputs()

    __magic_name__								=			model_class(UpperCamelCase__       )
    model.to(UpperCamelCase__       )
    model.train()

    __magic_name__								=			model(UpperCamelCase__     ,				mask_labels=UpperCamelCase__     ,				class_labels=UpperCamelCase__       ).loss
    loss.backward()





  def 				_lowercase				(					self     :					int       )     ->      List[Any]:







    """simple docstring"""






    __magic_name__								=			self.all_model_classes[1]
    __magic_name__	,       __magic_name__	,       __magic_name__	,       __magic_name__	,       __magic_name__								=			self.model_tester.prepare_config_and_inputs()
    __magic_name__								=			True
    __magic_name__								=			True

    __magic_name__								=			model_class(UpperCamelCase__       ).to(UpperCamelCase__       )
    model.train()

    __magic_name__								=			model(UpperCamelCase__     ,				mask_labels=UpperCamelCase__     ,				class_labels=UpperCamelCase__       )

    __magic_name__								=			outputs.encoder_hidden_states[0]
    encoder_hidden_states.retain_grad()

    __magic_name__								=			outputs.pixel_decoder_hidden_states[0]
    pixel_decoder_hidden_states.retain_grad()

    __magic_name__								=			outputs.transformer_decoder_hidden_states[0]
    transformer_decoder_hidden_states.retain_grad()

    __magic_name__								=			outputs.attentions[0]
    attentions.retain_grad()

    outputs.loss.backward(retain_graph=UpperCamelCase__       )

    self.assertIsNotNone(encoder_hidden_states.grad       )
    self.assertIsNotNone(pixel_decoder_hidden_states.grad       )
    self.assertIsNotNone(transformer_decoder_hidden_states.grad       )
    self.assertIsNotNone(attentions.grad       )







__lowerCAmelCase     :	List[Any]       			=  1e-4

def a__       (			):






  '''simple docstring'''





  __magic_name__								=			Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""   )
  return image





@require_vision
@slow
class 			UpperCAmelCase_     (					unittest.TestCase	):


  '''simple docstring'''







  @cached_property
  def 				_lowercase				(					self     :					Union[str, Any]       )     ->      int:







    """simple docstring"""






    return "facebook/mask2former-swin-small-coco-instance"
  @cached_property
  def 				_lowercase				(					self     :					Optional[Any]       )     ->      Union[str, Any]:







    """simple docstring"""






    return MaskaFormerImageProcessor.from_pretrained(self.model_checkpoints       ) if is_vision_available() else None
  def 				_lowercase				(					self     :					List[Any]       )     ->      int:







    """simple docstring"""






    __magic_name__								=			MaskaFormerModel.from_pretrained(self.model_checkpoints       ).to(UpperCamelCase__       )
    __magic_name__								=			self.default_image_processor
    __magic_name__								=			prepare_img()
    __magic_name__								=			image_processor(UpperCamelCase__     ,				return_tensors="""pt"""       ).to(UpperCamelCase__       )
    __magic_name__								=			inputs["""pixel_values"""].shape
    # check size is divisible by 32
    self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0       )
    # check size
    self.assertEqual(UpperCamelCase__     ,				(1, 3, 384, 384)       )

    with torch.no_grad():
      __magic_name__								=			model(**UpperCamelCase__       )

    __magic_name__								=			torch.tensor(
        [[-0.2790, -1.0717, -1.1668], [-0.5128, -0.3128, -0.4987], [-0.5832, 0.1971, -0.0197]]       ).to(UpperCamelCase__       )
    self.assertTrue(
        torch.allclose(
            outputs.encoder_last_hidden_state[0, 0, :3, :3]     ,				UpperCamelCase__     ,				atol=UpperCamelCase__       )       )

    __magic_name__								=			torch.tensor(
        [[0.8973, 1.1847, 1.1776], [1.1934, 1.5040, 1.5128], [1.1153, 1.4486, 1.4951]]       ).to(UpperCamelCase__       )
    self.assertTrue(
        torch.allclose(
            outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3]     ,				UpperCamelCase__     ,				atol=UpperCamelCase__       )       )

    __magic_name__								=			torch.tensor(
        [[2.1152, 1.7000, -0.8603], [1.5808, 1.8004, -0.9353], [1.6043, 1.7495, -0.5999]]       ).to(UpperCamelCase__       )
    self.assertTrue(
        torch.allclose(
            outputs.transformer_decoder_last_hidden_state[0, :3, :3]     ,				UpperCamelCase__     ,				atol=UpperCamelCase__       )       )
  def 				_lowercase				(					self     :					Optional[int]       )     ->      Union[str, Any]:







    """simple docstring"""






    __magic_name__								=			MaskaFormerForUniversalSegmentation.from_pretrained(self.model_checkpoints       ).to(UpperCamelCase__       ).eval()
    __magic_name__								=			self.default_image_processor
    __magic_name__								=			prepare_img()
    __magic_name__								=			image_processor(UpperCamelCase__     ,				return_tensors="""pt"""       ).to(UpperCamelCase__       )
    __magic_name__								=			inputs["""pixel_values"""].shape
    # check size is divisible by 32
    self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0       )
    # check size
    self.assertEqual(UpperCamelCase__     ,				(1, 3, 384, 384)       )

    with torch.no_grad():
      __magic_name__								=			model(**UpperCamelCase__       )
    # masks_queries_logits
    __magic_name__								=			outputs.masks_queries_logits
    self.assertEqual(
        masks_queries_logits.shape     ,				(1, model.config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)       )
    __magic_name__								=			[
        [-8.7839, -9.0056, -8.8121],
        [-7.4104, -7.0313, -6.5401],
        [-6.6105, -6.3427, -6.4675],
    ]
    __magic_name__								=			torch.tensor(UpperCamelCase__       ).to(UpperCamelCase__       )
    self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]     ,				UpperCamelCase__     ,				atol=UpperCamelCase__       )       )
    # class_queries_logits
    __magic_name__								=			outputs.class_queries_logits
    self.assertEqual(class_queries_logits.shape     ,				(1, model.config.num_queries, model.config.num_labels + 1)       )
    __magic_name__								=			torch.tensor(
        [
            [1.8324, -8.0835, -4.1922],
            [0.8450, -9.0050, -3.6053],
            [0.3045, -7.7293, -3.0275],
        ]       ).to(UpperCamelCase__       )
    self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]     ,				UpperCamelCase__     ,				atol=UpperCamelCase__       )       )





  def 				_lowercase				(					self     :					Tuple       )     ->      Union[str, Any]:







    """simple docstring"""






    __magic_name__								=			MaskaFormerForUniversalSegmentation.from_pretrained(self.model_checkpoints       ).to(UpperCamelCase__       ).eval()
    __magic_name__								=			self.default_image_processor

    __magic_name__								=			image_processor(
        [np.zeros((3, 800, 1333)       ), np.zeros((3, 800, 1333)       )]     ,				segmentation_maps=[np.zeros((384, 384)       ).astype(np.floataa       ), np.zeros((384, 384)       ).astype(np.floataa       )]     ,				return_tensors="""pt"""     ,				)

    __magic_name__								=			inputs["""pixel_values"""].to(UpperCamelCase__       )
    __magic_name__								=			[el.to(UpperCamelCase__       ) for el in inputs["""mask_labels"""]]
    __magic_name__								=			[el.to(UpperCamelCase__       ) for el in inputs["""class_labels"""]]

    with torch.no_grad():
      __magic_name__								=			model(**UpperCamelCase__       )

    self.assertTrue(outputs.loss is not None       )



import html

from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
from ...utils import is_bsa_available, logging, requires_backends


if is_bsa_available():
    import bsa
    from bsa import BeautifulSoup


__lowerCAmelCase     :	int       			=  logging.get_logger(__name__)




class 			UpperCAmelCase_     (					_A	):


  '''simple docstring'''







  def __init__(					self     :					Union[str, Any]     ,				**UpperCamelCase__     :					Union[str, Any]       )     ->      Union[str, Any]:







    """simple docstring"""






    requires_backends(self     ,				["""bs4"""]       )
    super().__init__(**UpperCamelCase__       )
  def 				_lowercase				(					self     :					Dict     ,				UpperCamelCase__     :					Union[str, Any]       )     ->      Optional[Any]:







    """simple docstring"""






    __magic_name__								=			[]
    __magic_name__								=			[]
    __magic_name__								=			element if element.name else element.parent
    for parent in child.parents:  # type: bs4.element.Tag
      __magic_name__								=			parent.find_all(child.name     ,				recursive=UpperCamelCase__       )
      xpath_tags.append(child.name       )
      xpath_subscripts.append(
          0 if 1 == len(UpperCamelCase__       ) else next(i for i, s in enumerate(UpperCamelCase__     ,				1       ) if s is child       )       )
      __magic_name__								=			parent
    xpath_tags.reverse()
    xpath_subscripts.reverse()
    return xpath_tags, xpath_subscripts
  def 				_lowercase				(					self     :					Union[str, Any]     ,				UpperCamelCase__     :					List[Any]       )     ->      str:







    """simple docstring"""






    __magic_name__								=			BeautifulSoup(UpperCamelCase__     ,				"""html.parser"""       )

    __magic_name__								=			[]
    __magic_name__								=			[]
    __magic_name__								=			[]

    for element in html_code.descendants:
      if type(UpperCamelCase__       ) == bsa.element.NavigableString:
        if type(element.parent       ) != bsa.element.Tag:
          continue

        __magic_name__								=			html.unescape(UpperCamelCase__       ).strip()
        if not text_in_this_tag:
          continue

        all_doc_strings.append(UpperCamelCase__       )

        __magic_name__	,       __magic_name__								=			self.xpath_soup(UpperCamelCase__       )
        stringaxtag_seq.append(UpperCamelCase__       )
        stringaxsubs_seq.append(UpperCamelCase__       )

    if len(UpperCamelCase__       ) != len(UpperCamelCase__       ):
      raise ValueError("""Number of doc strings and xtags does not correspond"""       )
    if len(UpperCamelCase__       ) != len(UpperCamelCase__       ):
      raise ValueError("""Number of doc strings and xsubs does not correspond"""       )

    return all_doc_strings, stringaxtag_seq, stringaxsubs_seq
  def 				_lowercase				(					self     :					List[Any]     ,				UpperCamelCase__     :					Dict     ,				UpperCamelCase__     :					List[Any]       )     ->      Optional[Any]:







    """simple docstring"""






    __magic_name__								=			""""""
    for tagname, subs in zip(UpperCamelCase__     ,				UpperCamelCase__       ):
      xpath += F'''/{tagname}'''
      if subs != 0:
        xpath += F'''[{subs}]'''
    return xpath





  def __call__(					self     :					str     ,				UpperCamelCase__     :					Tuple       )     ->      BatchFeature:







    """simple docstring"""






    __magic_name__								=			False

    # Check that strings has a valid type
    if isinstance(UpperCamelCase__     ,				UpperCamelCase__       ):
      __magic_name__								=			True
    elif isinstance(UpperCamelCase__     ,				(list, tuple)       ):
      if len(UpperCamelCase__       ) == 0 or isinstance(html_strings[0]     ,				UpperCamelCase__       ):
        __magic_name__								=			True

    if not valid_strings:
      raise ValueError(
          """HTML strings must of type `str`, `List[str]` (batch of examples), """
          F'''but is of type {type(UpperCamelCase__       )}.'''       )

    __magic_name__								=			bool(isinstance(UpperCamelCase__     ,				(list, tuple)       ) and (isinstance(html_strings[0]     ,				UpperCamelCase__       ))       )

    if not is_batched:
      __magic_name__								=			[html_strings]

    # Get nodes + xpaths
    __magic_name__								=			[]
    __magic_name__								=			[]
    for html_string in html_strings:
      __magic_name__	,       __magic_name__	,       __magic_name__								=			self.get_three_from_single(UpperCamelCase__       )
      nodes.append(UpperCamelCase__       )
      __magic_name__								=			[]
      for node, tag_list, sub_list in zip(UpperCamelCase__     ,				UpperCamelCase__     ,				UpperCamelCase__       ):
        __magic_name__								=			self.construct_xpath(UpperCamelCase__     ,				UpperCamelCase__       )
        xpath_strings.append(UpperCamelCase__       )
      xpaths.append(UpperCamelCase__       )

    # return as Dict
    __magic_name__								=			{"""nodes""": nodes, """xpaths""": xpaths}
    __magic_name__								=			BatchFeature(data=UpperCamelCase__     ,				tensor_type=UpperCamelCase__       )

    return encoded_inputs

