<jupyter_start><jupyter_text>Model definitionLet's create a model with 2 Relu with Dropout hidden layers, and a Softmax output layer. Set the number of units in each hidden layer to 32, and use dropout rate of 0.2. Moreover, let's use Adam optimizer with `learn_rate = 0.001`, 10 iterations over batches of 128 elements.<jupyter_code>!pip install "thinc>=8.0.0a0" ml_datasets "tqdm>=4.41" "tensorflow>2.0"

# Perform operations on GPU if available
from thinc.api import prefer_gpu
prefer_gpu()

# Add src to sys.path

import sys
import os
from pathlib import PurePath

# add custom python modules root to the path variable,
root_path = PurePath(os.getcwd()).parents[0]
print(root_path)
src_path = str(root_path.joinpath('src'))

if src_path not in sys.path:
    sys.path.insert(0, str(src_path))

print(sys.path)


from tensorflow.keras.layers import Dense, Dropout
from tensorflow.keras.models import Sequential
from thinc.api import TensorFlowWrapper, Adam
import ml_datasets

width = 32
nI = 784
nO = 10
dropout = 0.2

tf_model = Sequential()
tf_model.add(Dense(width, activation="relu", input_shape=(nI,)))
tf_model.add(Dropout(dropout))
tf_model.add(Dense(width, activation="relu", input_shape=(nI,)))
tf_model.add(Dropout(dropout))
tf_model.add(Dense(nO, activation="softmax"))

wrapped_tf_model = TensorFlowWrapper(tf_model)
wrapped_tf_model
# You can use this training code to train the model:

(train_X, train_Y), (test_X, test_Y) = ml_datasets.mnist()
optimizer = Adam(0.001)
# wrapped_tf_model.initialize(X=train_X[:5], Y=train_Y[:5])

from train import train_model
train_model(((train_X, train_Y), (test_X, test_Y)), wrapped_tf_model, optimizer, n_iter=10, batch_size=128)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11143523920653442, 'fraction_numerical': 0.026254375729288213, 'mean_word_length': 6.329059829059829, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '347734', 'license': 'MIT', 'n_tokens_mistral': 640, 'n_tokens_neox': 605, 'n_words': 169, 'path': 'notebooks/_6_1_wrapping_tensorflow.ipynb', 'repo_name': 'jmetzz/sandbox-thinc.ai', 'size': '1714'}