



import warnings
from typing import List, Optional, Union

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType


class   __lowerCAmelCase  (		UpperCAmelCase_   ):
					"""simple docstring"""






					A__					:		str      							=     ["image_processor", "tokenizer"]
					A__					:		str      							=     "LayoutLMv3ImageProcessor"
					A__					:		Tuple      							=     ("LayoutLMv3Tokenizer", "LayoutLMv3TokenizerFast")



					def __init__(  self       :							Optional[int]					,       _snake_case       :							Optional[int]=None					,       _snake_case       :							Optional[int]=None					,       **_snake_case       :							int       ):






								"""simple docstring"""


								A__	  =     None
								if "feature_extractor" in kwargs:
											warnings.warn(
											    'The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'
											    ' instead.'					,       _snake_case					,       )
											A__	  =     kwargs.pop('feature_extractor'       )

								A__	  =     image_processor if image_processor is not None else feature_extractor
								if image_processor is None:
											raise ValueError('You need to specify an `image_processor`.'       )
								if tokenizer is None:
											raise ValueError('You need to specify a `tokenizer`.'       )

								super().__init__(_snake_case					,       _snake_case       )



					def __call__(  self       :							Optional[int]					,       _snake_case       :							List[str]					,       _snake_case       :							Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None					,       _snake_case       :							Optional[Union[PreTokenizedInput, List[PreTokenizedInput]]] = None					,       _snake_case       :							Union[List[List[int]], List[List[List[int]]]] = None					,       _snake_case       :							Optional[Union[List[int], List[List[int]]]] = None					,       _snake_case       :							bool = True					,       _snake_case       :							Union[bool, str, PaddingStrategy] = False					,       _snake_case       :							Union[bool, str, TruncationStrategy] = None					,       _snake_case       :							Optional[int] = None					,       _snake_case       :							int = 0					,       _snake_case       :							Optional[int] = None					,       _snake_case       :							Optional[bool] = None					,       _snake_case       :							Optional[bool] = None					,       _snake_case       :							bool = False					,       _snake_case       :							bool = False					,       _snake_case       :							bool = False					,       _snake_case       :							bool = False					,       _snake_case       :							bool = True					,       _snake_case       :							Optional[Union[str, TensorType]] = None					,       **_snake_case       :							Optional[Any]					,       ):






								"""simple docstring"""


								if self.image_processor.apply_ocr and (boxes is not None):
											raise ValueError(
											    'You cannot provide bounding boxes if you initialized the image processor with apply_ocr set to True.'       )

								if self.image_processor.apply_ocr and (word_labels is not None):
											raise ValueError(
											    'You cannot provide word labels if you initialized the image processor with apply_ocr set to True.'       )

								# first, apply the image processor
								A__	  =     self.image_processor(images=_snake_case					,       return_tensors=_snake_case       )

								# second, apply the tokenizer
								if text is not None and self.image_processor.apply_ocr and text_pair is None:
											if isinstance(_snake_case					,       _snake_case       ):
														A__	  =     [text]  # add batch dimension (as the image processor always adds a batch dimension)
											A__	  =     features['words']

								A__	  =     self.tokenizer(
								    text=text if text is not None else features['words']					,       text_pair=text_pair if text_pair is not None else None					,       boxes=boxes if boxes is not None else features['boxes']					,       word_labels=_snake_case					,       add_special_tokens=_snake_case					,       padding=_snake_case					,       truncation=_snake_case					,       max_length=_snake_case					,       stride=_snake_case					,       pad_to_multiple_of=_snake_case					,       return_token_type_ids=_snake_case					,       return_attention_mask=_snake_case					,       return_overflowing_tokens=_snake_case					,       return_special_tokens_mask=_snake_case					,       return_offsets_mapping=_snake_case					,       return_length=_snake_case					,       verbose=_snake_case					,       return_tensors=_snake_case					,       **_snake_case					,       )

								# add pixel values
								A__	  =     features.pop('pixel_values'       )
								if return_overflowing_tokens is True:
											A__	  =     self.get_overflowing_images(_snake_case					,       encoded_inputs['overflow_to_sample_mapping']       )
								A__	  =     images

								return encoded_inputs



					def      _a				(  self       :							int					,       _snake_case       :							List[str]					,       _snake_case       :							Union[str, Any]       ):






								"""simple docstring"""


								A__	  =     []
								for sample_idx in overflow_to_sample_mapping:
											images_with_overflow.append(images[sample_idx]       )

								if len(_snake_case       ) != len(_snake_case       ):
											raise ValueError(
											    'Expected length of images to be the same as the length of `overflow_to_sample_mapping`, but got'
											    F''' {len(_snake_case       )} and {len(_snake_case       )}'''       )

								return images_with_overflow



					def      _a				(  self       :							Union[str, Any]					,       *_snake_case       :							List[Any]					,       **_snake_case       :							Any       ):






								"""simple docstring"""


								return self.tokenizer.batch_decode(*_snake_case					,       **_snake_case       )



					def      _a				(  self       :							List[str]					,       *_snake_case       :							Optional[int]					,       **_snake_case       :							int       ):






								"""simple docstring"""


								return self.tokenizer.decode(*_snake_case					,       **_snake_case       )



					@property
					def      _a				(  self       :							Optional[Any]       ):






								"""simple docstring"""


								return ["input_ids", "bbox", "attention_mask", "pixel_values"]



					@property
					def      _a				(  self       :							Any       ):






								"""simple docstring"""


								warnings.warn(
								    '`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'					,       _snake_case					,       )
								return self.image_processor_class



					@property
					def      _a				(  self       :							int       ):






								"""simple docstring"""


								warnings.warn(
								    '`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.'					,       _snake_case					,       )
								return self.image_processor







from scipy.stats import spearmanr

import datasets


a__												=						'''
The Spearman rank-order correlation coefficient is a measure of the
relationship between two datasets. Like other correlation coefficients,
this one varies between -1 and +1 with 0 implying no correlation.
Positive correlations imply that as data in dataset x increases, so
does data in dataset y. Negative correlations imply that as x increases,
y decreases. Correlations of -1 or +1 imply an exact monotonic relationship.

Unlike the Pearson correlation, the Spearman correlation does not
assume that both datasets are normally distributed.

The p-value roughly indicates the probability of an uncorrelated system
producing datasets that have a Spearman correlation at least as extreme
as the one computed from these datasets. The p-values are not entirely
reliable but are probably reasonable for datasets larger than 500 or so.
'''

a__												=						'''
Args:
    predictions (`List[float]`): Predicted labels, as returned by a model.
    references (`List[float]`): Ground truth labels.
    return_pvalue (`bool`): If `True`, returns the p-value. If `False`, returns
            only the spearmanr score. Defaults to `False`.
Returns:
    spearmanr (`float`): Spearman correlation coefficient.
    p-value (`float`): p-value. **Note**: is only returned if `return_pvalue=True` is input.
Examples:
    Example 1:
        >>> spearmanr_metric = datasets.load_metric("spearmanr")
        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5], predictions=[10, 9, 2.5, 6, 4])
        >>> print(results)
        {\'spearmanr\': -0.7}

    Example 2:
        >>> spearmanr_metric = datasets.load_metric("spearmanr")
        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5],
        ...                                     predictions=[10, 9, 2.5, 6, 4],
        ...                                     return_pvalue=True)
        >>> print(results[\'spearmanr\'])
        -0.7
        >>> print(round(results[\'spearmanr_pvalue\'], 2))
        0.19
'''

a__												=						R'''\
@book{kokoska2000crc,
  title={CRC standard probability and statistics tables and formulae},
  author={Kokoska, Stephen and Zwillinger, Daniel},
  year={2000},
  publisher={Crc Press}
}
@article{2020SciPy-NMeth,
  author  = {Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E. and
            Haberland, Matt and Reddy, Tyler and Cournapeau, David and
            Burovski, Evgeni and Peterson, Pearu and Weckesser, Warren and
            Bright, Jonathan and {van der Walt}, St{\'e}fan J. and
            Brett, Matthew and Wilson, Joshua and Millman, K. Jarrod and
            Mayorov, Nikolay and Nelson, Andrew R. J. and Jones, Eric and
            Kern, Robert and Larson, Eric and Carey, C J and
            Polat, {\.I}lhan and Feng, Yu and Moore, Eric W. and
            {VanderPlas}, Jake and Laxalde, Denis and Perktold, Josef and
            Cimrman, Robert and Henriksen, Ian and Quintero, E. A. and
            Harris, Charles R. and Archibald, Anne M. and
            Ribeiro, Ant{\^o}nio H. and Pedregosa, Fabian and
            {van Mulbregt}, Paul and {SciPy 1.0 Contributors}},
  title   = {{{SciPy} 1.0: Fundamental Algorithms for Scientific
            Computing in Python}},
  journal = {Nature Methods},
  year    = {2020},
  volume  = {17},
  pages   = {261--272},
  adsurl  = {https://rdcu.be/b08Wh},
  doi     = {10.1038/s41592-019-0686-2},
}
'''

@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION							,			_KWARGS_DESCRIPTION  )
class 							UpperCAmelCase_						(     datasets.Metric  ):
							"""simple docstring"""







							def 							__lowercase							(     self			)       ->       int:
												return datasets.MetricInfo(
												    description=_DESCRIPTION			,				citation=_CITATION			,				inputs_description=_KWARGS_DESCRIPTION			,				features=datasets.Features(
												        {
												            '''predictions''': datasets.Value('''float'''			),
												            '''references''': datasets.Value('''float'''			),
												        }			)			,				reference_urls=['''https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.spearmanr.html''']			,				)




							def 							__lowercase							(     self			,				_a			,				_a			,				_a=False			)       ->       str:
												_a      :       int   =						spearmanr(_a			,				_a			)
												if return_pvalue:
																	return {"spearmanr": results[0], "spearmanr_pvalue": results[1]}
												else:
																	return {"spearmanr": results[0]}



