<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Felix Kiprotich</title>
    <description>The latest articles on DEV Community by Felix Kiprotich (@penscola).</description>
    <link>https://dev.to/penscola</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1426735%2Fe15d6c0f-1b86-47c9-8662-eb188168a0ad.jpeg</url>
      <title>DEV Community: Felix Kiprotich</title>
      <link>https://dev.to/penscola</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/penscola"/>
    <language>en</language>
    <item>
      <title>Unveiling the Depths of Deep Learning</title>
      <dc:creator>Felix Kiprotich</dc:creator>
      <pubDate>Sun, 12 Jan 2025 18:58:17 +0000</pubDate>
      <link>https://dev.to/penscola/unveiling-the-depths-of-deep-learning-38mf</link>
      <guid>https://dev.to/penscola/unveiling-the-depths-of-deep-learning-38mf</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Deep learning is a subset of machine learning that involves training artificial neural networks with multiple layers (deep neural networks) to automatically learn and make decisions without explicit programming. Its significance in artificial intelligence (AI) and data science lies in its ability to handle complex tasks and extract meaningful patterns from large datasets.&lt;/p&gt;

&lt;h4&gt;
  
  
  Significance in AI and Data Science:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Complex Pattern Recognition: Deep learning excels at recognizing intricate patterns and features in data, allowing it to solve complex problems that may be challenging for traditional algorithms.&lt;/li&gt;
&lt;li&gt;Hierarchical Learning: Deep neural networks can automatically learn hierarchical representations of data, capturing abstract and nuanced information through layers of interconnected nodes.&lt;/li&gt;
&lt;li&gt;Adaptability: Deep learning models can adapt and improve their performance over time as they are exposed to more data, making them suitable for dynamic and evolving environments.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Real-World Applications:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Image Recognition: Deep learning powers advanced image recognition systems, enabling applications like facial recognition, object detection, and autonomous vehicles to accurately interpret visual data.&lt;/li&gt;
&lt;li&gt;Natural Language Processing (NLP): In NLP, deep learning is used for tasks such as sentiment analysis, language translation, and chatbot interactions, making machines more proficient in understanding and generating human language.&lt;/li&gt;
&lt;li&gt;Speech Recognition: Deep learning algorithms are employed in speech recognition systems, allowing devices like virtual assistants to understand and respond to spoken commands.&lt;/li&gt;
&lt;li&gt;Healthcare: Deep learning is applied in medical image analysis for tasks like diagnosing diseases from medical scans. It also plays a role in drug discovery and personalized medicine.&lt;/li&gt;
&lt;li&gt;Finance: In finance, deep learning models are utilized for fraud detection, risk assessment, and predicting market trends by analyzing large and complex financial datasets.&lt;/li&gt;
&lt;li&gt;Autonomous Vehicles: Deep learning contributes to the development of self-driving cars by enabling them to perceive and interpret their surroundings through sensors and cameras.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Neural Networks:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fosffg600tisvc2cyf5bo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fosffg600tisvc2cyf5bo.png" alt="Image description" width="581" height="287"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A neural network is a computational model inspired by the structure and function of the human brain. It consists of interconnected nodes organized into layers. These nodes, or artificial neurons, process information and learn from data, allowing the network to make predictions or decisions without explicit programming. Neural networks are the fundamental building blocks of deep learning.&lt;/p&gt;

&lt;h4&gt;
  
  
  Layers and Nodes:
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fapgzepxm5qbbwzehv0zf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fapgzepxm5qbbwzehv0zf.png" alt="Image description" width="509" height="255"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Neural networks are organized into layers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input Layer: Receives the initial data.&lt;/li&gt;
&lt;li&gt;Hidden Layers: Intermediate layers between the input and output layers where computations and learning take place.&lt;/li&gt;
&lt;li&gt;Output Layer: Produces the final output or prediction.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nodes within each layer process information. The connections between nodes have associated weights, which are adjusted during the learning process to optimize the network’s performance.&lt;/p&gt;

&lt;h4&gt;
  
  
  Activation Functions:
&lt;/h4&gt;

&lt;p&gt;Activation functions introduce non-linearity to the neural network, enabling it to learn and approximate complex relationships in data. Common activation functions include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sigmoid: Squeezes values between 0 and 1, often used in the output layer for binary classification.&lt;/li&gt;
&lt;li&gt;ReLU (Rectified Linear Unit): Outputs the input for positive values and zero for negative values, commonly used in hidden layers.&lt;/li&gt;
&lt;li&gt;Tanh: Similar to the sigmoid but maps values between -1 and 1.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Activation functions add flexibility to the model, allowing it to capture and represent a wide range of patterns and features in the data.&lt;/p&gt;

&lt;p&gt;Back propagation Algorithm: Backpropagation is the optimization algorithm used to train neural networks. It involves the following steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Forward Pass: Input data is passed through the network to make predictions.&lt;/li&gt;
&lt;li&gt;Calculate Error: The difference between the predicted output and the actual target is calculated.&lt;/li&gt;
&lt;li&gt;Backward Pass (Backpropagation): The error is propagated backward through the network.&lt;/li&gt;
&lt;li&gt;Update Weights: The weights of the connections are adjusted to minimize the error, using optimization techniques like gradient descent.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Backpropagation iteratively adjusts the weights, optimizing the network to make more accurate predictions over time. This process is crucial for the learning and adaptation of the neural network to the underlying patterns in the data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of Neural Networks
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Feed-forward Neural Networks (FNN):
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgsliurwynlulfznpkvp6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgsliurwynlulfznpkvp6.png" alt="Image description" width="525" height="236"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Structure&lt;/strong&gt;: In FNNs, information flows in one direction, from the input layer through hidden layers to the output layer. There are no cycles or loops in the network.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Cases:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Classification: FNNs are commonly used for tasks like image classification, where the goal is to assign input data to predefined categories.&lt;/li&gt;
&lt;li&gt;Regression: They are effective for predicting continuous values, such as predicting the price of a house based on various features.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Convolutional Neural Networks (CNNs):
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4fbgot90v6pw9lz18rqy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4fbgot90v6pw9lz18rqy.png" alt="Image description" width="525" height="235"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Structure:&lt;/strong&gt; CNNs are designed for processing structured grid data, like images. They consist of convolutional layers that learn spatial hierarchies of features.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Cases:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Image Recognition: CNNs excel in tasks like object detection and recognition within images. They can identify patterns and features hierarchically, making them powerful for visual tasks.&lt;/li&gt;
&lt;li&gt;Image Generation: CNNs are used in generative models for tasks like image synthesis and style transfer.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Recurrent Neural Networks (RNNs):
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feqpmadl3jlvwx0netbn7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feqpmadl3jlvwx0netbn7.png" alt="Image description" width="640" height="329"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Structure:&lt;/strong&gt; RNNs have connections that create loops, allowing information to persist. This makes them well-suited for sequential data processing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Cases:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Natural Language Processing (NLP): RNNs are used for language modeling, text generation, and machine translation. They can capture contextual information in sequences of words.&lt;/li&gt;
&lt;li&gt;Time Series Prediction: RNNs are effective for predicting future values in time series data, such as stock prices or weather patterns.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each type of neural network has its strengths and is tailored for specific tasks. Choosing the right architecture depends on the nature of the data and the problem at hand. Combining these architectures in hybrid models is also common for addressing more complex challenges.&lt;/p&gt;

&lt;h2&gt;
  
  
  Training Deep Learning Models
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Data Preprocessing and Normalization:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Data Cleaning: Remove or handle missing data, outliers, or irrelevant features to ensure a clean dataset.&lt;/li&gt;
&lt;li&gt;Normalization: Scale features to a similar range to prevent certain features from dominating others. Common methods include Min-Max scaling or Z-score normalization.&lt;/li&gt;
&lt;li&gt;Data Augmentation: Generate additional training samples by applying random transformations (rotations, flips, etc.) to the existing data. This helps improve model generalization.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Loss Functions and Optimization Algorithms:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Loss Functions: Measure the difference between the predicted output and the actual target. Common loss functions include Mean Squared Error (MSE) for regression and Cross-Entropy for classification tasks.&lt;/li&gt;
&lt;li&gt;Optimization Algorithms: Adjust model parameters to minimize the loss function during training. Gradient Descent and its variants (Adam, RMSprop) are popular optimization algorithms. They iteratively update weights to find the optimal values.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Overfitting and Regularization Techniques:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Overfitting: Occurs when a model learns the training data too well, performing poorly on new, unseen data.&lt;/li&gt;
&lt;li&gt;Regularization Techniques:&lt;/li&gt;
&lt;li&gt;L1 and L2 Regularization: Add penalty terms to the loss function based on the magnitudes of the weights, discouraging overly complex models.&lt;/li&gt;
&lt;li&gt;Dropout: Randomly deactivate a fraction of neurons during training to prevent over-reliance on specific nodes.&lt;/li&gt;
&lt;li&gt;Early Stopping: Monitor the validation loss during training and stop when it starts increasing, preventing overfitting.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These techniques collectively contribute to creating a robust and well-generalized deep learning model. The key is finding the right balance between model complexity and the ability to generalize to new, unseen data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deep Learning Frameworks
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Popular Deep Learning Frameworks:
&lt;/h4&gt;

&lt;h5&gt;
  
  
  TensorFlow:
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Developed by Google Brain, TensorFlow is an open-source deep learning framework widely used in both research and industry.&lt;/li&gt;
&lt;li&gt;TensorFlow provides a comprehensive ecosystem for building and deploying machine learning models, including support for neural networks, natural language processing, and computer vision.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  PyTorch:
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;PyTorch is an open-source deep learning library developed by Facebook’s AI Research lab (FAIR).&lt;/li&gt;
&lt;li&gt;Known for its dynamic computational graph, PyTorch is favored for its flexibility and ease of debugging. It has gained popularity in research communities.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Advantages and Use Cases:
&lt;/h4&gt;

&lt;h5&gt;
  
  
  TensorFlow:
&lt;/h5&gt;

&lt;h6&gt;
  
  
  Advantages:
&lt;/h6&gt;

&lt;ul&gt;
&lt;li&gt;Scalability: TensorFlow is designed for efficient deployment across a variety of devices, from CPUs to GPUs and TPUs.&lt;/li&gt;
&lt;li&gt;Extensive Community and Ecosystem: The large community ensures continuous support and a vast collection of pre-trained models.&lt;/li&gt;
&lt;/ul&gt;

&lt;h6&gt;
  
  
  Use Cases:
&lt;/h6&gt;

&lt;ul&gt;
&lt;li&gt;TensorFlow is well-suited for large-scale applications, such as training deep neural networks on large datasets for tasks like image classification and natural language processing.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  PyTorch:
&lt;/h5&gt;

&lt;h6&gt;
  
  
  Advantages:
&lt;/h6&gt;

&lt;ul&gt;
&lt;li&gt;Dynamic Computational Graph: PyTorch’s dynamic graph allows for more intuitive and flexible model building and debugging.&lt;/li&gt;
&lt;li&gt;Research-Friendly: PyTorch is often preferred in research settings due to its ease of experimentation and prototyping.&lt;/li&gt;
&lt;/ul&gt;

&lt;h6&gt;
  
  
  Use Cases:
&lt;/h6&gt;

&lt;ul&gt;
&lt;li&gt;PyTorch is commonly used in research projects, academic environments, and smaller-scale applications where rapid experimentation is crucial.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Simple Code Example:
&lt;/h4&gt;

&lt;p&gt;Let’s consider a simple example of building and training a feedforward neural network for image classification using PyTorch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;torch.nn&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;nn&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;torch.optim&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;optim&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;torchvision.transforms&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;transforms&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;torchvision.datasets&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;MNIST&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;torch.utils.data&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;DataLoader&lt;/span&gt;

&lt;span class="c1"&gt;# Define a simple neural network
&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SimpleNN&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Module&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;SimpleNN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;flatten&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Flatten&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fc1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Linear&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;28&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;28&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;128&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;relu&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ReLU&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fc2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Linear&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;128&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;forward&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;flatten&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fc1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;relu&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fc2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;

&lt;span class="c1"&gt;# Instantiate the model, define loss function and optimizer
&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;SimpleNN&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;criterion&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CrossEntropyLoss&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;optimizer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;optim&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Adam&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parameters&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;lr&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.001&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Load MNIST dataset
&lt;/span&gt;&lt;span class="n"&gt;transform&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;transforms&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Compose&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;transforms&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToTensor&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;transforms&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Normalize&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,),&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,))])&lt;/span&gt;
&lt;span class="n"&gt;train_dataset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MNIST&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;./data&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;train&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;transform&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;download&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;train_loader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;DataLoader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;train_dataset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;batch_size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shuffle&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Training loop
&lt;/span&gt;&lt;span class="n"&gt;epochs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;epoch&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;epochs&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;images&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;labels&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;train_loader&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;optimizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;zero_grad&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;outputs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;images&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;loss&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;criterion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;outputs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;loss&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;backward&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;optimizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;step&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Epoch &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;epoch&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;epochs&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;, Loss: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;loss&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;item&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Real-World Applications
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Image and Speech Recognition:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Image Recognition:&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Application&lt;/strong&gt;: Facial recognition systems in security, image tagging on social media, and autonomous vehicle perception.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Technology&lt;/strong&gt;: Convolutional Neural Networks (CNNs) are commonly used for image classification and object detection.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Speech Recognition:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Application&lt;/strong&gt;: Virtual assistants (e.g., Siri, Alexa), transcription services, voice-controlled devices.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Technology&lt;/strong&gt;: Recurrent Neural Networks (RNNs) and Convolutional Neural Networks (CNNs) can be applied to process and understand spoken language.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Natural Language Processing and Understanding:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Application&lt;/strong&gt;: Chatbots, sentiment analysis, language translation, and document summarization.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Technology&lt;/strong&gt;: Recurrent Neural Networks (RNNs), Long Short-Term Memory (LSTM) networks, and Transformers (e.g., BERT) are used for tasks like language modeling and understanding context in natural language.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Autonomous Vehicles:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Application&lt;/strong&gt;: Self-driving cars and drones.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Technology&lt;/strong&gt;: Convolutional Neural Networks (CNNs) process visual input from cameras, LIDAR, and radar to recognize objects, pedestrians, and navigate the vehicle safely. Recurrent Neural Networks (RNNs) may be used for decision-making based on sequential data.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Healthcare Applications:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Application&lt;/strong&gt;: Medical image analysis, disease diagnosis, drug discovery, personalized medicine.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Technology&lt;/strong&gt;: Convolutional Neural Networks (CNNs) are employed for tasks like detecting abnormalities in medical images (X-rays, MRIs). Recurrent Neural Networks (RNNs) may be used for analyzing sequential patient data. Generative models contribute to drug discovery and molecular design.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These applications showcase the impact of deep learning in solving complex real-world problems across various domains, improving efficiency, accuracy, and decision-making processes. The adaptability of deep learning models makes them valuable tools for addressing challenges in diverse industries.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Challenges in Deep Learning:
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Interpretability:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Challenge&lt;/strong&gt;: Deep learning models are often considered as “black boxes,” making it challenging to understand how they arrive at specific decisions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implications&lt;/strong&gt;: Lack of interpretability can hinder trust in the model’s decisions, especially in critical applications like healthcare and finance.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Bias and Fairness:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Challenge&lt;/strong&gt;: Models can inherit and perpetuate biases present in training data, leading to unfair or discriminatory outcomes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implications&lt;/strong&gt;: Unintended bias in models can lead to unfair treatment of certain groups, impacting the ethical and responsible deployment of AI systems.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Data Quality and Quantity:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Challenge&lt;/strong&gt;: Deep learning models require large amounts of high-quality labeled data for effective training.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implications&lt;/strong&gt;: Limited availability of quality data can hinder the performance and generalization of models.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Emerging Trends in Deep Learning:
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Explainable AI (XAI):
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Trend&lt;/strong&gt;: Focus on developing models that provide interpretable explanations for their decisions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Importance&lt;/strong&gt;: Enhances trust and transparency, making it easier to understand and validate model decisions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Federated Learning:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Trend&lt;/strong&gt;: Training machine learning models across decentralized devices while keeping data localized.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Importance&lt;/strong&gt;: Addresses privacy concerns by minimizing the need to centralize sensitive data, making it suitable for applications like healthcare and IoT.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Self-Supervised Learning:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Trend&lt;/strong&gt;: Models learn from the data itself without the need for explicit labels, often leveraging pretext tasks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Importance&lt;/strong&gt;: Reduces the reliance on labeled data, making it more feasible to train models in scenarios where labeled data is scarce.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Ethical AI and Responsible AI Practices:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Trend&lt;/strong&gt;: Increased emphasis on ethical considerations in AI development, deployment, and decision-making.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Importance&lt;/strong&gt;: Ensures that AI technologies are developed and used ethically, considering societal impacts and potential biases.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Continual Learning:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Trend&lt;/strong&gt;: Models capable of learning and adapting continuously over time with new data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Importance&lt;/strong&gt;: Enables models to stay relevant and accurate in dynamic and evolving environments.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As deep learning continues to advance, addressing these challenges and embracing emerging trends will be crucial for realizing the full potential of AI while ensuring its responsible and ethical deployment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Recap Key Points:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Fundamentals: Deep learning involves neural networks with multiple layers, each processing information to make predictions without explicit programming.&lt;/li&gt;
&lt;li&gt;Building Blocks: Different types of neural networks, such as feedforward, convolutional, and recurrent, are tailored for specific tasks like classification, image processing, and sequential data analysis.&lt;/li&gt;
&lt;li&gt;Training Models: Data preprocessing, normalization, loss functions, and optimization algorithms are crucial for effective model training. Overfitting is mitigated through regularization techniques.&lt;/li&gt;
&lt;li&gt;Frameworks: TensorFlow and PyTorch are popular deep learning frameworks, each with its advantages and use cases.&lt;/li&gt;
&lt;li&gt;Real-World Applications: Deep learning powers image and speech recognition, natural language processing, autonomous vehicles, and healthcare applications.&lt;/li&gt;
&lt;li&gt;Challenges: Interpretability, bias, and data quality pose challenges in deploying deep learning models responsibly.&lt;/li&gt;
&lt;li&gt;Emerging Trends: Explainable AI, federated learning, self-supervised learning, ethical AI, and continual learning are shaping the future of deep learning.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Emphasize the Transformative Potential of Deep Learning:
&lt;/h4&gt;

&lt;p&gt;Deep learning has revolutionized artificial intelligence and data science, providing powerful tools for solving complex problems across diverse domains. Its ability to automatically learn hierarchical representations from data has led to breakthroughs in image recognition, natural language understanding, and beyond. The transformative potential of deep learning extends to reshaping industries, improving efficiency, and advancing technological frontiers.&lt;/p&gt;

&lt;h4&gt;
  
  
  Encourage Further Exploration and Learning:
&lt;/h4&gt;

&lt;p&gt;As deep learning continues to evolve, there are endless opportunities for exploration and learning. Whether you’re a seasoned practitioner or just starting, staying updated on emerging trends, mastering new techniques, and delving into real-world applications will contribute to your growth in the dynamic field of deep learning. The journey of exploration and learning in deep learning is not just about understanding the technology; it’s about actively contributing to its progress and applying it to make a positive impact on the world. Keep exploring, experimenting, and pushing the boundaries of what deep learning can achieve!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to structure your ML project code</title>
      <dc:creator>Felix Kiprotich</dc:creator>
      <pubDate>Sun, 12 Jan 2025 12:18:10 +0000</pubDate>
      <link>https://dev.to/penscola/how-to-structure-your-ml-project-code-18ac</link>
      <guid>https://dev.to/penscola/how-to-structure-your-ml-project-code-18ac</guid>
      <description>&lt;p&gt;We are going to use poetry to structure our Machine Learning project.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Poetry is a tool for dependency management and packaging in Python. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you. Poetry offers a lockfile to ensure repeatable installs, and can build your project for distribution.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;You should note that:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Poetry should always be installed in a dedicated virtual environment to isolate it from the rest of your system. It should in no case be installed in the environment of the project that is to be managed by Poetry. This ensures that Poetry’s own dependencies will not be accidentally upgraded or uninstalled. (Each of the following installation methods ensures that Poetry is installed into an isolated environment.) In addition, the isolated virtual environment in which poetry is installed should not be activated for running poetry commands.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install poetry
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Basic Usage
&lt;/h2&gt;

&lt;p&gt;First, let’s create our new project, let’s call it &lt;code&gt;poetry-demo&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;poetry new poetry-demo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create the &lt;code&gt;poetry-demo&lt;/code&gt; directory with the following content:&lt;/p&gt;

&lt;p&gt;poetry-demo&lt;br&gt;
├── pyproject.toml&lt;br&gt;
├── README.md&lt;br&gt;
├── poetry_demo ← — — — — All you script file are written here&lt;br&gt;
│ └── &lt;strong&gt;init&lt;/strong&gt;.py&lt;br&gt;
└── tests&lt;br&gt;
└── &lt;strong&gt;init&lt;/strong&gt;.py&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;pyproject.toml&lt;/code&gt; file is what is the most important here. This will orchestrate your project and its dependencies. For now, it looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[tool.poetry]
name = "poetry-demo"
version = "0.1.0"
description = ""
authors = ["Sébastien Eustace &amp;lt;sebastien@eustace.io&amp;gt;"]
readme = "README.md"
packages = [{include = "poetry_demo"}]

[tool.poetry.dependencies]
python = "^3.8"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to add any dependencies, you can use the simple command below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;poetry add pendulum
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are using notebooks you can add a folder named notebook and alter you project to look like this :&lt;/p&gt;

&lt;p&gt;poetry-demo&lt;br&gt;
├── pyproject.toml&lt;br&gt;
├── README.md&lt;br&gt;
├── poetry_demo ← — — — — All you script file are written here&lt;br&gt;
│ └── &lt;strong&gt;init&lt;/strong&gt;.py&lt;br&gt;
└── tests&lt;br&gt;
└── &lt;strong&gt;init&lt;/strong&gt;.py&lt;br&gt;
└── notebook&lt;br&gt;
└── notebook.ipynb&lt;/p&gt;
&lt;h2&gt;
  
  
  Dockerization
&lt;/h2&gt;

&lt;p&gt;Dockerization, also known as “containerization,” refers to the process of packaging an application and its dependencies into a standardized container called a “Docker container.”&lt;/p&gt;

&lt;p&gt;For out case we prepare a Dockerfile&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Use an official Python Runtime as a parent image
FROM Python:3.9-slim

#set the working directory in the container
WORKDIR /app

# Copy the current directory contents into the container /app
COPY ..

#Install sytem dependencies
RUN apt-get update &amp;amp;&amp;amp; apt-get install -y \ curl \ &amp;amp;&amp;amp; rm -rf /var/lib/apt/lists/*

# Install poetry
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -

# Use poetry to install python dependencies
RUN /root/.poetry/bin/poetry config virtualenvs.create false \ &amp;amp;&amp;amp; /root/.poetry/bin/poetry install --no-interaction --no-ansi

# Specify the command to run on start
CMD ['python', 'poetry-demo/train.py']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;poetry-demo&lt;br&gt;
├── pyproject.toml&lt;br&gt;
├── Dockerfile&lt;br&gt;
├── README.md&lt;br&gt;
├── poetry_demo ← — — — — All you script file are written here&lt;br&gt;
│ └── &lt;strong&gt;init&lt;/strong&gt;.py&lt;br&gt;
└── tests&lt;br&gt;
└── &lt;strong&gt;init&lt;/strong&gt;.py&lt;br&gt;
└── notebook&lt;br&gt;
└── notebook.ipynb&lt;/p&gt;

&lt;p&gt;Then run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build -t IMAGE-NAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to build your image then run your docker image&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run IMAGE-NAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These is How to structure you Machine Learning project, give me a clap or incase you have any question or something to add up reply it here and I will reach out Thank you.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Create Two-Factor Authentication (2FA) in Python</title>
      <dc:creator>Felix Kiprotich</dc:creator>
      <pubDate>Thu, 02 Jan 2025 20:37:38 +0000</pubDate>
      <link>https://dev.to/penscola/how-to-create-two-factor-authentication-2fa-in-python-2l9m</link>
      <guid>https://dev.to/penscola/how-to-create-two-factor-authentication-2fa-in-python-2l9m</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Two-factor authentication (2FA) is a security process that requires users to provide two different authentication factors to verify their identity before gaining access to a system or service. Typically, these factors fall into three categories: something the user knows (like a password or PIN), something the user has (such as a smartphone or token), or something the user is (biometric data like fingerprints or facial recognition). By combining two factors from different categories, 2FA adds an extra layer of security beyond just a password, making it significantly more difficult for unauthorized users to access sensitive information or accounts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding the code
&lt;/h2&gt;

&lt;p&gt;We are going to use to a python library ‘pyotp’ which enables us to easily implement one-time password (OTP) generation and verification for two-factor authentication (2FA).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Importing required library&lt;/strong&gt;&lt;br&gt;
To get started we import ‘pyotp’ and ‘qrcode’&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pyotp&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;qrcode&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. We then initialize a Time-Based One-Time Password (TOTP)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;NeuralNineMySuperSecretKey&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;

&lt;span class="c1"&gt;# initializes a Time-Based One-Time Password (TOTP)
&lt;/span&gt;&lt;span class="n"&gt;totp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pyotp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TOTP&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Generate a qrcode for our authentication app&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;uri&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pyotp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;totp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TOTP&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;provisioning_uri&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;penscola&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                                            &lt;span class="n"&gt;issuer_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Penscola@Tech&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
                                            &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Save the qrcode image&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;qrcode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;totp.png&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb39kd6qhqjq5ol3dgz55.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb39kd6qhqjq5ol3dgz55.png" alt="Image description" width="392" height="392"&gt;&lt;/a&gt;&lt;br&gt;
You can scan the qrcode to get the One Time Password which changes after 30 seconds.&lt;br&gt;
&lt;strong&gt;5. Verify the code if it is true or false&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;totp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;verify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Enter code: &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F32pm5q72bfws0g6hqoxg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F32pm5q72bfws0g6hqoxg.png" alt="Image description" width="800" height="202"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In conclusion, two-factor authentication (2FA) stands as a critical component in modern cybersecurity practices, significantly bolstering the security of user accounts and sensitive information. By requiring users to provide two different authentication factors, typically something they know (like a password) and something they have (such as a smartphone or token), 2FA adds an extra layer of protection against unauthorized access. This approach mitigates the risks associated with password breaches and phishing attacks, enhancing the overall resilience of authentication mechanisms. As cyber threats continue to evolve, the widespread adoption of 2FA remains paramount in safeguarding digital identities and preserving the integrity of online services and systems.&lt;/p&gt;

&lt;p&gt;You’ve come a long way; thanks for reading this article. For more related posts and articles, follow me on &lt;a href="https://www.linkedin.com/in/felix-kiprotich-a2ba1a1a4/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;, &lt;a href="https://github.com/penscola" rel="noopener noreferrer"&gt;GitHub &lt;/a&gt;and &lt;a href="https://twitter.com/PenscolaF" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
