



"""simple docstring"""
import unittest

from transformers import BertGenerationConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
						import torch

						from transformers import BertGenerationDecoder, BertGenerationEncoder
class 				lowerCamelCase  :






					'''simple docstring'''





					def __init__(       self:							str						,     snake_case:							List[Any]						,     snake_case:							Dict=13						,     snake_case:							Union[str, Any]=7						,     snake_case:							List[Any]=True						,     snake_case:							Any=True						,     snake_case:							Optional[int]=99						,     snake_case:							str=32						,     snake_case:							Optional[int]=5						,     snake_case:							List[Any]=4						,     snake_case:							str=37						,     snake_case:							List[Any]="gelu"						,     snake_case:							Optional[int]=0.1						,     snake_case:							List[Any]=0.1						,     snake_case:							str=50						,     snake_case:							str=0.0_2						,     snake_case:							Optional[Any]=True						,     snake_case:							Any=None						,     )   ->	int:
											snake_case_ :Union[str, Any]						=			parent
											snake_case_ :Optional[int]						=			batch_size
											snake_case_ :Any						=			seq_length
											snake_case_ :str						=			is_training
											snake_case_ :int						=			use_input_mask
											snake_case_ :Optional[int]						=			vocab_size
											snake_case_ :int						=			hidden_size
											snake_case_ :Optional[Any]						=			num_hidden_layers
											snake_case_ :List[str]						=			num_attention_heads
											snake_case_ :Optional[Any]						=			intermediate_size
											snake_case_ :Optional[int]						=			hidden_act
											snake_case_ :int						=			hidden_dropout_prob
											snake_case_ :Optional[int]						=			attention_probs_dropout_prob
											snake_case_ :List[Any]						=			max_position_embeddings
											snake_case_ :str						=			initializer_range
											snake_case_ :List[str]						=			use_labels
											snake_case_ :List[str]						=			scope






					def    lowerCAmelCase_				(       self:							str						)   ->	Dict:
											snake_case_ :Union[str, Any]						=			ids_tensor([self.batch_size, self.seq_length]						,     self.vocab_size						)

											snake_case_ :Any						=			None
											if self.use_input_mask:
																	snake_case_ :List[Any]						=			random_attention_mask([self.batch_size, self.seq_length]						)

											if self.use_labels:
																	snake_case_ :List[Any]						=			ids_tensor([self.batch_size, self.seq_length]						,     self.vocab_size						)

											snake_case_ :List[Any]						=			self.get_config()

											return config, input_ids, input_mask, token_labels






					def    lowerCAmelCase_				(       self:							Tuple						)   ->	str:
											return BertGenerationConfig(
											    vocab_size=self.vocab_size						,     hidden_size=self.hidden_size						,     num_hidden_layers=self.num_hidden_layers						,     num_attention_heads=self.num_attention_heads						,     intermediate_size=self.intermediate_size						,     hidden_act=self.hidden_act						,     hidden_dropout_prob=self.hidden_dropout_prob						,     attention_probs_dropout_prob=self.attention_probs_dropout_prob						,     max_position_embeddings=self.max_position_embeddings						,     is_decoder=snake_case						,     initializer_range=self.initializer_range						,     )






					def    lowerCAmelCase_				(       self:							Optional[Any]						)   ->	Union[str, Any]:
											(
											    (
											    snake_case_
											),       (
											    snake_case_
											),       (
											    snake_case_
											),       (
											    snake_case_
											),       
											) :List[str]						=			self.prepare_config_and_inputs()

											snake_case_ :List[str]						=			True
											snake_case_ :Dict						=			floats_tensor([self.batch_size, self.seq_length, self.hidden_size]						)
											snake_case_ :Any						=			ids_tensor([self.batch_size, self.seq_length]						,     vocab_size=2						)

											return (
											    config,
											    input_ids,
											    input_mask,
											    token_labels,
											    encoder_hidden_states,
											    encoder_attention_mask,
											)






					def    lowerCAmelCase_				(       self:							Tuple						,     snake_case:							List[Any]						,     snake_case:							int						,     snake_case:							Tuple						,     snake_case:							List[str]						,     **snake_case:							Any						,     )   ->	List[Any]:
											snake_case_ :List[Any]						=			BertGenerationEncoder(config=snake_case						)
											model.to(snake_case						)
											model.eval()
											snake_case_ :List[str]						=			model(snake_case						,     attention_mask=snake_case						)
											snake_case_ :Union[str, Any]						=			model(snake_case						)
											self.parent.assertEqual(result.last_hidden_state.shape						,     (self.batch_size, self.seq_length, self.hidden_size)						)






					def    lowerCAmelCase_				(       self:							List[Any]						,     snake_case:							List[Any]						,     snake_case:							Dict						,     snake_case:							int						,     snake_case:							Optional[int]						,     snake_case:							Optional[Any]						,     snake_case:							List[Any]						,     **snake_case:							Tuple						,     )   ->	List[Any]:
											snake_case_ :Dict						=			True
											snake_case_ :List[str]						=			BertGenerationEncoder(config=snake_case						)
											model.to(snake_case						)
											model.eval()
											snake_case_ :Tuple						=			model(
											    snake_case						,     attention_mask=snake_case						,     encoder_hidden_states=snake_case						,     encoder_attention_mask=snake_case						,     )
											snake_case_ :int						=			model(
											    snake_case						,     attention_mask=snake_case						,     encoder_hidden_states=snake_case						,     )
											self.parent.assertEqual(result.last_hidden_state.shape						,     (self.batch_size, self.seq_length, self.hidden_size)						)






					def    lowerCAmelCase_				(       self:							List[str]						,     snake_case:							Union[str, Any]						,     snake_case:							Optional[Any]						,     snake_case:							str						,     snake_case:							int						,     snake_case:							Optional[Any]						,     snake_case:							Any						,     **snake_case:							Any						,     )   ->	List[str]:
											snake_case_ :Optional[Any]						=			True
											snake_case_ :Any						=			True
											snake_case_ :Any						=			BertGenerationDecoder(config=snake_case						).to(snake_case						).eval()

											# first forward pass
											snake_case_ :int						=			model(
											    snake_case						,     attention_mask=snake_case						,     encoder_hidden_states=snake_case						,     encoder_attention_mask=snake_case						,     use_cache=snake_case						,     )
											snake_case_ :Any						=			outputs.past_key_values

											# create hypothetical multiple next token and extent to next_input_ids
											snake_case_ :Any						=			ids_tensor((self.batch_size, 3)						,     config.vocab_size						)
											snake_case_ :Optional[Any]						=			ids_tensor((self.batch_size, 3)						,     vocab_size=2						)

											# append to next input_ids and
											snake_case_ :Dict						=			torch.cat([input_ids, next_tokens]						,     dim=-1						)
											snake_case_ :Union[str, Any]						=			torch.cat([input_mask, next_mask]						,     dim=-1						)

											snake_case_ :Dict						=			model(
											    snake_case						,     attention_mask=snake_case						,     encoder_hidden_states=snake_case						,     encoder_attention_mask=snake_case						,     output_hidden_states=snake_case						,     )["""hidden_states"""][0]
											snake_case_ :Any						=			model(
											    snake_case						,     attention_mask=snake_case						,     encoder_hidden_states=snake_case						,     encoder_attention_mask=snake_case						,     past_key_values=snake_case						,     output_hidden_states=snake_case						,     )["""hidden_states"""][0]

											# select random slice
											snake_case_ :Any						=			ids_tensor((1,)						,     output_from_past.shape[-1]						).item()
											snake_case_ :Any						=			output_from_no_past[:, -3:, random_slice_idx].detach()
											snake_case_ :Dict						=			output_from_past[:, :, random_slice_idx].detach()

											self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]						)

											# test that outputs are equal for slice
											self.parent.assertTrue(torch.allclose(snake_case						,     snake_case						,     atol=1E-3						)						)






					def    lowerCAmelCase_				(       self:							List[Any]						,     snake_case:							Dict						,     snake_case:							int						,     snake_case:							Tuple						,     snake_case:							Dict						,     *snake_case:							Tuple						,     )   ->	str:
											snake_case_ :Optional[Any]						=			BertGenerationDecoder(snake_case						)
											model.to(snake_case						)
											model.eval()
											snake_case_ :int						=			model(snake_case						,     attention_mask=snake_case						,     labels=snake_case						)
											self.parent.assertEqual(result.logits.shape						,     (self.batch_size, self.seq_length, self.vocab_size)						)






					def    lowerCAmelCase_				(       self:							Dict						)   ->	Tuple:
											snake_case_,       snake_case_,       snake_case_,       snake_case_ :List[str]						=			self.prepare_config_and_inputs()
											snake_case_ :Optional[Any]						=			{"""input_ids""": input_ids, """attention_mask""": input_mask}
											return config, inputs_dict

@require_torch
class 				lowerCamelCase  (			_lowerCAmelCase    ,						_lowerCAmelCase    ,						_lowerCAmelCase    ,						unittest.TestCase				):






					'''simple docstring'''





					_A		:			Any						=     (BertGenerationEncoder, BertGenerationDecoder) if is_torch_available() else ()
					_A		:			Union[str, Any]						=     (BertGenerationDecoder,) if is_torch_available() else ()
					_A		:			Any						=     (
					    {"""feature-extraction""": BertGenerationEncoder, """text-generation""": BertGenerationDecoder}
					    if is_torch_available()
					    else {}
					)






					def    lowerCAmelCase_				(       self:							int						)   ->	Dict:
											snake_case_ :Optional[Any]						=			BertGenerationEncoderTester(self						)
											snake_case_ :List[str]						=			ConfigTester(self						,     config_class=snake_case						,     hidden_size=37						)






					def    lowerCAmelCase_				(       self:							Dict						)   ->	List[Any]:
											self.config_tester.run_common_tests()






					def    lowerCAmelCase_				(       self:							List[str]						)   ->	Dict:
											snake_case_ :Optional[Any]						=			self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*snake_case						)






					def    lowerCAmelCase_				(       self:							List[str]						)   ->	Tuple:
											snake_case_,       snake_case_,       snake_case_,       snake_case_ :Tuple						=			self.model_tester.prepare_config_and_inputs()
											snake_case_ :Dict						=			"""bert"""
											self.model_tester.create_and_check_model(snake_case						,     snake_case						,     snake_case						,     snake_case						)






					def    lowerCAmelCase_				(       self:							str						)   ->	Dict:
											snake_case_ :Union[str, Any]						=			self.model_tester.prepare_config_and_inputs_for_decoder()
											self.model_tester.create_and_check_model_as_decoder(*snake_case						)






					def    lowerCAmelCase_				(       self:							List[Any]						)   ->	List[str]:
											snake_case_ :Union[str, Any]						=			self.model_tester.prepare_config_and_inputs_for_decoder()
											self.model_tester.create_and_check_decoder_model_past_large_inputs(*snake_case						)






					def    lowerCAmelCase_				(       self:							List[Any]						)   ->	List[Any]:
											# This regression test was failing with PyTorch < 1.3
											(
											    (
											    snake_case_
											),       (
											    snake_case_
											),       (
											    snake_case_
											),       (
											    snake_case_
											),       (
											    snake_case_
											),       (
											    snake_case_
											),       
											) :Tuple						=			self.model_tester.prepare_config_and_inputs_for_decoder()

											snake_case_ :Union[str, Any]						=			None

											self.model_tester.create_and_check_model_as_decoder(
											    snake_case						,     snake_case						,     snake_case						,     snake_case						,     snake_case						,     snake_case						,     )






					def    lowerCAmelCase_				(       self:							Dict						)   ->	Optional[int]:
											snake_case_ :Union[str, Any]						=			self.model_tester.prepare_config_and_inputs_for_decoder()
											self.model_tester.create_and_check_for_causal_lm(*snake_case						)






					@slow
					def    lowerCAmelCase_				(       self:							int						)   ->	str:
											snake_case_ :int						=			BertGenerationEncoder.from_pretrained("""google/bert_for_seq_generation_L-24_bbc_encoder"""						)
											self.assertIsNotNone(snake_case						)

@require_torch
class 				lowerCamelCase  (			unittest.TestCase				):






					'''simple docstring'''





					@slow
					def    lowerCAmelCase_				(       self:							List[str]						)   ->	str:
											snake_case_ :Optional[Any]						=			BertGenerationEncoder.from_pretrained("""google/bert_for_seq_generation_L-24_bbc_encoder"""						)
											snake_case_ :Any						=			torch.tensor([[101, 7_592, 1_010, 2_026, 3_899, 2_003, 10_140, 102]]						)
											with torch.no_grad():
																	snake_case_ :Optional[int]						=			model(snake_case						)[0]
											snake_case_ :int						=			torch.Size([1, 8, 1_024]						)
											self.assertEqual(output.shape						,     snake_case						)
											snake_case_ :List[str]						=			torch.tensor(
											    [[[0.1_7_7_5, 0.0_0_8_3, -0.0_3_2_1], [1.6_0_0_2, 0.1_2_8_7, 0.3_9_1_2], [2.1_4_7_3, 0.5_7_9_1, 0.6_0_6_6]]]						)
											self.assertTrue(torch.allclose(output[:, :3, :3]						,     snake_case						,     atol=1E-4						)						)

@require_torch
class 				lowerCamelCase  (			unittest.TestCase				):






					'''simple docstring'''





					@slow
					def    lowerCAmelCase_				(       self:							Any						)   ->	List[Any]:
											snake_case_ :Tuple						=			BertGenerationDecoder.from_pretrained("""google/bert_for_seq_generation_L-24_bbc_encoder"""						)
											snake_case_ :List[str]						=			torch.tensor([[101, 7_592, 1_010, 2_026, 3_899, 2_003, 10_140, 102]]						)
											with torch.no_grad():
																	snake_case_ :Optional[int]						=			model(snake_case						)[0]
											snake_case_ :Optional[Any]						=			torch.Size([1, 8, 50_358]						)
											self.assertEqual(output.shape						,     snake_case						)
											snake_case_ :Any						=			torch.tensor(
											    [[[-0.5_7_8_8, -2.5_9_9_4, -3.7_0_5_4], [0.0_4_3_8, 4.7_9_9_7, 1.8_7_9_5], [1.5_8_6_2, 6.6_4_0_9, 4.4_6_3_8]]]						)
											self.assertTrue(torch.allclose(output[:, :3, :3]						,     snake_case						,     atol=1E-4						)						)





"""simple docstring"""
import argparse
import glob
import logging
import os
from argparse import Namespace
from importlib import import_module

import numpy as np
import torch
from lightning_base import BaseTransformer, add_generic_args, generic_train
from seqeval.metrics import accuracy_score, fa_score, precision_score, recall_score
from torch.nn import CrossEntropyLoss
from torch.utils.data import DataLoader, TensorDataset
from utils_ner import TokenClassificationTask


__a      =				logging.getLogger(__name__)
class 				lowerCamelCase  (			_lowerCAmelCase				):






					'''simple docstring'''





					_A		:			Union[str, Any]						=     """token-classification"""






					def __init__(       self:							Any						,     snake_case:							Tuple						)   ->	List[Any]:
											if type(snake_case						) == dict:
																	snake_case_ :Optional[int]						=			Namespace(**snake_case						)
											snake_case_ :Optional[int]						=			import_module("""tasks"""						)
											try:
																	snake_case_ :Any						=			getattr(snake_case						,     hparams.task_type						)
																	snake_case_ :TokenClassificationTask						=			token_classification_task_clazz()
											except AttributeError:
																	raise ValueError(
																	    f"""Task {hparams.task_type} needs to be defined as a TokenClassificationTask subclass in {module}. """
																	    f"""Available tasks classes are: {TokenClassificationTask.__subclasses__()}"""						)
											snake_case_ :Any						=			self.token_classification_task.get_labels(hparams.labels						)
											snake_case_ :str						=			CrossEntropyLoss().ignore_index
											super().__init__(snake_case						,     len(self.labels						)						,     self.mode						)






					def    lowerCAmelCase_				(       self:							Dict						,     **snake_case:							List[Any]						)   ->	Any:
											return self.model(**snake_case						)






					def    lowerCAmelCase_				(       self:							str						,     snake_case:							Tuple						,     snake_case:							List[Any]						)   ->	Optional[int]:
											snake_case_ :List[str]						=			{"""input_ids""": batch[0], """attention_mask""": batch[1], """labels""": batch[3]}
											if self.config.model_type != "distilbert":
																	snake_case_ :List[str]						=			(
																	    batch[2] if self.config.model_type in ["""bert""", """xlnet"""] else None
																	)  # XLM and RoBERTa don"t use token_type_ids

											snake_case_ :Optional[Any]						=			self(**snake_case						)
											snake_case_ :List[str]						=			outputs[0]
											# tensorboard_logs = {"loss": loss, "rate": self.lr_scheduler.get_last_lr()[-1]}
											return {"loss": loss}






					def    lowerCAmelCase_				(       self:							int						)   ->	Dict:
											snake_case_ :List[Any]						=			self.hparams
											for mode in ["train", "dev", "test"]:
																	snake_case_ :Optional[int]						=			self._feature_file(snake_case						)
																	if os.path.exists(snake_case						) and not args.overwrite_cache:
																							logger.info("""Loading features from cached file %s"""						,     snake_case						)
																							snake_case_ :Optional[int]						=			torch.load(snake_case						)
																	else:
																							logger.info("""Creating features from dataset file at %s"""						,     args.data_dir						)
																							snake_case_ :Optional[int]						=			self.token_classification_task.read_examples_from_file(args.data_dir						,     snake_case						)
																							snake_case_ :Any						=			self.token_classification_task.convert_examples_to_features(
																							    snake_case						,     self.labels						,     args.max_seq_length						,     self.tokenizer						,     cls_token_at_end=bool(self.config.model_type in ["""xlnet"""]						)						,     cls_token=self.tokenizer.cls_token						,     cls_token_segment_id=2 if self.config.model_type in ["""xlnet"""] else 0						,     sep_token=self.tokenizer.sep_token						,     sep_token_extra=snake_case						,     pad_on_left=bool(self.config.model_type in ["""xlnet"""]						)						,     pad_token=self.tokenizer.pad_token_id						,     pad_token_segment_id=self.tokenizer.pad_token_type_id						,     pad_token_label_id=self.pad_token_label_id						,     )
																							logger.info("""Saving features into cached file %s"""						,     snake_case						)
																							torch.save(snake_case						,     snake_case						)






					def    lowerCAmelCase_				(       self:							Optional[int]						,     snake_case:							int						,     snake_case:							int						,     snake_case:							bool = False						)   ->	DataLoader:
											snake_case_ :int						=			self._feature_file(snake_case						)
											logger.info("""Loading features from cached file %s"""						,     snake_case						)
											snake_case_ :str						=			torch.load(snake_case						)
											snake_case_ :Dict						=			torch.tensor([f.input_ids for f in features]						,     dtype=torch.long						)
											snake_case_ :str						=			torch.tensor([f.attention_mask for f in features]						,     dtype=torch.long						)
											if features[0].token_type_ids is not None:
																	snake_case_ :List[Any]						=			torch.tensor([f.token_type_ids for f in features]						,     dtype=torch.long						)
											else:
																	snake_case_ :List[str]						=			torch.tensor([0 for f in features]						,     dtype=torch.long						)
																	# HACK(we will not use this anymore soon)
											snake_case_ :Any						=			torch.tensor([f.label_ids for f in features]						,     dtype=torch.long						)
											return DataLoader(
											    TensorDataset(snake_case						,     snake_case						,     snake_case						,     snake_case						)						,     batch_size=snake_case						)






					def    lowerCAmelCase_				(       self:							List[str]						,     snake_case:							Dict						,     snake_case:							Union[str, Any]						)   ->	List[str]:
											"""Compute validation""" ""
											snake_case_ :List[str]						=			{"""input_ids""": batch[0], """attention_mask""": batch[1], """labels""": batch[3]}
											if self.config.model_type != "distilbert":
																	snake_case_ :Dict						=			(
																	    batch[2] if self.config.model_type in ["""bert""", """xlnet"""] else None
																	)  # XLM and RoBERTa don"t use token_type_ids
											snake_case_ :Dict						=			self(**snake_case						)
											snake_case_,       snake_case_ :Dict						=			outputs[:2]
											snake_case_ :Union[str, Any]						=			logits.detach().cpu().numpy()
											snake_case_ :List[Any]						=			inputs["""labels"""].detach().cpu().numpy()
											return {"val_loss": tmp_eval_loss.detach().cpu(), "pred": preds, "target": out_label_ids}






					def    lowerCAmelCase_				(       self:							List[Any]						,     snake_case:							int						)   ->	Tuple:
											snake_case_ :Union[str, Any]						=			torch.stack([x["""val_loss"""] for x in outputs]						).mean()
											snake_case_ :Tuple						=			np.concatenate([x["""pred"""] for x in outputs]						,     axis=0						)
											snake_case_ :Tuple						=			np.argmax(snake_case						,     axis=2						)
											snake_case_ :List[str]						=			np.concatenate([x["""target"""] for x in outputs]						,     axis=0						)

											snake_case_ :Optional[Any]						=			dict(enumerate(self.labels						)						)
											snake_case_ :Dict						=			[[] for _ in range(out_label_ids.shape[0]						)]
											snake_case_ :Dict						=			[[] for _ in range(out_label_ids.shape[0]						)]

											for i in range(out_label_ids.shape[0]						):
																	for j in range(out_label_ids.shape[1]						):
																							if out_label_ids[i, j] != self.pad_token_label_id:
																													out_label_list[i].append(label_map[out_label_ids[i][j]]						)
																													preds_list[i].append(label_map[preds[i][j]]						)

											snake_case_ :str						=			{
											    """val_loss""": val_loss_mean,
											    """accuracy_score""": accuracy_score(snake_case						,     snake_case						),
											    """precision""": precision_score(snake_case						,     snake_case						),
											    """recall""": recall_score(snake_case						,     snake_case						),
											    """f1""": fa_score(snake_case						,     snake_case						),
											}

											snake_case_ :List[Any]						=			dict(results.items()						)
											snake_case_ :Union[str, Any]						=			results
											return ret, preds_list, out_label_list






					def    lowerCAmelCase_				(       self:							Optional[Any]						,     snake_case:							Dict						)   ->	Optional[Any]:
											# when stable
											snake_case_,       snake_case_,       snake_case_ :Tuple						=			self._eval_end(snake_case						)
											snake_case_ :str						=			ret["""log"""]
											return {"val_loss": logs["val_loss"], "log": logs, "progress_bar": logs}






					def    lowerCAmelCase_				(       self:							Tuple						,     snake_case:							Optional[int]						)   ->	Any:
											# updating to test_epoch_end instead of deprecated test_end
											snake_case_,       snake_case_,       snake_case_ :Any						=			self._eval_end(snake_case						)

											# Converting to the dict required by pl
											# https://github.com/PyTorchLightning/pytorch-lightning/blob/master/\
											# pytorch_lightning/trainer/logging.py#L139
											snake_case_ :Optional[int]						=			ret["""log"""]
											# `val_loss` is the key returned by `self._eval_end()` but actually refers to `test_loss`
											return {"avg_test_loss": logs["val_loss"], "log": logs, "progress_bar": logs}






					@staticmethod
					def    lowerCAmelCase_				(       snake_case:							Any						,     snake_case:							int						)   ->	Dict:
											# Add NER specific options
											BaseTransformer.add_model_specific_args(snake_case						,     snake_case						)
											parser.add_argument(
											    """--task_type"""						,     default="""NER"""						,     type=snake_case						,     help="""Task type to fine tune in training (e.g. NER, POS, etc)"""						)
											parser.add_argument(
											    """--max_seq_length"""						,     default=128						,     type=snake_case						,     help=(
											        """The maximum total input sequence length after tokenization. Sequences longer """
											        """than this will be truncated, sequences shorter will be padded."""
											    )						,     )

											parser.add_argument(
											    """--labels"""						,     default=""""""						,     type=snake_case						,     help="""Path to a file containing all labels. If not specified, CoNLL-2003 labels are used."""						,     )
											parser.add_argument(
											    """--gpus"""						,     default=0						,     type=snake_case						,     help="""The number of GPUs allocated for this, it is by default 0 meaning none"""						,     )

											parser.add_argument(
											    """--overwrite_cache"""						,     action="""store_true"""						,     help="""Overwrite the cached training and evaluation sets"""						)

											return parser


if __name__ == "__main__":
						__a      =				argparse.ArgumentParser()
						add_generic_args(parser, os.getcwd())
						__a      =				NERTransformer.add_model_specific_args(parser, os.getcwd())
						__a      =				parser.parse_args()
						__a      =				NERTransformer(args)
						__a      =				generic_train(model, args)

						if args.do_predict:
												# See https://github.com/huggingface/transformers/issues/3159
												# pl use this default format to create a checkpoint:
												# https://github.com/PyTorchLightning/pytorch-lightning/blob/master\
												# /pytorch_lightning/callbacks/model_checkpoint.py#L322
												__a      =				sorted(glob.glob(os.path.join(args.output_dir, "checkpoint-epoch=*.ckpt"), recursive=True))
												__a      =				model.load_from_checkpoint(checkpoints[-1])
												trainer.test(model)
