





import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin







class     __snake_case       (							__lowerCamelCase			):





       '''simple docstring'''







       lowerCAmelCase__      		=     """MCTCTFeatureExtractor"""
       lowerCAmelCase__      		=     """AutoTokenizer"""




       def __init__(  self :    str							,				A :    List[str]							,				A :    int		):
         super().__init__(A							,				A		)
         __snake_case:						Tuple   =						self.feature_extractor
         __snake_case:						List[str]   =						False




       def __call__(  self :    str							,				*A :    Union[str, Any]							,				**A :    Optional[int]		):
         # For backward compatibility
         if self._in_target_context_manager:
           return self.current_processor(*A							,				**A		)

         if "raw_speech" in kwargs:
           warnings.warn("""Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead."""		)
           __snake_case:						Any   =						kwargs.pop("""raw_speech"""		)
         else:
           __snake_case:						str   =						kwargs.pop("""audio"""							,				A		)
         __snake_case:						int   =						kwargs.pop("""sampling_rate"""							,				A		)
         __snake_case:						Dict   =						kwargs.pop("""text"""							,				A		)
         if len(A		) > 0:
           __snake_case:						Optional[Any]   =						args[0]
           __snake_case:						List[str]   =						args[1:]

         if audio is None and text is None:
           raise ValueError("""You need to specify either an `audio` or `text` input to process."""		)

         if audio is not None:
           __snake_case:						Dict   =						self.feature_extractor(A							,				*A							,				sampling_rate=A							,				**A		)
         if text is not None:
           __snake_case:						Optional[Any]   =						self.tokenizer(A							,				**A		)

         if text is None:
           return inputs
         elif audio is None:
           return encodings
         else:
           __snake_case:						List[str]   =						encodings["""input_ids"""]
           return inputs




       def 							UpperCAmelCase__ (  self :    Tuple							,				*A :    int							,				**A :    List[str]		):
         return self.tokenizer.batch_decode(*A							,				**A		)




       def 							UpperCAmelCase__ (  self :    int							,				*A :    Optional[Any]							,				**A :    Dict		):
         # For backward compatibility
         if self._in_target_context_manager:
           return self.current_processor.pad(*A							,				**A		)

         __snake_case:						Optional[int]   =						kwargs.pop("""input_features"""							,				A		)
         __snake_case:						str   =						kwargs.pop("""labels"""							,				A		)
         if len(A		) > 0:
           __snake_case:						Union[str, Any]   =						args[0]
           __snake_case:						List[str]   =						args[1:]

         if input_features is not None:
           __snake_case:						List[str]   =						self.feature_extractor.pad(A							,				*A							,				**A		)
         if labels is not None:
           __snake_case:						Tuple   =						self.tokenizer.pad(A							,				**A		)

         if labels is None:
           return input_features
         elif input_features is None:
           return labels
         else:
           __snake_case:						Tuple   =						labels["""input_ids"""]
           return input_features




       def 							UpperCAmelCase__ (  self :    Union[str, Any]							,				*A :    Dict							,				**A :    str		):
         return self.tokenizer.decode(*A							,				**A		)






       @contextmanager
       def 							UpperCAmelCase__ (  self :    List[str]		):
         warnings.warn(
             """`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your """
             """labels by using the argument `text` of the regular `__call__` method (either in the same call as """
             """your audio inputs, or in a separate call."""		)
         __snake_case:						str   =						True
         __snake_case:						Any   =						self.tokenizer
         yield
         __snake_case:						Union[str, Any]   =						self.feature_extractor
         __snake_case:						Dict   =						False













from dataclasses import dataclass
from typing import Optional, Tuple

import torch
from torch import nn
from transformers import RobertaPreTrainedModel, XLMRobertaConfig, XLMRobertaModel
from transformers.utils import ModelOutput







@dataclass
class     __snake_case       (							__lowerCamelCase			):





       '''simple docstring'''







       lowerCAmelCase__      		=     None
       lowerCAmelCase__      		=     None
       lowerCAmelCase__      		=     None
       lowerCAmelCase__      		=     None







class     __snake_case       (							__lowerCamelCase			):





       '''simple docstring'''







       def __init__(  self :    Any							,				A :    List[str]=1							,				A :    str=0							,				A :    List[Any]=2							,				A :    Union[str, Any]=512							,				A :    Tuple="cls"							,				A :    Union[str, Any]=False							,				A :    Optional[Any]=True							,				**A :    Optional[int]							,				):
         super().__init__(pad_token_id=A							,				bos_token_id=A							,				eos_token_id=A							,				**A		)
         __snake_case:						str   =						project_dim
         __snake_case:						Optional[int]   =						pooler_fn
         __snake_case:						Dict   =						learn_encoder
         __snake_case:						str   =						use_attention_mask







class     __snake_case       (							__lowerCamelCase			):





       '''simple docstring'''







       lowerCAmelCase__      		=     [R"""pooler""", R"""logit_scale"""]
       lowerCAmelCase__      		=     [R"""position_ids""", R"""predictions.decoder.bias"""]
       lowerCAmelCase__      		=     """roberta"""
       lowerCAmelCase__      		=     RobertaSeriesConfig




       def __init__(  self :    Dict							,				A :    Dict		):
         super().__init__(A		)
         __snake_case:						Optional[Any]   =						XLMRobertaModel(A		)
         __snake_case:						List[Any]   =						nn.Linear(config.hidden_size							,				config.project_dim		)
         __snake_case:						Optional[int]   =						getattr(A							,				"""has_pre_transformation"""							,				A		)
         if self.has_pre_transformation:
           __snake_case:						Optional[Any]   =						nn.Linear(config.hidden_size							,				config.project_dim		)
           __snake_case:						Optional[Any]   =						nn.LayerNorm(config.hidden_size							,				eps=config.layer_norm_eps		)
         self.post_init()






       def 							UpperCAmelCase__ (  self :    Optional[Any]							,				A :    Optional[torch.Tensor] = None							,				A :    Optional[torch.Tensor] = None							,				A :    Optional[torch.Tensor] = None							,				A :    Optional[torch.Tensor] = None							,				A :    Optional[torch.Tensor] = None							,				A :    Optional[torch.Tensor] = None							,				A :    Optional[torch.Tensor] = None							,				A :    Optional[torch.Tensor] = None							,				A :    Optional[bool] = None							,				A :    Optional[bool] = None							,				A :    Optional[bool] = None							,				):
         __snake_case:						Any   =						return_dict if return_dict is not None else self.config.use_return_dict

         __snake_case:						Optional[int]   =						self.base_model(
             input_ids=A							,				attention_mask=A							,				token_type_ids=A							,				position_ids=A							,				head_mask=A							,				inputs_embeds=A							,				encoder_hidden_states=A							,				encoder_attention_mask=A							,				output_attentions=A							,				output_hidden_states=True if self.has_pre_transformation else output_hidden_states							,				return_dict=A							,				)

         if self.has_pre_transformation:
           __snake_case:						int   =						outputs["""hidden_states"""][-2]
           __snake_case:						List[str]   =						self.pre_LN(A		)
           __snake_case:						List[str]   =						self.transformation_pre(A		)

           return TransformationModelOutput(
               projection_state=A							,				last_hidden_state=outputs.last_hidden_state							,				hidden_states=outputs.hidden_states							,				attentions=outputs.attentions							,				)
         else:
           __snake_case:						Optional[int]   =						self.transformation(outputs.last_hidden_state		)
           return TransformationModelOutput(
               projection_state=A							,				last_hidden_state=outputs.last_hidden_state							,				hidden_states=outputs.hidden_states							,				attentions=outputs.attentions							,				)






