



import numpy as np
from matplotlib import pyplot as plt
from sklearn.datasets import load_iris
from sklearn.metrics import ConfusionMatrixDisplay
from sklearn.model_selection import train_test_split
from xgboost import XGBClassifier






def     __a					(		__UpperCAmelCase       ):
 return (data["data"], data["target"])






def     __a					(		__UpperCAmelCase							,  __UpperCAmelCase       ):
 a__												= XGBClassifier()
 classifier.fit(__UpperCAmelCase							,  __UpperCAmelCase       )
 return classifier






def     __a					(		):
 a__												= load_iris()
 a__							,			a__												= data_handling(__UpperCAmelCase       )
 a__							,			a__							,			a__							,			a__												= train_test_split(
     __UpperCAmelCase							,  __UpperCAmelCase							,  test_size=0.25       )

 a__												= iris['''target_names''']

 # Create an XGBoost Classifier from the training data
 a__												= xgboost(__UpperCAmelCase							,  __UpperCAmelCase       )

 # Display the confusion matrix of the classifier with both training and test sets
 ConfusionMatrixDisplay.from_estimator(
     __UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase							,  display_labels=__UpperCAmelCase							,  cmap='''Blues'''							,  normalize='''true'''							,  )
 plt.title('''Normalized Confusion Matrix - IRIS Dataset'''       )
 plt.show()


if __name__ == "__main__":
     import doctest

     doctest.testmod(verbose=True)
     main()










import argparse
import os

import numpy as np
import tensorflow as tf
import torch

from transformers import BertModel






def     __a					(		__UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase       ):
 a__												= ('''dense.weight''', '''attention.self.query''', '''attention.self.key''', '''attention.self.value''')

 a__												= (
     ('''layer.''', '''layer_'''),
     ('''word_embeddings.weight''', '''word_embeddings'''),
     ('''position_embeddings.weight''', '''position_embeddings'''),
     ('''token_type_embeddings.weight''', '''token_type_embeddings'''),
     ('''.''', '''/'''),
     ('''LayerNorm/weight''', '''LayerNorm/gamma'''),
     ('''LayerNorm/bias''', '''LayerNorm/beta'''),
     ('''weight''', '''kernel'''),
 )

 if not os.path.isdir(__UpperCAmelCase       ):
  os.makedirs(__UpperCAmelCase       )

 a__												= model.state_dict()

 def to_tf_var_name(__UpperCAmelCase       ):
  for patt, repl in iter(__UpperCAmelCase       ):
   a__												= name.replace(__UpperCAmelCase							,  __UpperCAmelCase       )
  return f"bert/{name}"

 def create_tf_var(__UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase       ):
  a__												= tf.dtypes.as_dtype(tensor.dtype       )
  a__												= tf.get_variable(dtype=__UpperCAmelCase							,  shape=tensor.shape							,  name=__UpperCAmelCase							,  initializer=tf.zeros_initializer()       )
  session.run(tf.variables_initializer([tf_var]       )       )
  session.run(__UpperCAmelCase       )
  return tf_var

 tf.reset_default_graph()
 with tf.Session() as session:
  for var_name in state_dict:
   a__												= to_tf_var_name(__UpperCAmelCase       )
   a__												= state_dict[var_name].numpy()
   if any(x in var_name for x in tensors_to_transpose       ):
    a__												= torch_tensor.T
   a__												= create_tf_var(tensor=__UpperCAmelCase							,  name=__UpperCAmelCase							,  session=__UpperCAmelCase       )
   tf.keras.backend.set_value(__UpperCAmelCase							,  __UpperCAmelCase       )
   a__												= session.run(__UpperCAmelCase       )
   print(f"Successfully created {tf_name}: {np.allclose(__UpperCAmelCase							,  __UpperCAmelCase       )}"       )

  a__												= tf.train.Saver(tf.trainable_variables()       )
  saver.save(__UpperCAmelCase							,  os.path.join(__UpperCAmelCase							,  model_name.replace('''-'''							,  '''_'''       ) + '''.ckpt'''       )       )






def     __a					(		__UpperCAmelCase=None       ):
 a__												= argparse.ArgumentParser()
 parser.add_argument('''--model_name'''							,  type=__UpperCAmelCase							,  required=__UpperCAmelCase							,  help='''model name e.g. bert-base-uncased'''       )
 parser.add_argument(
     '''--cache_dir'''							,  type=__UpperCAmelCase							,  default=__UpperCAmelCase							,  required=__UpperCAmelCase							,  help='''Directory containing pytorch model'''       )
 parser.add_argument('''--pytorch_model_path'''							,  type=__UpperCAmelCase							,  required=__UpperCAmelCase							,  help='''/path/to/<pytorch-model-name>.bin'''       )
 parser.add_argument('''--tf_cache_dir'''							,  type=__UpperCAmelCase							,  required=__UpperCAmelCase							,  help='''Directory in which to save tensorflow model'''       )
 a__												= parser.parse_args(__UpperCAmelCase       )

 a__												= BertModel.from_pretrained(
     pretrained_model_name_or_path=args.model_name							,  state_dict=torch.load(args.pytorch_model_path       )							,  cache_dir=args.cache_dir							,  )

 convert_pytorch_checkpoint_to_tf(model=__UpperCAmelCase							,  ckpt_dir=args.tf_cache_dir							,  model_name=args.model_name       )


if __name__ == "__main__":
     main()





