


# 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.
import torch

from ..models.auto import AutoModelForSequenceClassification, AutoTokenizer
from .base import PipelineTool





class   SCREAMING_SNAKE_CASE_			(a__						):




       '''simple docstring'''



       _a   							=							"facebook/bart-large-mnli"
       _a   							=							(
           "This is a tool that classifies an English text using provided labels. It takes two inputs: `text`, which "
           "should be the text to classify, and `labels`, which should be the list of labels to use for classification. "
           "It returns the most likely label in the list of provided `labels` for the input text."
       )
       _a   							=							"text_classifier"
       _a   							=							AutoTokenizer
       _a   							=							AutoModelForSequenceClassification

       _a   							=							["text", ["text"]]
       _a   							=							["text"]



       def 				_lowerCAmelCase							(						self				:				List[Any]							)					->int:
          super().setup()
          lowerCamelCase_						:   Union[str, Any]		= self.model.config
          lowerCamelCase_						:   int		= -1
          for idx, label in config.idalabel.items():
             if label.lower().startswith("""entail"""							):
                lowerCamelCase_						:   Union[str, Any]		= int(__a							)
          if self.entailment_id == -1:
             raise ValueError("""Could not determine the entailment ID from the model config, please pass it at init."""							)



       def 				_lowerCAmelCase							(						self				:				Optional[Any]		,				__a				:				Union[str, Any]		,				__a				:				str							)					->List[str]:
          lowerCamelCase_						:   List[str]		= labels
          return self.pre_processor(
              [text] * len(__a							)		,				[F'''This example is {label}''' for label in labels]		,				return_tensors="""pt"""		,				padding="""max_length"""		,				)




       def 				_lowerCAmelCase							(						self				:				str		,				__a				:				Union[str, Any]							)					->List[str]:
          lowerCamelCase_						:   Optional[Any]		= outputs.logits
          lowerCamelCase_						:   Optional[int]		= torch.argmax(logits[:, 2]							).item()
          return self._labels[label_id]









from ...configuration_utils import PretrainedConfig
from ...utils import logging


snake_case__				:	List[Any]					       =					logging.get_logger(__name__)

snake_case__				:	str					       =					{
    'facebook/dpr-ctx_encoder-single-nq-base': (
        'https://huggingface.co/facebook/dpr-ctx_encoder-single-nq-base/resolve/main/config.json'
    ),
    'facebook/dpr-question_encoder-single-nq-base': (
        'https://huggingface.co/facebook/dpr-question_encoder-single-nq-base/resolve/main/config.json'
    ),
    'facebook/dpr-reader-single-nq-base': (
        'https://huggingface.co/facebook/dpr-reader-single-nq-base/resolve/main/config.json'
    ),
    'facebook/dpr-ctx_encoder-multiset-base': (
        'https://huggingface.co/facebook/dpr-ctx_encoder-multiset-base/resolve/main/config.json'
    ),
    'facebook/dpr-question_encoder-multiset-base': (
        'https://huggingface.co/facebook/dpr-question_encoder-multiset-base/resolve/main/config.json'
    ),
    'facebook/dpr-reader-multiset-base': (
        'https://huggingface.co/facebook/dpr-reader-multiset-base/resolve/main/config.json'
    ),
}





class   SCREAMING_SNAKE_CASE_			(a__						):




       '''simple docstring'''



       _a   							=							"dpr"



       def __init__(						self				:				Union[str, Any]		,				__a				:				Optional[Any]=30_522		,				__a				:				List[Any]=768		,				__a				:				List[Any]=12		,				__a				:				Dict=12		,				__a				:				Union[str, Any]=3_072		,				__a				:				Any="gelu"		,				__a				:				Any=0.1		,				__a				:				Any=0.1		,				__a				:				Tuple=512		,				__a				:				int=2		,				__a				:				Optional[Any]=0.02		,				__a				:				List[Any]=1e-12		,				__a				:				int=0		,				__a				:				int="absolute"		,				__a				:				int = 0		,				**__a				:				Optional[int]		,				)					->Tuple:
          super().__init__(pad_token_id=__a		,				**__a							)

          lowerCamelCase_						:   str		= vocab_size
          lowerCamelCase_						:   List[Any]		= hidden_size
          lowerCamelCase_						:   Optional[int]		= num_hidden_layers
          lowerCamelCase_						:   Optional[Any]		= num_attention_heads
          lowerCamelCase_						:   List[Any]		= hidden_act
          lowerCamelCase_						:   Optional[Any]		= intermediate_size
          lowerCamelCase_						:   List[Any]		= hidden_dropout_prob
          lowerCamelCase_						:   Any		= attention_probs_dropout_prob
          lowerCamelCase_						:   Any		= max_position_embeddings
          lowerCamelCase_						:   Tuple		= type_vocab_size
          lowerCamelCase_						:   Dict		= initializer_range
          lowerCamelCase_						:   List[Any]		= layer_norm_eps
          lowerCamelCase_						:   List[str]		= projection_dim
          lowerCamelCase_						:   Optional[int]		= position_embedding_type





