"""simple docstring"""


import numpy as np
import torch
import torch.nn as nn
from transformers import CLIPConfig, CLIPVisionModelWithProjection, PreTrainedModel

from ...utils import logging


UpperCAmelCase__  		=						logging.get_logger(__name__)


class        a				(		lowerCAmelCase_   ):
    _snake_case     :  Optional[Any]     							=							CLIPConfig

    _snake_case     :  Optional[int]     							=							['CLIPEncoderLayer']


    def __init__(					self	:  Dict   ,				__lowerCAmelCase	:  CLIPConfig					):
      super().__init__(__lowerCAmelCase					)

      _UpperCAmelCase						 =      CLIPVisionModelWithProjection(config.vision_config					)

      _UpperCAmelCase						 =      nn.Linear(config.vision_config.projection_dim   ,				1					)
      _UpperCAmelCase						 =      nn.Linear(config.vision_config.projection_dim   ,				1					)


    @torch.no_grad()
    def      lowerCAmelCase_  (					self	:  List[Any]   ,				__lowerCAmelCase	:  Optional[Any]   ,				__lowerCAmelCase	:  Tuple   ,				__lowerCAmelCase	:  Union[str, Any]=0.5   ,				__lowerCAmelCase	:  int=0.5					):
      _UpperCAmelCase						 =      self.vision_model(__lowerCAmelCase					)[0]

      _UpperCAmelCase						 =      self.p_head(__lowerCAmelCase					)
      _UpperCAmelCase						 =      nsfw_detected.flatten()
      _UpperCAmelCase						 =      nsfw_detected > p_threshold
      _UpperCAmelCase						 =      nsfw_detected.tolist()

      if any(__lowerCAmelCase					):
        logger.warning(
            """Potential NSFW content was detected in one or more images. A black image will be returned instead."""
            """ Try again with a different prompt and/or seed."""					)

      for idx, nsfw_detected_ in enumerate(__lowerCAmelCase					):
        if nsfw_detected_:
          _UpperCAmelCase						 =      np.zeros(images[idx].shape					)

      _UpperCAmelCase						 =      self.w_head(__lowerCAmelCase					)
      _UpperCAmelCase						 =      watermark_detected.flatten()
      _UpperCAmelCase						 =      watermark_detected > w_threshold
      _UpperCAmelCase						 =      watermark_detected.tolist()

      if any(__lowerCAmelCase					):
        logger.warning(
            """Potential watermarked content was detected in one or more images. A black image will be returned instead."""
            """ Try again with a different prompt and/or seed."""					)

      for idx, watermark_detected_ in enumerate(__lowerCAmelCase					):
        if watermark_detected_:
          _UpperCAmelCase						 =      np.zeros(images[idx].shape					)

      return images, nsfw_detected, watermark_detected

"""simple docstring"""


import datasets


UpperCAmelCase__  		=						"""\
@InProceedings{conneau2018xnli,
  author = \"Conneau, Alexis
                 and Rinott, Ruty
                 and Lample, Guillaume
                 and Williams, Adina
                 and Bowman, Samuel R.
                 and Schwenk, Holger
                 and Stoyanov, Veselin\",
  title = \"XNLI: Evaluating Cross-lingual Sentence Representations\",
  booktitle = \"Proceedings of the 2018 Conference on Empirical Methods
               in Natural Language Processing\",
  year = \"2018\",
  publisher = \"Association for Computational Linguistics\",
  location = \"Brussels, Belgium\",
}
"""

UpperCAmelCase__  		=						"""\
XNLI is a subset of a few thousand examples from MNLI which has been translated
into a 14 different languages (some low-ish resource). As with MNLI, the goal is
to predict textual entailment (does sentence A imply/contradict/neither sentence
B) and is a classification task (given two sentences, predict one of three
labels).
"""

UpperCAmelCase__  		=						"""
Computes XNLI score which is just simple accuracy.
Args:
    predictions: Predicted labels.
    references: Ground truth labels.
Returns:
    'accuracy': accuracy
Examples:

    >>> predictions = [0, 1]
    >>> references = [0, 1]
    >>> xnli_metric = datasets.load_metric(\"xnli\")
    >>> results = xnli_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {'accuracy': 1.0}
"""






def     __UpperCAmelCase					(			lowercase   ,lowercase		):







  """simple docstring"""
  return (preds == labels).mean()


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


    def      lowerCAmelCase_  (					self	:  Union[str, Any]					):
      return datasets.MetricInfo(
          description=_DESCRIPTION   ,				citation=_CITATION   ,				inputs_description=_KWARGS_DESCRIPTION   ,				features=datasets.Features(
              {
                  """predictions""": datasets.Value("""int64""" if self.config_name != """sts-b""" else """float32"""					),
                  """references""": datasets.Value("""int64""" if self.config_name != """sts-b""" else """float32"""					),
              }					)   ,				codebase_urls=[]   ,				reference_urls=[]   ,				format="""numpy"""   ,				)


    def      lowerCAmelCase_  (					self	:  List[str]   ,				__lowerCAmelCase	:  int   ,				__lowerCAmelCase	:  Any					):
      return {"accuracy": simple_accuracy(__lowerCAmelCase   ,				__lowerCAmelCase					)}
