code: 
  
  
  
  import jax
  import jax.numpy as jnp
  from bigbird_flax import FlaxBigBirdForNaturalQuestions
  from datasets import load_from_disk
  
  from transformers import BigBirdTokenizerFast
  
  
  __UpperCAmelCase      = {0: 'null', 1: 'short', 2: 'long', 3: 'yes', 4: 'no'}
  __UpperCAmelCase      = set(''''''.join(['''‘''', '''’''', '''´''', '''`''', '''.''', ''',''', '''-''', '''"''']))
  def 	UpperCamelCase			(     snake_case__ :					Tuple ,  snake_case__ :					Dict=0 ,  snake_case__ :					Dict=None			)			->  Union[str, Any]:
  			return [" ".join(x.split(' '			)[begin:end]			) for x in answers if len(x.split(' '			)			) > 1]
  def 	UpperCamelCase			(     snake_case__ :					Tuple ,  snake_case__ :					List[str]=False			)			->  List[Any]:
  
  
  
  			if make_sub_answers:
  						# if answers are longer than one word, make sure a predictions is correct if it coresponds to the complete 1: or :-1 sub word
  						# *e.g.* if the correct answer contains a prefix such as "the", or "a"
  						UpperCamelCase					:						Dict					=			(
  						    given_answers + get_sub_answers(__A ,  begin=1			) + get_sub_answers(__A ,  end=-1			)
  						)
  			UpperCamelCase					:						Tuple					=			[]
  			for answer in given_answers:
  						UpperCamelCase					:						Optional[Any]					=			answer.replace('_' ,  ' '			).lower()
  						UpperCamelCase					:						List[str]					=			''.join(c if c not in PUNCTUATION_SET_TO_EXCLUDE else ' ' for c in alias			)
  						answers.append(' '.join(alias.split()			).strip()			)
  			return set(__A			)
  def 	UpperCamelCase			(     snake_case__ :					Optional[int] ,  snake_case__ :					Any ,  snake_case__ :					Optional[int]=1 ,  snake_case__ :					List[str]=100			)			->  Union[str, Any]:
  			UpperCamelCase			,  UpperCamelCase					:						str					=			jax.lax.top_k(__A ,  __A			)
  			UpperCamelCase			,  UpperCamelCase					:						Tuple					=			jax.lax.top_k(__A ,  __A			)
  
  			UpperCamelCase					:						Dict					=			best_end_idx[:, None] - best_start_idx[None, :]
  			UpperCamelCase					:						str					=			jnp.logical_or(widths < 0 ,  widths > max_size			)
  			UpperCamelCase					:						Optional[Any]					=			(best_end_scores[:, None] + best_start_scores[None, :]) - (1E8 * mask)
  			UpperCamelCase					:						Optional[int]					=			jnp.argmax(__A			).item()
  
  			return best_start_idx[best_score % top_k], best_end_idx[best_score // top_k]
  def 	UpperCamelCase			(     snake_case__ :					List[Any]			)			->  List[str]:
  			UpperCamelCase					:						Optional[Any]					=			sample['question']['text']
  			UpperCamelCase					:						Tuple					=			sample['document']['tokens']['token']
  			UpperCamelCase					:						int					=			sample['document']['tokens']['is_html']
  			UpperCamelCase					:						str					=			sample['annotations']['long_answer']
  			UpperCamelCase					:						Optional[int]					=			sample['annotations']['short_answers']
  
  			UpperCamelCase					:						int					=			' '.join([context[i] for i in range(len(__A			)			) if not is_html[i]]			)
  
  			# 0 - No ; 1 - Yes
  			for answer in sample["annotations"]["yes_no_answer"]:
  						if answer == 0 or answer == 1:
  									return {
  									    "question": question,
  									    "context": context_string,
  									    "short": [],
  									    "long": [],
  									    "category": "no" if answer == 0 else "yes",
  									}
  
  			UpperCamelCase					:						Dict					=			[]
  			for s in short_answers:
  						short_targets.extend(s['text']			)
  			UpperCamelCase					:						str					=			list(set(__A			)			)
  
  			UpperCamelCase					:						Dict					=			[]
  			for s in long_answers:
  						if s["start_token"] == -1:
  									continue
  						UpperCamelCase					:						int					=			context[s['start_token'] : s['end_token']]
  						UpperCamelCase					:						str					=			is_html[s['start_token'] : s['end_token']]
  						UpperCamelCase					:						List[str]					=			' '.join([answer[i] for i in range(len(__A			)			) if not html[i]]			)
  						if new_answer not in long_targets:
  									long_targets.append(__A			)
  
  			UpperCamelCase					:						List[Any]					=			'long_short' if len(short_targets + long_targets			) > 0 else 'null'
  
  			return {
  			    "question": question,
  			    "context": context_string,
  			    "short": short_targets,
  			    "long": long_targets,
  			    "category": category,
  			}
  def 	UpperCamelCase			(     )			->  Dict:
  			UpperCamelCase					:						Tuple					=			load_from_disk('natural-questions-validation'			)
  			UpperCamelCase					:						str					=			dataset.map(__A			).remove_columns(['annotations', 'document', 'id']			)
  			print(__A			)
  
  			UpperCamelCase					:						List[Any]					=			dataset.filter(lambda snake_case__			: (len(x['question']			) + len(x['context']			)) < 4 * 4096			)
  			UpperCamelCase					:						Tuple					=			short_validation_dataset.filter(lambda snake_case__			: x["category"] != "null"			)
  			short_validation_dataset
  
  			UpperCamelCase					:						int					=			'vasudevgupta/flax-bigbird-natural-questions'
  			UpperCamelCase					:						Tuple					=			FlaxBigBirdForNaturalQuestions.from_pretrained(__A			)
  			UpperCamelCase					:						Union[str, Any]					=			BigBirdTokenizerFast.from_pretrained(__A			)
  
  			@jax.jit
  			def forward(*snake_case__ :					Dict ,  **snake_case__ :					Dict			):
  						UpperCamelCase			,  UpperCamelCase			,  UpperCamelCase					:						List[Any]					=			model(*__A ,  **__A			)
  						return start_logits, end_logits, jnp.argmax(__A ,  axis=-1			)
  
  			def evaluate(snake_case__ :					Tuple			):
  						# encode question and context so that they are separated by a tokenizer.sep_token and cut at max_length
  						UpperCamelCase					:						str					=			tokenizer(
  						    example['question'] ,  example['context'] ,  return_tensors='np' ,  max_length=4096 ,  padding='max_length' ,  truncation=__A ,  )
  
  						UpperCamelCase			,  UpperCamelCase			,  UpperCamelCase					:						Union[str, Any]					=			forward(**__A			)
  
  						UpperCamelCase					:						List[str]					=			CATEGORY_MAPPING[category.item()]
  
  						UpperCamelCase					:						str					=			example['long'] + example['short']
  						if example["category"] in ["yes", "no", "null"]:
  									UpperCamelCase					:						Optional[int]					=			[example['category']]
  						UpperCamelCase					:						Optional[int]					=			example['category'] != 'null'
  						# Now target can be: "yes", "no", "null", "list of long & short answers"
  
  						if predicted_category in ["yes", "no", "null"]:
  									UpperCamelCase					:						int					=			[predicted_category]
  									UpperCamelCase					:						Optional[Any]					=			example['output'] == example['targets']
  									UpperCamelCase					:						List[str]					=			predicted_category != 'null'
  									return example
  
  						UpperCamelCase					:						Optional[int]					=			38 if predicted_category == 'short' else 1024
  						UpperCamelCase			,  UpperCamelCase					:						List[Any]					=			get_best_valid_start_end_idx(
  						    start_scores[0] ,  end_scores[0] ,  top_k=8 ,  max_size=__A			)
  
  						UpperCamelCase					:						str					=			inputs['input_ids'][0].tolist()
  						UpperCamelCase					:						int					=			[tokenizer.decode(input_ids[start_score : end_score + 1]			)]
  
  						UpperCamelCase					:						Dict					=			expand_to_aliases(example['targets'] ,  make_sub_answers=__A			)
  						UpperCamelCase					:						Tuple					=			expand_to_aliases(example['output']			)
  
  						# some preprocessing to both prediction and answer
  						UpperCamelCase					:						Any					=			{''.join(a.split()			) for a in answers}
  						UpperCamelCase					:						List[Any]					=			{''.join(p.split()			) for p in predictions}
  						UpperCamelCase					:						str					=			{s for s in predictions if s not in ['``', '\'\'', '`', '\'']}
  
  						# if there is a common element, it's a exact match
  						UpperCamelCase					:						Dict					=			len(list(answers & predictions			)			) > 0
  						UpperCamelCase					:						str					=			predicted_category != 'null' and len(__A			) > 0
  
  						return example
  
  			UpperCamelCase					:						List[str]					=			short_validation_dataset.map(__A			)
  
  			UpperCamelCase					:						Tuple					=			len(__A			)
  			UpperCamelCase					:						Tuple					=			len(short_validation_dataset.filter(lambda snake_case__			: x["match"] == 1			)			)
  			print('EM score:' ,  (matched / total) * 100 ,  '%'			)
  
  
  if __name__ == "__main__":
  				main()
  
  
  
  
style_context: 
  
  
  
  from __future__ import annotations
  
  import sys
  def 	UpperCamelCase			(     snake_case__ :					int ,  snake_case__ :					int			)			->  tuple[int, int]:
     # base cases
     if abs(snake_case__			) == 1:
        return a, 0
     elif abs(snake_case__			) == 1:
        return 0, b
  
     UpperCamelCase			,  UpperCamelCase					:						Dict					=			a, b
     UpperCamelCase			,  UpperCamelCase					:						int					=			1, 0
     UpperCamelCase			,  UpperCamelCase					:						Union[str, Any]					=			0, 1
  
     while remainder != 0:
        UpperCamelCase					:						str					=			old_remainder // remainder
        UpperCamelCase			,  UpperCamelCase					:						Union[str, Any]					=			remainder, old_remainder - quotient * remainder
        UpperCamelCase			,  UpperCamelCase					:						List[Any]					=			coeff_a, old_coeff_a - quotient * coeff_a
        UpperCamelCase			,  UpperCamelCase					:						Optional[Any]					=			coeff_b, old_coeff_b - quotient * coeff_b
  
     # sign correction for negative numbers
     if a < 0:
        UpperCamelCase					:						Dict					=			-old_coeff_a
     if b < 0:
        UpperCamelCase					:						Any					=			-old_coeff_b
  
     return old_coeff_a, old_coeff_b
  def 	UpperCamelCase			(     )			->  Tuple:
     if len(sys.argv			) < 3:
        print('2 integer arguments required'			)
        return 1
     UpperCamelCase					:						Union[str, Any]					=			int(sys.argv[1]			)
     UpperCamelCase					:						Optional[int]					=			int(sys.argv[2]			)
     print(extended_euclidean_algorithm(snake_case__ ,  snake_case__			)			)
     return 0
  
  
  if __name__ == "__main__":
      raise SystemExit(main())
  
  
  
  