<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pinaki Mishra on Medium]]></title>
        <description><![CDATA[Stories by Pinaki Mishra on Medium]]></description>
        <link>https://medium.com/@pinakimishra95?source=rss-1d1abea33c35------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*lNZFyl9cWkI-1W9e2TN4tw.jpeg</url>
            <title>Stories by Pinaki Mishra on Medium</title>
            <link>https://medium.com/@pinakimishra95?source=rss-1d1abea33c35------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 12:27:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pinakimishra95/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to use PyCaret ?]]></title>
            <link>https://medium.com/@pinakimishra95/how-to-use-pycaret-89df89f081b9?source=rss-1d1abea33c35------2</link>
            <guid isPermaLink="false">https://medium.com/p/89df89f081b9</guid>
            <category><![CDATA[modeling]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-scientist]]></category>
            <category><![CDATA[pycaret]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Pinaki Mishra]]></dc:creator>
            <pubDate>Sat, 04 Feb 2023 07:04:41 GMT</pubDate>
            <atom:updated>2023-02-04T07:04:41.057Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to use PyCaret ?</h3><p>PyCaret is an open-source, low-code machine learning library in Python that provides an easy-to-use interface for solving end-to-end machine learning problems. It is designed to simplify the process of training, testing, and deploying machine learning models by providing a high-level API that abstracts the complexity of underlying algorithms.</p><p>In this blog, we’ll cover the basics of PyCaret and demonstrate how to use it with a code example.</p><ol><li>Installation</li></ol><p>To install PyCaret, you can use the following command in your terminal or command prompt:</p><pre>pip install pycaret</pre><p>2. Loading Data</p><p>PyCaret provides a convenient function to load and split your data into training and testing sets. The setup function accepts a pandas DataFrame or a path to a CSV file and returns an object that contains the training and testing datasets, as well as additional information such as the target column and data types.</p><pre>from pycaret.datasets import get_data<br>data = get_data(&#39;diabetes&#39;)<br>from pycaret.classification import setup<br>clf1 = setup(data, target = &#39;Class variable&#39;)</pre><p>3. Model Training and Comparison</p><p>Once your data is loaded, PyCaret makes it easy to train and compare multiple machine learning algorithms. The compare_models function trains and compares several models and returns a leaderboard that ranks the models based on their performance.</p><pre>from pycaret.classification import compare_models<br>best = compare_models()</pre><p>4. Model Tuning</p><p>After selecting the best model, you can use PyCaret’s tune_model function to fine-tune the hyperparameters and improve the performance of the model.</p><pre>from pycaret.classification import tune_model<br>tuned = tune_model(best)</pre><p>5. Model Ensemble</p><p>PyCaret also provides an easy-to-use ensemble learning capability that allows you to combine multiple models to form a more powerful model. The ensemble_model function trains an ensemble of the best models and returns a single, combined model that outperforms each individual model.</p><pre>from pycaret.classification import ensemble_model<br>ensembled = ensemble_model(best)</pre><p>6. Model Deployment</p><p>Finally, PyCaret makes it easy to deploy your model by providing a deploy function that saves the model to disk for later use.</p><pre>from pycaret.classification import deploy<br>deploy(ensembled, model_name = &#39;diabetes_model&#39;)</pre><p>In conclusion, PyCaret is a powerful and user-friendly library that streamlines the machine learning pipeline and reduces the amount of code required to build, tune, and deploy machine learning models. With its intuitive API and built-in support for multiple algorithms and techniques, PyCaret makes it easy to get started with machine learning, even for those with limited coding experience.</p><p>for reference : <a href="https://pycaret.gitbook.io/docs/">https://pycaret.gitbook.io/docs/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89df89f081b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to handle imbalance]]></title>
            <link>https://medium.com/@pinakimishra95/how-to-handle-imbalance-5dcc0f781966?source=rss-1d1abea33c35------2</link>
            <guid isPermaLink="false">https://medium.com/p/5dcc0f781966</guid>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[imbalanced-data]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Pinaki Mishra]]></dc:creator>
            <pubDate>Fri, 03 Feb 2023 18:56:21 GMT</pubDate>
            <atom:updated>2023-02-03T18:56:21.829Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to handle imbalance dataset ?</h3><p>Handling imbalanced datasets is a common challenge in machine learning. An imbalanced dataset is one where the distribution of target classes is uneven, with one or more classes significantly outnumbered by others. This can lead to biased models that perform poorly on underrepresented classes.</p><p>In this blog, we’ll discuss various techniques for handling imbalanced datasets using Python. We’ll also provide code examples to illustrate each technique.</p><ol><li>Over-sampling minority class</li></ol><p>One approach to handling imbalanced datasets is to over-sample the minority class. This technique involves duplicating instances of the minority class to balance the distribution of target classes.</p><p>To implement over-sampling in Python, we can use the resampling module from the imbalanced-learn library.</p><pre>from imblearn.over_sampling import RandomOverSampler<br>ros = RandomOverSampler()<br>X_resampled, y_resampled = ros.fit_resample(X, y)</pre><p>2. Under-sampling majority class</p><p>Another approach to handling imbalanced datasets is to under-sample the majority class. This technique involves reducing the number of instances in the majority class to balance the distribution of target classes.</p><p>To implement under-sampling in Python, we can use the resampling module from the imbalanced-learn library.</p><pre>from imblearn.under_sampling import RandomUnderSampler<br>rus = RandomUnderSampler()<br>X_resampled, y_resampled = rus.fit_resample(X, y)</pre><p>3. Synthetic Minority Over-sampling Technique (SMOTE)</p><p>SMOTE is a popular over-sampling technique that generates synthetic samples of the minority class by interpolating between existing instances.</p><p>To implement SMOTE in Python, we can use the SMOTE class from the imbalanced-learn library.</p><pre>from imblearn.over_sampling import SMOTE<br>smote = SMOTE()<br>X_resampled, y_resampled = smote.fit_resample(X, y)</pre><p>4. Class weight adjustment</p><p>Another approach to handling imbalanced datasets is to adjust the weight of the classes in the loss function used by the model. This can be achieved by setting the class_weight argument in scikit-learn’s implementations of machine learning algorithms.</p><pre>from sklearn.ensemble import RandomForestClassifier<br>clf = RandomForestClassifier(class_weight=&#39;balanced&#39;)<br>clf.fit(X, y)</pre><p>5. Cost-sensitive learning</p><p>Cost-sensitive learning is a machine learning technique that incorporates the cost of misclassification into the model’s learning process. This can help to mitigate the impact of class imbalance by assigning a higher cost to misclassifying instances from the minority class.</p><p>To implement cost-sensitive learning in Python, we can use the cost_sensitive module from the imbalanced-learn library.</p><pre>from imblearn.metrics import classification_report_imbalanced<br>clf = RandomForestClassifier()<br>clf.fit(X, y)<br>y_pred = clf.predict(X_test)<br>print(classification_report_imbalanced(y_test, y_pred))</pre><p>In conclusion, handling imbalanced datasets is an important challenge in machine learning. The techniques discussed in this blog, including over-sampling, under-sampling, SMOTE, Class weight adjustment,Cost-sensitive learning. There can be other solutions depends on the problem statement and the dataset .</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5dcc0f781966" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Summary of Gartner Hype cycle 2022 on AI.]]></title>
            <link>https://medium.com/@pinakimishra95/summary-of-gartner-hype-cycle-2022-on-ai-e916505db412?source=rss-1d1abea33c35------2</link>
            <guid isPermaLink="false">https://medium.com/p/e916505db412</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[gartner]]></category>
            <category><![CDATA[trending]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Pinaki Mishra]]></dc:creator>
            <pubDate>Fri, 03 Feb 2023 18:44:10 GMT</pubDate>
            <atom:updated>2023-02-03T18:44:10.974Z</atom:updated>
            <content:encoded><![CDATA[<p>Gartner Hype Cycle is a widely recognized tool for tracking the maturity, adoption, and social application of technologies. In 2022, the Gartner Hype Cycle for Artificial Intelligence (AI) provides a comprehensive overview of the state of AI and its impact on various industries. The Hype Cycle aims to help organizations understand the potential of AI and make informed decisions about its adoption and use.</p><p>AI is one of the most rapidly evolving technologies, and the 2022 Gartner Hype Cycle reflects this trend. The Hype Cycle consists of five phases: Innovation Trigger, Peak of Inflated Expectations, Trough of Disillusionment, Slope of Enlightenment, and Plateau of Productivity. According to Gartner, AI has reached the Plateau of Productivity, which means that the technology has moved beyond the hype and is delivering real business value to organizations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zsGqC6VJdG059Pd7o_FgEQ.jpeg" /></figure><p>The 2022 Gartner Hype Cycle for AI identifies several key trends that are shaping the future of the technology. Some of these trends include:</p><ul><li>AI-powered conversational interfaces: AI-powered conversational interfaces, such as chatbots and virtual assistants, are becoming increasingly sophisticated, allowing for more natural and intuitive interactions between humans and machines.</li><li>AI-powered analytics: AI-powered analytics is becoming increasingly prevalent, providing organizations with insights and predictions that were previously not possible.</li><li>AI-powered automation: AI-powered automation is revolutionizing traditional workflows and improving efficiency in various industries, including manufacturing, finance, and healthcare.</li><li>AI-powered cybersecurity: AI-powered cybersecurity is becoming increasingly important as organizations seek to protect against cyber threats and mitigate risk.</li></ul><p>In addition to these trends, the 2022 Gartner Hype Cycle for AI highlights several AI technologies that are poised to have a significant impact on various industries. Some of these technologies include:</p><ul><li>Natural Language Processing (NLP): NLP is a field of AI that deals with the interaction between computers and human language. It is used for various applications, including sentiment analysis, text classification, and machine translation.</li><li>Computer Vision: Computer Vision is a field of AI that deals with the analysis and interpretation of visual information. It is used for various applications, including image recognition, object detection, and facial recognition.</li><li>Deep Learning: Deep Learning is a subfield of machine learning that uses artificial neural networks to model complex patterns in data. It is used for various applications, including image recognition, speech recognition, and natural language processing.</li></ul><p>The 2022 Gartner Hype Cycle for AI provides valuable insights into the state of AI and its impact on various industries. By understanding the trends and technologies that are shaping the future of AI, organizations can make informed decisions about its adoption and use.</p><p>In conclusion, the 2022 Gartner Hype Cycle for AI is an essential tool for organizations that want to stay ahead of the curve in the rapidly evolving world of AI. By staying up-to-date with the latest trends and technologies, organizations can capitalize on the opportunities presented by AI and maximize its potential for business value.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e916505db412" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[All About Loss functions ..]]></title>
            <link>https://medium.com/@pinakimishra95/all-about-loss-functions-b8947c617b7f?source=rss-1d1abea33c35------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8947c617b7f</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[loss-function]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Pinaki Mishra]]></dc:creator>
            <pubDate>Fri, 03 Feb 2023 14:36:42 GMT</pubDate>
            <atom:updated>2023-02-03T14:36:42.966Z</atom:updated>
            <content:encoded><![CDATA[<h3>All About Loss functions …</h3><p>Loss functions are an essential component of machine learning algorithms. They measure the difference between the predicted output and the actual output and help to optimize the model to minimize the error. In this blog, we’ll discuss what loss functions are, how they work, and provide code examples to help you understand the concept better.</p><p>What are Loss Functions?</p><p>Loss functions are mathematical equations used to evaluate the performance of a machine learning model. They compare the predicted output and the actual output, and calculate the difference between them. The goal of the machine learning model is to minimize the loss function, thus minimizing the error in the predictions.</p><p>Types of Loss Functions</p><p>There are several types of loss functions, including:</p><ol><li><strong>Mean Squared Error (MSE): </strong>This is a popular loss function used in regression problems. It calculates the average of the squared differences between the predicted output and the actual output.</li><li><strong>Cross-Entropy Loss:</strong> This is a popular loss function used in classification problems. It measures the dissimilarity between the predicted probabilities and the actual target.</li><li><strong>Hinge Loss:</strong> This is a loss function used in support vector machines (SVM) for classification problems. It measures the maximum margin between the predicted class and the actual class.</li><li><strong>Log-Cosh Loss:</strong> This is a smooth approximation of the mean absolute error loss function used in regression problems.</li><li><strong>Kullback-Leibler (KL) Divergence: </strong>This is a loss function used in deep learning for evaluating the difference between two probability distributions.</li></ol><p>Code Example: MSE Loss Function</p><p>Here’s an example of how to implement the MSE loss function in Python</p><pre>import numpy as np<br>def mse_loss(y_true, y_pred):<br>    return np.mean((y_true - y_pred)**2)<br>y_true = [1, 2, 3, 4, 5]<br>y_pred = [1.5, 2.5, 2.8, 4.2, 4.9]<br>print(&quot;MSE Loss:&quot;, mse_loss(y_true, y_pred))</pre><p>In this example, we define a function to calculate the MSE loss between the true values and the predicted values. We then define the true values and predicted values and print the MSE loss.</p><p>Code Example: Cross-Entropy Loss</p><p>Here’s an example of how to implement the cross-entropy loss function in Python:</p><pre>import numpy as np<br>def cross_entropy_loss(y_true, y_pred):<br>    return -np.mean(y_true * np.log(y_pred) + (1 - y_true) * np.log(1 - y_pred))<br>y_true = [1, 0, 1, 0, 1]<br>y_pred = [0.9, 0.1, 0.8, 0.2, 0.7]<br>print(&quot;Cross-Entropy Loss:&quot;, cross_entropy_loss(y_true, y_pred))</pre><p>In this example, we define a function to calculate the cross-entropy loss between the true values and the predicted values. We then define the true values and predicted values and print the cross-entropy loss.</p><p>Code Example: <strong>Hinge Loss</strong></p><p>Here’s an example of how to implement the <strong>Hinge Loss</strong> function in Python:</p><pre>import numpy as np<br><br>def hinge_loss(y_true, y_pred):<br>    return max(0, 1 - y_true * y_pred)<br><br>y_true = [-1, 1, -1, 1, -1]<br>y_pred = [-0.8, 0.9, -0.7, 1.0, -0.6]<br><br>loss = [hinge_loss(y_true[i], y_pred[i]) for i in range(len(y_true))]<br>print(&quot;Hinge Loss:&quot;, np.mean(loss))</pre><p>In this example, we define a function to calculate the Hinge Loss between the true class labels and the predicted class scores. We then define the true class labels and predicted class scores and calculate the mean of the Hinge Loss.</p><p>Code Example: <strong>Log-Cosh Loss</strong></p><p>Here’s an example of how to implement the <strong>Log-Cosh Loss </strong>function in Python:</p><pre>import numpy as np<br><br>def log_cosh_loss(y_true, y_pred):<br>    return np.log(np.cosh(y_pred - y_true))<br><br>y_true = [-1, 1, -1, 1, -1]<br>y_pred = [-0.8, 0.9, -0.7, 1.0, -0.6]<br><br>loss = [log_cosh_loss(y_true[i], y_pred[i]) for i in range(len(y_true))]<br>print(&quot;Log-Cosh Loss:&quot;, np.mean(loss))</pre><p>In this example, we define a function to calculate the Log-Cosh Loss between the true class labels and the predicted class scores. We then define the true class labels and predicted class scores and calculate the mean of the Log-Cosh Loss.</p><p>Code Example: <strong>Kullback-Leibler (KL) Divergence</strong></p><p>Here’s an example of how to implement the <strong>Kullback-Leibler (KL) Divergence</strong> function in Python:</p><pre>import numpy as np<br><br>def kl_divergence(p, q):<br>    return np.sum(p * np.log(p / q))<br><br>p = [0.8, 0.2, 0.0]<br>q = [0.7, 0.3, 0.0]<br><br>print(&quot;KL Divergence:&quot;, kl_divergence(p, q))</pre><p>In this example, we define a function to calculate the KL Divergence between two probability distributions. We then define two probability distributions, p and q, and calculate the KL Divergence between them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8947c617b7f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[All About Support Vector Machine(SVM)..]]></title>
            <link>https://medium.com/@pinakimishra95/all-about-support-vector-machine-svm-c5f89074e8c5?source=rss-1d1abea33c35------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5f89074e8c5</guid>
            <category><![CDATA[regression]]></category>
            <category><![CDATA[svm]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Pinaki Mishra]]></dc:creator>
            <pubDate>Thu, 02 Feb 2023 12:29:32 GMT</pubDate>
            <atom:updated>2023-02-02T12:29:32.632Z</atom:updated>
            <content:encoded><![CDATA[<p>Support Vector Machines (SVM) are one of the most powerful and widely used algorithms in Machine Learning. It is mainly used for classification problems, but it can also be used for regression problems. In this blog, we’ll discuss what SVM is, how it works, and provide code examples to help you understand the concept better.</p><p><strong>What is SVM?</strong></p><p>Support Vector Machines (SVM) are a type of supervised learning algorithms used for classification and regression problems. The goal of SVM is to find a hyperplane that separates the data into classes. A hyperplane is a decision boundary that separates the data into different classes.</p><p><strong>How SVM Works</strong></p><p>SVM works by finding the hyperplane that separates the data into classes with the largest margin. The margin is defined as the distance between the hyperplane and the closest data points. These closest data points are called support vectors, and they are the most important data points in determining the hyperplane.</p><p>SVM can handle non-linearly separable data by transforming the data into a higher dimensional space using a technique called the kernel trick. In this higher dimensional space, a linear hyperplane can be found to separate the data into classes.</p><p><strong>Code Example: SVM for Classification</strong></p><p>Here’s an example of how to implement an SVM classifier in Python using the scikit-learn library:</p><pre>from sklearn import datasets<br>from sklearn.model_selection import train_test_split<br>from sklearn import svm<br><br># Load the iris dataset<br>iris = datasets.load_iris()<br><br># Split the data into training and test sets<br>X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.2)<br><br># Train the SVM classifier<br>clf = svm.SVC()<br>clf.fit(X_train, y_train)<br><br># Test the classifier on the test data<br>accuracy = clf.score(X_test, y_test)<br><br>print(&quot;Accuracy:&quot;, accuracy)</pre><p>In this example, we first load the iris dataset and split it into training and test sets. Then, we train the SVM classifier on the training data using the fit() method. Finally, we test the classifier on the test data and print the accuracy.</p><p>Code Example: SVM for Regression</p><p>Here’s an example of how to implement an SVM regressor in Python using the scikit-learn library:</p><pre>from sklearn import datasets<br>from sklearn.model_selection import train_test_split<br>from sklearn import svm<br><br># Load the diabetes dataset<br>diabetes = datasets.load_diabetes()<br><br># Split the data into training and test sets<br>X_train, X_test, y_train, y_test = train_test_split(diabetes.data, diabetes.target, test_size=0.2)<br><br># Train the SVM regressor<br>reg = svm.SVR()<br>reg.fit(X_train, y_train)<br><br># Predict on the test data<br>y_pred = reg.predict(X_test)<br><br># Evaluate the regressor<br>score = reg.score(X_test, y_test)<br><br>print(&quot;Score:&quot;, score)</pre><p>In this example, we first load the diabetes dataset and split it into training and test sets. Then, we train the SVM regressor on the training data using the fit() method. Finally, we test the regressor on the test data and print the score.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5f89074e8c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Attention-mask works ?]]></title>
            <link>https://medium.com/@pinakimishra95/how-attention-mask-works-9023383c4c65?source=rss-1d1abea33c35------2</link>
            <guid isPermaLink="false">https://medium.com/p/9023383c4c65</guid>
            <category><![CDATA[attention]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[bert]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Pinaki Mishra]]></dc:creator>
            <pubDate>Wed, 01 Feb 2023 15:40:18 GMT</pubDate>
            <atom:updated>2023-02-01T15:40:18.663Z</atom:updated>
            <content:encoded><![CDATA[<h3>How Attention-mask works ?</h3><p>Attention masks are a key component in the implementation of attention mechanisms in deep learning models. They are used to restrict the attention mechanism to only consider certain parts of the input, allowing the model to focus on the most relevant elements while ignoring irrelevant ones. In this blog, we will discuss what attention masks are, how they work, and provide code examples to illustrate their use.</p><h3>What are Attention Masks?</h3><p>Attention masks are binary masks that are applied to the input sequence before it is processed by the attention mechanism. Each element in the mask corresponds to a position in the input sequence and takes on a value of either 0 or 1. A value of 1 indicates that the corresponding position in the input sequence should be considered by the attention mechanism, while a value of 0 indicates that it should be ignored.</p><p>Attention masks are commonly used in NLP tasks such as machine translation, where the attention mechanism is used to weigh the importance of each word in a sentence when generating the target sequence. In these cases, attention masks can be used to restrict the attention mechanism to only consider the input sequence and ignore padding, which is used to pad the input sequence to a fixed length.</p><h3>How do Attention Masks Work?</h3><p>Attention masks work by modifying the attention scores that are used to compute the attention weights. The attention scores are computed using a dot product between the query and key vectors, which are generated from the input sequence. By applying the attention mask, we can set the attention scores for masked positions to a large negative number, effectively making them zero. This results in the attention mechanism assigning zero weight to the masked positions, effectively ignoring them.</p><h3>Code Examples</h3><p>Here are two code examples to illustrate the use of attention masks in deep learning models. The first example is in PyTorch, while the second is in TensorFlow.</p><h3>Example 1: PyTorch</h3><pre>import torch<br>import torch.nn as nn<br><br>class Attention(nn.Module):<br>    def __init__(self, dim):<br>        super().__init__()<br>        self.query = nn.Linear(dim, dim)<br>        self.key = nn.Linear(dim, dim)<br>        self.value = nn.Linear(dim, dim)<br>        <br>    def forward(self, query, key, value, mask=None):<br>        scores = torch.matmul(query, key.transpose(-2, -1)) / math.sqrt(dim)<br>        if mask is not None:<br>            scores = scores.masked_fill(mask == 0, -1e9)<br>        attention_weights = nn.Softmax(dim=-1)(scores)<br>        output = torch.matmul(attention_weights, value)<br>        return output, attention_weights<br><br></pre><h3>Example 2: TensorFlow</h3><pre>import tensorflow as tf<br><br>class Attention(tf.keras.layers.Layer):<br>    def __init__(self, dim, **kwargs):<br>        super().__init__(**kwargs)<br>        self.query = tf.keras.layers.Dense(dim)<br>        self.key = tf.keras.layers.Dense(dim)<br>        self.value = tf.keras.layers.Dense(dim)<br>        <br>    def call(self, query, key, value, mask=None):<br>        scores = tf.matmul(query, key, transpose_b=True)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9023383c4c65" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Attention vs Self-Attention]]></title>
            <link>https://medium.com/@pinakimishra95/attention-vs-self-attention-db53ed3125e0?source=rss-1d1abea33c35------2</link>
            <guid isPermaLink="false">https://medium.com/p/db53ed3125e0</guid>
            <category><![CDATA[attention]]></category>
            <category><![CDATA[transformers]]></category>
            <category><![CDATA[self-attention]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[Pinaki Mishra]]></dc:creator>
            <pubDate>Wed, 01 Feb 2023 15:24:10 GMT</pubDate>
            <atom:updated>2023-02-01T15:24:10.760Z</atom:updated>
            <content:encoded><![CDATA[<p>Attention and self-attention layers are two of the most widely used techniques in deep learning for natural language processing (NLP) tasks such as machine translation, text classification, and sentiment analysis. In this blog, we will discuss what these layers are, how they work, and provide a simple example to illustrate their operation.</p><h3>Attention Layer</h3><p>Attention is a mechanism that allows the model to focus on the most relevant parts of the input while processing it. The attention layer computes a weight or importance score for each input element, and then the output is computed as a weighted sum of the inputs, where the weights are determined by the importance scores.</p><p>In NLP, attention is used to weigh the importance of each word in a sentence when generating a summary or translation. The attention layer takes in a sequence of hidden states generated by the encoder, and outputs a weighted sum of these hidden states, which is used as the context for generating the target sequence.</p><h3>Self-Attention Layer</h3><p>Self-attention is an extension of the attention mechanism that allows the model to attend to the different positions in the input sequence. This allows the model to learn dependencies between words within the same sentence, and understand the relationships between words, such as subject-verb-object relationships.</p><p>In a self-attention layer, the input is first transformed into a set of query, key, and value vectors. The dot product between the query and key vectors is then computed, and the resulting scores are used to compute the attention weights. Finally, the attention weights are used to compute a weighted sum of the value vectors, which is used as the output of the self-attention layer.</p><h3>Example</h3><p>Let’s consider a simple example of how an attention layer can be used in machine translation. Suppose we have an English sentence “I love dogs” that we want to translate into French. The encoder will produce a sequence of hidden states for each word in the sentence. The attention layer will then compute a weight for each hidden state, based on its importance for generating the target sequence.</p><p>The attention weights could be computed using a simple dot product between the query and key vectors. For example, the weight for the hidden state corresponding to the word “love” would be higher than the weight for the hidden state corresponding to the word “I”, since the word “love” is more important for generating the target sequence.</p><p>Finally, the attention layer will use the attention weights to compute a weighted sum of the hidden states, which will be used as the context for generating the target sentence. In this case, the target sentence could be “J’aime les chiens”.</p><p>In conclusion, attention and self-attention layers are powerful tools that allow deep learning models to focus on the most relevant parts of the input, and understand relationships between elements in a sequence. These techniques have proven to be very effective in NLP tasks, and are widely used in state-of-the-art models.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db53ed3125e0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fact about chatGPT by chatGPT]]></title>
            <link>https://medium.com/@pinakimishra95/fact-about-chatgpt-by-chatgpt-a663e6185d6f?source=rss-1d1abea33c35------2</link>
            <guid isPermaLink="false">https://medium.com/p/a663e6185d6f</guid>
            <category><![CDATA[chatgpt]]></category>
            <dc:creator><![CDATA[Pinaki Mishra]]></dc:creator>
            <pubDate>Tue, 31 Jan 2023 13:41:36 GMT</pubDate>
            <atom:updated>2023-01-31T13:41:36.460Z</atom:updated>
            <content:encoded><![CDATA[<p>OpenAI’s GPT-3, including its chatbot variant ChatGPT, is a powerful language model with impressive abilities in text generation and conversation. However, there are some lesser-known facts about ChatGPT that may surprise you:</p><ol><li>ChatGPT is not pre-programmed with specific responses, but instead generates its answers based on patterns it has learned from a massive amount of text data. This means that ChatGPT can generate new and unexpected responses, sometimes even cracking jokes or making puns.</li><li>ChatGPT is not capable of emotions, empathy, or self-awareness. It is simply a machine that uses statistical algorithms to generate text based on patterns it has learned.</li><li>ChatGPT has been trained on a diverse range of text, including websites, books, and other sources, but it is still limited by the biases and limitations of the data it was trained on. This means that ChatGPT may perpetuate harmful stereotypes or perpetuate misinformation.</li><li>ChatGPT can be fine-tuned for specific purposes, such as answering customer service inquiries or generating creative writing. The ability to fine-tune the model allows for customization to specific domains and tasks.</li><li>The size and computational resources required to run ChatGPT are substantial, making it difficult for individuals or small organizations to utilize the model for their own purposes.</li></ol><p>Overall, ChatGPT is a remarkable technology that demonstrates the power of deep learning for natural language processing tasks. However, it is important to understand the limitations and potential biases of the model to ensure that it is used in an ethical and responsible manner.</p><p>Credit :chatGPT</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a663e6185d6f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[All about Bias and variance .]]></title>
            <link>https://medium.com/@pinakimishra95/all-about-bias-and-variance-ff671a37baa4?source=rss-1d1abea33c35------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff671a37baa4</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[bias-variance-tradeoff]]></category>
            <dc:creator><![CDATA[Pinaki Mishra]]></dc:creator>
            <pubDate>Tue, 31 Jan 2023 13:36:55 GMT</pubDate>
            <atom:updated>2023-01-31T13:36:55.407Z</atom:updated>
            <content:encoded><![CDATA[<h3>All about Bias and variance .</h3><p>Bias and variance are two important concepts in the field of machine learning and statistical modeling. They are used to evaluate the performance of models and determine how well they can generalize to unseen data.</p><p>Bias refers to the systematic error in a model’s predictions. It occurs when a model oversimplifies the relationship between the features and the target variable. For example, a linear regression model with a high bias will have a straight line fit, which may not accurately represent the relationship between the features and the target variable. High bias models tend to underfit the data and have a high training error.</p><p>Variance, on the other hand, refers to the amount of variability or randomness in a model’s predictions. It occurs when a model is too complex and overly sensitive to the noise in the data. For example, a polynomial regression model with a high variance will have a highly flexible fit, which may overfit the data and have a high test error.</p><p>A good model should have a low bias and low variance, meaning it accurately represents the relationship between the features and the target variable and is not overly sensitive to the noise in the data. The goal of model selection is to find the optimal balance between bias and variance.</p><p>Here is a simple example in Python using the scikit-learn library to illustrate the concept of bias and variance:</p><pre>import numpy as np<br>import matplotlib.pyplot as plt<br>from sklearn.linear_model import LinearRegression<br>from sklearn.pipeline import Pipeline<br>from sklearn.preprocessing import PolynomialFeatures<br><br># Generate random data<br>np.random.seed(0)<br>X = np.random.uniform(0, 1, size=100)<br>y = np.sin(2 * np.pi * X) + np.random.normal(0, 0.1, size=100)<br><br># Fit linear regression model<br>model_linear = LinearRegression()<br>model_linear.fit(X[:, np.newaxis], y)<br><br># Fit polynomial regression model<br>model_polynomial = Pipeline([<br>    (&#39;poly&#39;, PolynomialFeatures(degree=10)),<br>    (&#39;linear&#39;, LinearRegression())<br>])<br>model_polynomial.fit(X[:, np.newaxis], y)<br><br># Plot the results<br>plt.scatter(X, y, color=&#39;blue&#39;)<br>plt.plot(X, model_linear.predict(X[:, np.newaxis]), color=&#39;red&#39;, label=&#39;Linear Regression&#39;)<br>plt.plot(X, model_polynomial.predict(X[:, np.newaxis]), color=&#39;green&#39;, label=&#39;Polynomial Regression&#39;)<br>plt.legend()<br>plt.show()</pre><p>In this example, we first generate random data with a sine function and add random noise. We then fit two models: a linear regression model and a polynomial regression model. The polynomial regression model is created using a pipeline that first applies a polynomial feature transform and then fits a linear regression model. The results are plotted and compared.</p><p>As seen in the plot, the linear regression model has a high bias and low variance, while the polynomial regression model has a low bias and high variance. The linear regression model oversimplifies the relationship between the features and the target variable, resulting in a straight line fit that does not accurately capture the sine wave pattern. The polynomial regression model, on the other hand, is highly flexible and captures the sine wave pattern</p><p><strong>Bias-variance tradeoff:</strong></p><p>The bias-variance tradeoff is a fundamental concept in supervised machine learning that refers to the balancing act between a model’s ability to fit the training data well (low bias) and its ability to generalize to new data (low variance).</p><ul><li>Bias refers to the error that results from assuming a model that is too simple or inflexible to fit the training data. A high-bias model has difficulty capturing the true relationship between the features and target variables, leading to underfitting.</li><li>Variance refers to the error that results from a model that is too complex or flexible and overfits the training data, capturing noise or random fluctuations in the data rather than the underlying pattern.</li></ul><p>An overfitting model has a low bias and high variance, whereas an underfitting model has high bias and low variance.</p><p>Examples of Overfitting:</p><ol><li>Decision Tree with a large depth, capturing noise rather than the underlying pattern in the data.</li><li>Neural Network with too many hidden layers and neurons, memorizing the training data rather than generalizing.</li></ol><p>Examples of Underfitting:</p><ol><li>Linear Regression model to fit a non-linear relationship between the features and target variable.</li><li>Decision Tree with a small depth, failing to capture the true relationship between the features and target variable.</li></ol><p>The goal is to find a model that strikes a balance between bias and variance, achieving good fit for the training data and generalization to new data. This can be achieved through techniques such as regularization, cross-validation, and ensemble methods.</p><p>Credit : ChatGPT</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff671a37baa4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[All about LSTM .]]></title>
            <link>https://medium.com/@pinakimishra95/all-about-lstm-46eae64f9a49?source=rss-1d1abea33c35------2</link>
            <guid isPermaLink="false">https://medium.com/p/46eae64f9a49</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[lstm]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Pinaki Mishra]]></dc:creator>
            <pubDate>Tue, 31 Jan 2023 13:22:59 GMT</pubDate>
            <atom:updated>2023-01-31T13:22:59.295Z</atom:updated>
            <content:encoded><![CDATA[<h3>All about LSTM .</h3><p>Long Short-Term Memory (LSTM) is a type of Recurrent Neural Network (RNN) used for processing sequential data, such as time-series data, speech, text, and video. LSTMs are designed to overcome the vanishing gradient problem that occurs in traditional RNNs and allow the network to process and retain information from long sequences.</p><p>An LSTM cell consists of an additional memory cell, input gate, forget gate, and output gate, compared to a traditional RNN. The memory cell stores the information over time and the gates regulate the flow of information in and out of the memory cell, determining what information should be kept or forgotten. The input gate regulates the flow of new information into the memory cell, the forget gate determines which information should be deleted, and the output gate controls the flow of information out of the memory cell.</p><p>The following is an example of a simple LSTM model in Python using the Keras library:</p><pre>import numpy as np<br>from keras.models import Sequential<br>from keras.layers import LSTM, Dense<br><br># Generate dummy data<br>data = np.random.random((1000, 100, 1))<br>labels = np.random.randint(2, size=(1000, 1))<br><br># Build the model<br>model = Sequential()<br>model.add(LSTM(32, input_shape=(100, 1)))<br>model.add(Dense(1, activation=&#39;sigmoid&#39;))<br>model.compile(loss=&#39;binary_crossentropy&#39;, optimizer=&#39;adam&#39;, metrics=[&#39;accuracy&#39;])<br><br># Train the model<br>model.fit(data, labels, epochs=10, batch_size=32)</pre><p>In this example, we first generate dummy data using the numpy library. The data is a three-dimensional array of size (1000, 100, 1), representing 1000 samples of 100 time steps with a single feature. The labels are binary values of size (1000, 1).</p><p>Next, we define our LSTM model using the Keras library. The model consists of a single LSTM layer with 32 units and an input shape of (100, 1). The final layer is a dense layer with a single output and a sigmoid activation function, used for binary classification. The model is then compiled using the binary cross-entropy loss function and the Adam optimizer, with accuracy as the metric. Finally, we train the model for 10 epochs with a batch size of 32.</p><p>LSTMs have proven to be very effective in solving complex problems where the sequence of data is important. They are widely used in various applications such as sentiment analysis, speech recognition, and language translation.</p><p>In conclusion, LSTMs are an important type of RNN that have the ability to process and retain information from long sequences of data. With the example code provided, you can quickly build and train your own LSTM model in Python using the Keras library. Understanding how LSTMs work and the structure of the cells can help you improve the performance of your sequential data processing tasks.</p><p>Credit : ChatGPT</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46eae64f9a49" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>