<?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>Forem: Ambarish Ganguly</title>
    <description>The latest articles on Forem by Ambarish Ganguly (@ambarishg).</description>
    <link>https://forem.com/ambarishg</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%2F509885%2Fed5d0768-08c9-44bb-a7d8-1136baa97129.jpg</url>
      <title>Forem: Ambarish Ganguly</title>
      <link>https://forem.com/ambarishg</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ambarishg"/>
    <language>en</language>
    <item>
      <title>Understanding BBC News Q&amp;A with Advanced RAG and Microsoft Phi3</title>
      <dc:creator>Ambarish Ganguly</dc:creator>
      <pubDate>Sat, 18 May 2024 11:09:10 +0000</pubDate>
      <link>https://forem.com/ambarishg/understanding-bbc-news-qa-with-advanced-rag-and-microsoft-phi3-425n</link>
      <guid>https://forem.com/ambarishg/understanding-bbc-news-qa-with-advanced-rag-and-microsoft-phi3-425n</guid>
      <description>&lt;p&gt;In this blog, we would be doing question and answering on a news data feed.&lt;/p&gt;

&lt;p&gt;For this we are using the &lt;a href="https://www.kaggle.com/datasets/gpreda/bbc-news/versions/801" rel="noopener noreferrer"&gt;BBC News Dataset&lt;/a&gt; . This is a &lt;code&gt;self updating dataset&lt;/code&gt; and is updated daily.&lt;/p&gt;

&lt;p&gt;We would be learning Simple and Advanced RAG [ &lt;strong&gt;Retrieval Augmented Generation&lt;/strong&gt;] using a small language model &lt;strong&gt;Phi3  mini 128K instruct&lt;/strong&gt; through this blog.&lt;/p&gt;

&lt;p&gt;We would be asking questions like &lt;code&gt;What is the news in Ukraine&lt;/code&gt; and the application will provide the &lt;strong&gt;answers&lt;/strong&gt; using this technique.&lt;/p&gt;

&lt;p&gt;The Phi-3-Mini-128K-Instruct is a &lt;code&gt;3.8 billion-parameter&lt;/code&gt;, lightweight, state-of-the-art open model trained using the Phi-3 datasets. In comparison GPT-4 has more than a trillion parameters and the smallest Llama 3 model has 8 billion. &lt;/p&gt;

&lt;p&gt;RAG has 3 major components&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Ingestion&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Querying&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Generation &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Ingestion
&lt;/h2&gt;




&lt;p&gt;For Ingestion, following are the key components&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Read the Data Source&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Convert the read text into manageable chunks&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Convert the manageable chunks into embeddings. This is a technique in which you convert text into an array of numbers&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Store the embeddings into a vector database&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Store the metadata such as the filename, text , and other relevant things in the vector database&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2Fvcccw0V.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2Fvcccw0V.png" alt="Ingestion"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Query the data using Simple RAG
&lt;/h2&gt;




&lt;p&gt;In the query component, we require 3 main components&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Orchestrating application&lt;/code&gt; which is responsible for coordinating the interactions between the other components such as the user , vector database , Language Model .&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Vector Database which stores the information&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Language model which is helpful for generating the information after it has been provided &lt;strong&gt;contextual&lt;/strong&gt; information&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Data Flow of a Simple RAG
&lt;/h2&gt;




&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The user inputs the question . Example : &lt;code&gt;What is the news in Ukraine&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Orchestrating application uses a &lt;strong&gt;encoder&lt;/strong&gt; to transform the text into embedding We have used the &lt;code&gt;all-MiniLM-L6-v2&lt;/code&gt; of the Sentence Transformer as the encoder&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The embedding is searched in the Vector database. In this case we have used the &lt;strong&gt;Qdrant&lt;/strong&gt; database as the vector database&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Search results are obtained from the vector database. We get the top K results from the vector database. The number of results to be obtained is configurable&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A consolidated answer or popularly called &lt;strong&gt;context&lt;/strong&gt; is prepared from the answers. In the implementation that we would do is done by concatenating the search results&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This context is sent to the language model for generating the answers relevant for the context. In the implementation we have used a small language model &lt;strong&gt;Phi3&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2Fb2xtcFG.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2Fb2xtcFG.png" alt="Simple RAG"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Data Flow of a Advanced RAG
&lt;/h2&gt;




&lt;p&gt;The steps remain the same.&lt;/p&gt;

&lt;p&gt;Except the following&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Step 4&lt;/code&gt; - Search results are obtained from the vector database. We get the top K2 results from the vector database. The number of results to be obtained is configurable. The results K2 is larger than K&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Step 4A&lt;/code&gt;. The results obtained are passed into a new type of block known as the &lt;strong&gt;cross-encoder&lt;/strong&gt; which distills the number of results and provides a smaller set of results which has high similarity between the results and the query. These smaller set of results can be the top K results.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FEM41f5k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FEM41f5k.png" alt="Advanced RAG"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Implementation details
&lt;/h2&gt;




&lt;p&gt;For this implementation , we have used the following&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Dataset - &lt;strong&gt;BBC News&lt;/strong&gt; dataset&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Vector Database - Qdrant. We have a used in memory version of Qdrant for demonstration&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Language Model - Small language model &lt;code&gt;Phi3&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Orchestrator application - Kaggle notebook&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Install the python libraries
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;! pip install -U qdrant-client --quiet
! pip install -U sentence-transformers --quiet
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Imports
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from qdrant_client import models, QdrantClient
from sentence_transformers import SentenceTransformer,CrossEncoder
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Sentence Transformer Encoder
&lt;/h3&gt;

&lt;p&gt;Instantiate the sentence transformer encoder&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;encoder = SentenceTransformer("all-MiniLM-L6-v2")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create the Qdrant Collection
&lt;/h3&gt;

&lt;p&gt;We are creating&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In memory qdrant collection&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The collection name is BBC&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The size of the vector embedding to be inserted is the dimention of the encoder . In this case , the dimension when evaluated is &lt;code&gt;384&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Distance of similarity is &lt;code&gt;cosine&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;qdrant = QdrantClient(":memory:")

qdrant.recreate_collection(
    collection_name="BBC",
    vectors_config=models.VectorParams(
        size=encoder.get_sentence_embedding_dimension(),  # Vector size is defined by used model
        distance=models.Distance.COSINE,
    ),
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Data Ingestion
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Read the Dataset
&lt;/h3&gt;

&lt;p&gt;Read the BBC News Dataset&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LIMIT = 500
df = pd.read_csv("/kaggle/input/bbc-news/bbc_news.csv")
docs = df[:LIMIT]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FySY37Kx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FySY37Kx.png" alt="BBC News Dataset Rows"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Upload the documents into Qdrant
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import uuid
%%capture --no-display
qdrant.upload_points(
    collection_name="BBC",
    points=[
        models.PointStruct(
            id=str(uuid.uuid4()), 
            vector=encoder.encode(row[1]["title"]),
            payload={ "title":row[1]["title"] ,
                     "description":row[1]["description"] }
        )
        for row in docs.iterrows()
    ],
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Verify the documents have been uploaded into Qdrant
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;qdrant.count(
    collection_name="BBC",
    exact=True,
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you have reached till this point, Congratulations 👌 . You have been able to complete the understanding of the &lt;strong&gt;Data Ingestion into Qdrant&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Query the Qdrant database
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Query for the user
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;query_string = "Describe the news for Ukraine"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Search Qdrant for the query
&lt;/h3&gt;

&lt;p&gt;For searching , note how we have converted the user input into a embedding&lt;/p&gt;

&lt;p&gt;&lt;code&gt;encoder.encode(query_string).tolist()&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;hits = qdrant.search(
    collection_name="BBC",
    query_vector=encoder.encode(query_string).tolist(),
    limit=35,
)

for hit in hits:
    print(hit.payload, "score:", hit.score)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Refine the result with the CrossEncoder
&lt;/h3&gt;

&lt;p&gt;We are refining the results from the CrossEncoder .&lt;/p&gt;

&lt;p&gt;We have got in our implementation K2 = 35 results from Qdrant. We have used the Cross Encoder &lt;code&gt;cross-encoder/ms-marco-MiniLM-L-6-v2&lt;/code&gt; to refine the results The refined results in our case K = 5 after we pass the results through the cross encoder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CROSSENCODER_MODEL_NAME = 'cross-encoder/ms-marco-MiniLM-L-6-v2'
RANKER_RESULTS_LIMIT = 5

user_input = query_string

contexts_list = []
for result in hits:
    contexts_list.append(result.payload['description'])

cross_encoder = CrossEncoder(CROSSENCODER_MODEL_NAME)
cross_inp = [[user_input, hit] for hit in contexts_list]
cross_scores = cross_encoder.predict(cross_inp)

cross_scores_text = []
cross_scores_length = len(cross_scores)
for i in range(cross_scores_length):
    d = {}
    d['score'] = cross_scores[i]
    d['text'] = contexts_list[i]
    cross_scores_text.append(d)

hits_selected = sorted(cross_scores_text, key=lambda x: x['score'], reverse=True)
contexts =""
hits = hits_selected[:RANKER_RESULTS_LIMIT]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create the context
&lt;/h3&gt;

&lt;p&gt;We create the Context for RAG using the search results&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;contexts =""
for i in range(len(hits)):
    contexts  +=  hits[i]['text']+"\n---\n"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you have reached till this point, Congratulations 👌 👌 again. You have been able to complete the understanding of the *&lt;em&gt;Getting Results from Qdrant [ Vector Database ] *&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Generate the answer with the Small Language Model
&lt;/h2&gt;




&lt;p&gt;Now we have got the context from the Vector Database , Qdrant and we would send the results to our small language model &lt;strong&gt;Phi3&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We also use the small language model &lt;strong&gt;microsoft/Phi-3-mini-128k-instruct&lt;/strong&gt; model .&lt;/p&gt;

&lt;p&gt;From the Hugging Face model card &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The Phi-3-Mini-128K-Instruct is a 3.8 billion-parameter, lightweight, state-of-the-art open model trained using the Phi-3 datasets. This dataset includes both synthetic data and filtered publicly available website data, with an emphasis on high-quality and reasoning-dense properties. The model belongs to the Phi-3 family with the Mini version in two variants 4K and 128K which is the context length (in tokens) that it can support.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;From the &lt;a href="https://azure.microsoft.com/en-us/blog/introducing-phi-3-redefining-whats-possible-with-slms/" rel="noopener noreferrer"&gt;Microsoft blog&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Thanks to their smaller size, Phi-3 models can be used in compute-limited inference environments. Phi-3-mini, in particular, can be used on-device, especially when further optimized with ONNX Runtime for cross-platform availability. The smaller size of Phi-3 models also makes fine-tuning or customization easier and more affordable. In addition, their lower computational needs make them a lower cost option with much better latency. The longer context window enables taking in and reasoning over large text content—documents, web pages, code, and more. Phi-3-mini demonstrates strong reasoning and logic capabilities, making it a good candidate for analytical tasks.&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;import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline

torch.random.manual_seed(0)

model = AutoModelForCausalLM.from_pretrained(
    "microsoft/Phi-3-mini-128k-instruct", 
    device_map="cuda", 
    torch_dtype="auto", 
    trust_remote_code=True, 
)
tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-128k-instruct")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create the prompt
&lt;/h3&gt;

&lt;p&gt;The prompt is created with 2 components &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Context which we created in the section &lt;code&gt;Create the context&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;User input which is the user input
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;prompt = f"""Answer based on context:\n\n{contexts}\n\n{user_input}"""
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create the message template
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;messages = [
     {"role": "user", "content": prompt},
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Generate the message
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;%%time
model_inputs = tokenizer.apply_chat_template(messages, return_tensors="pt")
model_inputs =  model_inputs.to('cuda')
generated_ids = model.generate(model_inputs, max_new_tokens=1000, do_sample=True)
decoded = tokenizer.batch_decode(generated_ids)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Print the answer
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print(decoded[0].split("&amp;lt;|assistant|&amp;gt;")[-1].split("&amp;lt;|end|&amp;gt;")[0])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;

&lt;p&gt;The code can be found in the &lt;strong&gt;Kaggle&lt;/strong&gt; notebook &lt;br&gt;
&lt;a href="https://www.kaggle.com/code/ambarish/bbc-news-advanced-rag-phi3" rel="noopener noreferrer"&gt;BBC NEWS Advanced RAG PHI3&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Apache Spark architecture</title>
      <dc:creator>Ambarish Ganguly</dc:creator>
      <pubDate>Fri, 30 Sep 2022 21:02:07 +0000</pubDate>
      <link>https://forem.com/ambarishg/apache-spark-architecture-5ehh</link>
      <guid>https://forem.com/ambarishg/apache-spark-architecture-5ehh</guid>
      <description>&lt;h1&gt;
  
  
  apachespark #spark #sparkarchitecture
&lt;/h1&gt;

&lt;p&gt;01 - Spark Architecture Basics in 6 mins. Concepts explained&lt;br&gt;
📓 Application&lt;br&gt;
📓 Driver&lt;br&gt;
📓 Executor&lt;br&gt;
📓 Partition&lt;br&gt;
📓 Job &lt;br&gt;
📓 Stage&lt;br&gt;
📓 Tasks&lt;br&gt;
📓 Slots&lt;br&gt;
📓 Lazy evaluation&lt;br&gt;
📓 Narrow and wide Transformations&lt;br&gt;
📓 Actions&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/dSZ8-Ounnvs"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>apachespark</category>
      <category>spark</category>
    </item>
    <item>
      <title>Paddy Disease Classification using Azure AI</title>
      <dc:creator>Ambarish Ganguly</dc:creator>
      <pubDate>Sat, 23 Jul 2022 06:13:00 +0000</pubDate>
      <link>https://forem.com/ambarishg/paddy-doctor-paddy-disease-classification-1b7i</link>
      <guid>https://forem.com/ambarishg/paddy-doctor-paddy-disease-classification-1b7i</guid>
      <description>&lt;p&gt;&lt;strong&gt;Rice (Oryza sativa)&lt;/strong&gt; is one of the staple foods worldwide.    &lt;/p&gt;

&lt;p&gt;Paddy, the raw grain before removal of husk, is cultivated in tropical climates, mainly in Asian countries. Paddy cultivation requires consistent supervision because several diseases and pests might affect the paddy crops, leading to up to 70% yield loss. Expert supervision is usually necessary to mitigate these diseases and prevent crop loss. With the limited availability of crop protection experts, manual disease diagnosis is tedious and expensive. Thus, it is increasingly &lt;strong&gt;important to automate the disease identification process by leveraging computer vision-based techniques&lt;/strong&gt; that achieved promising results in various domains.   &lt;/p&gt;

&lt;h1&gt;
  
  
  Data
&lt;/h1&gt;

&lt;p&gt;Data is taken from &lt;a href="https://www.kaggle.com/competitions/paddy-disease-classification" rel="noopener noreferrer"&gt;Paddy Disease Classification Dataset from Kaggle&lt;/a&gt; We have taken a subset of the data provided in the dataset to demonstrate the power of Azure Cognitive Services&lt;/p&gt;

&lt;p&gt;I have made a small dataset [ &lt;strong&gt;1000 images - around 100 images of 10 classes&lt;/strong&gt; ] from the parent dataset in Kaggle mentioned above for quick experimentation. The data has around 100 images of each of the classes &lt;code&gt;bacterial_leaf_blight, bacterial_leaf_streak , bacterial_panicle_blight , blast , brown spot , dead heart , downy mildew , hispa , normal and tungro&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The steps to model and predict for this problem are as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a Custom Vision AI project&lt;/li&gt;
&lt;li&gt;Add Images to the project&lt;/li&gt;
&lt;li&gt;Train on the images and create the model&lt;/li&gt;
&lt;li&gt;Publish the model and expose the endpoint for use by other clients&lt;/li&gt;
&lt;li&gt;Use the exposed endpoint and predict using new images
&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Create a Custom Vision AI project
&lt;/h1&gt;

&lt;p&gt;Navigate to &lt;a href="https://www.customvision.ai/projects" rel="noopener noreferrer"&gt;https://www.customvision.ai/projects&lt;/a&gt; to create a custom vision project.&lt;/p&gt;

&lt;p&gt;We created a project with&lt;/p&gt;

&lt;p&gt;Name - paddy  &lt;/p&gt;

&lt;p&gt;Project Type - &lt;strong&gt;Classification&lt;/strong&gt;. Since we are classifying whether the image is having bacterial_leaf_blight, bacterial_leaf_streak , bacterial_panicle_blight , blast , brown spot , dead heart , downy mildew , hispa , normal and tungro       &lt;/p&gt;

&lt;p&gt;Classification Type - &lt;strong&gt;Multiclass&lt;/strong&gt;. There are 2 choices here, Multiclass and Multilabel. We choose Multiclass since the image is associated with only one class ( bacterial_leaf_blight, bacterial_leaf_streak , bacterial_panicle_blight , blast , brown spot , dead heart , downy mildew , hispa , normal and tungro ). A single image is not associated with multiple classes.   &lt;/p&gt;

&lt;p&gt;If a single image was associated with multiple classes, then we had to choose the Classification type as Multilabel.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fw5xub5dyo7puiokd7hx6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fw5xub5dyo7puiokd7hx6.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Add Images
&lt;/h1&gt;

&lt;p&gt;We upload the &lt;strong&gt;bacterial_leaf_blight&lt;/strong&gt; images and also tag them. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fa6lacyv76ex6pqrr7bkq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fa6lacyv76ex6pqrr7bkq.png" alt="Image description"&gt;&lt;/a&gt;             &lt;/p&gt;

&lt;p&gt;We also add images of other classes&lt;br&gt;&lt;br&gt;
&lt;em&gt;bacterial_leaf_streak , bacterial_panicle_blight , blast , brown spot , dead heart , downy mildew , hispa , normal and tungro&lt;/em&gt;        &lt;/p&gt;

&lt;h1&gt;
  
  
  Train the images
&lt;/h1&gt;

&lt;p&gt;We train the images by clicking the &lt;strong&gt;Train button&lt;/strong&gt;  in the portal     &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fim8jjvq6loaycul8sczs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fim8jjvq6loaycul8sczs.png" alt="Image description"&gt;&lt;/a&gt;    &lt;/p&gt;

&lt;h1&gt;
  
  
  Training
&lt;/h1&gt;

&lt;p&gt;We can select &lt;strong&gt;Quick Training&lt;/strong&gt; or &lt;strong&gt;Advanced Training&lt;/strong&gt; for training the images     &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2F32km85fygpc0u86uvdo2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F32km85fygpc0u86uvdo2.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We choose &lt;strong&gt;Advanced Training&lt;/strong&gt;  to train the images. Each of the 10 classess have around 100 images   .&lt;/p&gt;

&lt;p&gt;We do model training and we can see the various iterations    &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2F80flotqb852xlpk8ficu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F80flotqb852xlpk8ficu.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the output of the &lt;strong&gt;4th Iteration&lt;/strong&gt; [ Advanced Training ] . In Advanced Training, we can limit the budget by specifying the time duration    &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fyrf0qkjyws0ugitvvlsa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fyrf0qkjyws0ugitvvlsa.png" alt="Image description"&gt;&lt;/a&gt;         &lt;/p&gt;

&lt;h1&gt;
  
  
  Publish
&lt;/h1&gt;

&lt;p&gt;We can now Publish the model so that we can use the endpoint of the model for the prediction of unseen images.       &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fs89d2bp3tn1fqtzwjr9k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fs89d2bp3tn1fqtzwjr9k.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Project details
&lt;/h1&gt;

&lt;p&gt;We display the Azure Cognitive project which has the &lt;strong&gt;project id, the published endpoint&lt;/strong&gt;. This will be used for predicting the unseen test images. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2F6er1p35dogdpfkhxhnq7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F6er1p35dogdpfkhxhnq7.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2F7nauaapo4dq5gd783cic.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F7nauaapo4dq5gd783cic.png" alt="Image description"&gt;&lt;/a&gt;             &lt;/p&gt;

&lt;h1&gt;
  
  
  Prediction
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Import the libraries
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;azure.cognitiveservices.vision.customvision.training&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;CustomVisionTrainingClient&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;azure.cognitiveservices.vision.customvision.prediction&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;CustomVisionPredictionClient&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;azure.cognitiveservices.vision.customvision.training.models&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ImageFileCreateBatch&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ImageFileCreateEntry&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Region&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;msrest.authentication&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ApiKeyCredentials&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;uuid&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Set the parameters
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;ENDPOINT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;YOUR ENDPOINT&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;training_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;YOUR training_key&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;prediction_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;YOUR prediction_key&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;prediction_resource_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;YOUR prediction_resource_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;project_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;YOUR project_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;publish_iteration_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;YOUR publish_iteration_name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Complete the prediction
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;base_image_location&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dirname&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__file__&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;train_images&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="c1"&gt;# Now there is a trained endpoint that can be used to make a prediction
&lt;/span&gt;&lt;span class="n"&gt;prediction_credentials&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ApiKeyCredentials&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;in_headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Prediction-key&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;prediction_key&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="n"&gt;predictor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;CustomVisionPredictionClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ENDPOINT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prediction_credentials&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;base_image_location&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;blast/110406.jpg&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;rb&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;image_contents&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;predictor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;classify_image&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;project_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;publish_iteration_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;image_contents&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

    &lt;span class="c1"&gt;# Display the results.
&lt;/span&gt;    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;prediction&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;predictions&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="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\t&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;prediction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tag_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;: {0:.2f}%&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prediction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;probability&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  References
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://www.kaggle.com/competitions/paddy-disease-classification/overview" rel="noopener noreferrer"&gt;Paddy Disease Classsification Dataset&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;2.&lt;a href="https://docs.microsoft.com/en-us/azure/cognitive-services/custom-vision-service/quickstarts/image-classification?tabs=visual-studio&amp;amp;pivots=programming-language-python" rel="noopener noreferrer"&gt;Azure Custom Vision&lt;/a&gt;        &lt;/p&gt;

</description>
      <category>azure</category>
      <category>azurecustomvision</category>
      <category>computervision</category>
    </item>
    <item>
      <title>Hidden Gems Book</title>
      <dc:creator>Ambarish Ganguly</dc:creator>
      <pubDate>Mon, 16 May 2022 03:43:30 +0000</pubDate>
      <link>https://forem.com/ambarishg/hidden-gems-book-1342</link>
      <guid>https://forem.com/ambarishg/hidden-gems-book-1342</guid>
      <description>&lt;p&gt;If you are interested in &lt;br&gt;
🌟 Data Visualization &lt;br&gt;
🌟 Text Mining&lt;br&gt;
🌟 Network Graphs &lt;br&gt;
🌟 Cosine Similarity Recommenders &lt;br&gt;
🌟 Topic Modelling &lt;br&gt;
🌟 Dimension Reduction using Principal Component Analysis&lt;/p&gt;

&lt;p&gt;please check out the notebook written in book format in &lt;a href="https://ambarishg.github.io/hiddengems/what-is-kaggle.html"&gt;Hidden Gems Book&lt;/a&gt;          &lt;/p&gt;

&lt;h1&gt;
  
  
  What is Kaggle
&lt;/h1&gt;

&lt;p&gt;From the Kaggle website            &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Kaggle offers a no-setup, customizable, Jupyter Notebooks environment. Access GPUs at no cost to you and a huge repository of community published data &amp;amp; code.       &lt;/p&gt;

&lt;p&gt;Inside Kaggle you’ll find all the code &amp;amp; data you need to do your data science work. Use over 50,000 public datasets and 400,000 public notebooks to conquer any analysis in no time.         &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Kernels in Kaggle Terminology are scripts , notebooks which have been shared in Kaggle to be viewed by the community         &lt;/p&gt;

&lt;p&gt;Kaggle also hosts &lt;strong&gt;data science competitions , datasets , notebooks&lt;/strong&gt; shared by the community and also a number of wonderful &lt;strong&gt;courses to learn hands on data science&lt;/strong&gt;                         &lt;/p&gt;

&lt;h1&gt;
  
  
  Hidden Gems
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Heads or Tails&lt;/strong&gt; [&lt;code&gt;Martin Henze&lt;/code&gt;] has compiled a list of 300 kernels for a period of 100 weeks which he believes are &lt;strong&gt;Hidden Gems&lt;/strong&gt; , Kernels which are Gems but they did not get their due recognition. Thanks to the wonderful effort, Heads or Tails for the Kaggle Community.                          &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Photo by Dan Farrell on Unsplash&lt;/em&gt;&lt;/p&gt;

</description>
      <category>datascience</category>
      <category>eventdriven</category>
      <category>recommender</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Logistic Regression and Classification</title>
      <dc:creator>Ambarish Ganguly</dc:creator>
      <pubDate>Tue, 29 Mar 2022 06:10:37 +0000</pubDate>
      <link>https://forem.com/aws-builders/logistic-regression-2i31</link>
      <guid>https://forem.com/aws-builders/logistic-regression-2i31</guid>
      <description>&lt;p&gt;💎 Concept of Logistic Regression&lt;br&gt;
💎 Applications of Classification&lt;br&gt;
💎 Concepts of True Positive, True Negative, False Positive , False Negative &lt;br&gt;
💎 Concepts of Sensitivity and Specificity&lt;br&gt;
💎 Concepts of Precision and Recall and when to apply what&lt;br&gt;
💎 Concepts of F [ Beta ] Score and F1 Score&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/s3SYWRD3i0g"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>datascience</category>
      <category>classification</category>
    </item>
    <item>
      <title>PCA with Cricket Analytics and AWS SageMaker in 15 minutes</title>
      <dc:creator>Ambarish Ganguly</dc:creator>
      <pubDate>Sun, 20 Mar 2022 16:23:03 +0000</pubDate>
      <link>https://forem.com/aws-builders/pca-with-cricket-analytics-and-aws-sagemaker-in-15-minutes-4fj6</link>
      <guid>https://forem.com/aws-builders/pca-with-cricket-analytics-and-aws-sagemaker-in-15-minutes-4fj6</guid>
      <description>&lt;p&gt;🎁 Best Bowler in Indian Premier League [ Cricket ] 2020 season using PCA &lt;br&gt;
🎁 Principal Component Analysis  concepts&lt;br&gt;
🎁 Usage of AWS Sagemaker and PCA&lt;br&gt;
🎁 Code  and Data Files in the comments&lt;br&gt;
&lt;a href="https://github.com/ambarishg/sagemaker"&gt;https://github.com/ambarishg/sagemaker&lt;/a&gt; has the code and data files&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/InTBvFRzz-0?start=42"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>aws</category>
      <category>sagemaker</category>
      <category>datascience</category>
      <category>pca</category>
    </item>
    <item>
      <title>Central Limit Theorem</title>
      <dc:creator>Ambarish Ganguly</dc:creator>
      <pubDate>Tue, 15 Mar 2022 15:46:50 +0000</pubDate>
      <link>https://forem.com/aws-builders/central-limit-theorem-892</link>
      <guid>https://forem.com/aws-builders/central-limit-theorem-892</guid>
      <description>&lt;p&gt;The following video on Central Limit Theorem in 5 minutes discusses the following topics        &lt;/p&gt;

&lt;p&gt;✅ Population&lt;br&gt;&lt;br&gt;
✅ Sample&lt;br&gt;&lt;br&gt;
✅ Central Limit Theorem&lt;br&gt;&lt;br&gt;
✅ Central Limit Theorem example      &lt;/p&gt;

&lt;p&gt;Hope you find it useful in your datascience and machine learning journey          &lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/4nUhy9kc2VU"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>statistics</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Binomial Distribution and Case studies</title>
      <dc:creator>Ambarish Ganguly</dc:creator>
      <pubDate>Sun, 31 Oct 2021 18:39:04 +0000</pubDate>
      <link>https://forem.com/ambarishg/binomial-distribution-and-case-studies-md3</link>
      <guid>https://forem.com/ambarishg/binomial-distribution-and-case-studies-md3</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Mti755NyFNc"&gt;
&lt;/iframe&gt;
            &lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/yyqoggEqMG8"&gt;
&lt;/iframe&gt;
           &lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/wYY52gc-QFc"&gt;
&lt;/iframe&gt;
  &lt;/p&gt;

</description>
      <category>statistics</category>
    </item>
    <item>
      <title>Descriptive Statistics Part 2</title>
      <dc:creator>Ambarish Ganguly</dc:creator>
      <pubDate>Sun, 24 Oct 2021 15:43:16 +0000</pubDate>
      <link>https://forem.com/ambarishg/descriptive-statistics-part-2-51hb</link>
      <guid>https://forem.com/ambarishg/descriptive-statistics-part-2-51hb</guid>
      <description>&lt;p&gt;&lt;code&gt;statistics&lt;/code&gt; &lt;br&gt;
Chebyshev Theorem, Skewness, Kurtosis, Percentiles explained&lt;br&gt;&lt;br&gt;
I enjoyed creating this video and hope all of you will like it.         &lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/h_bc3eirBcM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>statistics</category>
    </item>
    <item>
      <title>Descriptive Statistics Part 1</title>
      <dc:creator>Ambarish Ganguly</dc:creator>
      <pubDate>Thu, 09 Sep 2021 04:58:54 +0000</pubDate>
      <link>https://forem.com/ambarishg/descriptive-statistics-part-1-3pke</link>
      <guid>https://forem.com/ambarishg/descriptive-statistics-part-1-3pke</guid>
      <description>&lt;p&gt;This is the 1st video in the Descriptive Statistics playlist. This is an introduction to Descriptive Statistics in a very simple manner.We will discuss the following&lt;br&gt;
💎 Mean , Median , Mode&lt;br&gt;&lt;br&gt;
💎 Variance and Standard Deviation&lt;br&gt;&lt;br&gt;
💎 Covariance and Correlation &lt;/p&gt;

&lt;p&gt;I enjoyed creating this video and hope all of you will like it.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/2rk-dpfOGTU"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Single Neuron video</title>
      <dc:creator>Ambarish Ganguly</dc:creator>
      <pubDate>Fri, 02 Jul 2021 19:00:09 +0000</pubDate>
      <link>https://forem.com/ambarishg/single-neuron-video-4i7a</link>
      <guid>https://forem.com/ambarishg/single-neuron-video-4i7a</guid>
      <description>&lt;p&gt;This is the first video. We explain the single neuron here.&lt;br&gt;&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/B8wrXc9QvH8"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>deeplearning</category>
    </item>
    <item>
      <title>Convolution in 1 dimension</title>
      <dc:creator>Ambarish Ganguly</dc:creator>
      <pubDate>Mon, 26 Apr 2021 10:48:58 +0000</pubDate>
      <link>https://forem.com/ambarishg/convolution-in-1-dimension-42l9</link>
      <guid>https://forem.com/ambarishg/convolution-in-1-dimension-42l9</guid>
      <description>&lt;h1&gt;
  
  
  Basics
&lt;/h1&gt;

&lt;p&gt;The &lt;strong&gt;Convolutional&lt;/strong&gt; block is one of the basic building blocks used in deep learning. We go in-depth with Convolution in 1 dimension and understand the basics of convolution, strides, and padding. We explain visually and also through PyTorch code to verify our concepts.   &lt;/p&gt;

&lt;p&gt;The Kernel takes an Input and provides an output which is sometimes referred to as  a &lt;code&gt;feature map&lt;/code&gt;   &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2F3cao5kxt96zowgh1kjwn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F3cao5kxt96zowgh1kjwn.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Kernel is made up of many things . This is a very simplified picture of the things it has . The weights , biases , strides and padding are some of them   &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fawd103mfeb2bxq02vcxx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fawd103mfeb2bxq02vcxx.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Kernel Size =  1 , Stride = 1
&lt;/h1&gt;

&lt;p&gt;Here the size of the kernel is 1. It has a single weight and bias.               &lt;/p&gt;

&lt;p&gt;Input is [ 2, 3, 4 ]    &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Stride is 1&lt;/code&gt;, therefore the kernel moves 1 slot after every operation.&lt;/p&gt;

&lt;p&gt;Outputs are    &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;2 * weight +  bias
&lt;/li&gt;
&lt;li&gt;3 * weight +  bias . The kernel moves 1 slot and operates on 3
&lt;/li&gt;
&lt;li&gt;4 * weight +  bias. The kernel moves 1 slot and operates on 4
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.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%2F9ryyg64gs3ho46f7gggg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F9ryyg64gs3ho46f7gggg.png" alt="image"&gt;&lt;/a&gt;    &lt;/p&gt;

&lt;p&gt;We implemented this in Pytorch and obtained the same result.&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;m&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;Conv1d&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;in_channels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;out_channels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;kernel_size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stride&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  

&lt;span class="nb"&gt;input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;tensor&lt;/span&gt;&lt;span class="p"&gt;([[[&lt;/span&gt;&lt;span class="mf"&gt;2.&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mf"&gt;3.&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mf"&gt;4.&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="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;m&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;input&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;output&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="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bias&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="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bias&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="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bias&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Kernel Size =  2 , Stride = 1
&lt;/h1&gt;

&lt;p&gt;Here the size of the kernel is 2. It has &lt;strong&gt;2 weights&lt;/strong&gt; and bias.   &lt;/p&gt;

&lt;p&gt;Input is [ 2, 3, 4 ]&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Step 1&lt;/code&gt;:&lt;br&gt;&lt;br&gt;
The weights w0 and w1 operate on inputs 2, 3. This provides the output 2 * w0 + 3 * w1 +  bias           &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Step 2&lt;/code&gt;:&lt;br&gt;&lt;br&gt;
The weights w0 and w1 operate on inputs 3, 4. This provides the output 3 * w0 + 4 * w1 +  bias   &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fcidd5y3rkwa29c710myt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fcidd5y3rkwa29c710myt.png" alt="image"&gt;&lt;/a&gt;   &lt;/p&gt;

&lt;p&gt;We implemented this in Pytorch and obtained the same result.&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;m&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;Conv1d&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;in_channels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;out_channels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;kernel_size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stride&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bias&lt;/span&gt;

&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;  &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bias&lt;/span&gt; 
&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;  &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bias&lt;/span&gt; 

&lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;m&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;input&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;output&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Kernel Size =  2 , Stride = 2
&lt;/h1&gt;

&lt;p&gt;Here the size of the kernel is 2. It has &lt;strong&gt;2 weights&lt;/strong&gt; and bias.   &lt;/p&gt;

&lt;p&gt;Input is [ 2, 3, 4 ]&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Step 1&lt;/code&gt;:&lt;br&gt;&lt;br&gt;
The weights w0 and w1 operate on inputs 2, 3. This provides the output 2 * w0 + 3 * w1 +  bias           &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Step 2&lt;/code&gt;:&lt;br&gt;&lt;br&gt;
The kernel moves &lt;strong&gt;2&lt;/strong&gt; slots. Therefore, the kernel cannot operate on 4.    &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2F4fxf50byzy2ujynf59fo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F4fxf50byzy2ujynf59fo.png" alt="image"&gt;&lt;/a&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;m&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;Conv1d&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;in_channels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;out_channels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;kernel_size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stride&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bias&lt;/span&gt;

&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;  &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bias&lt;/span&gt; 

&lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;m&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;input&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;output&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Kernel Size =  2 , Stride = 2 , Padding = 1
&lt;/h1&gt;

&lt;p&gt;Here the size of the kernel is 2. It has &lt;strong&gt;2 weights&lt;/strong&gt; and bias.&lt;/p&gt;

&lt;p&gt;With padding = 1, the kernel has zeros on both sides of the input as you can see in the figure  &lt;/p&gt;

&lt;p&gt;Input is [ 2, 3, 4 ]&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Step 1&lt;/code&gt;:&lt;br&gt;&lt;br&gt;
The weights w0 and w1 operate on inputs 0, 2. This provides the output 0 * w0 + 2 * w1 +  bias           &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Step 2&lt;/code&gt;:&lt;br&gt;&lt;br&gt;
The kernel moves &lt;strong&gt;2&lt;/strong&gt; slots. &lt;br&gt;
The weights w0 and w1 operate on inputs 3, 4. This provides the output 3 * w0 + 4 * w1 +  bias &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fkkejb1yjvag15mknnio4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fkkejb1yjvag15mknnio4.png" alt="image"&gt;&lt;/a&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;m&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;Conv1d&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;in_channels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;out_channels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;kernel_size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stride&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;padding&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bias&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;  &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bias&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="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bias&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;m&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;input&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;output&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Kaggle notebook link
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://www.kaggle.com/ambarish/conv1d-deep-dive" rel="noopener noreferrer"&gt;Convolution in 1 dimension deep dive&lt;/a&gt;&lt;/p&gt;

</description>
      <category>deeplearning</category>
      <category>pytorch</category>
    </item>
  </channel>
</rss>
