From 325eab6a5fec3a3179234c3d4641741e2912b8a6 Mon Sep 17 00:00:00 2001 From: Kashif Ali Khan <113260067+kashifalikhan36@users.noreply.github.com> Date: Fri, 17 Jan 2025 21:32:16 +0530 Subject: [PATCH 1/3] Create recurrent-neural-networks.md --- .../recurrent-neural-networks.md | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 docs/algorithms/artificial-intelligence/reinforcement-learning/recurrent-neural-networks.md diff --git a/docs/algorithms/artificial-intelligence/reinforcement-learning/recurrent-neural-networks.md b/docs/algorithms/artificial-intelligence/reinforcement-learning/recurrent-neural-networks.md new file mode 100644 index 00000000..786ecc7b --- /dev/null +++ b/docs/algorithms/artificial-intelligence/reinforcement-learning/recurrent-neural-networks.md @@ -0,0 +1,96 @@ +# Recurrent Neural Networks (RNNs) + +
+ +
+ +## Overview +Recurrent Neural Networks (RNNs) are a class of neural networks designed to model sequential data. They are particularly effective for tasks involving time series, natural language processing, and any application where context is crucial. + +--- + +## How RNNs Work + +### 1. **Architecture** +RNNs process sequential data by maintaining a hidden state that captures information about previous inputs. Key components include: +- **Input Layer**: Accepts input data, often in a time-series format. +- **Recurrent Layer**: Includes connections between neurons that form loops, enabling memory of past computations. +- **Output Layer**: Produces predictions based on the current hidden state. + +### 2. **Key Concepts** +- **Hidden State**: Acts as memory, retaining context from prior inputs. +- **Weight Sharing**: Parameters are shared across time steps, reducing the complexity of the model. +- **Backpropagation Through Time (BPTT)**: A specialized training process to compute gradients over sequences. + +--- + +## RNN Variants + +### 1. **Basic RNN** +- **Use Case**: Simplest form of RNN, but struggles with long-term dependencies due to vanishing gradients. +- **Architecture**: + - Input → Hidden Layer → Output + - Hidden state is updated at each time step. + +### 2. **Long Short-Term Memory (LSTM)** +- **Proposed By**: Sepp Hochreiter and Jürgen Schmidhuber (1997) +- **Use Case**: Overcomes vanishing gradient issues in basic RNNs. +- **Key Features**: + - Incorporates **forget gates**, **input gates**, and **output gates**. + - Capable of learning long-term dependencies. + +### 3. **Gated Recurrent Unit (GRU)** +- **Proposed By**: Kyunghyun Cho et al. (2014) +- **Use Case**: Simplifies LSTM by combining forget and input gates. +- **Key Features**: + - Fewer parameters compared to LSTM. + - Suitable for smaller datasets or faster computation. + +### 4. **Bidirectional RNN** +- **Use Case**: Utilizes both past and future context for prediction. +- **Key Features**: + - Processes input sequences in both forward and backward directions. + +--- + +## Code Example: Implementing a Simple RNN + +Here’s a Python example of a basic RNN using **TensorFlow/Keras**: + +* **SimpleRNN:** Implements the recurrent layer. +* **LSTM/GRU:** Alternate layers that can replace SimpleRNN for enhanced performance. + +```python +from tensorflow.keras.models import Sequential +from tensorflow.keras.layers import SimpleRNN, Dense, Embedding + +# Build the RNN +model = Sequential([ + Embedding(input_dim=1000, output_dim=64), # Embedding for text data (vocab size: 1000) + SimpleRNN(128, activation='relu', return_sequences=False), + Dense(10, activation='softmax') # Replace 10 with the number of classes in your dataset +]) + +# Compile the model +model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) + +# Summary +model.summary() +``` + +--- + +# Visualizations +* **Hidden States**: Visualizing how the hidden states evolve over time. +* **Training Metrics**: Plotting accuracy and loss during training. + +```python +import matplotlib.pyplot as plt + +# Example: Visualizing accuracy and loss +plt.plot(history.history['accuracy'], label='Accuracy') +plt.plot(history.history['val_accuracy'], label='Validation Accuracy') +plt.xlabel('Epochs') +plt.ylabel('Accuracy') +plt.legend() +``` From 8f4e18ee080551b92dfb7f9e89aab25a53ab85d5 Mon Sep 17 00:00:00 2001 From: Kashif Ali Khan <113260067+kashifalikhan36@users.noreply.github.com> Date: Sun, 19 Jan 2025 13:25:24 +0530 Subject: [PATCH 2/3] Create recurrent-neural-networks.md --- .../recurrent-neural-networks.md | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 docs/algorithms/deep-learning/neural-networks/recurrent-neural-networks.md diff --git a/docs/algorithms/deep-learning/neural-networks/recurrent-neural-networks.md b/docs/algorithms/deep-learning/neural-networks/recurrent-neural-networks.md new file mode 100644 index 00000000..e72bb0fe --- /dev/null +++ b/docs/algorithms/deep-learning/neural-networks/recurrent-neural-networks.md @@ -0,0 +1,115 @@ +# Convolutional Neural Networks + +
+ +
+ +## Overview +Convolutional Neural Networks (CNNs) are a type of deep learning algorithm specifically designed for processing structured grid data such as images. They are widely used in computer vision tasks like image classification, object detection, and image segmentation. + +--- + +## How CNNs Work + +### 1. **Architecture** +CNNs are composed of the following layers: +- **Convolutional Layers**: Extract spatial features from the input data. +- **Pooling Layers**: Reduce the spatial dimensions of feature maps to lower computational costs. +- **Fully Connected Layers**: Perform high-level reasoning for final predictions. + +### 2. **Key Concepts** +- **Filters (Kernels)**: Small matrices that slide over the input to extract features. +- **Strides**: Step size of the filter movement. +- **Padding**: Adding borders to the input for better filter coverage. +- **Activation Functions**: Introduce non-linearity (e.g., ReLU). + +--- + +## CNN Algorithms + +### 1. **LeNet** +- **Proposed By**: Yann LeCun (1998) +- **Use Case**: Handwritten digit recognition (e.g., MNIST dataset). +- **Architecture**: + - Input → Convolution → Pooling → Convolution → Pooling → Fully Connected → Output + +### 2. **AlexNet** +- **Proposed By**: Alex Krizhevsky (2012) +- **Use Case**: ImageNet classification challenge. +- **Key Features**: + - Uses ReLU for activation. + - Includes dropout to prevent overfitting. + - Designed for GPUs for faster computation. + +### 3. **VGGNet** +- **Proposed By**: Visual Geometry Group (2014) +- **Use Case**: Image classification and transfer learning. +- **Key Features**: + - Uses small 3x3 filters. + - Depth of the network increases (e.g., VGG-16, VGG-19). + +### 4. **ResNet** +- **Proposed By**: Kaiming He et al. (2015) +- **Use Case**: Solving vanishing gradient problems in deep networks. +- **Key Features**: + - Introduces residual blocks with skip connections. + - Enables training of very deep networks (e.g., ResNet-50, ResNet-101). + +### 5. **MobileNet** +- **Proposed By**: Google (2017) +- **Use Case**: Mobile and embedded vision applications. +- **Key Features**: + - Utilizes depthwise separable convolutions. + - Lightweight architecture suitable for mobile devices. + +--- + +## Code Example: Implementing a Simple CNN + +Here’s a Python example of a CNN using **TensorFlow/Keras**: + +* **Sequential:** Used to stack layers to create a neural network model. +* **Conv2D:** Implements the convolutional layers to extract features from input images. +* **MaxPooling2D:** Reduces the size of feature maps while retaining important features. +* **Flatten:** Converts 2D feature maps into a 1D vector to pass into fully connected layers. +* **Dense:** Implements fully connected (dense) layers, responsible for decision-making. + + +```python +from tensorflow.keras.models import Sequential +from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense + +# Build the CNN +model = Sequential([ + Conv2D(32, (3, 3), activation='relu', input_shape=(64, 64, 3)), + MaxPooling2D(pool_size=(2, 2)), + Conv2D(64, (3, 3), activation='relu'), + MaxPooling2D(pool_size=(2, 2)), + Flatten(), + Dense(128, activation='relu'), + Dense(10, activation='softmax') # Replace 10 with the number of classes in your dataset +]) + +# Compile the model +model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy']) + +# Summary +model.summary() +``` + +--- + +# Visualizations +* **Filters and Feature Maps:** Visualizing how the CNN learns features from images. +* **Training Metrics:** Plotting accuracy and loss during training. + +```python +import matplotlib.pyplot as plt + +# Example: Visualizing accuracy and loss +plt.plot(history.history['accuracy'], label='Accuracy') +plt.plot(history.history['val_accuracy'], label='Validation Accuracy') +plt.xlabel('Epochs') +plt.ylabel('Accuracy') +plt.legend() +``` From 96b223bbdbfc862676bcd03c9d6bcf141813f196 Mon Sep 17 00:00:00 2001 From: Kashif Ali Khan <113260067+kashifalikhan36@users.noreply.github.com> Date: Sun, 19 Jan 2025 13:25:45 +0530 Subject: [PATCH 3/3] Delete docs/algorithms/artificial-intelligence/reinforcement-learning/recurrent-neural-networks.md --- .../recurrent-neural-networks.md | 96 ------------------- 1 file changed, 96 deletions(-) delete mode 100644 docs/algorithms/artificial-intelligence/reinforcement-learning/recurrent-neural-networks.md diff --git a/docs/algorithms/artificial-intelligence/reinforcement-learning/recurrent-neural-networks.md b/docs/algorithms/artificial-intelligence/reinforcement-learning/recurrent-neural-networks.md deleted file mode 100644 index 786ecc7b..00000000 --- a/docs/algorithms/artificial-intelligence/reinforcement-learning/recurrent-neural-networks.md +++ /dev/null @@ -1,96 +0,0 @@ -# Recurrent Neural Networks (RNNs) - -
- -
- -## Overview -Recurrent Neural Networks (RNNs) are a class of neural networks designed to model sequential data. They are particularly effective for tasks involving time series, natural language processing, and any application where context is crucial. - ---- - -## How RNNs Work - -### 1. **Architecture** -RNNs process sequential data by maintaining a hidden state that captures information about previous inputs. Key components include: -- **Input Layer**: Accepts input data, often in a time-series format. -- **Recurrent Layer**: Includes connections between neurons that form loops, enabling memory of past computations. -- **Output Layer**: Produces predictions based on the current hidden state. - -### 2. **Key Concepts** -- **Hidden State**: Acts as memory, retaining context from prior inputs. -- **Weight Sharing**: Parameters are shared across time steps, reducing the complexity of the model. -- **Backpropagation Through Time (BPTT)**: A specialized training process to compute gradients over sequences. - ---- - -## RNN Variants - -### 1. **Basic RNN** -- **Use Case**: Simplest form of RNN, but struggles with long-term dependencies due to vanishing gradients. -- **Architecture**: - - Input → Hidden Layer → Output - - Hidden state is updated at each time step. - -### 2. **Long Short-Term Memory (LSTM)** -- **Proposed By**: Sepp Hochreiter and Jürgen Schmidhuber (1997) -- **Use Case**: Overcomes vanishing gradient issues in basic RNNs. -- **Key Features**: - - Incorporates **forget gates**, **input gates**, and **output gates**. - - Capable of learning long-term dependencies. - -### 3. **Gated Recurrent Unit (GRU)** -- **Proposed By**: Kyunghyun Cho et al. (2014) -- **Use Case**: Simplifies LSTM by combining forget and input gates. -- **Key Features**: - - Fewer parameters compared to LSTM. - - Suitable for smaller datasets or faster computation. - -### 4. **Bidirectional RNN** -- **Use Case**: Utilizes both past and future context for prediction. -- **Key Features**: - - Processes input sequences in both forward and backward directions. - ---- - -## Code Example: Implementing a Simple RNN - -Here’s a Python example of a basic RNN using **TensorFlow/Keras**: - -* **SimpleRNN:** Implements the recurrent layer. -* **LSTM/GRU:** Alternate layers that can replace SimpleRNN for enhanced performance. - -```python -from tensorflow.keras.models import Sequential -from tensorflow.keras.layers import SimpleRNN, Dense, Embedding - -# Build the RNN -model = Sequential([ - Embedding(input_dim=1000, output_dim=64), # Embedding for text data (vocab size: 1000) - SimpleRNN(128, activation='relu', return_sequences=False), - Dense(10, activation='softmax') # Replace 10 with the number of classes in your dataset -]) - -# Compile the model -model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) - -# Summary -model.summary() -``` - ---- - -# Visualizations -* **Hidden States**: Visualizing how the hidden states evolve over time. -* **Training Metrics**: Plotting accuracy and loss during training. - -```python -import matplotlib.pyplot as plt - -# Example: Visualizing accuracy and loss -plt.plot(history.history['accuracy'], label='Accuracy') -plt.plot(history.history['val_accuracy'], label='Validation Accuracy') -plt.xlabel('Epochs') -plt.ylabel('Accuracy') -plt.legend() -```