<jupyter_start><jupyter_text>Introduction to Keras

Keras is an API designed for human beings, not machines. Keras follows best practices for reducing cognitive load: it offers consistent & simple APIs, it minimizes the number of user actions required for common use cases, and it provides clear & actionable error messages. It also has extensive documentation and developer guides. Keras is a wrapper around a backend library, so a backend like TensorFlow must be provided.

 A simple neural network!

You will build a network that takes two numbers as an input, passes them through a hidden layer of 10 neurons, and finally outputs a single number.<jupyter_code># Import the Sequential model and Dense layer
from keras.models import Sequential
from keras.layers import Dense

# Create a Sequential model
model = Sequential()

# Add an input layer and a hidden layer with 10 neurons
model.add(Dense(10, input_shape=(2,), activation="relu"))

# Add a 1-neuron output layer
model.add(Dense(1))

# Summarise your model
model.summary()<jupyter_output>Model: "sequential"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
dense (Dense)                (None, 10)                30        
_________________________________________________________________
dense_1 (Dense)              (None, 1)                 11        
=================================================================
Total params: 41
Trainable params: 41
Non-trainable params: 0
_________________________________________________________________<jupyter_text>Analyzing the number of parameters:

dense: 2 * 10 + 1 * 10 = 20 + 10 = 30

dense_1: 10 * 1 + 1 = 11<jupyter_code>from tensorflow.keras.utils import plot_model
plot_model(model, to_file='basic-net.png', show_shapes=True)
!pip install ann_visualizer
from ann_visualizer.visualize import ann_viz
ann_viz(model, title="Artificial Neural network - Model Visualization")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1186359269932757, 'fraction_numerical': 0.0196926032660903, 'mean_word_length': 4.481578947368421, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '230551', 'license': 'MIT', 'n_tokens_mistral': 559, 'n_tokens_neox': 498, 'n_words': 207, 'path': 'Basic_Neural_Nets.ipynb', 'repo_name': 'debolina201/Building-Neural-Nets-with-Keras', 'size': '2082'}