





# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from ..models.whisper import WhisperForConditionalGeneration, WhisperProcessor
from .base import PipelineTool







class 				__lowerCAmelCase       (    UpperCamelCase__):
      _lowercase				:					Any						=			"""openai/whisper-base"""
      _lowercase				:					List[str]						=			(
          """This is a tool that transcribes an audio into text. It takes an input named `audio` and returns the """
          """transcribed text."""
      )
      _lowercase				:					Dict						=			"""transcriber"""
      _lowercase				:					Tuple						=			WhisperProcessor
      _lowercase				:					Optional[int]						=			WhisperForConditionalGeneration

      _lowercase				:					Optional[int]						=			["""audio"""]
      _lowercase				:					List[str]						=			["""text"""]







      def    _lowercase  (    self		,      lowerCAmelCase__							)   ->						Any:



        '''simple docstring'''




        return self.pre_processor(lowerCAmelCase__		,      return_tensors="pt"							).input_features







      def    _lowercase  (    self		,      lowerCAmelCase__							)   ->						List[Any]:



        '''simple docstring'''




        return self.model.generate(inputs=lowerCAmelCase__							)







      def    _lowercase  (    self		,      lowerCAmelCase__							)   ->						List[Any]:



        '''simple docstring'''




        return self.pre_processor.batch_decode(lowerCAmelCase__		,      skip_special_tokens=lowerCAmelCase__							)[0]













import numpy

# List of input, output pairs
UpperCAmelCase	:	str		     =       (
    ((5, 2, 3), 15),
    ((6, 5, 9), 25),
    ((11, 12, 13), 41),
    ((1, 1, 1), 8),
    ((11, 12, 13), 41),
)
UpperCAmelCase	:	Optional[int]		     =       (((515, 22, 13), 555), ((61, 35, 49), 150))
UpperCAmelCase	:	str		     =       [2, 4, 1, 5]
UpperCAmelCase	:	List[str]		     =       len(train_data)
UpperCAmelCase	:	Dict		     =       0.0_0_9
def      _A       (		SCREAMING_SNAKE_CASE     :   Tuple       ,       SCREAMING_SNAKE_CASE     :   Tuple="train"						):





  """simple docstring"""



  return calculate_hypothesis_value(SCREAMING_SNAKE_CASE       ,       SCREAMING_SNAKE_CASE						) - output(
      SCREAMING_SNAKE_CASE       ,       SCREAMING_SNAKE_CASE						)
def      _A       (		SCREAMING_SNAKE_CASE     :   Tuple						):





  """simple docstring"""



  a__	:					Tuple										=0
  for i in range(len(SCREAMING_SNAKE_CASE						) - 1						):
    hyp_val += data_input_tuple[i] * parameter_vector[i + 1]
  hyp_val += parameter_vector[0]
  return hyp_val
def      _A       (		SCREAMING_SNAKE_CASE     :   Dict       ,       SCREAMING_SNAKE_CASE     :   Dict						):





  """simple docstring"""



  if data_set == "train":
    return train_data[example_no][1]
  elif data_set == "test":
    return test_data[example_no][1]
  return None
def      _A       (		SCREAMING_SNAKE_CASE     :   Optional[Any]       ,       SCREAMING_SNAKE_CASE     :   Tuple						):





  """simple docstring"""



  if data_set == "train":
    return _hypothesis_value(train_data[example_no][0]						)
  elif data_set == "test":
    return _hypothesis_value(test_data[example_no][0]						)
  return None
def      _A       (		SCREAMING_SNAKE_CASE     :   Union[str, Any]       ,       SCREAMING_SNAKE_CASE     :   int=m						):





  """simple docstring"""



  a__	:					Any										=0
  for i in range(SCREAMING_SNAKE_CASE						):
    if index == -1:
      summation_value += _error(SCREAMING_SNAKE_CASE						)
    else:
      summation_value += _error(SCREAMING_SNAKE_CASE						) * train_data[i][0][index]
  return summation_value
def      _A       (		SCREAMING_SNAKE_CASE     :   int						):





  """simple docstring"""



  a__	:					Any										=summation_of_cost_derivative(SCREAMING_SNAKE_CASE       ,       SCREAMING_SNAKE_CASE						) / m
  return cost_derivative_value
def      _A       (		):





  """simple docstring"""



  global parameter_vector
  # Tune these values to set a tolerance value for predicted output
  a__	:					Dict										=0.0_0_0_0_0_2
  a__	:					Union[str, Any]										=0
  a__	:					Any										=0
  while True:
    j += 1
    a__	:					Any										=[0, 0, 0, 0]
    for i in range(0       ,       len(SCREAMING_SNAKE_CASE						)						):
      a__	:					Tuple										=get_cost_derivative(i - 1						)
      a__	:					List[Any]										=(
          parameter_vector[i] - LEARNING_RATE * cost_derivative
      )
    if numpy.allclose(
        SCREAMING_SNAKE_CASE       ,       SCREAMING_SNAKE_CASE       ,       atol=SCREAMING_SNAKE_CASE       ,       rtol=SCREAMING_SNAKE_CASE       ,       ):
      break
    a__	:					Optional[Any]										=temp_parameter_vector
  print(("Number of iterations:", j)						)
def      _A       (		):





  """simple docstring"""



  for i in range(len(SCREAMING_SNAKE_CASE						)						):
    print(("Actual output value:", output(SCREAMING_SNAKE_CASE       ,       "test"						))						)
    print(("Hypothesis output:", calculate_hypothesis_value(SCREAMING_SNAKE_CASE       ,       "test"						))						)


if __name__ == "__main__":
     run_gradient_descent()
     print("""\nTesting gradient descent for a linear hypothesis function.\n""")
     test_gradient_descent()






