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     =			"block_records.npy"
  
  
  __lowerCAmelCase     =			logging.get_logger(__name__)
  
  def     a						(      _lowercase   :     str ,						_lowercase   :     int       )     ->np.ndarray:
  		import tensorflow.compat.va as tf
  
  		UpperCamelCase__         =	tf.data.TFRecordDataset(_lowercase ,						buffer_size=5_1_2 * 1_0_2_4 * 1_0_2_4       )
  		UpperCamelCase__         =	blocks_dataset.batch(_lowercase ,						drop_remainder=_lowercase       )
  		UpperCamelCase__         =	next(blocks_dataset.take(1       ).as_numpy_iterator()       )
  
  		return np_record
  
  
  
  
  class   _UpperCAmelCase	:
  
  
  
  
  					def __init__(						self    ,      __lowerCAmelCase    ,      __lowerCAmelCase    ,      __lowerCAmelCase=2    ,      __lowerCAmelCase=1_000    ,      __lowerCAmelCase=100    ,      __lowerCAmelCase=100_000    ,      )						->  Dict:
  							from scann.scann_ops.py.scann_ops_pybind import builder as Builder
  
  							UpperCamelCase__         =	Builder(db=__lowerCAmelCase    ,      num_neighbors=__lowerCAmelCase    ,      distance_measure="""dot_product"""       )
  							UpperCamelCase__         =	builder.tree(
  							    num_leaves=__lowerCAmelCase    ,      num_leaves_to_search=__lowerCAmelCase    ,      training_sample_size=__lowerCAmelCase       )
  							UpperCamelCase__         =	builder.score_ah(dimensions_per_block=__lowerCAmelCase       )
  
  							UpperCamelCase__         =	builder.build()
  
  
  
  
  					def 	snake_case_		(						self    ,      __lowerCAmelCase       )						->  Dict:
  							UpperCamelCase__  ,			UpperCamelCase__         =	self.searcher.search_batched(question_projection.detach().cpu()       )
  							return retrieved_block_ids.astype("""int64"""       )
  
  
  
  
  class   _UpperCAmelCase	:
  
  
  
  
  					def __init__(						self    ,      __lowerCAmelCase    ,      __lowerCAmelCase       )						->  Any:
  							super().__init__()
  							UpperCamelCase__         =	block_records
  							UpperCamelCase__         =	tokenizer
  
  
  
  
  					def __call__(						self    ,      __lowerCAmelCase    ,      __lowerCAmelCase    ,      __lowerCAmelCase    ,      __lowerCAmelCase=None    ,      __lowerCAmelCase="pt"       )						->  List[str]:
  							UpperCamelCase__         =	np.take(self.block_records    ,      indices=__lowerCAmelCase    ,      axis=0       )
  
  							UpperCamelCase__         =	self.tokenizer.decode(question_input_ids[0]    ,      skip_special_tokens=__lowerCAmelCase       )
  
  							UpperCamelCase__         =	[]
  							UpperCamelCase__         =	[]
  							for retrieved_block in retrieved_blocks:
  									text.append(__lowerCAmelCase       )
  									text_pair.append(retrieved_block.decode()       )
  
  							UpperCamelCase__         =	self.tokenizer(
  							    __lowerCAmelCase    ,      __lowerCAmelCase    ,      padding=__lowerCAmelCase    ,      truncation=__lowerCAmelCase    ,      return_special_tokens_mask=__lowerCAmelCase    ,      max_length=__lowerCAmelCase       )
  							UpperCamelCase__         =	concat_inputs.convert_to_tensors(__lowerCAmelCase       )
  
  							if answer_ids is not None:
  									return self.block_has_answer(__lowerCAmelCase    ,      __lowerCAmelCase       ) + (concat_inputs_tensors,)
  							else:
  									return (None, None, None, concat_inputs_tensors)
  
  
  
  
  					@classmethod
  					def 	snake_case_		(						cls    ,      __lowerCAmelCase    ,      *__lowerCAmelCase    ,      **__lowerCAmelCase       )						->  Optional[Any]:
  							if os.path.isdir(__lowerCAmelCase       ):
  									UpperCamelCase__         =	os.path.join(__lowerCAmelCase    ,      _REALM_BLOCK_RECORDS_FILENAME       )
  							else:
  									UpperCamelCase__         =	hf_hub_download(
  									    repo_id=__lowerCAmelCase    ,      filename=_REALM_BLOCK_RECORDS_FILENAME    ,      **__lowerCAmelCase       )
  							UpperCamelCase__         =	np.load(__lowerCAmelCase    ,      allow_pickle=__lowerCAmelCase       )
  
  							UpperCamelCase__         =	AutoTokenizer.from_pretrained(__lowerCAmelCase    ,      *__lowerCAmelCase    ,      **__lowerCAmelCase       )
  
  							return cls(__lowerCAmelCase    ,      __lowerCAmelCase       )
  
  
  
  
  					def 	snake_case_		(						self    ,      __lowerCAmelCase       )						->  str:
  							# save block records
  							np.save(os.path.join(__lowerCAmelCase    ,      _REALM_BLOCK_RECORDS_FILENAME       )    ,      self.block_records       )
  							# save tokenizer
  							self.tokenizer.save_pretrained(__lowerCAmelCase       )
  
  
  
  
  					def 	snake_case_		(						self    ,      __lowerCAmelCase    ,      __lowerCAmelCase       )						->  Any:
  							UpperCamelCase__         =	[]
  							UpperCamelCase__         =	[]
  							UpperCamelCase__         =	[]
  							UpperCamelCase__         =	0
  
  							for input_id in concat_inputs.input_ids:
  									UpperCamelCase__         =	input_id.tolist()
  									# Check answers between two [SEP] tokens
  									UpperCamelCase__         =	input_id_list.index(self.tokenizer.sep_token_id       )
  									UpperCamelCase__         =	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    ,      __lowerCAmelCase       ):
  													if answer[0] == input_id_list[idx]:
  															if input_id_list[idx : idx + len(__lowerCAmelCase       )] == answer:
  																	start_pos[-1].append(__lowerCAmelCase       )
  																	end_pos[-1].append(idx + len(__lowerCAmelCase       ) - 1       )
  
  									if len(start_pos[-1]       ) == 0:
  											has_answers.append(__lowerCAmelCase       )
  									else:
  											has_answers.append(__lowerCAmelCase       )
  											if len(start_pos[-1]       ) > max_answers:
  													UpperCamelCase__         =	len(start_pos[-1]       )
  
          # Pad -1 to max_answers
  							for start_pos_, end_pos_ in zip(__lowerCAmelCase    ,      __lowerCAmelCase       ):
  									if len(start_pos_       ) < max_answers:
  											UpperCamelCase__         =	[-1] * (max_answers - len(start_pos_       ))
  											start_pos_ += padded
  											end_pos_ += padded
  							return has_answers, start_pos, end_pos
  
  
  
  
  
  
style_context: 
  
  
  
  
  
  def     a						(      _lowercase   :     List[str]       )     ->List[str]:
  		UpperCamelCase__         =	[7_0_1, 3_0_1, 1_3_2, 5_7, 2_3, 1_0, 4, 1]
  		for gap in gaps:
  				for i in range(_lowercase ,						len(_lowercase       )       ):
  						UpperCamelCase__         =	collection[i]
  						UpperCamelCase__         =	i
  						while j >= gap and collection[j - gap] > insert_value:
  								UpperCamelCase__         =	collection[j - gap]
  								j -= gap
  						if j != i:
  								UpperCamelCase__         =	insert_value
  		return collection
  
  
  if __name__ == "__main__":
  				from doctest import testmod
  
  				testmod()
  				__lowerCAmelCase     =			input("Enter numbers separated by a comma:\n").strip()
  				__lowerCAmelCase     =			[int(item) for item in user_input.split(",")]
  				print(shell_sort(unsorted))
  
  
  
  
  
  