'''simple docstring'''






from dataclasses import dataclass, field
from typing import ClassVar, Dict

from ..features import Features, Value
from .base import TaskTemplate




@dataclass(frozen=__lowerCAmelCase				)
class    a (       __lowerCAmelCase				):



  """simple docstring"""
  # `task` is not a ClassVar since we want it to be part of the `asdict` output for JSON serialization
  __lowerCAmelCase				      =					field(default="""summarization"""						,  metadata={"""include_in_asdict_even_if_is_default""": True}				)
  __lowerCAmelCase				      =					Features({"""text""": Value("""string"""				)}				)
  __lowerCAmelCase				      =					Features({"""summary""": Value("""string"""				)}				)
  __lowerCAmelCase				      =					"text"
  __lowerCAmelCase				      =					"summary"







  @property
  def    lowercase_  (							self					):

    '''simple docstring'''







    return {self.text_column: "text", self.summary_column: "summary"}
'''simple docstring'''






import unittest

import numpy as np

from transformers import AlbertConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
    import jax.numpy as jnp

    from transformers.models.albert.modeling_flax_albert import (
        FlaxAlbertForMaskedLM,
        FlaxAlbertForMultipleChoice,
        FlaxAlbertForPreTraining,
        FlaxAlbertForQuestionAnswering,
        FlaxAlbertForSequenceClassification,
        FlaxAlbertForTokenClassification,
        FlaxAlbertModel,
    )




class    a (       unittest.TestCase				):



  """simple docstring"""







  def __init__(							self   ,    snake_case_   ,    snake_case_=13   ,    snake_case_=7   ,    snake_case_=True   ,    snake_case_=True   ,    snake_case_=True   ,    snake_case_=True   ,    snake_case_=99   ,    snake_case_=32   ,    snake_case_=5   ,    snake_case_=4   ,    snake_case_=37   ,    snake_case_="gelu"   ,    snake_case_=0.1   ,    snake_case_=0.1   ,    snake_case_=512   ,    snake_case_=16   ,    snake_case_=2   ,    snake_case_=0.0_2   ,    snake_case_=4   ,    ):

    '''simple docstring'''







    __UpperCAmelCase:					Optional[Any]		= parent
    __UpperCAmelCase:					List[str]		= batch_size
    __UpperCAmelCase:					Optional[int]		= seq_length
    __UpperCAmelCase:					Optional[Any]		= is_training
    __UpperCAmelCase:					Any		= use_attention_mask
    __UpperCAmelCase:					List[str]		= use_token_type_ids
    __UpperCAmelCase:					List[str]		= use_labels
    __UpperCAmelCase:					List[str]		= vocab_size
    __UpperCAmelCase:					Optional[Any]		= hidden_size
    __UpperCAmelCase:					List[Any]		= num_hidden_layers
    __UpperCAmelCase:					List[Any]		= num_attention_heads
    __UpperCAmelCase:					Tuple		= intermediate_size
    __UpperCAmelCase:					Dict		= hidden_act
    __UpperCAmelCase:					Dict		= hidden_dropout_prob
    __UpperCAmelCase:					Tuple		= attention_probs_dropout_prob
    __UpperCAmelCase:					List[str]		= max_position_embeddings
    __UpperCAmelCase:					List[Any]		= type_vocab_size
    __UpperCAmelCase:					List[Any]		= type_sequence_label_size
    __UpperCAmelCase:					List[str]		= initializer_range
    __UpperCAmelCase:					List[Any]		= num_choices







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					int		= ids_tensor([self.batch_size, self.seq_length]   ,    self.vocab_size					)

    __UpperCAmelCase:					str		= None
    if self.use_attention_mask:
      __UpperCAmelCase:					Any		= random_attention_mask([self.batch_size, self.seq_length]					)

    __UpperCAmelCase:					List[Any]		= None
    if self.use_token_type_ids:
      __UpperCAmelCase:					Optional[int]		= ids_tensor([self.batch_size, self.seq_length]   ,    self.type_vocab_size					)

    __UpperCAmelCase:					List[Any]		= AlbertConfig(
        vocab_size=self.vocab_size   ,    hidden_size=self.hidden_size   ,    num_hidden_layers=self.num_hidden_layers   ,    num_attention_heads=self.num_attention_heads   ,    intermediate_size=self.intermediate_size   ,    hidden_act=self.hidden_act   ,    hidden_dropout_prob=self.hidden_dropout_prob   ,    attention_probs_dropout_prob=self.attention_probs_dropout_prob   ,    max_position_embeddings=self.max_position_embeddings   ,    type_vocab_size=self.type_vocab_size   ,    is_decoder=snake_case_   ,    initializer_range=self.initializer_range   ,    )

    return config, input_ids, token_type_ids, attention_mask







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Tuple		= self.prepare_config_and_inputs()
    __UpperCAmelCase, __UpperCAmelCase, __UpperCAmelCase, __UpperCAmelCase:					List[str]		= config_and_inputs
    __UpperCAmelCase:					List[Any]		= {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": attention_mask}
    return config, inputs_dict




@require_flax
class    a (       __lowerCAmelCase						,  unittest.TestCase				):



  """simple docstring"""
  __lowerCAmelCase				      =					(
      (
          FlaxAlbertModel,
          FlaxAlbertForPreTraining,
          FlaxAlbertForMaskedLM,
          FlaxAlbertForMultipleChoice,
          FlaxAlbertForQuestionAnswering,
          FlaxAlbertForSequenceClassification,
          FlaxAlbertForTokenClassification,
          FlaxAlbertForQuestionAnswering,
      )
      if is_flax_available()
      else ()
  )







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Union[str, Any]		= FlaxAlbertModelTester(self					)







  @slow
  def    lowercase_  (							self					):

    '''simple docstring'''







    for model_class_name in self.all_model_classes:
      __UpperCAmelCase:					str		= model_class_name.from_pretrained("""albert-base-v2"""					)
      __UpperCAmelCase:					int		= model(np.ones((1, 1)					)					)
      self.assertIsNotNone(snake_case_					)




@require_flax
class    a (       unittest.TestCase				):



  """simple docstring"""







  @slow
  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					str		= FlaxAlbertModel.from_pretrained("""albert-base-v2"""					)
    __UpperCAmelCase:					Dict		= np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]					)
    __UpperCAmelCase:					int		= np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]					)
    __UpperCAmelCase:					Optional[int]		= model(snake_case_   ,    attention_mask=snake_case_					)[0]
    __UpperCAmelCase:					Optional[int]		= (1, 11, 768)
    self.assertEqual(output.shape   ,    snake_case_					)
    __UpperCAmelCase:					str		= np.array(
        [[[-0.6_5_1_3, 1.5_0_3_5, -0.2_7_6_6], [-0.6_5_1_5, 1.5_0_4_6, -0.2_7_8_0], [-0.6_5_1_2, 1.5_0_4_9, -0.2_7_8_4]]]					)

    self.assertTrue(jnp.allclose(output[:, 1:4, 1:4]   ,    snake_case_   ,    atol=1e-4					)					)