






"""simple docstring"""







from typing import Optional, Tuple, Union

import tensorflow as tf

from ...activations_tf import ACTaFN
from ...modeling_tf_outputs import (
    TFBaseModelOutputWithNoAttention,
    TFBaseModelOutputWithPoolingAndNoAttention,
    TFImageClassifierOutputWithNoAttention,
)
from ...modeling_tf_utils import TFPreTrainedModel, TFSequenceClassificationLoss, keras_serializable, unpack_inputs
from ...tf_utils import shape_list
from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
from .configuration_resnet import ResNetConfig


__a							:						Union[str, Any]   							=			logging.get_logger(__name__)

# General docstring
__a							:						Any   							=			'ResNetConfig'

# Base docstring
__a							:						List[str]   							=			'microsoft/resnet-50'
__a							:						str   							=			[1, 2048, 7, 7]

# Image classification docstring
__a							:						Dict   							=			'microsoft/resnet-50'
__a							:						List[Any]   							=			'tiger cat'

__a							:						Dict   							=			[
    'microsoft/resnet-50',
    # See all resnet models at https://huggingface.co/models?filter=resnet
]







class 							_SCREAMING_SNAKE_CASE    (	tf.keras.layers.Layer				):





							"""simple docstring"""





							def __init__( self:  Tuple					,		__A:  int					,		__A:  int = 3					,		__A:  int = 1					,		__A:  str = "relu"					,		**__A:  str     ):

												'''simple docstring'''

												super().__init__(**__A     )
												a__ 							=	kernel_size // 2
												a__ 							=	tf.keras.layers.ConvaD(
												    __A					,		kernel_size=__A					,		strides=__A					,		padding='''valid'''					,		use_bias=__A					,		name='''convolution'''     )
												# Use same default momentum and epsilon as PyTorch equivalent
												a__ 							=	tf.keras.layers.BatchNormalization(epsilon=1e-5					,		momentum=0.9					,		name='''normalization'''     )
												a__ 							=	ACTaFN[activation] if activation is not None else tf.keras.layers.Activation('''linear'''     )




							def 			lowercase		( self:  str					,		__A:  tf.Tensor     ):

												'''simple docstring'''

												a__ 							=	a__ 							=	(self.pad_value, self.pad_value)
												a__ 							=	tf.pad(__A					,		[(0, 0), height_pad, width_pad, (0, 0)]     )
												a__ 							=	self.conv(__A     )
												return hidden_state





							def 			lowercase		( self:  str					,		__A:  tf.Tensor					,		__A:  bool = False     ):

												'''simple docstring'''

												a__ 							=	self.convolution(__A     )
												a__ 							=	self.normalization(__A					,		training=__A     )
												a__ 							=	self.activation(__A     )
												return hidden_state







class 							_SCREAMING_SNAKE_CASE    (	tf.keras.layers.Layer				):





							"""simple docstring"""





							def __init__( self:  Tuple					,		__A:  ResNetConfig					,		**__A:  Dict     ):

												'''simple docstring'''

												super().__init__(**__A     )
												a__ 							=	TFResNetConvLayer(
												    config.embedding_size					,		kernel_size=7					,		stride=2					,		activation=config.hidden_act					,		name='''embedder'''					,		)
												a__ 							=	tf.keras.layers.MaxPoolaD(pool_size=3					,		strides=2					,		padding='''valid'''					,		name='''pooler'''     )
												a__ 							=	config.num_channels





							def 			lowercase		( self:  Optional[int]					,		__A:  tf.Tensor					,		__A:  bool = False     ):

												'''simple docstring'''

												a__							,a__							,a__							,a__ 							=	shape_list(__A     )
												if tf.executing_eagerly() and num_channels != self.num_channels:
																	raise ValueError(
																	    '''Make sure that the channel dimension of the pixel values match with the one set in the configuration.'''     )
												a__ 							=	pixel_values
												a__ 							=	self.embedder(__A     )
												a__ 							=	tf.pad(__A					,		[[0, 0], [1, 1], [1, 1], [0, 0]]     )
												a__ 							=	self.pooler(__A     )
												return hidden_state







class 							_SCREAMING_SNAKE_CASE    (	tf.keras.layers.Layer				):





							"""simple docstring"""





							def __init__( self:  Tuple					,		__A:  int					,		__A:  int = 2					,		**__A:  Optional[Any]     ):

												'''simple docstring'''

												super().__init__(**__A     )
												a__ 							=	tf.keras.layers.ConvaD(
												    __A					,		kernel_size=1					,		strides=__A					,		use_bias=__A					,		name='''convolution'''     )
												# Use same default momentum and epsilon as PyTorch equivalent
												a__ 							=	tf.keras.layers.BatchNormalization(epsilon=1e-5					,		momentum=0.9					,		name='''normalization'''     )





							def 			lowercase		( self:  str					,		__A:  tf.Tensor					,		__A:  bool = False     ):

												'''simple docstring'''

												a__ 							=	x
												a__ 							=	self.convolution(__A     )
												a__ 							=	self.normalization(__A					,		training=__A     )
												return hidden_state







class 							_SCREAMING_SNAKE_CASE    (	tf.keras.layers.Layer				):





							"""simple docstring"""





							def __init__( self:  Dict					,		__A:  int					,		__A:  int					,		__A:  int = 1					,		__A:  str = "relu"					,		**__A:  int     ):

												'''simple docstring'''

												super().__init__(**__A     )
												a__ 							=	in_channels != out_channels or stride != 1
												a__ 							=	TFResNetConvLayer(__A					,		stride=__A					,		name='''layer.0'''     )
												a__ 							=	TFResNetConvLayer(__A					,		activation=__A					,		name='''layer.1'''     )
												a__ 							=	(
												    TFResNetShortCut(__A					,		stride=__A					,		name='''shortcut'''     )
												    if should_apply_shortcut
												    else tf.keras.layers.Activation('''linear'''					,		name='''shortcut'''     )
												)
												a__ 							=	ACTaFN[activation]





							def 			lowercase		( self:  Any					,		__A:  tf.Tensor					,		__A:  bool = False     ):

												'''simple docstring'''

												a__ 							=	hidden_state
												a__ 							=	self.conva(__A					,		training=__A     )
												a__ 							=	self.conva(__A					,		training=__A     )
												a__ 							=	self.shortcut(__A					,		training=__A     )
												hidden_state += residual
												a__ 							=	self.activation(__A     )
												return hidden_state







class 							_SCREAMING_SNAKE_CASE    (	tf.keras.layers.Layer				):





							"""simple docstring"""





							def __init__( self:  Union[str, Any]					,		__A:  int					,		__A:  int					,		__A:  int = 1					,		__A:  str = "relu"					,		__A:  int = 4					,		**__A:  Optional[Any]					,		):

												'''simple docstring'''

												super().__init__(**__A     )
												a__ 							=	in_channels != out_channels or stride != 1
												a__ 							=	out_channels // reduction
												a__ 							=	TFResNetConvLayer(__A					,		kernel_size=1					,		name='''layer.0'''     )
												a__ 							=	TFResNetConvLayer(__A					,		stride=__A					,		name='''layer.1'''     )
												a__ 							=	TFResNetConvLayer(__A					,		kernel_size=1					,		activation=__A					,		name='''layer.2'''     )
												a__ 							=	(
												    TFResNetShortCut(__A					,		stride=__A					,		name='''shortcut'''     )
												    if should_apply_shortcut
												    else tf.keras.layers.Activation('''linear'''					,		name='''shortcut'''     )
												)
												a__ 							=	ACTaFN[activation]





							def 			lowercase		( self:  str					,		__A:  tf.Tensor					,		__A:  bool = False     ):

												'''simple docstring'''

												a__ 							=	hidden_state
												a__ 							=	self.conva(__A					,		training=__A     )
												a__ 							=	self.conva(__A					,		training=__A     )
												a__ 							=	self.conva(__A					,		training=__A     )
												a__ 							=	self.shortcut(__A					,		training=__A     )
												hidden_state += residual
												a__ 							=	self.activation(__A     )
												return hidden_state







class 							_SCREAMING_SNAKE_CASE    (	tf.keras.layers.Layer				):





							"""simple docstring"""





							def __init__( self:  Optional[Any]					,		__A:  ResNetConfig					,		__A:  int					,		__A:  int					,		__A:  int = 2					,		__A:  int = 2					,		**__A:  Tuple     ):

												'''simple docstring'''

												super().__init__(**__A     )

												a__ 							=	TFResNetBottleNeckLayer if config.layer_type == '''bottleneck''' else TFResNetBasicLayer

												a__ 							=	[layer(__A					,		__A					,		stride=__A					,		activation=config.hidden_act					,		name='''layers.0'''     )]
												layers += [
												    layer(__A					,		__A					,		activation=config.hidden_act					,		name=F'layers.{i + 1}'     )
												    for i in range(depth - 1     )
												]
												a__ 							=	layers





							def 			lowercase		( self:  Optional[Any]					,		__A:  tf.Tensor					,		__A:  bool = False     ):

												'''simple docstring'''

												for layer in self.stage_layers:
																	a__ 							=	layer(__A					,		training=__A     )
												return hidden_state







class 							_SCREAMING_SNAKE_CASE    (	tf.keras.layers.Layer				):





							"""simple docstring"""





							def __init__( self:  Any					,		__A:  ResNetConfig					,		**__A:  Optional[int]     ):

												'''simple docstring'''

												super().__init__(**__A     )
												# based on `downsample_in_first_stage` the first layer of the first stage may or may not downsample the input
												a__ 							=	[
												    TFResNetStage(
												        __A					,		config.embedding_size					,		config.hidden_sizes[0]					,		stride=2 if config.downsample_in_first_stage else 1					,		depth=config.depths[0]					,		name='''stages.0'''					,		)
												]
												for i, (in_channels, out_channels, depth) in enumerate(
												    zip(config.hidden_sizes					,		config.hidden_sizes[1:]					,		config.depths[1:]     )     ):
																	self.stages.append(TFResNetStage(__A					,		__A					,		__A					,		depth=__A					,		name=F'stages.{i + 1}'     )     )





							def 			lowercase		( self:  Any					,		__A:  tf.Tensor					,		__A:  bool = False					,		__A:  bool = True					,		__A:  bool = False					,		):

												'''simple docstring'''

												a__ 							=	() if output_hidden_states else None

												for stage_module in self.stages:
																	if output_hidden_states:
																						a__ 							=	hidden_states + (hidden_state,)

																	a__ 							=	stage_module(__A					,		training=__A     )

												if output_hidden_states:
																	a__ 							=	hidden_states + (hidden_state,)

												if not return_dict:
																	return tuple(v for v in [hidden_state, hidden_states] if v is not None     )

												return TFBaseModelOutputWithNoAttention(last_hidden_state=__A					,		hidden_states=__A     )







class 							_SCREAMING_SNAKE_CASE    (	__snake_case				):





							"""simple docstring"""





							_SCREAMING_SNAKE_CASE     =ResNetConfig
							_SCREAMING_SNAKE_CASE     ='resnet'
							_SCREAMING_SNAKE_CASE     ='pixel_values'




							@property
							def 			lowercase		( self:  Optional[int]     ):

												'''simple docstring'''

												return {"pixel_values": tf.TensorSpec(shape=(None, self.config.num_channels, 224, 224)					,		dtype=tf.floataa     )}

__a							:						Tuple   							=			r'\n    This model is a TensorFlow\n    [tf.keras.layers.Layer](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Layer) sub-class. Use it as a\n    regular TensorFlow Module and refer to the TensorFlow documentation for all matter related to general usage and\n    behavior.\n\n    Parameters:\n        config ([`ResNetConfig`]): Model configuration class with all the parameters of the model.\n            Initializing with a config file does not load the weights associated with the model, only the\n            configuration. Check out the [`~TFPreTrainedModel.from_pretrained`] method to load the model weights.\n'


__a							:						List[Any]   							=			r'\n    Args:\n        pixel_values (`tf.Tensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See\n            [`ConvNextImageProcessor.__call__`] for details.\n\n        output_hidden_states (`bool`, *optional*):\n            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for\n            more detail.\n        return_dict (`bool`, *optional*):\n            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.\n'







@keras_serializable
class 							_SCREAMING_SNAKE_CASE    (	tf.keras.layers.Layer				):





							"""simple docstring"""





							_SCREAMING_SNAKE_CASE     =ResNetConfig




							def __init__( self:  str					,		__A:  ResNetConfig					,		**__A:  Optional[int]     ):

												'''simple docstring'''

												super().__init__(**__A     )
												a__ 							=	config
												a__ 							=	TFResNetEmbeddings(__A					,		name='''embedder'''     )
												a__ 							=	TFResNetEncoder(__A					,		name='''encoder'''     )
												a__ 							=	tf.keras.layers.GlobalAveragePoolingaD(keepdims=__A     )





							@unpack_inputs
							def 			lowercase		( self:  List[Any]					,		__A:  tf.Tensor					,		__A:  Optional[bool] = None					,		__A:  Optional[bool] = None					,		__A:  bool = False					,		):

												'''simple docstring'''

												a__ 							=	(
												    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
												)
												a__ 							=	return_dict if return_dict is not None else self.config.use_return_dict

												# TF 2.0 image layers can't use NCHW format when running on CPU.
												# We transpose to NHWC format and then transpose back after the full forward pass.
												# (batch_size, num_channels, height, width) -> (batch_size, height, width, num_channels)
												a__ 							=	tf.transpose(__A					,		perm=[0, 2, 3, 1]     )
												a__ 							=	self.embedder(__A					,		training=__A     )

												a__ 							=	self.encoder(
												    __A					,		output_hidden_states=__A					,		return_dict=__A					,		training=__A     )

												a__ 							=	encoder_outputs[0]

												a__ 							=	self.pooler(__A     )

												# Transpose all the outputs to the NCHW format
												# (batch_size, height, width, num_channels) -> (batch_size, num_channels, height, width)
												a__ 							=	tf.transpose(__A					,		(0, 3, 1, 2)     )
												a__ 							=	tf.transpose(__A					,		(0, 3, 1, 2)     )
												a__ 							=	()
												for hidden_state in encoder_outputs[1:]:
																	a__ 							=	hidden_states + tuple(tf.transpose(__A					,		(0, 3, 1, 2)     ) for h in hidden_state     )

												if not return_dict:
																	return (last_hidden_state, pooled_output) + hidden_states

												a__ 							=	hidden_states if output_hidden_states else None

												return TFBaseModelOutputWithPoolingAndNoAttention(
												    last_hidden_state=__A					,		pooler_output=__A					,		hidden_states=__A					,		)







@add_start_docstrings(
    'The bare ResNet model outputting raw features without any specific head on top.'							,			__snake_case							,			)
class 							_SCREAMING_SNAKE_CASE    (	__snake_case				):





							"""simple docstring"""





							def __init__( self:  Dict					,		__A:  ResNetConfig					,		**__A:  Dict     ):

												'''simple docstring'''

												super().__init__(__A					,		**__A     )
												a__ 							=	TFResNetMainLayer(config=__A					,		name='''resnet'''     )





							@add_start_docstrings_to_model_forward(__A     )
							@add_code_sample_docstrings(
							    checkpoint=_CHECKPOINT_FOR_DOC					,		output_type=__A					,		config_class=_CONFIG_FOR_DOC					,		modality='''vision'''					,		expected_output=_EXPECTED_OUTPUT_SHAPE					,		)
							@unpack_inputs
							def 			lowercase		( self:  List[Any]					,		__A:  tf.Tensor					,		__A:  Optional[bool] = None					,		__A:  Optional[bool] = None					,		__A:  bool = False					,		):

												'''simple docstring'''

												a__ 							=	(
												    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
												)
												a__ 							=	return_dict if return_dict is not None else self.config.use_return_dict

												a__ 							=	self.resnet(
												    pixel_values=__A					,		output_hidden_states=__A					,		return_dict=__A					,		training=__A					,		)
												return resnet_outputs







@add_start_docstrings(
    '\n    ResNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for\n    ImageNet.\n    '							,			__snake_case							,			)
class 							_SCREAMING_SNAKE_CASE    (	__snake_case							,			__snake_case				):





							"""simple docstring"""





							def __init__( self:  List[str]					,		__A:  ResNetConfig					,		**__A:  str     ):

												'''simple docstring'''

												super().__init__(__A					,		**__A     )
												a__ 							=	config.num_labels
												a__ 							=	TFResNetMainLayer(__A					,		name='''resnet'''     )
												# classification head
												a__ 							=	(
												    tf.keras.layers.Dense(config.num_labels					,		name='''classifier.1'''     )
												    if config.num_labels > 0
												    else tf.keras.layers.Activation('''linear'''					,		name='''classifier.1'''     )
												)




							def 			lowercase		( self:  Any					,		__A:  tf.Tensor     ):

												'''simple docstring'''

												a__ 							=	tf.keras.layers.Flatten()(__A     )
												a__ 							=	self.classifier_layer(__A     )
												return logits





							@add_start_docstrings_to_model_forward(__A     )
							@add_code_sample_docstrings(
							    checkpoint=_IMAGE_CLASS_CHECKPOINT					,		output_type=__A					,		config_class=_CONFIG_FOR_DOC					,		expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT					,		)
							@unpack_inputs
							def 			lowercase		( self:  str					,		__A:  tf.Tensor = None					,		__A:  tf.Tensor = None					,		__A:  bool = None					,		__A:  bool = None					,		__A:  bool = False					,		):

												'''simple docstring'''

												a__ 							=	return_dict if return_dict is not None else self.config.use_return_dict

												a__ 							=	self.resnet(
												    __A					,		output_hidden_states=__A					,		return_dict=__A					,		training=__A     )

												a__ 							=	outputs.pooler_output if return_dict else outputs[1]

												a__ 							=	self.classifier(__A     )

												a__ 							=	None if labels is None else self.hf_compute_loss(__A					,		__A     )

												if not return_dict:
																	a__ 							=	(logits,) + outputs[2:]
																	return (loss,) + output if loss is not None else output

												return TFImageClassifierOutputWithNoAttention(loss=__A					,		logits=__A					,		hidden_states=outputs.hidden_states     )










"""simple docstring"""







import jax
import jax.numpy as jnp
from bigbird_flax import FlaxBigBirdForNaturalQuestions
from datasets import load_from_disk

from transformers import BigBirdTokenizerFast


__a							:						Optional[int]   							=			{0: 'null', 1: 'short', 2: 'long', 3: 'yes', 4: 'no'}
__a							:						Dict   							=			set(''.join(['‘', '’', '´', '`', '.', ',', '-', '"']))





def 							SCREAMING_SNAKE_CASE							(   lowerCamelCase_			,  lowerCamelCase_=0			,  lowerCamelCase_=None):
					return [" ".join(x.split(''' ''')[begin:end]) for x in answers if len(x.split(''' ''')) > 1]





def 							SCREAMING_SNAKE_CASE							(   lowerCamelCase_			,  lowerCamelCase_=False):
					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"
										a__ 							=	(
										    given_answers + get_sub_answers(lowerCamelCase_			,  begin=1) + get_sub_answers(lowerCamelCase_			,  end=-1)
										)
					a__ 							=	[]
					for answer in given_answers:
										a__ 							=	answer.replace('''_'''			,  ''' ''').lower()
										a__ 							=	''''''.join(c if c not in PUNCTUATION_SET_TO_EXCLUDE else ''' ''' for c in alias)
										answers.append(''' '''.join(alias.split()).strip())
					return set(lowerCamelCase_)





def 							SCREAMING_SNAKE_CASE							(   lowerCamelCase_			,  lowerCamelCase_			,  lowerCamelCase_=1			,  lowerCamelCase_=100):
					a__							,a__ 							=	jax.lax.top_k(lowerCamelCase_			,  lowerCamelCase_)
					a__							,a__ 							=	jax.lax.top_k(lowerCamelCase_			,  lowerCamelCase_)

					a__ 							=	best_end_idx[:, None] - best_start_idx[None, :]
					a__ 							=	jnp.logical_or(widths < 0			,  widths > max_size)
					a__ 							=	(best_end_scores[:, None] + best_start_scores[None, :]) - (1E8 * mask)
					a__ 							=	jnp.argmax(lowerCamelCase_).item()

					return best_start_idx[best_score % top_k], best_end_idx[best_score // top_k]





def 							SCREAMING_SNAKE_CASE							(   lowerCamelCase_):
					a__ 							=	sample['''question''']['''text''']
					a__ 							=	sample['''document''']['''tokens''']['''token''']
					a__ 							=	sample['''document''']['''tokens''']['''is_html''']
					a__ 							=	sample['''annotations''']['''long_answer''']
					a__ 							=	sample['''annotations''']['''short_answers''']

					a__ 							=	''' '''.join([context[i] for i in range(len(lowerCamelCase_)) 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",
															}

					a__ 							=	[]
					for s in short_answers:
										short_targets.extend(s['''text'''])
					a__ 							=	list(set(lowerCamelCase_))

					a__ 							=	[]
					for s in long_answers:
										if s["start_token"] == -1:
															continue
										a__ 							=	context[s['''start_token'''] : s['''end_token''']]
										a__ 							=	is_html[s['''start_token'''] : s['''end_token''']]
										a__ 							=	''' '''.join([answer[i] for i in range(len(lowerCamelCase_)) if not html[i]])
										if new_answer not in long_targets:
															long_targets.append(lowerCamelCase_)

					a__ 							=	'''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 							SCREAMING_SNAKE_CASE							(   ):
					a__ 							=	load_from_disk('''natural-questions-validation''')
					a__ 							=	dataset.map(lowerCamelCase_).remove_columns(['''annotations''', '''document''', '''id'''])
					print(lowerCamelCase_)

					a__ 							=	dataset.filter(lambda lowerCamelCase_: (len(x['''question''']) + len(x['''context'''])) < 4 * 4096)
					a__ 							=	short_validation_dataset.filter(lambda lowerCamelCase_: x["category"] != "null")
					short_validation_dataset

					a__ 							=	'''vasudevgupta/flax-bigbird-natural-questions'''
					a__ 							=	FlaxBigBirdForNaturalQuestions.from_pretrained(lowerCamelCase_)
					a__ 							=	BigBirdTokenizerFast.from_pretrained(lowerCamelCase_)

					@jax.jit
					def forward(*lowerCamelCase_			,  **lowerCamelCase_):
										a__							,a__							,a__ 							=	model(*lowerCamelCase_			,  **lowerCamelCase_)
										return start_logits, end_logits, jnp.argmax(lowerCamelCase_			,  axis=-1)

					def evaluate(lowerCamelCase_):
										# encode question and context so that they are separated by a tokenizer.sep_token and cut at max_length
										a__ 							=	tokenizer(
										    example['''question''']			,  example['''context''']			,  return_tensors='''np'''			,  max_length=4096			,  padding='''max_length'''			,  truncation=lowerCamelCase_			,  )

										a__							,a__							,a__ 							=	forward(**lowerCamelCase_)

										a__ 							=	CATEGORY_MAPPING[category.item()]

										a__ 							=	example['''long'''] + example['''short''']
										if example["category"] in ["yes", "no", "null"]:
															a__ 							=	[example['''category''']]
										a__ 							=	example['''category'''] != '''null'''
										# Now target can be: "yes", "no", "null", "list of long & short answers"

										if predicted_category in ["yes", "no", "null"]:
															a__ 							=	[predicted_category]
															a__ 							=	example['''output'''] == example['''targets''']
															a__ 							=	predicted_category != '''null'''
															return example

										a__ 							=	38 if predicted_category == '''short''' else 1024
										a__							,a__ 							=	get_best_valid_start_end_idx(
										    start_scores[0]			,  end_scores[0]			,  top_k=8			,  max_size=lowerCamelCase_)

										a__ 							=	inputs['''input_ids'''][0].tolist()
										a__ 							=	[tokenizer.decode(input_ids[start_score : end_score + 1])]

										a__ 							=	expand_to_aliases(example['''targets''']			,  make_sub_answers=lowerCamelCase_)
										a__ 							=	expand_to_aliases(example['''output'''])

										# some preprocessing to both prediction and answer
										a__ 							=	{''''''.join(a.split()) for a in answers}
										a__ 							=	{''''''.join(p.split()) for p in predictions}
										a__ 							=	{s for s in predictions if s not in ['''``''', '''\'\'''', '''`''', '''\'''']}

										# if there is a common element, it's a exact match
										a__ 							=	len(list(answers & predictions)) > 0
										a__ 							=	predicted_category != '''null''' and len(lowerCamelCase_) > 0

										return example

					a__ 							=	short_validation_dataset.map(lowerCamelCase_)

					a__ 							=	len(lowerCamelCase_)
					a__ 							=	len(short_validation_dataset.filter(lambda lowerCamelCase_: x["match"] == 1))
					print('''EM score:'''			,  (matched / total) * 100			,  '''%''')


if __name__ == "__main__":
	main()


