






'''simple docstring'''


from manim import *
class    _SCREAMING_SNAKE_CASE							(		__snake_case	):






			def 				A      (   self							:						Any			)							->    str:

									'''simple docstring'''







									UpperCamelCase__         = Rectangle(height=0.5 ,      width=0.5			)
									UpperCamelCase__         = Rectangle(height=0.2_5 ,      width=0.2_5			)
									UpperCamelCase__         = Rectangle(height=0.4_6 ,      width=0.4_6			).set_stroke(width=0			)

									UpperCamelCase__         = [mem.copy() for i in range(6			)]
									UpperCamelCase__         = [mem.copy() for i in range(6			)]
									UpperCamelCase__         = VGroup(*A_			).arrange(A_ ,      buff=0			)
									UpperCamelCase__         = VGroup(*A_			).arrange(A_ ,      buff=0			)
									UpperCamelCase__         = VGroup(A_ ,      A_			).arrange(A_ ,      buff=0			)
									UpperCamelCase__         = Text("""CPU""" ,      font_size=2_4			)
									UpperCamelCase__         = Group(A_ ,      A_			).arrange(A_ ,      buff=0.5 ,      aligned_edge=A_			)
									cpu.move_to([-2.5, -0.5, 0]			)
									self.add(A_			)

									UpperCamelCase__         = [mem.copy() for i in range(4			)]
									UpperCamelCase__         = VGroup(*A_			).arrange(A_ ,      buff=0			)
									UpperCamelCase__         = Text("""GPU""" ,      font_size=2_4			)
									UpperCamelCase__         = Group(A_ ,      A_			).arrange(A_ ,      buff=0.5 ,      aligned_edge=A_			)
									gpu.move_to([-1, -1, 0]			)
									self.add(A_			)

									UpperCamelCase__         = [mem.copy() for i in range(6			)]
									UpperCamelCase__         = VGroup(*A_			).arrange(A_ ,      buff=0			)

									UpperCamelCase__         = Text("""Model""" ,      font_size=2_4			)
									UpperCamelCase__         = Group(A_ ,      A_			).arrange(A_ ,      buff=0.5 ,      aligned_edge=A_			)
									model.move_to([3, -1.0, 0]			)
									self.add(A_			)

									UpperCamelCase__         = []
									UpperCamelCase__         = []
									UpperCamelCase__         = []

									for i, rect in enumerate(A_			):
															rect.set_stroke(A_			)

															UpperCamelCase__         = Rectangle(height=0.4_6 / 4 ,      width=0.4_6 / 3			).set_stroke(width=0.0			).set_fill(A_ ,      opacity=0.7			)

															if i == 0:
																					cpu_target.next_to(cpu_left_col_base[0].get_corner(DOWN + LEFT			) ,      buff=0.0_2 ,      direction=A_			)
																					cpu_target.set_x(cpu_target.get_x() + 0.1			)
															elif i == 3:
																					cpu_target.next_to(model_cpu_arr[0] ,      direction=A_ ,      buff=0.0			)
															else:
																					cpu_target.next_to(model_cpu_arr[i - 1] ,      direction=A_ ,      buff=0.0			)
															self.add(A_			)
															model_cpu_arr.append(A_			)

									self.add(*A_ ,      *A_ ,      *A_			)

									UpperCamelCase__         = [mem.copy() for i in range(6			)]
									UpperCamelCase__         = VGroup(*A_			).arrange(A_ ,      buff=0			)

									UpperCamelCase__         = Text("""Loaded Checkpoint""" ,      font_size=2_4			)
									UpperCamelCase__         = Group(A_ ,      A_			).arrange(A_ ,      buff=0.5 ,      aligned_edge=A_			)
									checkpoint.move_to([3, 0.5, 0]			)

									self.add(A_			)

									UpperCamelCase__         = []
									UpperCamelCase__         = []

									for i, rect in enumerate(A_			):
															UpperCamelCase__         = fill.copy().set_fill(A_ ,      opacity=0.7			)
															target.move_to(A_			)
															ckpt_arr.append(A_			)

															UpperCamelCase__         = target.copy()
															if i < 5:
																					cpu_target.move_to(cpu_left_col_base[i + 1]			)
															else:
																					cpu_target.move_to(cpu_right_col_base[i - 5]			)
															ckpt_cpu_arr.append(A_			)
									self.add(*A_ ,      *A_			)

									UpperCamelCase__         = Square(side_length=2.2			)
									key.move_to([-5, 2, 0]			)

									UpperCamelCase__         = MarkupText(
									    f"<b>Key:</b>\n\n<span fgcolor='{YELLOW}'>●</span> Empty Model" ,      font_size=1_8 ,      )

									key_text.move_to([-5, 2.4, 0]			)

									self.add(A_ ,      A_			)

									UpperCamelCase__         = MarkupText(
									    f"<span fgcolor='{BLUE}'>●</span> Checkpoint" ,      font_size=1_8 ,      )

									blue_text.next_to(A_ ,      DOWN * 2.4 ,      aligned_edge=key_text.get_left()			)
									self.add(A_			)

									UpperCamelCase__         = MarkupText(
									    f"Based on the passed in configuration, weights are stored in\na variety of np.memmaps on disk or to a particular device." ,      font_size=2_4 ,      )
									step_a.move_to([2, 2, 0]			)

									UpperCamelCase__         = [meta_mem.copy() for i in range(6			)]
									UpperCamelCase__         = [meta_mem.copy() for i in range(6			)]
									UpperCamelCase__         = VGroup(*A_			).arrange(A_ ,      buff=0			)
									UpperCamelCase__         = VGroup(*A_			).arrange(A_ ,      buff=0			)
									UpperCamelCase__         = VGroup(A_ ,      A_			).arrange(A_ ,      buff=0			)
									UpperCamelCase__         = Text("""Disk""" ,      font_size=2_4			)
									UpperCamelCase__         = Group(A_ ,      A_			).arrange(A_ ,      buff=0.5 ,      aligned_edge=A_			)
									disk.move_to([-4.0, -1.2_5, 0]			)
									self.play(Write(A_ ,      run_time=3			) ,      Write(A_ ,      run_time=1			) ,      Create(A_ ,      run_time=1			)			)

									UpperCamelCase__         = []
									for i, rect in enumerate(A_			):
															UpperCamelCase__         = rect.copy()
															target.generate_target()
															target.target.move_to(disk_left_col_base[i]			).scale(0.5			)
															animations.append(MoveToTarget(A_ ,      run_time=1.5			)			)
									self.play(*A_			)

									self.play(FadeOut(A_			)			)

									UpperCamelCase__         = MarkupText(f"Then, the checkpoint is removed from memory\nthrough garbage collection." ,      font_size=2_4			)
									step_a.move_to([2, 2, 0]			)

									self.play(Write(A_ ,      run_time=3			)			)

									self.play(
									    FadeOut(A_ ,      A_ ,      *A_ ,      *A_			) ,      )

									self.wait()








'''simple docstring'''


import numpy as np

from transformers import Pipeline







def 	__magic_name__( _A					):
						'''simple docstring'''





						UpperCamelCase__         = np.max(_A						,      axis=-1						,      keepdims=_A					)
						UpperCamelCase__         = np.exp(outputs - maxes					)
						return shifted_exp / shifted_exp.sum(axis=-1						,      keepdims=_A					)







class    _SCREAMING_SNAKE_CASE							(		SCREAMING_SNAKE_CASE	):


			'''simple docstring'''





			def 				A      (   self							:						int ,      **lowercase							:						List[Any]			)							->    List[str]:

									'''simple docstring'''







									UpperCamelCase__         = {}
									if "second_text" in kwargs:
															UpperCamelCase__         = kwargs["""second_text"""]
									return preprocess_kwargs, {}, {}






			def 				A      (   self							:						Optional[int] ,      lowercase							:						Union[str, Any] ,      lowercase							:						Any=None			)							->    Optional[int]:

									'''simple docstring'''







									return self.tokenizer(lowercase ,      text_pair=lowercase ,      return_tensors=self.framework			)






			def 				A      (   self							:						Union[str, Any] ,      lowercase							:						Optional[int]			)							->    Any:

									'''simple docstring'''







									return self.model(**lowercase			)







			def 				A      (   self							:						List[str] ,      lowercase							:						Any			)							->    Optional[int]:

									'''simple docstring'''







									UpperCamelCase__         = model_outputs.logits[0].numpy()
									UpperCamelCase__         = softmax(lowercase			)

									UpperCamelCase__         = np.argmax(lowercase			)
									UpperCamelCase__         = self.model.config.idalabel[best_class]
									UpperCamelCase__         = probabilities[best_class].item()
									UpperCamelCase__         = logits.tolist()
									return {"label": label, "score": score, "logits": logits}
