




'''simple docstring'''




# 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      UpperCAmelCase_     (  __a     ):


	"""simple docstring"""


	snake_case									=		'''facebook/bart-large-mnli'''
	snake_case									=		(
	    '''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.'''
	)
	snake_case									=		'''text_classifier'''
	snake_case									=		AutoTokenizer
	snake_case									=		AutoModelForSequenceClassification

	snake_case									=		['''text''', ['''text''']]
	snake_case									=		['''text''']







	def  _lowercase    (						self				):
						super().setup()
						snake_case_	=      self.model.config
						snake_case_	=      -1
						for idx, label in config.idalabel.items():
											if label.lower().startswith("entail"				):
																snake_case_	=      int(__UpperCamelCase				)
						if self.entailment_id == -1:
											raise ValueError("Could not determine the entailment ID from the model config, please pass it at init."				)







	def  _lowercase    (						self						, UpperCAmelCase_						, UpperCAmelCase_				):
						snake_case_	=      labels
						return self.pre_processor(
						    [text] * len(__UpperCamelCase				)						, [f'''This example is {label}''' for label in labels]						, return_tensors="pt"						, padding="max_length"						, )







	def  _lowercase    (						self						, UpperCAmelCase_				):
						snake_case_	=      outputs.logits
						snake_case_	=      torch.argmax(logits[:, 2]				).item()
						return self._labels[label_id]






from heapq import heappop, heappush

import numpy as np






def     lowerCAmelCase_			(   _SCREAMING_SNAKE_CASE     :				np.ndarray		, _SCREAMING_SNAKE_CASE     :				tuple[int, int]		, _SCREAMING_SNAKE_CASE     :				tuple[int, int]		, _SCREAMING_SNAKE_CASE     :				bool		, ):
						UpperCamelCase_,UpperCamelCase_		:							Union[str, Any]  =		grid.shape
						UpperCamelCase_		:							List[str]  =		[-1, 1, 0, 0]
						UpperCamelCase_		:							Dict  =		[0, 0, -1, 1]
						if allow_diagonal:
												dx += [-1, -1, 1, 1]
												dy += [-1, 1, -1, 1]

						UpperCamelCase_,UpperCamelCase_		:							List[Any]  =		[(0, source)], set()
						UpperCamelCase_		:							Any  =		np.full((rows, cols)		, np.inf			)
						UpperCamelCase_		:							List[str]  =		0
						UpperCamelCase_		:							Union[str, Any]  =		np.empty((rows, cols)		, dtype=_SCREAMING_SNAKE_CASE			)
						UpperCamelCase_		:							Optional[int]  =		None

						while queue:
												((UpperCamelCase_),(UpperCamelCase_))		:							Any  =		heappop(_SCREAMING_SNAKE_CASE			)
												if (x, y) in visited:
																		continue
												visited.add((x, y)			)

												if (x, y) == destination:
																		UpperCamelCase_		:							Tuple  =		[]
																		while (x, y) != source:
																								path.append((x, y)			)
																								UpperCamelCase_,UpperCamelCase_		:							Union[str, Any]  =		predecessors[x, y]
																		path.append(_SCREAMING_SNAKE_CASE			)  # add the source manually
																		path.reverse()
																		return matrix[destination], path

												for i in range(len(_SCREAMING_SNAKE_CASE			)			):
																		UpperCamelCase_,UpperCamelCase_		:							Optional[Any]  =		x + dx[i], y + dy[i]
																		if 0 <= nx < rows and 0 <= ny < cols:
																								UpperCamelCase_		:							Union[str, Any]  =		grid[nx][ny]
																								if next_node == 1 and matrix[nx, ny] > dist + 1:
																														heappush(_SCREAMING_SNAKE_CASE		, (dist + 1, (nx, ny))			)
																														UpperCamelCase_		:							Optional[Any]  =		dist + 1
																														UpperCamelCase_		:							List[Any]  =		(x, y)

						return np.inf, []


if __name__ == "__main__":
	import doctest

	doctest.testmod()






