



import numpy as np

import datasets


A_		:     Tuple        =     '''
Compute the Mahalanobis Distance

Mahalonobis distance is the distance between a point and a distribution.
And not between two distinct points. It is effectively a multivariate equivalent of the Euclidean distance.
It was introduced by Prof. P. C. Mahalanobis in 1936
and has been used in various statistical applications ever since
[source: https://www.machinelearningplus.com/statistics/mahalanobis-distance/]
'''

A_		:     List[Any]        =     '''\
@article{de2000mahalanobis,
  title={The mahalanobis distance},
  author={De Maesschalck, Roy and Jouan-Rimbaud, Delphine and Massart, D{\'e}sir{\'e} L},
  journal={Chemometrics and intelligent laboratory systems},
  volume={50},
  number={1},
  pages={1--18},
  year={2000},
  publisher={Elsevier}
}
'''

A_		:     Optional[Any]        =     '''
Args:
    X: List of datapoints to be compared with the `reference_distribution`.
    reference_distribution: List of datapoints from the reference distribution we want to compare to.
Returns:
    mahalanobis: The Mahalonobis distance for each datapoint in `X`.
Examples:

    >>> mahalanobis_metric = datasets.load_metric("mahalanobis")
    >>> results = mahalanobis_metric.compute(reference_distribution=[[0, 1], [1, 0]], X=[[0, 1]])
    >>> print(results)
    {\'mahalanobis\': array([0.5])}
'''



@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION,   _KWARGS_DESCRIPTION	)
class 		_lowercase		(       datasets.Metric	):

   def 		A							(      self			:       List[Any]							)       ->				List[Any]:


    """simple docstring"""






    return datasets.MetricInfo(
        description=_DESCRIPTION							,   citation=_CITATION							,   inputs_description=_KWARGS_DESCRIPTION							,   features=datasets.Features(
            {
                "X": datasets.Sequence(datasets.Value("float"							,   id="sequence"							)							,   id="X"							),
            }							)							,   )




   def 		A							(      self			:       Any							,   __lowerCAmelCase			:       Dict							,   __lowerCAmelCase			:       Dict							)       ->				Union[str, Any]:


    """simple docstring"""






    a						=		np.array(__lowerCAmelCase							)
    a						=		np.array(__lowerCAmelCase							)

    # Assert that arrays are 2D
    if len(X.shape							) != 2:
     raise ValueError("Expected `X` to be a 2D vector"							)
    if len(reference_distribution.shape							) != 2:
     raise ValueError("Expected `reference_distribution` to be a 2D vector"							)
    if reference_distribution.shape[0] < 2:
     raise ValueError(
         "Expected `reference_distribution` to be a 2D vector with more than one element in the first dimension"							)

    # Get mahalanobis distance for each prediction
    a						=		X - np.mean(__lowerCAmelCase							)
    a						=		np.cov(reference_distribution.T							)
    try:
     a						=		np.linalg.inv(__lowerCAmelCase							)
    except np.linalg.LinAlgError:
     a						=		np.linalg.pinv(__lowerCAmelCase							)
    a						=		np.dot(__lowerCAmelCase							,   __lowerCAmelCase							)
    a						=		np.dot(__lowerCAmelCase							,   X_minus_mu.T							).diagonal()

    return {"mahalanobis": mahal_dist}









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


A_		:     Any        =     logging.get_logger(__name__)

A_		:     Optional[int]        =     {
    '''SCUT-DLVCLab/lilt-roberta-en-base''': (
        '''https://huggingface.co/SCUT-DLVCLab/lilt-roberta-en-base/resolve/main/config.json'''
    ),
}



class 		_lowercase		(       UpperCAmelCase__	):
   _UpperCAmelCase     	=			'''lilt'''

   def __init__(      self			:       Union[str, Any]							,   __lowerCAmelCase			:       Optional[Any]=3_0522							,   __lowerCAmelCase			:       str=768							,   __lowerCAmelCase			:       Any=12							,   __lowerCAmelCase			:       Optional[Any]=12							,   __lowerCAmelCase			:       List[Any]=3072							,   __lowerCAmelCase			:       Dict="gelu"							,   __lowerCAmelCase			:       int=0.1							,   __lowerCAmelCase			:       Union[str, Any]=0.1							,   __lowerCAmelCase			:       List[str]=512							,   __lowerCAmelCase			:       Optional[int]=2							,   __lowerCAmelCase			:       int=0.0_2							,   __lowerCAmelCase			:       Union[str, Any]=1E-12							,   __lowerCAmelCase			:       Tuple=0							,   __lowerCAmelCase			:       List[Any]="absolute"							,   __lowerCAmelCase			:       int=None							,   __lowerCAmelCase			:       Dict=4							,   __lowerCAmelCase			:       Dict=1024							,   **__lowerCAmelCase			:       Dict							,   )       ->				int:


    """simple docstring"""






    super().__init__(pad_token_id=__lowerCAmelCase							,   **__lowerCAmelCase							)

    a						=		vocab_size
    a						=		hidden_size
    a						=		num_hidden_layers
    a						=		num_attention_heads
    a						=		hidden_act
    a						=		intermediate_size
    a						=		hidden_dropout_prob
    a						=		attention_probs_dropout_prob
    a						=		max_position_embeddings
    a						=		type_vocab_size
    a						=		initializer_range
    a						=		layer_norm_eps
    a						=		position_embedding_type
    a						=		classifier_dropout
    a						=		channel_shrink_ratio
    a						=		max_ad_position_embeddings

