×
1 Choose EITC/EITCA Certificates
2 Learn and take online exams
3 Get your IT skills certified

Confirm your IT skills and competencies under the European IT Certification framework from anywhere in the world fully online.

EITCA Academy

Digital skills attestation standard by the European IT Certification Institute aiming to support Digital Society development

LOG IN TO YOUR ACCOUNT

CREATE AN ACCOUNT FORGOT YOUR PASSWORD?

FORGOT YOUR PASSWORD?

AAH, WAIT, I REMEMBER NOW!

CREATE AN ACCOUNT

ALREADY HAVE AN ACCOUNT?
EUROPEAN INFORMATION TECHNOLOGIES CERTIFICATION ACADEMY - ATTESTING YOUR PROFESSIONAL DIGITAL SKILLS
  • SIGN UP
  • LOGIN
  • INFO

EITCA Academy

EITCA Academy

The European Information Technologies Certification Institute - EITCI ASBL

Certification Provider

EITCI Institute ASBL

Brussels, European Union

Governing European IT Certification (EITC) framework in support of the IT professionalism and Digital Society

  • CERTIFICATES
    • EITCA ACADEMIES
      • EITCA ACADEMIES CATALOGUE<
      • EITCA/CG COMPUTER GRAPHICS
      • EITCA/IS INFORMATION SECURITY
      • EITCA/BI BUSINESS INFORMATION
      • EITCA/KC KEY COMPETENCIES
      • EITCA/EG E-GOVERNMENT
      • EITCA/WD WEB DEVELOPMENT
      • EITCA/AI ARTIFICIAL INTELLIGENCE
    • EITC CERTIFICATES
      • EITC CERTIFICATES CATALOGUE<
      • COMPUTER GRAPHICS CERTIFICATES
      • WEB DESIGN CERTIFICATES
      • 3D DESIGN CERTIFICATES
      • OFFICE IT CERTIFICATES
      • BITCOIN BLOCKCHAIN CERTIFICATE
      • WORDPRESS CERTIFICATE
      • CLOUD PLATFORM CERTIFICATENEW
    • EITC CERTIFICATES
      • INTERNET CERTIFICATES
      • CRYPTOGRAPHY CERTIFICATES
      • BUSINESS IT CERTIFICATES
      • TELEWORK CERTIFICATES
      • PROGRAMMING CERTIFICATES
      • DIGITAL PORTRAIT CERTIFICATE
      • WEB DEVELOPMENT CERTIFICATES
      • DEEP LEARNING CERTIFICATESNEW
    • CERTIFICATES FOR
      • EU PUBLIC ADMINISTRATION
      • TEACHERS AND EDUCATORS
      • IT SECURITY PROFESSIONALS
      • GRAPHICS DESIGNERS & ARTISTS
      • BUSINESSMEN AND MANAGERS
      • BLOCKCHAIN DEVELOPERS
      • WEB DEVELOPERS
      • CLOUD AI EXPERTSNEW
  • FEATURED
  • SUBSIDY
  • HOW IT WORKS
  •   IT ID
  • ABOUT
  • CONTACT
  • MY ORDER
    Your current order is empty.
EITCIINSTITUTE
CERTIFIED

Does the activation function run on the input or output data of a layer?

by dkarayiannakis / Monday, 17 June 2024 / Published in Artificial Intelligence, EITC/AI/DLPP Deep Learning with Python and PyTorch, Neural network, Building neural network

In the context of deep learning and neural networks, the activation function is a important component that operates on the output data of a layer. This process is integral to introducing non-linearity into the model, enabling it to learn complex patterns and relationships within the data. To elucidate this concept comprehensively, let us consider the mechanics of neural networks, the role of activation functions, and how they are applied to the output data of layers.

Neural Network Structure

A neural network consists of multiple layers, each comprising several neurons or nodes. These layers can be categorized into three types:

1. Input Layer: This is the first layer of the network, which receives the raw input data.
2. Hidden Layers: These layers are situated between the input and output layers. They perform various computations and transformations on the data.
3. Output Layer: This is the final layer of the network, which produces the output predictions.

Each neuron in a layer is connected to neurons in the subsequent layer through weighted connections. The weights and biases associated with these connections are learned during the training process to minimize the error in predictions.

Role of Activation Functions

Activation functions are mathematical functions applied to the output of each neuron in a layer before passing it to the next layer. The primary purposes of activation functions are:

1. Introduction of Non-Linearity: Without activation functions, neural networks would merely be linear models, regardless of the number of layers. Linear models are limited in their ability to capture complex patterns in data. Activation functions introduce non-linearity, enabling the network to learn and approximate more intricate functions.
2. Normalization: Activation functions can also help in normalizing the output of neurons, ensuring that the values remain within a specific range. This can prevent issues such as exploding or vanishing gradients during training.

Application of Activation Functions

Activation functions operate on the output data of a layer, which is the result of the weighted sum of inputs plus a bias term. Mathematically, this can be represented as follows for a single neuron:

    \[ z = \sum_{i=1}^{n} w_i x_i + b \]

where:
– z is the pre-activation output.
– w_i are the weights.
– x_i are the input features.
– b is the bias term.

The activation function \phi(z) is then applied to this pre-activation output z to produce the final output of the neuron:

    \[ a = \phi(z) \]

This activated output a is then passed as input to the neurons in the next layer.

Common Activation Functions

Several activation functions are commonly used in deep learning, each with its unique properties and applications. Some of the most prevalent ones include:

1. Sigmoid Function: The sigmoid function squashes the input values to a range between 0 and 1. It is defined as:

    \[ \sigma(z) = \frac{1}{1 + e^{-z}} \]

The sigmoid function is often used in binary classification problems. However, it can suffer from the vanishing gradient problem, where gradients become very small for large positive or negative input values, slowing down the training process.

2. Hyperbolic Tangent (Tanh) Function: The tanh function maps input values to a range between -1 and 1. It is defined as:

    \[ \tanh(z) = \frac{e^z - e^{-z}}{e^z + e^{-z}} \]

The tanh function is similar to the sigmoid function but has a broader output range, making it more suitable for hidden layers in some cases.

3. Rectified Linear Unit (ReLU): The ReLU function is defined as:

    \[ \text{ReLU}(z) = \max(0, z) \]

ReLU is widely used due to its simplicity and effectiveness. It helps mitigate the vanishing gradient problem and allows for faster training. However, ReLU can suffer from the "dying ReLU" problem, where neurons can become inactive if they output zero for all inputs.

4. Leaky ReLU: To address the dying ReLU problem, the Leaky ReLU introduces a small slope for negative input values. It is defined as:

    \[ \text{Leaky ReLU}(z) = \begin{cases}  z & \text{if } z \geq 0 \\ \alpha z & \text{if } z < 0  \end{cases} \]

where \alpha is a small positive constant.

5. Softmax Function: The softmax function is typically used in the output layer of a neural network for multi-class classification problems. It converts the raw output scores into probabilities that sum to 1. It is defined as:

    \[ \text{softmax}(z_i) = \frac{e^{z_i}}{\sum_{j=1}^{K} e^{z_j}} \]

where K is the number of classes.

Implementation in PyTorch

In PyTorch, activation functions are readily available in the `torch.nn` module. Here is an example of how to implement a simple neural network with activation functions in PyTorch:

python
import torch
import torch.nn as nn
import torch.optim as optim

class SimpleNN(nn.Module):
    def __init__(self):
        super(SimpleNN, self).__init__()
        self.fc1 = nn.Linear(784, 128)  # Fully connected layer 1
        self.fc2 = nn.Linear(128, 64)   # Fully connected layer 2
        self.fc3 = nn.Linear(64, 10)    # Fully connected layer 3
        
        # Activation functions
        self.relu = nn.ReLU()
        self.softmax = nn.Softmax(dim=1)
    
    def forward(self, x):
        x = self.fc1(x)
        x = self.relu(x)  # Applying ReLU activation function
        x = self.fc2(x)
        x = self.relu(x)  # Applying ReLU activation function
        x = self.fc3(x)
        x = self.softmax(x)  # Applying Softmax activation function
        return x

# Example usage
model = SimpleNN()
criterion = nn.CrossEntropyLoss()
optimizer = optim.SGD(model.parameters(), lr=0.01)

# Dummy input data
input_data = torch.randn(64, 784)  # Batch size of 64, 784 features
target_labels = torch.randint(0, 10, (64,))  # Random target labels

# Forward pass
output = model(input_data)
loss = criterion(output, target_labels)

# Backward pass and optimization
loss.backward()
optimizer.step()

In this example, we define a simple neural network with three fully connected layers. We apply the ReLU activation function after the first and second layers to introduce non-linearity. Finally, we apply the softmax activation function in the output layer to obtain probability distributions for multi-class classification.Activation functions are essential in neural networks for introducing non-linearity and enabling the model to learn complex patterns. They are applied to the output data of a layer, transforming the pre-activation output into the activated output that is passed to the next layer. Various activation functions, such as sigmoid, tanh, ReLU, and softmax, serve different purposes and are chosen based on the specific requirements of the task at hand. PyTorch provides convenient implementations of these functions, facilitating the construction and training of neural networks.

Other recent questions and answers regarding Building neural network:

  • What is the function used in PyTorch to send a neural network to a processing unit which would create a specified neural network on a specified device?
  • In which cases neural networks can modify weights independently?
  • Does Keras differ from PyTorch in the way that PyTorch implements a built-in method for flattening the data, while Keras does not, and hence Keras requires manual solutions like for example passing fake data through the model?
  • How to measure the complexity of a neural network in terms of a number of variables and how large are some biggest neural networks models under such comparison?
  • How does data flow through a neural network in PyTorch, and what is the purpose of the forward method?
  • What is the purpose of the initialization method in the 'NNet' class?
  • Why do we need to flatten images before passing them through the network?
  • How do we define the fully connected layers of a neural network in PyTorch?
  • What libraries do we need to import when building a neural network using Python and PyTorch?

More questions and answers:

  • Field: Artificial Intelligence
  • Programme: EITC/AI/DLPP Deep Learning with Python and PyTorch (go to the certification programme)
  • Lesson: Neural network (go to related lesson)
  • Topic: Building neural network (go to related topic)
Tagged under: Activation Functions, Artificial Intelligence, Deep Learning, Machine Learning, Neural Networks, PyTorch
Home » Artificial Intelligence » EITC/AI/DLPP Deep Learning with Python and PyTorch » Neural network » Building neural network » » Does the activation function run on the input or output data of a layer?

Certification Center

USER MENU

  • My Account

CERTIFICATE CATEGORY

  • EITC Certification (117)
  • EITCA Certification (9)

What are you looking for?

  • Introduction
  • How it works?
  • EITCA Academies
  • EITCI DSJC Subsidy
  • Full EITC catalogue
  • Your order
  • Featured
  •   IT ID
  • EITCA reviews (Medium publ.)
  • About
  • Contact

EITCA Academy is a part of the European IT Certification framework

The European IT Certification framework has been established in 2008 as a Europe based and vendor independent standard in widely accessible online certification of digital skills and competencies in many areas of professional digital specializations. The EITC framework is governed by the European IT Certification Institute (EITCI), a non-profit certification authority supporting information society growth and bridging the digital skills gap in the EU.
Eligibility for EITCA Academy 90% EITCI DSJC Subsidy support
90% of EITCA Academy fees subsidized in enrolment

    EITCA Academy Secretary Office

    European IT Certification Institute ASBL
    Brussels, Belgium, European Union

    EITC / EITCA Certification Framework Operator
    Governing European IT Certification Standard
    Access contact form or call +32 25887351

    Follow EITCI on X
    Visit EITCA Academy on Facebook
    Engage with EITCA Academy on LinkedIn
    Check out EITCI and EITCA videos on YouTube

    Funded by the European Union

    Funded by the European Regional Development Fund (ERDF) and the European Social Fund (ESF) in series of projects since 2007, currently governed by the European IT Certification Institute (EITCI) since 2008

    Information Security Policy | DSRRM and GDPR Policy | Data Protection Policy | Record of Processing Activities | HSE Policy | Anti-Corruption Policy | Modern Slavery Policy

    Automatically translate to your language

    Terms and Conditions | Privacy Policy
    EITCA Academy
    • EITCA Academy on social media
    EITCA Academy


    © 2008-2026  European IT Certification Institute
    Brussels, Belgium, European Union

    TOP

    We care about your privacy

    EITCI uses cookies and similar technologies to keep this site secure, remember your choices, provide personalized experience, measure the traffic, serve more relevant content and certification programmes. You can accept all cookies or customize your preferences. Cookies are variables used to store website specific information on your device to facilitate processing of data for personalized website visit, such as login to your account, accessing the programmes, placing enrolment orders in chosen programmes and improving your EITC certification journey. You can change or withdraw your consent at any time by clicking the Consent Preferences button at the left-bottom of your screen. We respect your choices and are committed to providing you with a transparent and secure browsing experience, which may be limited when cookies aren't accepted. For more details refer to the Privacy Policy
    Customize Consent Preferences
    We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.
    The cookies categorized as Necessary are stored on your browser as they are essential for enabling the basic functionalities of the site.
    To learn more about how Google processes personal information, visit: Google privacy policy

    Necessary

    Always Active

    Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

    Functional

    Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

    Preferences

    Stores personalization choices such as interface preferences.

    External media and social features

    Allows embedded video, social, chat, and external interactive services that may set their own cookies. Keep off until the user chooses these features.

    Analytics

    Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

    Marketing and conversions

    Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

    CHAT WITH SUPPORT
    Do you have any questions?
    Attach files with the paperclip or paste screenshots into the message box (Ctrl+V). Max 5 file(s), 10 MB each.
    We will reply here and by email. Your conversation is tracked with a support token.