code: 
  
  
  import os
  from typing import Optional, Union
  
  import numpy as np
  from huggingface_hub import hf_hub_download
  
  from ... import AutoTokenizer
  from ...utils import logging
  
  
  __lowerCamelCase       :       List[str]				   =			"block_records.npy"
  
  
  __lowerCamelCase       :       List[str]				   =			logging.get_logger(__name__)
  
  
  
  def   SCREAMING_SNAKE_CASE__						(							snake_case_,	snake_case_	)			->							np.ndarray:
  				import tensorflow.compat.va as tf
  
  				A__     :							Union[str, Any]   				=tf.data.TFRecordDataset(snake_case_,	buffer_size=5_1_2 * 1_0_2_4 * 1_0_2_4	)
  				A__     :							int   				=blocks_dataset.batch(snake_case_,	drop_remainder=snake_case_	)
  				A__     :							Any   				=next(blocks_dataset.take(1	).as_numpy_iterator()	)
  
  				return np_record
  
  
  
  class 			a      :
  
  
  
  
  
  
  		def __init__(  self	,     __UpperCamelCase	,     __UpperCamelCase	,     __UpperCamelCase=2	,     __UpperCamelCase=10_00	,     __UpperCamelCase=1_00	,     __UpperCamelCase=10_00_00	,     )->			Dict:
  						'''simple docstring'''
  
  
  						from scann.scann_ops.py.scann_ops_pybind import builder as Builder
  
  						A__     :							List[Any]   				=Builder(db=__UpperCamelCase	,     num_neighbors=__UpperCamelCase	,     distance_measure='''dot_product'''							)
  						A__     :							Tuple   				=builder.tree(
  						    num_leaves=__UpperCamelCase	,     num_leaves_to_search=__UpperCamelCase	,     training_sample_size=__UpperCamelCase							)
  						A__     :							Optional[int]   				=builder.score_ah(dimensions_per_block=__UpperCamelCase							)
  
  						A__     :							Dict   				=builder.build()
  
  
  
  
  
  
  		def       lowerCAmelCase_  (  self	,     __UpperCamelCase							)->			Tuple:
  						'''simple docstring'''
  
  
  						A__				,  A__     :							int   				=self.searcher.search_batched(question_projection.detach().cpu()							)
  						return retrieved_block_ids.astype('''int64'''							)
  
  
  
  
  
  
  
  class 			a      :
  
  
  
  
  
  
  		def __init__(  self	,     __UpperCamelCase	,     __UpperCamelCase							)->			Any:
  						'''simple docstring'''
  
  
  						super().__init__()
  						A__     :							Dict   				=block_records
  						A__     :							Dict   				=tokenizer
  
  
  
  
  
  
  		def __call__(  self	,     __UpperCamelCase	,     __UpperCamelCase	,     __UpperCamelCase	,     __UpperCamelCase=None	,     __UpperCamelCase="pt"							)->			List[str]:
  						'''simple docstring'''
  
  
  						A__     :							Any   				=np.take(self.block_records	,     indices=__UpperCamelCase	,     axis=0							)
  
  						A__     :							List[Any]   				=self.tokenizer.decode(question_input_ids[0]	,     skip_special_tokens=__UpperCamelCase							)
  
  						A__     :							Union[str, Any]   				=[]
  						A__     :							Union[str, Any]   				=[]
  						for retrieved_block in retrieved_blocks:
  										text.append(__UpperCamelCase							)
  										text_pair.append(retrieved_block.decode()							)
  
  						A__     :							Dict   				=self.tokenizer(
  						    __UpperCamelCase	,     __UpperCamelCase	,     padding=__UpperCamelCase	,     truncation=__UpperCamelCase	,     return_special_tokens_mask=__UpperCamelCase	,     max_length=__UpperCamelCase							)
  						A__     :							List[Any]   				=concat_inputs.convert_to_tensors(__UpperCamelCase							)
  
  						if answer_ids is not None:
  										return self.block_has_answer(__UpperCamelCase	,     __UpperCamelCase							) + (concat_inputs_tensors,)
  						else:
  										return (None, None, None, concat_inputs_tensors)
  
  
  
  
  
  
  		@classmethod
  		def       lowerCAmelCase_  (  cls	,     __UpperCamelCase	,     *__UpperCamelCase	,     **__UpperCamelCase							)->			List[str]:
  						'''simple docstring'''
  
  
  						if os.path.isdir(__UpperCamelCase							):
  										A__     :							List[str]   				=os.path.join(__UpperCamelCase	,     _REALM_BLOCK_RECORDS_FILENAME							)
  						else:
  										A__     :							int   				=hf_hub_download(
  										    repo_id=__UpperCamelCase	,     filename=_REALM_BLOCK_RECORDS_FILENAME	,     **__UpperCamelCase							)
  						A__     :							int   				=np.load(__UpperCamelCase	,     allow_pickle=__UpperCamelCase							)
  
  						A__     :							str   				=AutoTokenizer.from_pretrained(__UpperCamelCase	,     *__UpperCamelCase	,     **__UpperCamelCase							)
  
  						return cls(__UpperCamelCase	,     __UpperCamelCase							)
  
  
  
  
  
  
  		def       lowerCAmelCase_  (  self	,     __UpperCamelCase							)->			Optional[Any]:
  						'''simple docstring'''
  
  
  						np.save(os.path.join(__UpperCamelCase	,     _REALM_BLOCK_RECORDS_FILENAME							)	,     self.block_records							)
  						# save tokenizer
  						self.tokenizer.save_pretrained(__UpperCamelCase							)
  
  
  
  
  
  
  		def       lowerCAmelCase_  (  self	,     __UpperCamelCase	,     __UpperCamelCase							)->			Optional[Any]:
  						'''simple docstring'''
  
  
  						A__     :							Tuple   				=[]
  						A__     :							str   				=[]
  						A__     :							Tuple   				=[]
  						A__     :							Any   				=0
  
  						for input_id in concat_inputs.input_ids:
  										A__     :							int   				=input_id.tolist()
  										# Check answers between two [SEP] tokens
  										A__     :							Tuple   				=input_id_list.index(self.tokenizer.sep_token_id							)
  										A__     :							List[Any]   				=first_sep_idx + 1 + input_id_list[first_sep_idx + 1 :].index(self.tokenizer.sep_token_id							)
  
  										start_pos.append([]							)
  										end_pos.append([]							)
  										for answer in answer_ids:
  														for idx in range(first_sep_idx + 1	,     __UpperCamelCase							):
  																		if answer[0] == input_id_list[idx]:
  																						if input_id_list[idx : idx + len(__UpperCamelCase							)] == answer:
  																										start_pos[-1].append(__UpperCamelCase							)
  																										end_pos[-1].append(idx + len(__UpperCamelCase							) - 1							)
  
  										if len(start_pos[-1]							) == 0:
  														has_answers.append(__UpperCamelCase							)
  										else:
  														has_answers.append(__UpperCamelCase							)
  														if len(start_pos[-1]							) > max_answers:
  																		A__     :							Union[str, Any]   				=len(start_pos[-1]							)
  
          # Pad -1 to max_answers
  						for start_pos_, end_pos_ in zip(__UpperCamelCase	,     __UpperCamelCase							):
  										if len(start_pos_							) < max_answers:
  														A__     :							int   				=[-1] * (max_answers - len(start_pos_							))
  														start_pos_ += padded
  														end_pos_ += padded
  						return has_answers, start_pos, end_pos
  
  
  
  
style_context: 
  
  
  def   SCREAMING_SNAKE_CASE__						(							snake_case_	)			->							int:
  				if number != int(snake_case_	):
  								raise ValueError('''factorial() only accepts integral values'''	)
  				if number < 0:
  								raise ValueError('''factorial() not defined for negative values'''	)
  				A__     :							Union[str, Any]   				=1
  				for i in range(1,	number + 1	):
  								value *= i
  				return value
  
  
  
  def   SCREAMING_SNAKE_CASE__						(							snake_case_	)			->							int:
  				if not isinstance(snake_case_,	snake_case_	):
  								raise ValueError('''factorial() only accepts integral values'''	)
  				if n < 0:
  								raise ValueError('''factorial() not defined for negative values'''	)
  				return 1 if n == 0 or n == 1 else n * factorial(n - 1	)
  
  
  if __name__ == "__main__":
  						import doctest
  
  						doctest.testmod()
  
  						__lowerCamelCase       :       Any				   =			int(input("Enter a positive integer: ").strip() or 0)
  						print(F"factorial{n} is {factorial(n)}")
  
  
  
  