





"""simple docstring"""





from __future__ import annotations

import unittest

from transformers import DistilBertConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
       import tensorflow as tf

       from transformers.models.distilbert.modeling_tf_distilbert import (
           TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
           TFDistilBertForMaskedLM,
           TFDistilBertForMultipleChoice,
           TFDistilBertForQuestionAnswering,
           TFDistilBertForSequenceClassification,
           TFDistilBertForTokenClassification,
           TFDistilBertModel,
       )

class 						lowercase   :





      def __init__(			self ,		lowercase ,		)						->	Any:
            lowerCAmelCase    		=			parent
            lowerCAmelCase    		=			13
            lowerCAmelCase    		=			7
            lowerCAmelCase    		=			True
            lowerCAmelCase    		=			True
            lowerCAmelCase    		=			False
            lowerCAmelCase    		=			True
            lowerCAmelCase    		=			99
            lowerCAmelCase    		=			32
            lowerCAmelCase    		=			2
            lowerCAmelCase    		=			4
            lowerCAmelCase    		=			37
            lowerCAmelCase    		=			"""gelu"""
            lowerCAmelCase    		=			0.1
            lowerCAmelCase    		=			0.1
            lowerCAmelCase    		=			512
            lowerCAmelCase    		=			16
            lowerCAmelCase    		=			2
            lowerCAmelCase    		=			0.02
            lowerCAmelCase    		=			3
            lowerCAmelCase    		=			4
            lowerCAmelCase    		=			None





      def        _snake_case     (			self					)						->	List[Any]:
            lowerCAmelCase    		=			ids_tensor([self.batch_size, self.seq_length] ,		self.vocab_size					)

            lowerCAmelCase    		=			None
            if self.use_input_mask:
                  lowerCAmelCase    		=			random_attention_mask([self.batch_size, self.seq_length]					)

            lowerCAmelCase    		=			None
            lowerCAmelCase    		=			None
            lowerCAmelCase    		=			None
            if self.use_labels:
                  lowerCAmelCase    		=			ids_tensor([self.batch_size] ,		self.type_sequence_label_size					)
                  lowerCAmelCase    		=			ids_tensor([self.batch_size, self.seq_length] ,		self.num_labels					)
                  lowerCAmelCase    		=			ids_tensor([self.batch_size] ,		self.num_choices					)

            lowerCAmelCase    		=			DistilBertConfig(
                vocab_size=self.vocab_size ,		dim=self.hidden_size ,		n_layers=self.num_hidden_layers ,		n_heads=self.num_attention_heads ,		hidden_dim=self.intermediate_size ,		hidden_act=self.hidden_act ,		dropout=self.hidden_dropout_prob ,		attention_dropout=self.attention_probs_dropout_prob ,		max_position_embeddings=self.max_position_embeddings ,		initializer_range=self.initializer_range ,		)

            return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels





      def        _snake_case     (			self ,		lowercase ,		lowercase ,		lowercase ,		lowercase ,		lowercase ,		lowercase					)						->	int:
            lowerCAmelCase    		=			TFDistilBertModel(config=lowercase					)
            lowerCAmelCase    		=			{"""input_ids""": input_ids, """attention_mask""": input_mask}

            lowerCAmelCase    		=			model(lowercase					)

            lowerCAmelCase    		=			[input_ids, input_mask]

            lowerCAmelCase    		=			model(lowercase					)

            self.parent.assertEqual(result.last_hidden_state.shape ,		(self.batch_size, self.seq_length, self.hidden_size)					)





      def        _snake_case     (			self ,		lowercase ,		lowercase ,		lowercase ,		lowercase ,		lowercase ,		lowercase					)						->	int:
            lowerCAmelCase    		=			TFDistilBertForMaskedLM(config=lowercase					)
            lowerCAmelCase    		=			{"""input_ids""": input_ids, """attention_mask""": input_mask}
            lowerCAmelCase    		=			model(lowercase					)
            self.parent.assertEqual(result.logits.shape ,		(self.batch_size, self.seq_length, self.vocab_size)					)





      def        _snake_case     (			self ,		lowercase ,		lowercase ,		lowercase ,		lowercase ,		lowercase ,		lowercase					)						->	int:
            lowerCAmelCase    		=			TFDistilBertForQuestionAnswering(config=lowercase					)
            lowerCAmelCase    		=			{
                """input_ids""": input_ids,
                """attention_mask""": input_mask,
            }
            lowerCAmelCase    		=			model(lowercase					)
            self.parent.assertEqual(result.start_logits.shape ,		(self.batch_size, self.seq_length)					)
            self.parent.assertEqual(result.end_logits.shape ,		(self.batch_size, self.seq_length)					)





      def        _snake_case     (			self ,		lowercase ,		lowercase ,		lowercase ,		lowercase ,		lowercase ,		lowercase					)						->	Union[str, Any]:
            lowerCAmelCase    		=			self.num_labels
            lowerCAmelCase    		=			TFDistilBertForSequenceClassification(lowercase					)
            lowerCAmelCase    		=			{"""input_ids""": input_ids, """attention_mask""": input_mask}
            lowerCAmelCase    		=			model(lowercase					)
            self.parent.assertEqual(result.logits.shape ,		(self.batch_size, self.num_labels)					)





      def        _snake_case     (			self ,		lowercase ,		lowercase ,		lowercase ,		lowercase ,		lowercase ,		lowercase					)						->	Tuple:
            lowerCAmelCase    		=			self.num_choices
            lowerCAmelCase    		=			TFDistilBertForMultipleChoice(lowercase					)
            lowerCAmelCase    		=			tf.tile(tf.expand_dims(lowercase ,		1					) ,		(1, self.num_choices, 1)					)
            lowerCAmelCase    		=			tf.tile(tf.expand_dims(lowercase ,		1					) ,		(1, self.num_choices, 1)					)
            lowerCAmelCase    		=			{
                """input_ids""": multiple_choice_inputs_ids,
                """attention_mask""": multiple_choice_input_mask,
            }
            lowerCAmelCase    		=			model(lowercase					)
            self.parent.assertEqual(result.logits.shape ,		(self.batch_size, self.num_choices)					)





      def        _snake_case     (			self ,		lowercase ,		lowercase ,		lowercase ,		lowercase ,		lowercase ,		lowercase					)						->	List[Any]:
            lowerCAmelCase    		=			self.num_labels
            lowerCAmelCase    		=			TFDistilBertForTokenClassification(lowercase					)
            lowerCAmelCase    		=			{"""input_ids""": input_ids, """attention_mask""": input_mask}
            lowerCAmelCase    		=			model(lowercase					)
            self.parent.assertEqual(result.logits.shape ,		(self.batch_size, self.seq_length, self.num_labels)					)





      def        _snake_case     (			self					)						->	Any:
            lowerCAmelCase    		=			self.prepare_config_and_inputs()
            ((lowerCAmelCase)		,						(lowerCAmelCase)		,						(lowerCAmelCase)		,						(lowerCAmelCase)		,						(lowerCAmelCase)		,						(lowerCAmelCase))    		=			config_and_inputs
            lowerCAmelCase    		=			{"""input_ids""": input_ids, """attention_mask""": input_mask}
            return config, inputs_dict







@require_tf
class 						lowercase   (   _UpperCAmelCase	,    _UpperCAmelCase	,    unittest.TestCase   ):
      _SCREAMING_SNAKE_CASE							      = (
          (
              TFDistilBertModel,
              TFDistilBertForMaskedLM,
              TFDistilBertForQuestionAnswering,
              TFDistilBertForSequenceClassification,
              TFDistilBertForTokenClassification,
              TFDistilBertForMultipleChoice,
          )
          if is_tf_available()
          else None
      )
      _SCREAMING_SNAKE_CASE							      = (
          {
              'feature-extraction': TFDistilBertModel,
              'fill-mask': TFDistilBertForMaskedLM,
              'question-answering': TFDistilBertForQuestionAnswering,
              'text-classification': TFDistilBertForSequenceClassification,
              'token-classification': TFDistilBertForTokenClassification,
              'zero-shot': TFDistilBertForSequenceClassification,
          }
          if is_tf_available()
          else {}
      )
      _SCREAMING_SNAKE_CASE							      = False
      _SCREAMING_SNAKE_CASE							      = False





      def        _snake_case     (			self					)						->	int:
            lowerCAmelCase    		=			TFDistilBertModelTester(self					)
            lowerCAmelCase    		=			ConfigTester(self ,		config_class=lowercase ,		dim=37					)





      def        _snake_case     (			self					)						->	Optional[Any]:
            self.config_tester.run_common_tests()





      def        _snake_case     (			self					)						->	Dict:
            lowerCAmelCase    		=			self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_distilbert_model(*lowercase					)





      def        _snake_case     (			self					)						->	str:
            lowerCAmelCase    		=			self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_distilbert_for_masked_lm(*lowercase					)





      def        _snake_case     (			self					)						->	str:
            lowerCAmelCase    		=			self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_distilbert_for_question_answering(*lowercase					)





      def        _snake_case     (			self					)						->	List[Any]:
            lowerCAmelCase    		=			self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_distilbert_for_sequence_classification(*lowercase					)





      def        _snake_case     (			self					)						->	List[str]:
            lowerCAmelCase    		=			self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_distilbert_for_multiple_choice(*lowercase					)





      def        _snake_case     (			self					)						->	Dict:
            lowerCAmelCase    		=			self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_distilbert_for_token_classification(*lowercase					)





      @slow
      def        _snake_case     (			self					)						->	List[str]:
            for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]					):
                  lowerCAmelCase    		=			TFDistilBertModel.from_pretrained(lowercase					)
                  self.assertIsNotNone(lowercase					)







@require_tf
class 						lowercase   (   unittest.TestCase   ):





      @slow
      def        _snake_case     (			self					)						->	List[str]:
            lowerCAmelCase    		=			TFDistilBertModel.from_pretrained("""distilbert-base-uncased"""					)
            lowerCAmelCase    		=			tf.constant([[0, 1, 2, 3, 4, 5]]					)
            lowerCAmelCase    		=			model(lowercase					)[0]

            lowerCAmelCase    		=			[1, 6, 768]
            self.assertEqual(output.shape ,		lowercase					)

            lowerCAmelCase    		=			tf.constant(
                [
                    [
                        [0.19_261_885, -0.13_732_955, 0.4_119_799],
                        [0.22_150_156, -0.07_422_661, 0.39_037_204],
                        [0.22_756_018, -0.0_896_414, 0.3_701_467],
                    ]
                ]					)
            tf.debugging.assert_near(output[:, :3, :3] ,		lowercase ,		atol=1e-4					)













"""simple docstring"""





from math import log

from scipy.constants import Boltzmann, physical_constants

SCREAMING_SNAKE_CASE__   =  300  # TEMPERATURE (unit = K)


def      UpperCAmelCase__				(    SCREAMING_SNAKE_CASE	:		float				,		SCREAMING_SNAKE_CASE	:		float				,		SCREAMING_SNAKE_CASE	:		float				,		):







      '''simple docstring'''




      if donor_conc <= 0:
            raise ValueError("""Donor concentration should be positive"""     )
      elif acceptor_conc <= 0:
            raise ValueError("""Acceptor concentration should be positive"""     )
      elif intrinsic_conc <= 0:
            raise ValueError("""Intrinsic concentration should be positive"""     )
      elif donor_conc <= intrinsic_conc:
            raise ValueError(
                """Donor concentration should be greater than intrinsic concentration"""     )
      elif acceptor_conc <= intrinsic_conc:
            raise ValueError(
                """Acceptor concentration should be greater than intrinsic concentration"""     )
      else:
            return (
                Boltzmann
                * T
                * log((donor_conc * acceptor_conc) / intrinsic_conc**2     )
                / physical_constants["electron volt"][0]
            )


if __name__ == "__main__":
       import doctest

       doctest.testmod()






