'''simple docstring'''
import math
from collections import defaultdict
from typing import List, Optional, Tuple, Union

import numpy as np
import torch

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import randn_tensor
from .scheduling_utils import KarrasDiffusionSchedulers, SchedulerMixin, SchedulerOutput







def 							__UpperCamelCase   (				__UpperCAmelCase     :				List[str]   ,      __UpperCAmelCase     :				str=0.999   ,      __UpperCAmelCase     :				int="cosine"   ,      )       ->  Optional[Any]:
  if alpha_transform_type == "cosine":

    def alpha_bar_fn(__UpperCAmelCase     :				Tuple ):
      return math.cos((t + 0.008) / 1.008 * math.pi / 2 ) ** 2

  elif alpha_transform_type == "exp":

    def alpha_bar_fn(__UpperCAmelCase     :				Dict ):
      return math.exp(t * -12.0 )

  else:
    raise ValueError(f"""Unsupported alpha_tranform_type: {alpha_transform_type}""" )

  lowercase							:       int											=      []
  for i in range(__UpperCAmelCase ):
    lowercase							:       int											=      i / num_diffusion_timesteps
    lowercase							:       List[Any]											=      (i + 1) / num_diffusion_timesteps
    betas.append(min(1 - alpha_bar_fn(__UpperCAmelCase ) / alpha_bar_fn(__UpperCAmelCase )   ,      __UpperCAmelCase ) )
  return torch.tensor(__UpperCAmelCase   ,      dtype=torch.floataa )






class _lowerCAmelCase (  snake_case       ,      snake_case				):
      UpperCAmelCase_  :	Tuple     =					[e.name for e in KarrasDiffusionSchedulers]
      UpperCAmelCase_  :	Tuple     =					2







      @register_to_config
      def __init__(     self     ,						lowercase = 1000     ,						lowercase = 0.0_0085     ,						lowercase = 0.012     ,						lowercase = "linear"     ,						lowercase = None     ,						lowercase = "epsilon"     ,						lowercase = "linspace"     ,						lowercase = 0     ,						):
        if trained_betas is not None:
          lowercase							:       Any											=      torch.tensor(lowercase     ,						dtype=torch.floataa    )
        elif beta_schedule == "linear":
          lowercase							:       Tuple											=      torch.linspace(lowercase     ,						lowercase     ,						lowercase     ,						dtype=torch.floataa    )
        elif beta_schedule == "scaled_linear":
          # this schedule is very specific to the latent diffusion model.
          lowercase							:       List[str]											=      (
              torch.linspace(beta_start**0.5     ,						beta_end**0.5     ,						lowercase     ,						dtype=torch.floataa    ) ** 2
          )
        elif beta_schedule == "squaredcos_cap_v2":
          # Glide cosine schedule
          lowercase							:       Optional[Any]											=      betas_for_alpha_bar(lowercase    )
        else:
          raise NotImplementedError(F"""{beta_schedule} does is not implemented for {self.__class__}"""    )

        lowercase							:       Optional[Any]											=      1.0 - self.betas
        lowercase							:       Optional[int]											=      torch.cumprod(self.alphas     ,						dim=0    )

        #  set all values
        self.set_timesteps(lowercase     ,						lowercase     ,						lowercase    )







      def     lowerCamelCase__			(     self     ,						lowercase     ,						lowercase=None    ):
        if schedule_timesteps is None:
          lowercase							:       Union[str, Any]											=      self.timesteps

        lowercase							:       Optional[int]											=      (schedule_timesteps == timestep).nonzero()

        # The sigma index that is taken for the **very** first `step`
        # is always the second index (or the last index if there is only 1)
        # This way we can ensure we don't accidentally skip a sigma in
        # case we start in the middle of the denoising schedule (e.g. for image-to-image)
        if len(self._index_counter    ) == 0:
          lowercase							:       Union[str, Any]											=      1 if len(lowercase    ) > 1 else 0
        else:
          lowercase							:       List[str]											=      timestep.cpu().item() if torch.is_tensor(lowercase    ) else timestep
          lowercase							:       Tuple											=      self._index_counter[timestep_int]

        return indices[pos].item()







      @property
      def     lowerCamelCase__			(     self    ):
        # standard deviation of the initial noise distribution
        if self.config.timestep_spacing in ["linspace", "trailing"]:
          return self.sigmas.max()

        return (self.sigmas.max() ** 2 + 1) ** 0.5







      def     lowerCamelCase__			(     self     ,						lowercase     ,						lowercase     ,						):
        lowercase							:       List[Any]											=      self.index_for_timestep(lowercase    )

        if self.state_in_first_order:
          lowercase							:       Any											=      self.sigmas[step_index]
        else:
          lowercase							:       int											=      self.sigmas_interpol[step_index - 1]

        lowercase							:       Optional[Any]											=      sample / ((sigma**2 + 1) ** 0.5)
        return sample







      def     lowerCamelCase__			(     self     ,						lowercase     ,						lowercase = None     ,						lowercase = None     ,						):
        lowercase							:       Dict											=      num_inference_steps

        lowercase							:       List[str]											=      num_train_timesteps or self.config.num_train_timesteps

        # "linspace", "leading", "trailing" corresponds to annotation of Table 2. of https://arxiv.org/abs/2305.08891
        if self.config.timestep_spacing == "linspace":
          lowercase							:       Tuple											=      np.linspace(0     ,						num_train_timesteps - 1     ,						lowercase     ,						dtype=lowercase    )[::-1].copy()
        elif self.config.timestep_spacing == "leading":
          lowercase							:       Tuple											=      num_train_timesteps // self.num_inference_steps
          # creates integer timesteps by multiplying by ratio
          # casting to int to avoid issues when num_inference_step is power of 3
          lowercase							:       Tuple											=      (np.arange(0     ,						lowercase    ) * step_ratio).round()[::-1].copy().astype(lowercase    )
          timesteps += self.config.steps_offset
        elif self.config.timestep_spacing == "trailing":
          lowercase							:       List[str]											=      num_train_timesteps / self.num_inference_steps
          # creates integer timesteps by multiplying by ratio
          # casting to int to avoid issues when num_inference_step is power of 3
          lowercase							:       Any											=      (np.arange(lowercase     ,						0     ,						-step_ratio    )).round().copy().astype(lowercase    )
          timesteps -= 1
        else:
          raise ValueError(
              F"""{self.config.timestep_spacing} is not supported. Please make sure to choose one of 'linspace', 'leading' or 'trailing'."""    )

        lowercase							:       Union[str, Any]											=      np.array(((1 - self.alphas_cumprod) / self.alphas_cumprod) ** 0.5    )
        lowercase							:       List[str]											=      torch.from_numpy(np.log(lowercase    )    ).to(lowercase    )

        lowercase							:       Dict											=      np.interp(lowercase     ,						np.arange(0     ,						len(lowercase    )    )     ,						lowercase    )
        lowercase							:       Optional[Any]											=      np.concatenate([sigmas, [0.0]]    ).astype(np.floataa    )
        lowercase							:       List[str]											=      torch.from_numpy(lowercase    ).to(device=lowercase    )

        # compute up and down sigmas
        lowercase							:       str											=      sigmas.roll(-1    )
        lowercase							:       Tuple											=      0.0
        lowercase							:       List[Any]											=      (sigmas_next**2 * (sigmas**2 - sigmas_next**2) / sigmas**2) ** 0.5
        lowercase							:       Any											=      (sigmas_next**2 - sigmas_up**2) ** 0.5
        lowercase							:       int											=      0.0

        # compute interpolated sigmas
        lowercase							:       List[str]											=      sigmas.log().lerp(sigmas_down.log()     ,						0.5    ).exp()
        lowercase							:       Dict											=      0.0

        # set sigmas
        lowercase							:       List[Any]											=      torch.cat([sigmas[:1], sigmas[1:].repeat_interleave(2    ), sigmas[-1:]]    )
        lowercase							:       Optional[Any]											=      torch.cat(
            [sigmas_interpol[:1], sigmas_interpol[1:].repeat_interleave(2    ), sigmas_interpol[-1:]]    )
        lowercase							:       Tuple											=      torch.cat([sigmas_up[:1], sigmas_up[1:].repeat_interleave(2    ), sigmas_up[-1:]]    )
        lowercase							:       List[Any]											=      torch.cat([sigmas_down[:1], sigmas_down[1:].repeat_interleave(2    ), sigmas_down[-1:]]    )

        if str(lowercase    ).startswith('''mps'''    ):
          # mps does not support float64
          lowercase							:       Tuple											=      torch.from_numpy(lowercase    ).to(lowercase     ,						dtype=torch.floataa    )
        else:
          lowercase							:       Optional[Any]											=      torch.from_numpy(lowercase    ).to(lowercase    )

        lowercase							:       List[str]											=      self.sigma_to_t(lowercase    ).to(lowercase     ,						dtype=timesteps.dtype    )
        lowercase							:       Optional[Any]											=      torch.stack((timesteps_interpol[:-2, None], timesteps[1:, None])     ,						dim=-1    ).flatten()

        lowercase							:       List[Any]											=      torch.cat([timesteps[:1], interleaved_timesteps]    )

        lowercase							:       List[Any]											=      None

        # for exp beta schedules, such as the one for `pipeline_shap_e.py`
        # we need an index counter
        lowercase							:       List[str]											=      defaultdict(lowercase    )







      def     lowerCamelCase__			(     self     ,						lowercase    ):
        # get log sigma
        lowercase							:       Tuple											=      sigma.log()

        # get distribution
        lowercase							:       Dict											=      log_sigma - self.log_sigmas[:, None]

        # get sigmas range
        lowercase							:       str											=      dists.ge(0    ).cumsum(dim=0    ).argmax(dim=0    ).clamp(max=self.log_sigmas.shape[0] - 2    )
        lowercase							:       Optional[Any]											=      low_idx + 1

        lowercase							:       List[str]											=      self.log_sigmas[low_idx]
        lowercase							:       Any											=      self.log_sigmas[high_idx]

        # interpolate sigmas
        lowercase							:       Tuple											=      (low - log_sigma) / (low - high)
        lowercase							:       Union[str, Any]											=      w.clamp(0     ,						1    )

        # transform interpolation to time range
        lowercase							:       Union[str, Any]											=      (1 - w) * low_idx + w * high_idx
        lowercase							:       List[str]											=      t.view(sigma.shape    )
        return t







      @property
      def     lowerCamelCase__			(     self    ):
        return self.sample is None







      def     lowerCamelCase__			(     self     ,						lowercase     ,						lowercase     ,						lowercase     ,						lowercase = None     ,						lowercase = True     ,						):
        lowercase							:       Optional[Any]											=      self.index_for_timestep(lowercase    )

        # advance index counter by 1
        lowercase							:       Optional[int]											=      timestep.cpu().item() if torch.is_tensor(lowercase    ) else timestep
        self._index_counter[timestep_int] += 1

        if self.state_in_first_order:
          lowercase							:       Optional[int]											=      self.sigmas[step_index]
          lowercase							:       Optional[Any]											=      self.sigmas_interpol[step_index]
          lowercase							:       Any											=      self.sigmas_up[step_index]
          lowercase							:       List[str]											=      self.sigmas_down[step_index - 1]
        else:
          # 2nd order / KPDM2's method
          lowercase							:       Optional[int]											=      self.sigmas[step_index - 1]
          lowercase							:       Any											=      self.sigmas_interpol[step_index - 1]
          lowercase							:       int											=      self.sigmas_up[step_index - 1]
          lowercase							:       Any											=      self.sigmas_down[step_index - 1]

        # currently only gamma=0 is supported. This usually works best anyways.
        # We can support gamma in the future but then need to scale the timestep before
        # passing it to the model which requires a change in API
        lowercase							:       Any											=      0
        lowercase							:       Tuple											=      sigma * (gamma + 1)  # Note: sigma_hat == sigma for now

        lowercase							:       Optional[int]											=      model_output.device
        lowercase							:       Optional[Any]											=      randn_tensor(model_output.shape     ,						dtype=model_output.dtype     ,						device=lowercase     ,						generator=lowercase    )

        # 1. compute predicted original sample (x_0) from sigma-scaled predicted noise
        if self.config.prediction_type == "epsilon":
          lowercase							:       str											=      sigma_hat if self.state_in_first_order else sigma_interpol
          lowercase							:       Union[str, Any]											=      sample - sigma_input * model_output
        elif self.config.prediction_type == "v_prediction":
          lowercase							:       Optional[Any]											=      sigma_hat if self.state_in_first_order else sigma_interpol
          lowercase							:       Optional[int]											=      model_output * (-sigma_input / (sigma_input**2 + 1) ** 0.5) + (
              sample / (sigma_input**2 + 1)
          )
        elif self.config.prediction_type == "sample":
          raise NotImplementedError('''prediction_type not implemented yet: sample'''    )
        else:
          raise ValueError(
              F"""prediction_type given as {self.config.prediction_type} must be one of `epsilon`, or `v_prediction`"""    )

        if self.state_in_first_order:
          # 2. Convert to an ODE derivative for 1st order
          lowercase							:       int											=      (sample - pred_original_sample) / sigma_hat
          # 3. delta timestep
          lowercase							:       Any											=      sigma_interpol - sigma_hat

          # store for 2nd order step
          lowercase							:       Any											=      sample
          lowercase							:       Any											=      dt
          lowercase							:       Optional[Any]											=      sample + derivative * dt
        else:
          # DPM-Solver-2
          # 2. Convert to an ODE derivative for 2nd order
          lowercase							:       Union[str, Any]											=      (sample - pred_original_sample) / sigma_interpol
          # 3. delta timestep
          lowercase							:       Dict											=      sigma_down - sigma_hat

          lowercase							:       Union[str, Any]											=      self.sample
          lowercase							:       Dict											=      None

          lowercase							:       Any											=      sample + derivative * dt
          lowercase							:       str											=      prev_sample + noise * sigma_up

        if not return_dict:
          return (prev_sample,)

        return SchedulerOutput(prev_sample=lowercase    )







      def     lowerCamelCase__			(     self     ,						lowercase     ,						lowercase     ,						lowercase     ,						):
        # Make sure sigmas and timesteps have the same device and dtype as original_samples
        lowercase							:       Optional[Any]											=      self.sigmas.to(device=original_samples.device     ,						dtype=original_samples.dtype    )
        if original_samples.device.type == "mps" and torch.is_floating_point(lowercase    ):
          # mps does not support float64
          lowercase							:       Union[str, Any]											=      self.timesteps.to(original_samples.device     ,						dtype=torch.floataa    )
          lowercase							:       Tuple											=      timesteps.to(original_samples.device     ,						dtype=torch.floataa    )
        else:
          lowercase							:       Any											=      self.timesteps.to(original_samples.device    )
          lowercase							:       Dict											=      timesteps.to(original_samples.device    )

        lowercase							:       int											=      [self.index_for_timestep(lowercase     ,						lowercase    ) for t in timesteps]

        lowercase							:       Tuple											=      sigmas[step_indices].flatten()
        while len(sigma.shape    ) < len(original_samples.shape    ):
          lowercase							:       Optional[int]											=      sigma.unsqueeze(-1    )

        lowercase							:       Optional[int]											=      original_samples + noise * sigma
        return noisy_samples







      def __len__(     self    ):
        return self.config.num_train_timesteps
'''simple docstring'''
import csv
import dataclasses
import json
from dataclasses import dataclass
from typing import List, Optional, Union

from ...utils import is_tf_available, is_torch_available, logging


_A		:			Any	      =logging.get_logger(__name__)




@dataclass
class _lowerCAmelCase :
      UpperCAmelCase_  :	str
      UpperCAmelCase_  :	str
      UpperCAmelCase_  :	Optional[str]     =					None
      UpperCAmelCase_  :	Optional[str]     =					None







      def     lowerCamelCase__			(     self    ):
        return json.dumps(dataclasses.asdict(self    )     ,						indent=2    ) + "\n"





@dataclass(frozen=snake_case				)
class _lowerCAmelCase :
      UpperCAmelCase_  :	List[int]
      UpperCAmelCase_  :	Optional[List[int]]     =					None
      UpperCAmelCase_  :	Optional[List[int]]     =					None
      UpperCAmelCase_  :	Optional[Union[int, float]]     =					None







      def     lowerCamelCase__			(     self    ):
        return json.dumps(dataclasses.asdict(self    )    ) + "\n"





class _lowerCAmelCase :







      def     lowerCamelCase__			(     self     ,						lowercase    ):
        raise NotImplementedError()







      def     lowerCamelCase__			(     self     ,						lowercase    ):
        raise NotImplementedError()







      def     lowerCamelCase__			(     self     ,						lowercase    ):
        raise NotImplementedError()







      def     lowerCamelCase__			(     self     ,						lowercase    ):
        raise NotImplementedError()







      def     lowerCamelCase__			(     self    ):
        raise NotImplementedError()







      def     lowerCamelCase__			(     self     ,						lowercase    ):
        if len(self.get_labels()    ) > 1:
          lowercase							:       Tuple											=      self.get_labels()[int(example.label    )]
        return example







      @classmethod
      def     lowerCamelCase__			(     cls     ,						lowercase     ,						lowercase=None    ):
        with open(lowercase     ,						'''r'''     ,						encoding='''utf-8-sig'''    ) as f:
          return list(csv.reader(lowercase     ,						delimiter='''\t'''     ,						quotechar=lowercase    )    )





class _lowerCAmelCase (  snake_case				):







      def __init__(     self     ,						lowercase=None     ,						lowercase=None     ,						lowercase="classification"     ,						lowercase=False    ):
        lowercase							:       Tuple											=      [] if labels is None else labels
        lowercase							:       Optional[int]											=      [] if examples is None else examples
        lowercase							:       Tuple											=      mode
        lowercase							:       Any											=      verbose







      def __len__(     self    ):
        return len(self.examples    )







      def __getitem__(     self     ,						lowercase    ):
        if isinstance(lowercase     ,						lowercase    ):
          return SingleSentenceClassificationProcessor(labels=self.labels     ,						examples=self.examples[idx]    )
        return self.examples[idx]







      @classmethod
      def     lowerCamelCase__			(     cls     ,						lowercase     ,						lowercase=""     ,						lowercase=0     ,						lowercase=1     ,						lowercase=None     ,						lowercase=False     ,						**lowercase    ):
        lowercase							:       int											=      cls(**lowercase    )
        processor.add_examples_from_csv(
            lowercase     ,						split_name=lowercase     ,						column_label=lowercase     ,						column_text=lowercase     ,						column_id=lowercase     ,						skip_first_row=lowercase     ,						overwrite_labels=lowercase     ,						overwrite_examples=lowercase     ,						)
        return processor







      @classmethod
      def     lowerCamelCase__			(     cls     ,						lowercase     ,						lowercase=None     ,						**lowercase    ):
        lowercase							:       Dict											=      cls(**lowercase    )
        processor.add_examples(lowercase     ,						labels=lowercase    )
        return processor







      def     lowerCamelCase__			(     self     ,						lowercase     ,						lowercase=""     ,						lowercase=0     ,						lowercase=1     ,						lowercase=None     ,						lowercase=False     ,						lowercase=False     ,						lowercase=False     ,						):
        lowercase							:       Union[str, Any]											=      self._read_tsv(lowercase    )
        if skip_first_row:
          lowercase							:       Tuple											=      lines[1:]
        lowercase							:       Dict											=      []
        lowercase							:       Tuple											=      []
        lowercase							:       List[str]											=      []
        for i, line in enumerate(lowercase    ):
          texts.append(line[column_text]    )
          labels.append(line[column_label]    )
          if column_id is not None:
            ids.append(line[column_id]    )
          else:
            lowercase							:       Dict											=      F"""{split_name}-{i}""" if split_name else str(lowercase    )
            ids.append(lowercase    )

        return self.add_examples(
            lowercase     ,						lowercase     ,						lowercase     ,						overwrite_labels=lowercase     ,						overwrite_examples=lowercase    )







      def     lowerCamelCase__			(     self     ,						lowercase     ,						lowercase=None     ,						lowercase=None     ,						lowercase=False     ,						lowercase=False    ):
        if labels is not None and len(lowercase    ) != len(lowercase    ):
          raise ValueError(
              F"""Text and labels have mismatched lengths {len(lowercase    )} and {len(lowercase    )}"""    )
        if ids is not None and len(lowercase    ) != len(lowercase    ):
          raise ValueError(F"""Text and ids have mismatched lengths {len(lowercase    )} and {len(lowercase    )}"""    )
        if ids is None:
          lowercase							:       Optional[Any]											=      [None] * len(lowercase    )
        if labels is None:
          lowercase							:       Dict											=      [None] * len(lowercase    )
        lowercase							:       int											=      []
        lowercase							:       Optional[Any]											=      set()
        for text_or_text_and_label, label, guid in zip(lowercase     ,						lowercase     ,						lowercase    ):
          if isinstance(lowercase     ,						(tuple, list)    ) and label is None:
            lowercase							,			lowercase							:       Optional[Any]											=      text_or_text_and_label
          else:
            lowercase							:       Tuple											=      text_or_text_and_label
          added_labels.add(lowercase    )
          examples.append(InputExample(guid=lowercase     ,						text_a=lowercase     ,						text_b=lowercase     ,						label=lowercase    )    )

        # Update examples
        if overwrite_examples:
          lowercase							:       List[str]											=      examples
        else:
          self.examples.extend(lowercase    )

        # Update labels
        if overwrite_labels:
          lowercase							:       Dict											=      list(lowercase    )
        else:
          lowercase							:       Tuple											=      list(set(self.labels    ).union(lowercase    )    )

        return self.examples







      def     lowerCamelCase__			(     self     ,						lowercase     ,						lowercase=None     ,						lowercase=False     ,						lowercase=0     ,						lowercase=True     ,						lowercase=None     ,						):
        if max_length is None:
          lowercase							:       Optional[Any]											=      tokenizer.max_len

        lowercase							:       int											=      {label: i for i, label in enumerate(self.labels    )}

        lowercase							:       str											=      []
        for ex_index, example in enumerate(self.examples    ):
          if ex_index % 1_0000 == 0:
            logger.info(F"""Tokenizing example {ex_index}"""    )

          lowercase							:       Optional[int]											=      tokenizer.encode(
              example.text_a     ,						add_special_tokens=lowercase     ,						max_length=min(lowercase     ,						tokenizer.max_len    )     ,						)
          all_input_ids.append(lowercase    )

        lowercase							:       int											=      max(len(lowercase    ) for input_ids in all_input_ids    )

        lowercase							:       Dict											=      []
        for ex_index, (input_ids, example) in enumerate(zip(lowercase     ,						self.examples    )    ):
          if ex_index % 1_0000 == 0:
            logger.info(F"""Writing example {ex_index}/{len(self.examples    )}"""    )
          # The mask has 1 for real tokens and 0 for padding tokens. Only real
          # tokens are attended to.
          lowercase							:       List[Any]											=      [1 if mask_padding_with_zero else 0] * len(lowercase    )

          # Zero-pad up to the sequence length.
          lowercase							:       List[Any]											=      batch_length - len(lowercase    )
          if pad_on_left:
            lowercase							:       Optional[int]											=      ([pad_token] * padding_length) + input_ids
            lowercase							:       Any											=      ([0 if mask_padding_with_zero else 1] * padding_length) + attention_mask
          else:
            lowercase							:       int											=      input_ids + ([pad_token] * padding_length)
            lowercase							:       List[str]											=      attention_mask + ([0 if mask_padding_with_zero else 1] * padding_length)

          if len(lowercase    ) != batch_length:
            raise ValueError(F"""Error with input length {len(lowercase    )} vs {batch_length}"""    )
          if len(lowercase    ) != batch_length:
            raise ValueError(F"""Error with input length {len(lowercase    )} vs {batch_length}"""    )

          if self.mode == "classification":
            lowercase							:       Dict											=      label_map[example.label]
          elif self.mode == "regression":
            lowercase							:       Optional[int]											=      float(example.label    )
          else:
            raise ValueError(self.mode    )

          if ex_index < 5 and self.verbose:
            logger.info('''*** Example ***'''    )
            logger.info(F"""guid: {example.guid}"""    )
            logger.info(F"""input_ids: {" ".join([str(lowercase    ) for x in input_ids]    )}"""    )
            logger.info(F"""attention_mask: {" ".join([str(lowercase    ) for x in attention_mask]    )}"""    )
            logger.info(F"""label: {example.label} (id = {label})"""    )

          features.append(InputFeatures(input_ids=lowercase     ,						attention_mask=lowercase     ,						label=lowercase    )    )

        if return_tensors is None:
          return features
        elif return_tensors == "tf":
          if not is_tf_available():
            raise RuntimeError('''return_tensors set to \'tf\' but TensorFlow 2.0 can\'t be imported'''    )
          import tensorflow as tf

          def gen():
            for ex in features:
              yield ({"input_ids": ex.input_ids, "attention_mask": ex.attention_mask}, ex.label)

          lowercase							:       Any											=      tf.data.Dataset.from_generator(
              lowercase     ,						({'''input_ids''': tf.intaa, '''attention_mask''': tf.intaa}, tf.intaa)     ,						({'''input_ids''': tf.TensorShape([None]    ), '''attention_mask''': tf.TensorShape([None]    )}, tf.TensorShape([]    ))     ,						)
          return dataset
        elif return_tensors == "pt":
          if not is_torch_available():
            raise RuntimeError('''return_tensors set to \'pt\' but PyTorch can\'t be imported'''    )
          import torch
          from torch.utils.data import TensorDataset

          lowercase							:       Any											=      torch.tensor([f.input_ids for f in features]     ,						dtype=torch.long    )
          lowercase							:       List[str]											=      torch.tensor([f.attention_mask for f in features]     ,						dtype=torch.long    )
          if self.mode == "classification":
            lowercase							:       int											=      torch.tensor([f.label for f in features]     ,						dtype=torch.long    )
          elif self.mode == "regression":
            lowercase							:       Tuple											=      torch.tensor([f.label for f in features]     ,						dtype=torch.float    )

          lowercase							:       int											=      TensorDataset(lowercase     ,						lowercase     ,						lowercase    )
          return dataset
        else:
          raise ValueError('''return_tensors should be one of \'tf\' or \'pt\''''    )