<jupyter_start><jupyter_text>SingleLayerPerceptron base hypermodel<jupyter_code>def build_SLP(hp):
    embedding_dim = hp.Choice('features_embedding_dim',
                              [1, 3, 6])
    X_train_embedding_layers = {}
    for input_name in X_train.columns:
        X_train_embedding_layers[input_name] = StringEmbedding(X_train[input_name].unique(),
                                                               embedding_dim)

    processing_layer = InputsProcessing(X_train_embedding_layers)

    SLP = SingleLayerPerceptron(tf.keras.layers.Dense(4,
                                                      activation='softmax'),
                                processing_layer=processing_layer)
    SLP.compile(loss='categorical_crossentropy',
                optimizer=tf.keras.optimizers.Adam(learning_rate=hp.Choice('learning_rate',
                                                                           [.01, .005, .001, .0005, .0001])),
                metrics=['acc'])
    return SLP<jupyter_output><empty_output><jupyter_text>Cross validation random search<jupyter_code>hyper_model_CV = HyperModelCrossValidation(build_model=build_SLP,
                                           nbr_folds=5,
                                           batch_sizes_to_try_list=[8, 16])

tuner = kt.RandomSearch(
    hypermodel=hyper_model_CV,
    objective="val_loss",
    max_trials=15,
    executions_per_trial=1,
    overwrite=True,
    directory="keras_tuners_logs",
    project_name="test_HyperModelCrossValidation",
)  # set 'overwrite' to true to resume a previous search

tuner.search(X_train_dict,
             y_train,
             epochs=10)
tuner.results_summary(1)
train_tensor = tf.data.Dataset.from_tensor_slices((X_train_dict,
                                                   y_train))
train_tensor = train_tensor.cache().shuffle(300).batch(8).prefetch(buffer_size=tf.data.experimental.AUTOTUNE)

test_tensor = tf.data.Dataset.from_tensor_slices((X_test_dict,
                                                  y_test)).batch(8)

best_hyperparameters = tuner.get_best_hyperparameters(1)[0]
SLP = build_SLP(best_hyperparameters)
history = SLP.fit(train_tensor,
                  epochs=10,
                  verbose=1)
SLP.evaluate(test_tensor)<jupyter_output>44/44 [==============================] - 0s 2ms/step - loss: 0.1581 - acc: 0.9249
{'fraction_non_alphanumeric': 0.10406091370558376, 'fraction_numerical': 0.023688663282571912, 'mean_word_length': 2.136604774535809, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '593916', 'license': 'MIT', 'n_tokens_mistral': 732, 'n_tokens_neox': 686, 'n_words': 85, 'path': 'test_HyperModelCrossValidation.ipynb', 'repo_name': 'LorisPilotto/LorisBallsBasedModel', 'size': '2364'}