<?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 Priyal Taneja on Medium]]></title>
        <description><![CDATA[Stories by Priyal Taneja on Medium]]></description>
        <link>https://medium.com/@priyaltaneja?source=rss-c6847f30c07a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*otpC7eDc6B_FbGnJ-Ccssw@2x.jpeg</url>
            <title>Stories by Priyal Taneja on Medium</title>
            <link>https://medium.com/@priyaltaneja?source=rss-c6847f30c07a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 23:38:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@priyaltaneja/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[From Query to Meaning; Reshaping the Landscape of Google Search Results Through Semantic Search.]]></title>
            <link>https://priyaltaneja.medium.com/from-query-to-meaning-reshaping-the-landscape-of-google-search-results-through-semantic-search-7f5aa02ebc65?source=rss-c6847f30c07a------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f5aa02ebc65</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[semantic-search]]></category>
            <dc:creator><![CDATA[Priyal Taneja]]></dc:creator>
            <pubDate>Wed, 07 Jun 2023 03:58:20 GMT</pubDate>
            <atom:updated>2023-06-07T03:58:20.661Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve always hated French class.</p><p>Not only was the class incredibly boring, but it was impossible to scam the system. Using Google Translate was strictly off-limits in that class.</p><p>Whenever I zoned out in the middle of a lesson, I was always questioning how my teachers just knew if our writing was authentic French or copied from Google Translate.</p><p>And, my semester-long question was answered when a classmate tried to translate ‘I am excited’ and wrote an inappropriate response on his test.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hSBFYs5OFW0_z6igCcUYEw.png" /></figure><p><em>If you know, you know.</em></p><p>Google Translate renders its translation word-by-word, and doesn’t consider the context of the phrase. So, instead of realizing its providing the wrong translation for the phrase asked, it just translates each word individually and calls it a day.</p><p>That’s how we get caught in class — <strong>when the results are contextually wrong.</strong></p><p>Although, I’m done French class for the rest of my life — <strong>but, this problem still exists. </strong>It extends beyond this one moment but rather into our lives as well.</p><p>With the usage of technology rising exponentially, it’s important that we are understood by our computers. It has a huge impact on so many aspects of our lives, with a significant focus on one essential element: <strong>information search.</strong></p><p>Searching for information on engines like Google has become a fundamental part of our daily routines, and we couldn’t see the world without it.</p><p><em>But, there’s flaws.</em></p><p>Sometimes, even powerful search engines like Google can’t decipher what you’re looking for.</p><p><strong>So, let’s optimize these engines to understand us, humans, while increasing the value plus efficiency of information retrieval.</strong></p><h3>Understanding the Problem.</h3><p>Let’s start by dumbing the problem down and understanding it at its fundamental level.</p><p>In order for us to get the correct translation or results based on the search we write, the computer needs to understand what we’re saying.</p><p>But, this is trickier than it sounds.</p><p>Humans excel at understanding and communicating through words. That’s why you’re understanding my words so easily. But, computers only understand numbers, specifically binary numbers.</p><p>There’s a disconnect between the two so, for us two to sit down and have a conversation, we need a coherent translator for both parties to understand.</p><p><strong>And, this translation needs to be as seamless as possible.</strong></p><p><em>Just like this Friends episode.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PS3Wbg-SLS7cYh2ysj-SjA.jpeg" /></figure><p>What we’re looking at is a notion called Natural Language Processing (NLP), <strong>which describes the ability of a computer to understand spoken and written human language.</strong></p><p>For years, it wasn’t even close to its optimal capability. In order for a search engine to be of true value to a user, they shouldn’t have to think twice about whether their question is worded 100% perfectly. And, the first few responses should be beneficial.</p><p>But, that isn’t the case.</p><h4>The Problem Lies In Keyword Search.</h4><p>In a statement released a couple of years ago, Google acknowledged that its search functionality was not performing optimally. They admitted that users needed to incorporate specific “keywords” into their queries to align with the <strong>keyword search algorithm</strong>, even if it resulted in a less authentic or natural way of asking for information.</p><blockquote>“At its core, Search is about understanding language. It’s our job to figure out what you’re searching for and surface helpful information from the web, no matter how you spell or combine the words in your query. While we’ve continued to improve our language understanding capabilities over the years, we sometimes still don’t quite get it right, particularly with complex or conversational queries. In fact, that’s one of the reasons why people often use “keyword-ese,” typing strings of words that they think we’ll understand, but aren’t actually how they’d naturally ask a question.”</blockquote><blockquote>— Google</blockquote><p>Before the advent of semantic search, the most popular method of searching was through <strong>keyword search.</strong></p><p>Let’s say I typed into the search bar <em>“What is an Apple, a Banana and Grapes?”</em></p><p><em>And I have a sample set of responses…</em></p><blockquote><em>1) The Apple is a fruit.</em></blockquote><blockquote><em>2) The Pear is a fruit.</em></blockquote><blockquote><em>3) The Apple and Banana are fruits.</em></blockquote><blockquote><em>4) An Apple is a fruit, a Banana is a fruit, and Grapes are not fruits.</em></blockquote><blockquote><em>5) There’s a tree outside.</em></blockquote><p>The process will involve the model analyzing the question and finding synonymous terms shared between the query and the response.</p><blockquote>“<strong>What is an Apple, a Banana and Grapes?</strong>”</blockquote><blockquote><em>1) The </em><strong><em>Apple</em></strong><em> </em><strong><em>is</em></strong><em> </em><strong><em>a</em></strong><em> fruit. [3 words]</em></blockquote><blockquote><em>2) The Pear </em><strong><em>is</em></strong><em> </em><strong><em>a</em></strong><em> fruit. [2 words]</em></blockquote><blockquote><em>3) The </em><strong><em>Apple</em></strong><em> </em><strong><em>and</em></strong><em> </em><strong><em>Banana</em></strong><em> are fruits. [3 words]</em></blockquote><blockquote><em>4)</em><strong><em> An</em></strong><em> </em><strong><em>Apple</em></strong><em> </em><strong><em>is</em></strong><em> </em><strong><em>a</em></strong><em> fruit, </em><strong><em>a</em></strong><em> Banana </em><strong><em>is a</em></strong><em> fruit, </em><strong><em>and</em></strong><em> </em><strong><em>Grapes</em></strong><em> are not fruits. [9 words]</em></blockquote><blockquote><em>5) There’s </em><strong><em>a</em></strong><em> tree outside. [1 word]</em></blockquote><p>Then, the response with the highest number of common words will be generated and returned to the user.</p><p><em>So, let’s rerank our responses now…</em></p><blockquote>“<strong>What is an Apple, a Banana and Grapes?</strong>”</blockquote><blockquote><strong><em>1) An</em></strong><em> </em><strong><em>Apple</em></strong><em> </em><strong><em>is</em></strong><em> </em><strong><em>a</em></strong><em> fruit, </em><strong><em>a</em></strong><em> Banana </em><strong><em>is a</em></strong><em> fruit, </em><strong><em>and</em></strong><em> </em><strong><em>Grapes</em></strong><em> are not fruits. [9 words]</em></blockquote><blockquote><em>2) The </em><strong><em>Apple</em></strong><em> </em><strong><em>and</em></strong><em> </em><strong><em>Banana</em></strong><em> are fruits. [3 words]</em></blockquote><blockquote><em>3) The </em><strong><em>Apple</em></strong><em> </em><strong><em>is</em></strong><em> </em><strong><em>a</em></strong><em> fruit. [3 words]</em></blockquote><blockquote><em>4) The Pear </em><strong><em>is</em></strong><em> </em><strong><em>a</em></strong><em> fruit. [2 words]</em></blockquote><blockquote><em>5) There’s </em><strong><em>a</em></strong><em> tree outside. [1 word]</em></blockquote><p><strong>There’s a clear issue with this.</strong></p><p>The returned response is misleading, as responses #2 and #3 are actually accurate. However, due to the program’s focus on identifying common words, response #1 is selected and returned simply because it mentions all three fruits.</p><p>This algorithm is why <strong>it’s extremely easy to receive irrelevant responses when you search a question on the internet, as it may fail to understand the actual ask behind what your words but rather recognize a ‘similarity’ score between the words involved.</strong></p><h3>An Upgraded Solution — Semantic Search.</h3><p><strong>TL;DR till this point </strong>— the problem is that computers evaluate our sentences based on individual words, which results in misunderstandings and inaccurate answers.</p><p>A quick way to to address this issue is to shift the computer’s reliance away from common words and instead focus on understanding the contextual meaning of the query and response. <strong>By understanding the intent behind the ask, the computer can improve its ability to provide accurate and meaningful answers.</strong></p><p>And, we can do this through a new NLP approach called <strong><em>Semantic Search.</em></strong></p><blockquote><strong>Let’s break our term into its two pieces.</strong></blockquote><blockquote>Search = the process of locating and retrieving a specific piece of information.</blockquote><blockquote>Semantic = the philosophical study of meaning.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jzyqDqVBBB-5Gt-P5m5zIA.png" /></figure><blockquote>And, this philosophical definition proves true within computer science as well.</blockquote><blockquote>Now, let’s reconnect the dots with our two components and understand semantic search.</blockquote><p>At its core, semantic search is <strong>a data-searching technique that aims to extend beyond the keywords interpretation within the search bar but also strives to determine the intent and contextual meaning behind a search query.</strong></p><p><em>In short, semantic search can be simplified down to a three-step process:</em></p><ol><li>Text Embedding Is Used To Turn Words into Vectors</li><li>Similarity Methods to Find the Vector Among the Responses Which is The Most Similar to the Vector Corresponding to the Query</li><li>The Corresponding Response to This Most Similar Vector is Outputted</li></ol><p><strong>Let’s take a deeper look.</strong></p><h4>1) Text Embeddings</h4><p>Our end objective is to have a smooth, knowledgeable translator between the computer and the human — and, <strong>text embeddings are responsible for making this a reality through correctly assigning a number to a word.</strong></p><p>But, this array of numbers that’s assigned to a word is very intentional and captures the words true meaning.</p><p><em>Let’s say I have a randomized list of words…</em></p><ol><li>Airpods</li><li>Apple</li><li>Banana</li><li>Bracelet</li><li>Earrings</li><li>iPhone</li><li>Macbook</li><li>Necklace</li><li>Pear</li></ol><p>Automatically, when you look at this set of words, you can internally divide them into three distinct categories:<strong> Fruits, jewelry and Apple products.</strong></p><p><em>So, let’s rearrange…</em></p><p><strong>Category #1: Fruits</strong></p><ol><li>Apple</li><li>Banana</li><li>Pear</li></ol><p><strong>Category #2: Jewelry</strong></p><ol><li>Bracelet</li><li>Earrings</li><li>Necklace</li></ol><p><strong>Category #3: Apple Products</strong></p><ol><li>Airpods</li><li>iPhone</li><li>Macbook</li></ol><p>Now, if I were to give you the word ‘Ring’, you’d probably think of category #2, since it fits with the theme of jewelry. And, you can see visually, how this separation would play out on an x-y axis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QnxbNGgwT1n1WIHnCcJHJQ.png" /></figure><p>Here, you can see that the categories are as far apart as possible. And, this is the very simple version of how text embeddings can assign a number to a word based on its graphical location in categories — Eg. Ring == [8, 6]</p><p>An ideal word embedding is characterized by close proximity between similar words and greater distances between dissimilar words.</p><p>But, this isn’t all.</p><p>We don’t want to rely on one form of ‘categories’ because that isn’t enough for the computer to <em>understand </em>the object individually. So, we want to build a text embedding that captures the relations between words, as relations between numbers.</p><p><em>Kind of like how these four objects are mapped out…</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TIAC1-k-A_1HQs6ycm-vVA.png" /></figure><p>Now, there’s two ways these four objects can be sorted into its respective categories. These two axes represent different relationships between the words; vertical = bigger items, horizontal = objective categories.</p><p>So, it seems that this embedding is comprehending that the words in it have two main properties. And, our computer also understands that if we included the bracelet and an iPad, they’d probably go in the middle of each horizontal axis. <strong>Basically, it’s identifying features.</strong></p><p>In terms of our array of numbers, each features represents two coordinates, since we can have multiple ‘graphs’ per feature.</p><p><em>Eg. a text embedding could look like [8, 6, 4, 3]</em></p><p><strong>But, a good text embedding has way more than two coordinates to truly capture the essence of the word.</strong> Companies like <a href="https://cohere.com/"><em>Cohere</em></a> that have deployed text embeddings API tools have 4096 coordinates associated with each word, so they capture 2048 features. Some of these features may even be beyond human comprehension, that’s how good it is at conceptualizing the meaning of words.</p><h4>2) Similarity Methods</h4><p>Overall, text embedding is the heart of NLP &amp; works towards truly understanding the intention behind a user’s words. But, our end goal is to ensure that the query is understood and matches the responses.</p><p><em>So, if we had this set of questions…</em></p><ol><li>Where does the bear live?</li><li>Where is the world cup?</li><li>What color is the sky?</li><li>What is an apple?</li></ol><p><em>And, this set of answers…</em></p><ol><li>The bear lives in the woods</li><li>The world cup is in Qatar</li><li>The sky is blue</li><li>An apple is a fruit</li></ol><p>And, we can encode these 8 sentences through text embeddings. Just like before, we can plot the sentences in the plane with 2 coordinates. But, in order to match the query and response, we need to evaluate the similarities between the text embeddings.</p><p>This is done through <strong>similarity methods</strong> — a way to tell if two pieces of text are similar or different.</p><p><em>There’s two common ways to assess similarity:</em></p><ul><li><strong>Dot Product Similarity</strong></li><li><strong>Cosine Similarity</strong></li></ul><p>Both of these involve the notion of comparing two documents or two texts and representing the contrast with a number. Overall, a high number demonstrates a comparison of text to itself, a relatively high number when comparing two similar pieces of text, and a small number when comparing two different pieces of text.</p><p>Today, we’re going to focus on <strong>cosine similarity, a metric commonly used to measure the similarity between two vectors in a vector space.</strong> It’s unique because the values it returns are between zero and one. And, the similarity between itself and the text is always one and the lowest value taken is 0 — meaning, they’re not similar at all.</p><p>So, back to our questions &amp; answers.</p><p>If we were to start off with our first question — <em>“Where is the world cup?” </em>— what’ll happen is that it’ll get compared to all 8 sentences, and each analysis is given a score from zero to one. But, you cannot output the highest score as it’ll be the question itself, with a score of 1, so the system will eliminate it and turn to the nearest ‘neighbour’ that’ll fall at a score of ~0.7.</p><p>And, this process is repeated for each sentence.</p><p><em>The plot is as follows:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n5J5o7eJSVjZA8dWG9n-IQ.png" /><figcaption><a href="https://txt.cohere.com/what-is-semantic-search/">source</a></figcaption></figure><p><em>Here, these properties can be derived:</em></p><ol><li>In the diagonal of the matrix, you will find all entries filled with the value of 1, indicating that the similarity between each sentence and itself is 1, as expected.</li><li>For the pairs of sentences and their corresponding responses, the similarity scores hover around 0.7 which suggests a relatively high degree of similarity between these sentence pairs.</li><li>And, any other comparisons have a value lower than 0.7.</li></ol><p>Once the sentence embeddings have been reviewed, <strong>the queries will match with their corresponding answers.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0JEzNooAWJQXFNgqcJONTQ.png" /><figcaption><a href="https://txt.cohere.com/what-is-semantic-search/">source</a></figcaption></figure><h4>3) Output of Response</h4><p>And, once the computer understands how the sentence embeddings correspond with one another, it can finally take its learnings and output it to the user.</p><p>It’s as simple as that.</p><h3>Activating a Semantic Search Engine With Cohere &amp; Pinecone!</h3><p>Now, let’s apply all of that theoretical knowledge and apply the Cohere Embed API endpoint to generate language embeddings and later indexing those embeddings in the Pinecone vector database for fast and scalable vector search.</p><p><strong><em>Let’s walk through a step-by-step annotation together.</em></strong></p><p>After setting up our environment and downloading the required libraries, we’ll start off by forming embeddings.</p><h4>Create Embeddings</h4><p>To do this, we need to initialize our connection to Cohere, through importing the libraries and utilizing our API keys.</p><pre>import cohere<br><br>co = cohere.Client(&quot;&lt;YOUR API KEY&gt;&quot;)</pre><p>And, we need a questionnaire dataset to work with. So, for this, we can import the Text Retrieval Conference (TREC) question classification dataset and scale it down to 1000 questions.</p><pre>from datasets import load_dataset<br><br># load the first 1K rows of the TREC dataset<br>trec = load_dataset(&#39;trec&#39;, split=&#39;train[:1000]&#39;)</pre><p>Within each sample in the TREC dataset, there are two label features as well as the text feature. Our focus will be on utilizing the text feature. By taking the questions from the text feature, we can pass them to Cohere in order to generate embeddings.</p><pre>embeds = co.embed(<br>    texts=trec[&#39;text&#39;],<br>    model=&#39;small&#39;,<br>    truncate=&#39;LEFT&#39;<br>).embeddings</pre><p>We can also check the dimensionality of our returning vectors to ensure our model is performing correctly till this point, and it is! It’s producing the expected result of (1000, 1024).</p><pre>import numpy as np<br><br>shape = np.array(embeds).shape<br>print(shape)</pre><pre>[Out]:<br>(1000, 1024)</pre><p>With our embeddings in hand, the next step is to proceed with indexing them in the Pinecone vector database.</p><h4>Storing Embeddings</h4><p>To begin, we establish the connection to Pinecone, initializing it for further interactions. Following that, we create a fresh index dedicated to storing the embeddings, which we’ll name “cohere-pinecone-trec.”</p><p>During the index creation process, we specify our preference for utilizing the <em>cosine similarity metric</em> to align with the embeddings from Cohere. Additionally, we provide the information about the embedding dimensionality we just a step earlier.</p><pre>import pinecone<br><br># initialize connection to pinecone<br>pinecone.init(api_key=&quot;&lt;YOUR API KEY&gt;&quot;, environment=&quot;&lt;YOUR ENVIRONMENT&quot;)<br><br>index_name = &#39;cohere-pinecone-trec&#39;<br><br># if the index does not exist, we create it<br>if index_name not in pinecone.list_indexes():<br>    pinecone.create_index(<br>        index_name,<br>        dimension=shape[1],<br>        metric=&#39;cosine&#39;<br>    )<br><br># connect to index<br>index = pinecone.Index(index_name)</pre><p>With the index prepared, we can populate it with our embeddings. In our case, we will store the original text of the embeddings as part of the metadata, which enables us to associate the embeddings with their corresponding textual content for future reference and analysis.</p><pre>batch_size = 128<br><br>ids = [str(i) for i in range(shape[0])]<br># create list of metadata dictionaries<br>meta = [{&#39;text&#39;: text} for text in trec[&#39;text&#39;]]<br><br># create list of (id, vector, metadata) tuples to be upserted<br>to_upsert = list(zip(ids, embeds, meta))<br><br>for i in range(0, shape[0], batch_size):<br>    i_end = min(i+batch_size, shape[0])<br>    index.upsert(vectors=to_upsert[i:i_end])<br><br># let&#39;s view the index statistics</pre><pre>[Out]:<br>{&#39;dimension&#39;: 1024,<br> &#39;index_fullness&#39;: 0.0,<br> &#39;namespaces&#39;: {&#39;&#39;: {&#39;vector_count&#39;: 1000}}}</pre><p>The output reveals that we have successfully populated a 1024-dimensional index with a total of 1000 embeddings. However, when examining the indexFullness metric, it indicates that our index is currently empty, meaning it has no entries or data stored within it.</p><h4>Semantic Search</h4><p><strong>Now that our vectors are indexed, we can move on to performing several search queries.</strong></p><p>To conduct a search, we start by embedding our query using Cohere, which generates a vector representation. From there, we use this returned vector to search within the Pinecone vector database we’ve set up.</p><pre>query = &quot;What caused the 1929 Great Depression?&quot;<br><br># create the query embedding<br>xq = co.embed(<br>    texts=[query],<br>    model=&#39;small&#39;,<br>    truncate=&#39;LEFT&#39;<br>).embeddings<br><br>print(np.array(xq).shape)<br><br># query, returning the top 5 most similar results<br>res = index.query(xq, top_k=5, include_metadata=True)</pre><pre>for match in res[&#39;matches&#39;]:<br>    print(f&quot;{match[&#39;score&#39;]:.2f}: {match[&#39;metadata&#39;][&#39;text&#39;]}&quot;)</pre><pre>[OUT]:<br>0.83: Why did the world enter a global depression in 1929 ?<br>0.75: When was `` the Great Depression &#39;&#39; ?<br>0.50: What crop failure caused the Irish Famine ?<br>0.34: What war did the Wanna-Go-Home Riots occur after ?<br>0.34: What were popular songs and types of songs in the 1920s ?</pre><p>Here, the output showcases the most related questions to the query in the correct ranking order, which is determined by the similarity vector.</p><p>The paraphrased version of the query receives a high rating of 0.83, indicating a strong degree of similarity. On the other hand, a less relevant question related to entertainment in the 1920s has a lower score of 0.34, signifying a reduced level of similarity.</p><p>It’s going great so far. But, now, we’re going to test the model and determine if it can judge flaws in the query based on its contextual understanding of the event.</p><p><strong>So, let’s change ‘depression’ to ‘recession.’</strong></p><pre>query = &quot;What was the cause of the major recession in the early 20th century?&quot;<br><br># create the query embedding<br>xq = co.embed(<br>    texts=[query],<br>    model=&#39;small&#39;,<br>    truncate=&#39;LEFT&#39;<br>).embeddings<br><br># query, returning the top 5 most similar results<br>res = index.query(xq, top_k=5, include_metadata=True)<br><br>for match in res[&#39;matches&#39;]:<br>    print(f&quot;{match[&#39;score&#39;]:.2f}: {match[&#39;metadata&#39;][&#39;text&#39;]}&quot;)</pre><pre>[OUT]:<br>0.66: Why did the world enter a global depression in 1929 ?<br>0.61: When was `` the Great Depression &#39;&#39; ?<br>0.43: What crop failure caused the Irish Famine ?<br>0.43: What are some of the significant historical events of the 1990s ?<br>0.37: What were popular songs and types of songs in the 1920s ?</pre><p>As you can see, the similarity scores for this set of responses are relatively lower compared to the previous ones. But, despite the lower scores, the computer comprehends that the user intends to refer to the Great Depression.</p><p>So, it generates a similar range of questions as before, maintaining consistency in understanding the user’s intended meaning.</p><p>Pretty cool, if you ask me.</p><p>Now, we’ll do one last search, but instead of giving the computer to bounce off of keywords, <strong>we’ll use the definition of the Great Depression to truly test its knowledge.</strong></p><pre>query = &quot;Why was there a long-term economic downturn in the early 20th century?&quot;<br><br># create the query embedding<br>xq = co.embed(<br>    texts=[query],<br>    model=&#39;small&#39;,<br>    truncate=&#39;LEFT&#39;<br>).embeddings<br><br># query, returning the top 10 most similar results<br>res = index.query(xq, top_k=10, include_metadata=True)<br><br>for match in res[&#39;matches&#39;]:<br>    print(f&quot;{match[&#39;score&#39;]:.2f}: {match[&#39;metadata&#39;][&#39;text&#39;]}&quot;)</pre><pre>[OUT]:<br>0.71: Why did the world enter a global depression in 1929 ?<br>0.62: When was `` the Great Depression &#39;&#39; ?<br>0.40: What crop failure caused the Irish Famine ?<br>0.38: What are some of the significant historical events of the 1990s ?<br>0.38: When did the Dow first reach ?<br>0.35: What were popular songs and types of songs in the 1920s ?<br>0.33: What was the education system in the 1960 &#39;s ?<br>0.32: Give a reason for American Indians oftentimes dropping out of school .<br>0.31: What war did the Wanna-Go-Home Riots occur after ?<br>0.30: What historical event happened in Dogtown in 1899 ?</pre><p>And, our highest similarity vector is 0.71. That’s amazing — we can see the computer recognize the event based on its definition and timings, so it’ll output relevant questions.</p><p><strong>These examples clearly demonstrate the effectiveness of a semantic search pipeline for accurately identifying the meaning behind each query. </strong>By leveraging these embeddings alongside Pinecone, we can efficiently retrieve the most similar questions from the pre-indexed TREC dataset.</p><h3>Closing Thoughts</h3><blockquote>Wow, this is all so so cool.</blockquote><blockquote>The future of semantic search is expected to bring advancements such as improved understanding of user intent, multimodal search incorporating various input types, advancements in natural language processing (NLP), integration with knowledge graphs, domain-specific search, and continued advancements in machine learning. And, all these developments will result in more personalized, accurate, and comprehensive search experiences, completely changing how we interact with information and access knowledge.</blockquote><blockquote>What started as a mere rabbit hole of a cool-sounding algorithm resulted in a project of building a system capable of it and a journey of technical depth in a new area. Semantic search makes me so very excited for the future of Natural Language Processing, and I cannot wait to see what’s next in this space as inspirational companies like Cohere continue working towards making an impact.</blockquote><p><em>Hey, I’m Priyal, a 17-year-old who’s ambition revolves around working on solving complex problems to meaningfully contribute to the world. If you enjoyed my article or learned something new, feel free to subscribe to my </em><a href="https://priyaltaneja.substack.com/p/coming-soon"><strong><em>monthly newsletter</em></strong></a><em> to keep up with my progress quantum computing &amp; AI development, along with an insight into everything I’ve been up to. You can also connect with me on </em><a href="https://www.linkedin.com/in/priyaltaneja/"><strong><em>LinkedIn</em></strong></a><em> and follow my </em><a href="https://medium.com/@priyaltaneja"><strong><em>Medium</em></strong></a> <em>for more content!</em></p><p><em>Thank you so much for reading. I appreciate it.</em></p><p>— <a href="https://priyaltaneja.carrd.co/">Priyal</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f5aa02ebc65" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“I’ll Be Happy When [insert here]” — A Reflection on Conditional Happiness Versus True Happiness.]]></title>
            <link>https://priyaltaneja.medium.com/ill-be-happy-when-insert-here-a-reflection-on-conditional-happiness-versus-true-happiness-d842c73fa385?source=rss-c6847f30c07a------2</link>
            <guid isPermaLink="false">https://medium.com/p/d842c73fa385</guid>
            <category><![CDATA[happiness]]></category>
            <category><![CDATA[growth]]></category>
            <category><![CDATA[mindset]]></category>
            <dc:creator><![CDATA[Priyal Taneja]]></dc:creator>
            <pubDate>Tue, 06 Jun 2023 13:05:41 GMT</pubDate>
            <atom:updated>2023-06-06T13:05:41.672Z</atom:updated>
            <content:encoded><![CDATA[<h3>“I’ll Be Happy When [insert here]” — A Reflection on Conditional Happiness Versus True Happiness.</h3><blockquote>“Conditional Happiness not only prevents us from being happy in the present, it also stunts our progress and personal growth. It holds us back from the success we are forfeiting happiness to achieve.”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kM_jkzzaycqCpDIV5Yt_yA.png" /></figure><p>Around two months ago, I started an article (which still remains in my drafts) called ‘<em>I’ve Been More Happy Now Than I Have In The Last Couple Of Years… Why?’</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JIqbl50CweCDRjLYUxZ_Mg.png" /><figcaption>this is all i wrote for this article.</figcaption></figure><p>But weeks later, this article was still blank. Every night at 10:56 pm, I’d find myself back in my own mind, desperately searching for answers that just refused to show up.</p><p>To be honest, this wasn’t the best move on my part.</p><p>The more I questioned the ‘why’ behind my mental state, the more I became attached to figuring out. And, throughout that entire process, I think I ended up entering a cycle of self-sabotage.</p><p>As I’m writing this, everything I just mentioned reminded me of a concept that I had read about in ‘The Mountain is You’ by Brianna Wiest — this idea of self-sabotaging when you ‘hitting your upper limit.’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*5OGtPqBQoOK0ZQQKibb3xw.jpeg" /><figcaption>pic of one of my fav books; check it out:)</figcaption></figure><h3>JavaScript is not available.</h3><p></p><p>Humans are wired to seek comfort everywhere they go; it explains why no one puts themselves out to face a rejection or sings in the street full of random people— it’s uncomfortable.</p><p>In the past month, without even realizing it, I ended up losing sight of the initial question about the reason behind my elevated happiness levels. Instead, I became overly fixated on the outcomes I was experiencing — because in my mind, there was a correlation between the two.</p><p><strong>I began setting conditions for my happiness</strong>, all of which were based on the tangible achievements I’d been getting. My happiness became contingent upon certain factors being present or certain outcomes being achieved.</p><p>The tech nerd side of myself felt like it was easier to represent this in code — but, this is exactly how my internal brain was perceiving the world.</p><pre>if (outcome == True):<br>  happiness == True<br>else:<br>  happiness == False</pre><p>And, this methodology is the way in which countless people navigate their lives — formally, it’s called <strong>‘conditional happiness.’</strong></p><p>But, it’s not a sustainable model of thinking.</p><p>It puts you in a constant pursuit of external validation or the fulfillment of certain conditions in order to feel happy, but what actually ends up happening is that you fall into an infinite loop of waiting for the next ‘big’ thing.</p><p>It’s this idea that life can always be better than the current moment which sets us on a perpetual chase for the next condition that promises happiness. This becomes a never-ending cycle of constantly seeking improvement, never fully embracing the present.</p><p>And, this extends beyond just me.</p><p>So many people in the world around us think this way.</p><blockquote><strong>Some quotes I’ve heard…</strong></blockquote><blockquote>“I’ll be happy when I buy a car.”</blockquote><blockquote>“I’ll be happy when I’m rich.”</blockquote><blockquote>“I’ll be happy once I get a scholarship.”</blockquote><blockquote>“I’ll be happy if I get a promotion.”</blockquote><blockquote>“I’ll be happy when I get into my dream program.”</blockquote><blockquote>“I’ll be happy if I buy a Gucci bag.”</blockquote><p>I think the saddest thing is that this mental model of thinking is drilled into so many of us as children.</p><p>As I sit down and reflect, I can remember countless of asks I demanded from my parents. What started from toys led to luxury clothing and bags — all with the common ‘if I get [insert here], I’ll be happy and never ask for anything again’ phrase attached.</p><p>But, I don’t mean to imply that goals shouldn’t exist, and that improvement shouldn’t be a priority. Rather, true happiness isn’t dependent on anything outside of ourselves; it’s internal.</p><p>When happiness becomes conditional and relies on external factors, it transforms into a goal we strive to achieve rather than a natural expression of our being. <strong>True happiness, however, is found in the simple joy of existence itself. </strong>It shouldn’t be treated as a distant objective, but rather embraced as a way of life.</p><p>And, I think the couple of months where I was so invested into my high levels of happiness followed a structure where I didn’t care about achievements. I was very invested into building projects I found interesting and personally connected with at the time, one being <a href="https://youtu.be/wa1CPHWzkwc">epiphany</a>. I was going to sleep with a smile on my face every night because I enjoyed what I was working on… a lot.</p><p>But, as soon as I hit that pinnacle of an upper-limit, I found myself slipping into a headspace consumed by comparison. Instead of staying true to what truly mattered to me, I became fixated on measuring my outcomes against those of others.</p><p>From now and then, I’ve learnt that everything you do should be from a place of self-love and genuine interest instead of completing something for the sake of a potential outcome.</p><p>But, that’s specific to my case. For a general overview, recognizing that your happiness is based on expectations and achievements is the <em>first</em> step to true happiness — because, now, you’re self-aware.</p><p>Arguably, it’s the easiest step as well.</p><p>The real challenge of reaching true happiness is actually rewiring your brain in the way you think and how you react to the circumstances involving you.</p><p>I’ve had countless conversations discussing the internal insecurity of not seeing tangible results, and the entire process of navigating my thoughts led to my two-step process to reverse my thinking and reconnect with with that initial passion and authenticity.</p><blockquote>note — this worked best for me! something else might work better for you… i think the process of overcoming these thoughts comes down to identifying the type of conditions you’re setting in place.</blockquote><h4>1) A Detox From The Source of Conditions</h4><p>Like I’ve mentioned, a lot of my mental space was consumed by comparison. I identified the source of this was LinkedIn, especially during my hour-long scrolls through the app.</p><p>So, I deleted it off my phone for a while.</p><p>It was a conscious choice to embark on a detox of sorts, allowing my mind the freedom to wander without the constant influence of what others were doing or achieving.</p><p>I still remained updated on the projects of the people closest to me and I stayed connected with multiple communities through platforms like Slack. Of course, their ambition is always so so inspiring to see.</p><p>But, I refrained from fixating on stalking everyone’s achievements and comparing them to my own.</p><p><strong>A mental separation was my first step to redirect my attention towards nurturing my own passions.</strong></p><p>The first couple of days of doing this was weird, because I was breaking apart from this subconscious habit I was never intentional about. But, it all came together as I continued to give my brain a lil’ break.</p><h4>2) Exploring and Going Down Rabbit Holes</h4><p>Main lesson from my mini-detox? <strong>The conditions I had been setting for my happiness were nothing more than a time-waster</strong>. Instead of investing my time in engaging in meaningful learning experiences, I found myself caught in a web of overthinking.</p><p>And, this wasn’t fun. But, as I took away the root cause, I naturally fell back into this state where I could explore and concentrate on what mattered.</p><p>I started getting excited about finding the next thing for me to work on. Instead of the spontaneous LinkedIn scrolls, I time-blocked that same ~1 hour every night to just read article on artificial intelligence and see what’s out there.</p><p>This habit was nice.</p><p>After a few days of doing this, when I was going down an entire rabbit hole of leading &amp; growing companies, I came across Cohere and how they’re working on semantic search.</p><p>I loved it.</p><p>I spent a couple of days just going through their documentation (<em>ended up with 20+ pages of notes</em>) but I felt excited again. It felt nice. Being able to spend hours understanding the fundamentals of Natural Language Processing was so fulfilling.</p><p>And, this is what filled me with momentum to continue down the trajectory of exploring, along with helping me realize the flaws of obsessing over results.</p><p>This may seem like a small achievement, but even a small step towards true happiness is a victory in my opinion.</p><p>And, I’ve come to realize that a significant change in the way you doesn’t happen overnight. It’s an iterative process of both failures and successes, and it’s common to find yourself reverting to what’s comfortable. But, as long as you are self-aware, you’ll continue being conscious of your method of thinking.</p><p>Regardless, I’m still finding my way, navigating through life, and striving to be the best version of myself.</p><p><strong>TL;DR? As humans, our greatest gift is that happiness is in our control.</strong></p><p>Thank you… for reading this. I appreciate you.</p><p>— <a href="https://priyaltaneja.carrd.co/">Priyal</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d842c73fa385" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Just Travelled to the Future and Saw What I’ll Look Like at 75 Years Old With GANs]]></title>
            <link>https://priyaltaneja.medium.com/i-just-travelled-to-the-future-and-saw-what-ill-look-like-at-75-years-old-with-gans-f5de15e5cb2b?source=rss-c6847f30c07a------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5de15e5cb2b</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Priyal Taneja]]></dc:creator>
            <pubDate>Sat, 08 Apr 2023 01:45:29 GMT</pubDate>
            <atom:updated>2023-04-08T04:49:44.442Z</atom:updated>
            <content:encoded><![CDATA[<h4>Artificial Intelligence Can Help Us Time-Travel With <strong>Generative Adversarial Networks</strong></h4><p>I have a confession to make.</p><p>In 2017, I spent <em>hours</em> on FaceApp, to see what everyone around me would look at an older or younger age.</p><p>I was obsessed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*FWt7Ah8Iz5BL8KL3.gif" /></figure><p><strong>And, I think it was because of how realistic the final images were.</strong> They weren’t another SnapChat filter that didn’t align with my face, but rather an actual progression of what I could look like…. not that the wrinkles looked good. Either way, it looked like a picture I took in real-time.</p><p><em>It was definitely the closest I’ve gotten to time-travelling.</em></p><p>Back then, I never looked into the ‘how’ behind this feature. I was too busy producing baby &amp; older pictures of all my friends and family members while having a good laugh to understand the workings behind it.</p><p>Although, the other day, I saw this picture of Elon Musk as an old man — thinking it was real, until I realized it was another FaceApp edit. Completely slipping my mind was this fixation of mine, and all of a sudden, I was reminded of its initial trendiness when it was first released.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*7kO6l8LXVUtY0LLn.jpg" /></figure><p>But the difference between 6 years ago and now, is that the first thing I wanted to know was… how? From there, I actually connected the dots within my head and realized it has to be related to <strong>Artificial Intelligence — specifically GANs, or Generative Adversarial Networks.</strong></p><h3>Generative… What Now?</h3><p>Humans posses remarkable abilities to recognize and create new things. And, while we’ve made significant progress in teaching computers to recognize objects in the same manner as humans, the capability to generate novel content has been elusive for AI systems.</p><p>However, in 2014, Ian Goodfellow made a change to this, as he invented <strong><em>Generative Adversarial Networks </em></strong>— to finally unlock this ‘creation’ potential for AI systems.</p><p>According to Yann LeCun, GANs are “the most interesting idea in the last 10 years in Machine Learning” — and when a prominent researcher within the field of AI compliments this idea, you know it’s about to be good.</p><blockquote>And, he’s not wrong. The hype around GANs is what initially got me excited about the world of artificial intelligence.</blockquote><blockquote>Also, a couple of quick notes about machine learning before we continue… if you’re new to the world of AI,<strong> these terms are pretty important to know:</strong></blockquote><blockquote>1) <strong>Supervised Learning: </strong>A machine learning approach where the algorithm learns to predict outputs based on input data that has been labeled with the correct output values.</blockquote><blockquote>2)<strong> Unsupervised Learning: </strong>A machine learning approach where the algorithm learns to identify patterns and relationships in the input data without any explicit labeling of the data.</blockquote><blockquote>3) <strong>Reinforcement Learning: </strong>A machine learning approach where the algorithm learns to make decisions based on feedback from the environment, with the goal of maximizing a reward signal that is tied to the quality of the decisions made.</blockquote><p>Formally, <em>Generative Adversarial Networks (GANs)</em> are a type of unsupervised machine learning algorithm that use two neural networks — a <strong><em>generator</em></strong> and a <strong><em>discriminator</em></strong> — to generate new data that closely mimics pre-existing data. And, this is done through the GAN learning patterns &amp; relationships in the original data to create new, realistic images.</p><p><em>But, here’s my personal favourite way to think of GANs:</em></p><p>I’ve always loved drawing, but I’ve never reached a level where my drawings look like photographs. But, maybe, through a bit of <em>training</em> I could.</p><p>Let’s say I wanted to have someone ‘mentor’ me so I could refine my drawings, and while doing this I had to keep drawing a flower until it looked like an actual photograph.</p><p>I would repeatedly draw the flower and submit it to my mentor for feedback, who would assess whether it resembles a photograph or not. If they decide it was a drawing, I would iterate on the feedback until the drawing eventually passes as a photograph, and then I’ll achieve my goal of creating a realistic flower drawing from scratch.</p><p>Within that context, I’m the <em>generator</em> and my mentor would be the <em>discriminator</em>; but in the end, we produce a new ‘image’ that’s never seen before.</p><p><strong>But, let’s break this down further.</strong></p><h3>Training Generative ‘Adversarial’ Networks</h3><p>The ‘adversarial’ nature of this algorithm stems from the combination of these two neural networks — as they go against each other, until a beautiful, final output is created.</p><blockquote>Even though we know the gist of them, let’s get the formal definitions out of the way first:</blockquote><blockquote><em>1) </em><strong><em>Generator: </em></strong><em>A neural network within the GAN that’s a unsupervised model, which learns to generate new data samples that are similar to a set of real data sample.</em></blockquote><blockquote><em>2) </em><strong><em>Discriminator:</em></strong><em> A neural network within the GAN that’s a supervised model, which takes a data sample as an input to determine whether it’s realistic or fake.</em></blockquote><p>The architecture of a GAN can vary depending on the data type being generated, but more often than not, it follows this general process:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aPgsjeZmzG8tQtvqFhjttg.jpeg" /></figure><p>This diagram represents exactly what we’ve established already, with the adversarial component between the generator and the discriminator — <em>with the drawing &amp; mentor analogy.</em></p><p>But, both these neural networks are being trained at the exact same time, while iterating to get better at their respective roles. And, as the two neural networks train, they’re apart of a type of ‘min-max game’ where the generator and discriminator play against each other.</p><p><em>This ‘game’ is formally known as an optimization function:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DRUImmBc3ja9OvgS.png" /></figure><p>And, behind all these complex symbols, here’s what’s happening.</p><p>G represents the generator, and D represents the discriminator. And, x is a real data point, z is a random noise vector that the generator uses to create fake data, and E is the expectation function.</p><p>But, the generator is trying to minimize the discriminator’s ability to tell real data from fake data, while the discriminator is trying to maximize its ability to tell real data from fake data — hence, the max &amp; the min involved.</p><p>So, we can break the function down into two parts; where the first part, E_x[log(D(x))] measures how well the discriminator can identify real data points and the second part E_z[log(1-D(G(z)))] measures how well the discriminator can correctly identify fake data points create by the generator.</p><p>The generator wants to minimize the second part of the function, whereas the discriminator wants to maximize the entire function. An on-going argument between the two.</p><p>This stops when an equilibrium is reached between both parts of the function, so that the generated image is passed as ‘real’ by the discriminator.</p><p>But, this is a good thing. Because, as the generator gets better at creating data that looks real to the discriminator, the discriminator gets trained at identifying fake data — so the generator can produce the most realistic data possible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HE1pL4dWpte-txOw.jpg" /><figcaption>Example of GANs</figcaption></figure><h3>Some Variations of GANs</h3><p>There are at least 20+ type of GANs, along with many more being developed and researched on the daily. The general process of GANs falls into the same concept of a generator plus a discriminator, but there’s differences between their use cases &amp; the data-types involved.</p><p>Each GAN has its own strengths and weaknesses, but here’s a collection of GANs I found interesting during my whole deep-dive.</p><h4>ProgressiveGANs</h4><p>A couple years back, Remini — <em>an app used to turn blurry photos into HD</em> — was trending all over social media. It took extremely zoomed-in and pixelated images and turned them into sharpened photos, without taking anything away from the actual image.</p><p>That app, along with many others, are an example of ProgressiveGANs. They generate high-quality images in a progressive manner. PGANs start with low-resolution images and gradually increase the resolution over time while generating higher quality images at each stage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ly3Sh5D_2vC1F_i-.jpg" /></figure><h4><strong>ConditionalGANs</strong></h4><p>Traditional GANs generate images randomly through taking noise as an input. On the other hand, cGANs use additional information to control the generation process — which means, the generator network takes in both random noise and a condition or label as its input.</p><p>For example, if we had a model that generates images of handwritten digits conditioned on a specific digit label, the cGAN would use the digit label (0–9) to generate an image of the digit.</p><p>So, basically, the user can have control of the image that’s being generated as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*vGxQJtdXr45BdDUYu45s0g.png" /></figure><h4><strong>StyleGANs</strong></h4><p>StyleGANs are able to generate high-quality images with fine-grained control over their appearance. Traditional GANs learn to map a random vector to an image, whereas StyleGANs generate images by controlling the style and structure of each feature within an input image.</p><p>And, these GANs are responsible for my initial curiosity — how we can generate pictures that are older versions of ourselves.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3QW4IzY_li9a--Dv.jpg" /></figure><h3>How StyleGANs Work Within FaceApp</h3><p>This process is a little more specific and different in comparison to the general overview of traditional GANs.</p><p>The first step involves training our neural networks on a large and diverse dataset of images — which in this case, diversified ages.</p><p>Both our generator and discriminator learn from this training set in their own manner.</p><p>The generator is trained to create new images that mimic those within a training dataset. It’ll receive a random input vector (which is also known as a latent code) so that it’ll generate an image based on that code. This image is then compared to the real images from the training dataset, so that the generated images are updated to produce images that are extremely similar to real images.</p><p>On the other hand, we already know that the discriminator is trained to distinguish between real and fake images — so, our discriminator familiarizes itself with all the human-like features to ensure that the generated images are realistic.</p><p>So, once our StyleGAN has been trained, our next step is to generate an older version of a specific person’s face. The network takes an input of the person’s face (so, I could input a picture of my face) and then encodes it into a latent code to capture the essential features of the image.</p><p>From there, the encoded input image is modified to create a new latent code that represents an older version of the person’s face — <em>through all the training our generator has done on older images. </em>And, this process continues until our generated image passes through the discriminator and gets its final checkmark.</p><p>From there, voila, you’ve got your output which is you 30–35 years older… <em>even though it was most definitely not my favourite image.</em></p><h3>The Future of GANs</h3><p>The future of Generative Adversarial Networks is extremely exciting and full of loads of possibilities. Knowing that we’ve reached a point within Artificial Intelligence where we can create novel content is extremely significant for the development of the field.</p><p>So many industries can be impacted with this enhancement of deep learning, including but not limited to:</p><p><strong><em>Art and Design: </em></strong>We could generate new forms of art within a matter of seconds, allowing for a personalized and creative world of visuals. But, more than anything, this could be applied to the industries that are behind all of our enjoyments and luxuries; architecture, fashion &amp; product design.</p><p><strong><em>Medical Research: </em></strong>We could leverage GANs to generate realistic and accurate models of the human anatomy, which could help within medical research and training — allowing for help within diagnosis and treatments.</p><p><strong><em>Robotics and Autonomous Systems: </em></strong>This one is my favourite. We could use GANs to generate synthetic training data for autonomous sytems. For example, we could generate images of different environments for self-driving cars, so they learn how to navigate and interact with their surroundings.</p><p>Truly a wide range.</p><p>Of course, there’s a few limitations and problems.</p><p>Deepfakes can converge extremely easily with GANs, which hold a lot of controversy behind them. Of course, it’s not the best use case as it can result in misuse of this technology for malicious purposes.</p><p>The training instability is another one. Because there’s two neural networks involved, it can be difficult to have an efficient training process and sometimes the conflicts make the networks collapse.</p><p>Although, I don’t want to sideline the potential GANs hold. For all the reasons and applications I talked about before the limitations, <strong>GANs have and continue to change the way we create content for our day-to-day lives.</strong></p><h3>TL;DR</h3><ol><li>Generative Adversarial Networks consist of a generator and a discriminator, which train against each other until a realistic image converges.</li><li>There are so many types of GANs for different use cases and data types, including: ProgressiveGANs, ConditionalGANs, StyleGANs.</li><li>Despite its limitations, GANs can impact so many industries in a positive manner — to lead to a more efficient and creative world.</li></ol><p>My personal TL;DR from all this? I agree with Yann LeCun, <strong>GANs are super sick.</strong></p><p><em>Hey, I’m Priyal, a 17-year-old driven to impact the world using emerging technologies. If you enjoyed my article or learned something new, feel free to subscribe to my </em><a href="https://priyaltaneja.substack.com/p/coming-soon"><strong><em>monthly newsletter</em></strong></a><em> to keep up with my progress in AI &amp; quantum computing exploration and an insight into everything I’ve been up to. You can also connect with me on </em><a href="https://www.linkedin.com/in/priyaltaneja/"><strong><em>LinkedIn</em></strong></a><em> and follow my </em><a href="https://medium.com/@priyaltaneja"><strong><em>Medium</em></strong></a><em> for more content! Thank you so much for reading.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5de15e5cb2b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Predicting Early Heart Diseases With Quantum Support Vector Machines]]></title>
            <link>https://priyaltaneja.medium.com/predicting-early-heart-diseases-with-quantum-support-vector-machines-2f2c678e80b7?source=rss-c6847f30c07a------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f2c678e80b7</guid>
            <category><![CDATA[quantum-computing]]></category>
            <dc:creator><![CDATA[Priyal Taneja]]></dc:creator>
            <pubDate>Mon, 03 Apr 2023 22:23:43 GMT</pubDate>
            <atom:updated>2023-04-04T14:18:48.185Z</atom:updated>
            <content:encoded><![CDATA[<h4>A Detailed Overview on QSVMs and Their Impact Towards Disease Prediction</h4><p>In the United States of America, <strong>one person dies from a cardiovascular disease every 34 seconds.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5NODpInG4y9fyG6q" /></figure><p>It took me roughly ~32 seconds to type that sentence out.</p><p>It’s absolutely insane.</p><p>Within the minute I’ve spent writing this article so far, 2 people have probably passed away with their cause of death being a heart disease of some sort. By the end of your read, the number will stand at ~26 people. <strong>Within a year, an estimated 17.9 million people die each year globally from cardiovascular diseases.</strong></p><p>Quantifying it in that sense is extremely scary, but it also provides a clearer indication of the magnitude of the problem.</p><p>Before getting into anything else, I want to understand the problem in its entirety. We’ve already figured out the quantitive impact of heart diseases. But, what about the basic fundamentals that are responsible for that number? What are its affecting variables? What is the root cause?</p><p>Of course, risk factors that impact the number include one’s record of smoking, high blood pressure, high cholesterol etc. But, when boiling this number down to determine why it’s so high — despite us having control on our habits that create those risk factors — it comes down to how often these diseases can go undetected. That is the root cause of the heart disease mortality rate being within the millions.</p><p>Like many other complex conditions, you’re not aware of it being present until its reached an advanced stage, as the early phases usually don’t have any obvious symptoms for us to question.</p><p>It’s why heart diseases are named as a ‘silent killer’ — because they silently progress over time, and by the time symptoms appear, it’s usually too late to prevent serious complications or death.</p><p>So, based on information, reducing that number down can fall into one of two paths; curing the disease at its last stage <em>or </em>diagnosing it earlier, when we are able to treat it.</p><p>The issue with the former is the complexity behind the solution — it’s nearly impossible to reverse the heart’s lack of ability to pump blood, due to the significant damage done.</p><p>But, diagnosing the disease earlier is a step towards streamlining the large rate of deaths that stem from heart diseases, so that we can manage and tackle this condition when are able to ‘easily’ do so.</p><p><strong>We need to take action towards avoiding preventable mortality rates.</strong></p><h3>Status Quo — What’s Being Done?</h3><p>Currently, scientists have been exploring a range of solutions — including screening programs, advanced imaging technologies, biomarkers, wearable devices and telemedicine — to test for risk factors of heart diseases. But, one of the greatest focuses right now lies within the field of <em>Artificial Intelligence</em>.</p><p>Right now, we’ve identified that there’s risk factors that may impact one having to battle a heart disease, <em>including:</em></p><ul><li>Age</li><li>Gender</li><li>Family History</li><li>Smoking</li><li>High Blood Pressure</li><li>High Cholesterol</li><li>Diabetes</li><li>Obesity</li><li>Physical Inactivity</li><li>Unhealthy Diet</li></ul><p>After a while, making connections or determining patterns between those risk factors’ state &amp; its correlation to a heart disease can help us. So, if someone had a high age, high blood pressure level and history of smoking, you could predict that they’re at risk for a heart disease — allowing for more preventative measures within their lifestyle to avoid or detect the disease earlier.</p><p>Humans could do this manually, but it is a time-consuming and labor-intensive process. Also, human analysis is subject to errors and biases, which can impact the accuracy and reliability of the results.</p><p>So. Technology. That’s our next bet.</p><p>We can leverage artificial intelligence to analyze vast amounts of data quickly and accurately along with identifying patterns and trends that may not be apparent to human analysts. This is done specifically through something called <em>Support Vector Machines.</em></p><p>Formally, <strong>Support Vector Machines (SVMs) are a type of machine learning algorithm that can be used for classification and regression analysis problems.</strong></p><p>They work by creating a boundary (also called a ‘hyperplane’) that separates different classes of data points in a high-dimensional space. The hyperplane’s goal is to maximize the margin between the data points of different classes, so that unseen data can be classified in the same manner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*e0yFShaI3owkj4bcrlYtWw.png" /><figcaption>Visual Representation of SVMs</figcaption></figure><p>If technical terms made no sense, let’s turn our sports brains on. Think of the SVM as a football coach that’s trying to create a good defensive strategy. The coach needs to create a game plan that effectively defends against the opposing team’s offensive strategy, so he’ll separate the different types of players accordingly on the field.</p><p>Support Vector Machines are very common. I’m sure we’re used to our mailing softwares predicting which email is meant for your inbox and which one is spam —<em> and SVMs are responsible for all of that.</em></p><p>In the context of diagnosis prediction, they’re quite strong as well… to a certain extent. They’re a powerful tool as the data is complex &amp; high-dimensional, and its accuracy is strong.</p><p>But, even though AI technology has advanced significantly, there is still a limit to the amount of data that our AI models can effectively analyze. Unfortunately, this limit is considerably smaller than the amount of data required to make accurate predictions in real-world scenarios.</p><p><strong>This limitation creates the solution to be one that’s inefficient and less effective for practical purposes.</strong></p><h3>Leveraging Quantum Support Vector Machines</h3><p>The key to overcoming this barrier between the problem and an efficient solution are <strong><em>Quantum</em> Support Vector Machines.</strong></p><blockquote><strong>Quantum + Support Vector Machines = QSVMs</strong></blockquote><blockquote>Note: This is probably a good time to highlight that if you’ve never heard of quantum computing before, the next part of this article won’t be easily digestible. So, I’d recommend reading my <a href="https://medium.com/@priyaltaneja/quantum-computing-101-27b09e110ac2">Quantum Computing 101</a> article first, and then coming back to this. Either way, I hope you learn something new today!</blockquote><p>QSVMs are exactly what you might be thinking; they’re <strong>a <em>quantum</em> machine learning algorithm that use the principles of <em>quantum mechanics</em> to perform classification and regression tasks.</strong></p><p>The basic idea behind them is that they use quantum computers to perform the computations we would with a SVM algorithm, in a more efficient manner. Therefore, QSVMs are resolving our efficiency challenge while preserving the current status of what we’re doing. Super simple.</p><p>But,<strong> let’s breakdown how Quantum Support Vector Machines work and how we can predict heart diseases earlier with this algorithm.</strong></p><h4>Data Preparation</h4><p>Of course, we’ve identified that we need to analyze a <em>bunch</em> of data, prior to our predictions. So, our first step is to prepare that data into a manner that is understandable by the quantum computer, because currently we’re working with classical data.</p><p><em>It’s represented as:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_IF97QbRNtdRe9j8k50FJg.png" /></figure><p>Here, |x<strong>⟩ </strong>represents a classical input data vector which is transformed into a quantum state — |Φ(x)<strong>⟩ — </strong>through applying a unitary operator — U(x)|0<strong>⟩ — </strong>to its initial quantum state |0<strong>⟩</strong>.</p><p>Without its complexity, the filtered data of risk factors for heart diseases (so the most relevant factors that is cleaned out without any biases or duplicates) is transformed into a quantum state using a <em>quantum feature map, </em>and this feature map is a unitary operation that maps classical data to a quantum state through applying a sequence of quantum gates.</p><p>This ‘feature map’ being discussed can be implemented through various quantum circuits, but the most common ones are quantum Fourier transform or amplitude encoding.</p><p>These two techniques have the end goal of mapping the classical input into a way that it can be processed by quantum algorithms, <em>but the paths there differ from each other:</em></p><ol><li><strong>Quantum Fourier transform (QFT): </strong>This quantum circuit transforms classical data into a quantum state that has the property of being periodic, which can help within certain types of classification problems that require periodic functions. And, this is done through manipulating the states with a series of Hadamard and controlled-phase gates to a set of qubits.</li><li><strong>Amplitude Encoding: </strong>This quantum circuit encodes the classical data into amplitudes of a quantum state through using the input data’s binary representation to provide it with a quantum representation of its amplitude, as in quantum mechanics the state of a quantum system is described by a wave function. It allows the quantum state to represent a much larger space of data than classical data, which can be useful for certain types of classification problems, such as those involving high-dimensional data.</li></ol><p>The choice of the quantum feature map within a QSVM depends on the nature of the data and the specific problem being solved, and these are simply the most common feature maps. Regardless, the intention behind the circuit is the exact same — <strong>to translate the classical input data of our risk factors into a quantum state.</strong></p><h4>Quantum Kernel Calculation</h4><p>Once our data is prepped and ready to go, we can proceed forward to our next step.</p><p>Now, we calculate a matrix<em> — an array of numbers — </em>that describes how similar each pair of input data points are in their quantum feature representation. And, this is done through a <strong>Quantum Kernel Calculation.</strong></p><p><strong>The results from this matrix can help us classify; heart disease present or healthy heart? </strong>Formally, the two categories we’ve stated for classification are known as ‘classes’ and since there’s two classes, it’s a binary classification problem.</p><p>The type of matrix we’re specifically looking for is called a kernel matrix, and it describes the pairwise inner products between the quantum feature vectors corresponding to the input data points.</p><p>In simple terms, this means that a mathematical operation with the vectors of the quantum states are calculated, to obtain a measure of similarity between those two data points in their quantum feature representation. That similarity value can help us form the hyperplane, so we can correctly categorize our data into its binary classifications.</p><p>So, let’s say that we preprocessed our data through amplitude encoding. <em>The quantum kernel function for the circuit is defined as:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r4qcrqZDCQxMCXb0_4apPg.png" /></figure><p>Here, |ϕ(x)⟩ and |ϕ(x’)⟩ are the quantum states corresponding to the input data points x and x’, respectively, and ⟨ϕ(x)| and ⟨ϕ(x’)| are their conjugate transpose states.</p><p>In order to determine the quantum kernel matrix for a set of input data points, we can use a quantum circuit to apply the amplitude encoding circuit to all pairs of data points, before measuring the overlap between their quantum states — which can be done through <a href="https://qiskit.org/textbook/ch-algorithms/quantum-phase-estimation.html"><em>quantum phase estimation</em></a><em>.</em></p><p>This algorithm estimates the eigenvalues of the unitary transformation matrix — U(x, x’) = U(x)† U(x’) — that is in correspondence to the quantum kernel function. And, once the estimated eigenvalues have been obtained, we can use those to compute the quantum kernel matrix that will calculate the inner-products.</p><p><em>It can be represented as…</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6H500JhT8Bmkb47ndzgiCQ.png" /></figure><p>… where λ_k and u_k are the eigenvalues and eigenvectors of the matrix U(x, x’), and u_ik and u_jk are their corresponding components for the k-th eigenstate.</p><p>All that’s happening within this computation is the calculation of the the kernel value Kij by summing up the product of the eigenvalues and corresponding eigenvector entries for all k. This is equivalent to taking the inner product between the i-th and j-th columns of the eigenvector matrix, weighted by the corresponding eigenvalues.</p><p>Once that step is completed,<strong> a hyperplane —</strong> that creates a margin to separate data points for a healthy heart and a heart-disease-infected heart —<strong> should be formed.</strong></p><h4>Quantum SVM Training</h4><p>Moving onto the most important part of this algorithm, the computer’s <em>training</em>.</p><p>Just like humans, our machines need to <em>learn </em>a task before mastering it. And, in this case, it’s more than important to ensure that our quantum computer is fully trained on how to predict someone being at risk for a heart disease.</p><p>The goal within this step is to optimize the parameters of our circuit to achieve the best classification results. This is usually done through optimization algorithms such as the <a href="https://qiskit.org/textbook/ch-applications/qaoa.html#:~:text=QAOA%20(Quantum%20Approximate%20Optimization%20Algorithm,to%20solve%20such%20combinatorial%20problems.">QAOA</a> or the <a href="https://qiskit.org/textbook/ch-applications/vqe-molecules.html">VQE</a>.</p><p>Either way, these algorithms are used to minimize the <strong><em>cost function</em></strong> — which is a measure of the model’s accuracy and how well it fits the training data.</p><p><em>Mathematically, it’s represented as…</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OkYZVSBVFSr1_bfx0E2JTA.png" /></figure><p>… <em>where</em>:</p><ul><li>w = weight vector</li><li>b = bias term</li><li>xi = training input vector</li><li>yi = corresponding output label</li><li>λ = regularization parameter</li></ul><p>Throughout this process, all the potential parameters value within the quantum circuit are represented through a Hamiltonian matrix. So, through here, the optimization algorithm works by finding the ground state of the Hamiltonian, which corresponds to the minimum energy state of the system.</p><p>Either way, the quantum circuit iteratively modifies the parameters of the model to find the minimum value of the cost functions. And, these parameters involve those in the equation above, including: the weight vector, the bias term and the kernel parameters. In the end, the optimization algorithm seeks to minimize the cost function by finding the optimal values of these parameters.</p><p>This is usually the most time-consuming aspect of the algorithm, but it’s also vital for the circuit to familiarize itself with the all of the data points — <em>in order to confidently make the correct analysis.</em></p><h4>Measurement and Prediction</h4><p>And, here comes the final step that concludes our algorithm.</p><p>Now, we’ll work towards obtaining a classical output from the quantum state that was prepared and manipulated in the previous steps. So, remember when we ‘mapped’ the classical states onto a quantum state? We’re essentially reversing that through mapping the existing quantum states onto its classical states.</p><p>This is done through a measurement that projects the quantum state onto a classical state — and, this outcome can be any of the possible classical states that correspond to the quantum state amplitudes.</p><p>Once our model is fully trained, in order to get the class label on a new input data point, the same steps in the training phase are applied where the input data is first encoded into a quantum state using the quantum feature map, and the quantum kernel is calculated using the same process as in training. So, when a new input reaches this stage, it’ll go through the processes above before getting measured into the two classes within this problem.</p><p>Anyways, the measurement process is a crucial step in the QSVM algorithm, as it enables the extraction of classical information from the quantum state — <em>which is what humans will use to further communicate results.</em></p><p>The measurement can be mathematically expressed as the probability of obtaining a particular classical state |i⟩ given the quantum state |ψ⟩ as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m6RqOI513XsW0VS8X3SHgQ.png" /></figure><p>Here, |i⟩ represents one of the possible classical output states that can be obtained upon measurement, and ⟨i| represents the corresponding conjugate transpose of |i⟩. And, the notation ⟨i|ψ⟩ represents the inner product between the classical state |i⟩ and the quantum state |ψ⟩.</p><p>And, the absolute value square of ⟨i|ψ⟩ represents the probability of obtaining the classical output state |i⟩ when measuring the quantum state |ψ⟩.</p><p>All in all, <strong>you’ve finally received your classical output that can be used to dictate whether or not someone is at risk for a heart disease or not.</strong></p><h3>A Quantum Advantage?</h3><p>In theory, QSVMs have the potential to offer an exponential speedup in comparison to classical SVMs, as they leverage quantum computers. The ability of quantum computers to perform certain computations in parallel can provide users with a ‘quantum advantage’ that can improve the efficiency of the existing solution.</p><p>The main area in which Quantum Support Vector Machines have this speedup is within the kernel calculation step. Within classical SVMs, the kernel matrix must be explicitly computed, which means the kernel function is applied to all pairs of data points. This creates a time-consuming step for larger datasets.</p><p>In contrast, QSVMs can use quantum algorithms to calculate the kernel matrix in parallel, and it’s implicitly computed using quantum circuits. <strong>This difference between these steps allows for a faster and more memory-efficient process.</strong></p><h3>Limitations</h3><p>However, the limitations in relation to this solution cannot be ignored, as it’s still a long time before this is deployed for regular use.</p><p><strong>Decoherence is the number one risk. </strong>Quantum computers are susceptible to noise, which means qubits are sensitive to compute on due to their external environment which can often interfere and mess-up the existing quantum states. This would be problematic for tasks such as disease prediction, as you require accurate results that humans can blindly trust.</p><p>Adding onto decoherence, <strong>QSVMs need a high number of qubits</strong>, and since we know they’re sensitive, having more qubits that aren’t definitive in producing accurate results would be hard to manage. The connectivity between the qubits may be difficult to achieve with the current quantum computers available today.</p><h3>Long-Term Impact</h3><p>But, all of these limitations are being worked on as the development of quantum computers continue. When we reach a point in building quantum computers where issues like the number of qubits and noise don’t exist, the long-term impact of leveraging QSVMs to predict early heart diseases can be significant.</p><p>We’ve already determined that early detection and accurate diagnosis of heart disease can help prevent the ‘silent killer’ and the serious health complications involved.</p><p><strong>Through a fully-developed QSVM, the earlier interventions can ultimately save lives — helping to reduce the status quo (17.9 million people globally) so we don’t see those around us losing their lives to a silent killer.</strong></p><p><em>Hey, I’m Priyal, a 17-year-old driven to impact the world using emerging technologies. If you enjoyed my article or learned something new, feel free to subscribe to my </em><a href="https://priyaltaneja.substack.com/p/coming-soon"><strong><em>monthly newsletter</em></strong></a><em> to keep up with my progress in quantum computing exploration and an insight into everything I’ve been up to. You can also connect with me on </em><a href="https://www.linkedin.com/in/priyaltaneja/"><strong><em>LinkedIn</em></strong></a><em> and follow my </em><a href="https://medium.com/@priyaltaneja"><strong><em>Medium</em></strong></a><em> for more content! Thank you so much for reading.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f2c678e80b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Intentionality — From Elon Musk’s First Principles Perspective.]]></title>
            <link>https://studentsxstudents.com/intentionality-from-elon-musks-first-principles-perspective-7aa4038bdd8d?source=rss-c6847f30c07a------2</link>
            <guid isPermaLink="false">https://medium.com/p/7aa4038bdd8d</guid>
            <category><![CDATA[mental-models]]></category>
            <category><![CDATA[intentionality]]></category>
            <category><![CDATA[growth]]></category>
            <category><![CDATA[enjoy-writing]]></category>
            <category><![CDATA[mindset]]></category>
            <dc:creator><![CDATA[Priyal Taneja]]></dc:creator>
            <pubDate>Sun, 26 Mar 2023 21:20:35 GMT</pubDate>
            <atom:updated>2023-05-07T16:10:31.114Z</atom:updated>
            <content:encoded><![CDATA[<h3>Intentionality — From Elon Musk’s First Principles Perspective.</h3><h4>Part 2: A Two-Part Reflection on Intentionality</h4><p>A few days ago, I sat down and wrote a <a href="https://medium.com/@priyaltaneja/intentionality-it-matters-3dccc24b826a">self-reflection on intentionality</a>, its significance and what it means to me. The TL;DR from it is to find the ‘why’ behind every aspect of your life, so you can optimize for the lifestyle that aligns with your core values.</p><p><strong>But, answering that ‘why’ can be difficult.</strong></p><p>Especially, when you’ve familiarized yourself with certain decisions you’ve taken. I’ve been there done that. It’s so easy to mentally answer that question with a biased answer, or a generic answer because I can’t seem to think of anything else.</p><p>I think it’s because we’ve gotten used to hearing instructions and following life on a societal basis. It’s taken away from our ability to evaluate our key virtues, and create a life based on that.</p><p><em>The path to answering our why behind everything we do?</em> <strong>First Principles Thinking.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ytXbnq9WA5fnkq1k.jpg" /></figure><p>If there’s anyone who’s mastered First Principles, it’s <em>Elon Musk</em>. Throughout building Tesla &amp; SpaceX, he’s worked on extremely complex problems and also provided innovative solutions for many. And, that’s come from adapting a first principles thought-process.</p><p>In the early days of Tesla, the high cost of batteries were one of the largest barriers to electronic vehicles. He didn’t sit back and agree with the ‘battery packs are expensive and always will be’ claim and let that disrupt his vision though. Instead, he broke down the cost of batteries into the fundamental components and questioned the underlying assumptions about how they were manufactured &amp; priced.</p><p>From there, he was able to identify factors that drove up the cost of batteries and then created solutions for those minor problems, to improve the efficiency of battery manufacturing.</p><p>At its core, that’s exactly what <strong>First Principles Thinking</strong> is; the process of breaking down complex problems or ideas into their most basic components, so that a solid foundation of understanding can be built upon this for new, innovative solutions.</p><blockquote>I like to think about First Principles like I’m building a puzzle; understanding the shape and colours of each individual piece is important to build that final collective image.</blockquote><blockquote>Elon also likes to describe it as a ‘physics way of looking at the world’ as you boil everything down to the most fundamental truths and reason up from there.</blockquote><p>First Principles can be applied to nearly everything. Innovation, entrepreneurship, engineering, you name it. But, I wanted to view this mental model from the approach of self-improvement, and tie it in with intentionality.</p><p><strong>The number one roadblock to First Principles Thinking is the human inclination towards imitation.</strong></p><p>It means that humans often rely on imitation or copying existing solutions when faced with a problem or task, instead of breaking down the problem and underlying principles that govern it. This tendency can hinder our ability to think creatively and limits the exploration of new ideas and approaches — which makes sense, as it’s so easy to give a generic, copy-pasted response to the ‘why’ question we talked about.</p><p>In theory, we know what we have to do now, to reach our final answer. But, still reaching that end-point might not be clear.</p><p>Recently, I was stuck in a dilemma about whether or not I wanted to start developing this complex project. I mean, I read a research paper and it stemmed an idea — but, it was going to take a lot of input on my end. And, that’s when answering the ‘why’ became a little bit harder. I could answer very simply and say that I want to just build or skill development etc. but was that enough?</p><p>I followed this framework of reaching the first principle behind why I found the ideation interesting, to understand if it was big enough for me to continue:</p><p><em>1) Identify the aspect of your life that you want to analyze.</em></p><p>Of course, pinpointing the area of my life I want to analyze is the place to start. In my case, it was that initial decision of continuing to work on the project or not.</p><p><em>2) Break down the aspect into its most basic components.</em></p><p>I considered what the fundamental principles or assumptions govern the project. What are the essential parts that would be necessary for the project to succeed? A bit more technical, but my project would require knowledge on how to build a QSVM and a lot of external discussions/</p><p><em>3) Identify the core values or intentions behind the aspect.</em></p><p>And now, I thought more about what initially motivated me to consider starting this project. To that, my answer simply was I loved the impact it could have. I wanted to make a dent within the healthcare industry, so it made sense why I gravitated towards this project with a foreseen impact rather than one that I just found ‘fun’ to create. So here, think about what you would hope to accomplish with this aspect or what your ultimate goal is.</p><p><em>4) Evaluate whether the aspect aligns with your core.</em></p><p>Finally, it comes down to seeing if what you want to achieve out of that aspect of your life aligns with your core values. Does it ‘make sense’ for you to work on this? If it does not align, consider whether you need to make changes to better align that aspect of your life with your values.</p><p>So for myself, I came to the conclusion that my doubts stemmed from the difficulty or lack of direction, not because it didn’t make sense for myself. Through figuring out the first principles of my dilemma, I confirmed that my intentions behind aligned with what I found important, and also determined my area-of-focus to proceed with my project.</p><p>But really, it’s this repetitive cycle of asking a bunch of ‘whys’ and ‘hows’ until you can’t reduce your answer further.</p><p>After all, as Shane Parrish said, <em>the thoughts of others imprison us if we’re not thinking for ourselves. </em><strong>By determining the underlying reasons behind our actions, we can act with greater intentionality and make choices that align with our values, ultimately leading to a more fulfilling life.</strong></p><p><em>Hey, I’m Priyal, a 17-year-old who’s ambition revolves around working on solving complex problems to meaningfully contribute to the world.</em> <em>If you enjoyed my article or learned something new, feel free to subscribe to my </em><a href="https://priyaltaneja.substack.com/p/coming-soon"><strong><em>monthly newsletter</em></strong></a><em> to keep up with my progress in quantum computing exploration and an insight into everything I’ve been up to. You can also connect with me on </em><a href="https://www.linkedin.com/in/priyaltaneja/"><strong><em>LinkedIn</em></strong></a><em> and follow my </em><a href="https://medium.com/@priyaltaneja"><strong><em>Medium</em></strong></a><em> for more content! Thank you so much for reading.</em></p><p><strong><em>We’re providing opportunities for the next generation of student thinkers, inventors, and learners, to publish their thoughts, ideas, and innovation through writing.</em></strong><br><em>Our writers span from all areas of topics — from </em><a href="https://studentsxstudents.com/"><em>Growth to Tech, all the way to Future and World</em></a><em>.</em><br><em>So if you feel like you’re about to jump into a rabbit hole of reading these incredible articles, don’t worry, we feel the same way. ;)</em><br><em>That’s why </em><a href="https://studentsxstudents.com/"><em>students x students</em></a><em> is the place for getting your voice heard!</em><br><em>Sounds interesting? </em><a href="https://studentsxstudents.com/for-students-by-students-becoming-a-contributor-and-expanding-your-impact-f6da9189fa78"><em>Why not join us on this epic journey</em></a>?</p><p><a href="https://studentsxstudents.com/">students x students</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7aa4038bdd8d" width="1" height="1" alt=""><hr><p><a href="https://studentsxstudents.com/intentionality-from-elon-musks-first-principles-perspective-7aa4038bdd8d">Intentionality — From Elon Musk’s First Principles Perspective.</a> was originally published in <a href="https://studentsxstudents.com/">students x students</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Intentionality. It Matters.]]></title>
            <link>https://studentsxstudents.com/intentionality-it-matters-3dccc24b826a?source=rss-c6847f30c07a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3dccc24b826a</guid>
            <category><![CDATA[self-improvement]]></category>
            <category><![CDATA[intentionality]]></category>
            <category><![CDATA[growth]]></category>
            <category><![CDATA[mindset]]></category>
            <category><![CDATA[enjoy-writing]]></category>
            <dc:creator><![CDATA[Priyal Taneja]]></dc:creator>
            <pubDate>Thu, 23 Mar 2023 00:35:29 GMT</pubDate>
            <atom:updated>2023-05-07T16:11:17.840Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part 1: A Two-Part Reflection on Intentionality</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rOI9O5kWxni7n8pn.jpg" /></figure><p>“When I’m older, I want to be rich.”</p><p>A sentence I know all too well, and hear all around me. I’m a victim of saying it as well. <strong>What I’ve failed to recognize throughout my whole life is… <em>why?</em></strong></p><blockquote>Is it because I have this lifestyle in mind that I want to support or is it because I’m accustomed to society viewing this as success? Is the importance I place on this lifestyle based on how it resonates with my core values, or is it solely because of the luxury status created by society?</blockquote><p>I could question almost every aspect of my life, because until now, I haven’t really focused on why my life has taken the shape it has. And, I think this is a huge contributor to why my life has just been flowing without any focus.</p><p>I really hate that. Getting caught up with everything around me and not being present within the moment, anywhere at anytime.<strong> </strong>It’s so easy to just rely on my autopilot to get through my life.<strong> </strong>By this, I’m referring to how easy it is for us to lose focus on our top priorities or to become sidetracked by fulfilling the expectations of others, rather than following our own path that gives us a sense of purpose and fulfillment.</p><p><strong>Avoiding this ‘autopilot lifestyle’ really boils down to understanding the value of every single conscious <em>and</em> subconscious actions &amp; decisions we make. </strong>And, that’s where my mind goes back to the entire concept of questioning everything I do, to see if I have any intentions behind it.</p><p>If I’m sitting down watching Netflix, I want to make sure I don’t enter this state where I’m just flowing, resulting in 5 hours of my life wasted on the couch. I’d much rather be intentional about the fact that I’m going to step back from my work hours to take a one hour break where I can relax and watch my favourite show.</p><p>This really helps me become more present and engaged within my day-to-day life, so that I can be mindful of what steps I need to take to reach my long-term goals. Acting with intention allows us to have a clear understanding of why we are doing something and what we hope to achieve from it, which usually plays a huge role in the quality of the final outcome.</p><p>Adrienne Enns said it best… <strong><em>intentional days create a life on purpose</em>; the answer to turning off the autopilot switch.</strong></p><h4>Being Intentional with Your Time</h4><p>I turned 17 exactly a week ago (at the time of me writing this) and naturally, I played back what the last 12 months looked like. Over the last year, I’ve worked on projects I never would have picture 14–15 year old me doing. From creating intensive recommendation decks for Walmart &amp; Amazon Alexa executives to continuously building projects within the quantum computing space, it’s insane to imagine.</p><p>It starts off with me identifying my lifelong priority of achieving <strong>eudaemonia</strong>, this deeper sense of satisfaction that comes from living in accordance with one’s values and fulfilling one’s potential. And then, acting upon it.</p><p>As I’m writing this, I’m conceptualizing the internal growth I’ve started to feel over the last couple of months; a feeling that I’ve never really experienced before this moment. And, I owe it all to my past-self for making decisions with the <em>intention</em> of optimizing my personal growth… and my future-self who’s excited to continue accelerating her growth.</p><p>The second I knew what I was working towards and the value of the steps I’m taking, I suddenly reduced my phone screen time by hours, and had hours of meaningful tasks on-hand. It wasn’t ‘work’ though… because it directly aligned with what I found important within my life. So I don’t find myself drained or tired with the lifestyle I’ve created for myself.</p><p>I think what I’m really trying to get at through highlighting my experience over the 6 months adapting this mindset, is to apply it in your daily life as well. Understanding what your ‘best case outcome’ or what you’re looking to achieve from your to-do list, so that you’re present in everything you’re acting upon and applying yourself to the fullest every single day.</p><p>Through that, I’ve been able to prioritize correctly, while making sure that I’m intentional about every step I’m taking within my life.</p><h4>Being Intentional about the People in your Life</h4><p>I’m a huge believer in the fact that you’re a reflection of the people around you. It’s why I’ve been so so selective about the friendships I maintain.</p><p>I’ve been mentioning money and work and hustle, but it’s important to note that intentionality encompasses much more than just those areas of life. If anything, I think being intentional about your personal relationships &amp; their maintenance is more significant.</p><p>I’m only 17, so I don’t want to use the quote ‘when I was younger’ but, a few years ago I was as social as I could get. I considered every person I conversed with as my friend, without thinking twice about who they were as a person. This isn’t to say being social and outgoing is a bad thing, it’s amazing. But, I <em>failed</em> to be intentional about who I was spending my time with and whether or not that relationship held value to either of us.</p><p>A super cool exercise I did to reflect on this was naming a friend for each category within the acronym, <em>FRIENDS</em>.</p><blockquote>F: Founder friend — Collaborative, Productive, Growth mindset</blockquote><blockquote>R: Reassuring friend — Share Emotions With</blockquote><blockquote>I: Incidental friend — Class Project, Sports Team</blockquote><blockquote>E: Entertaining friend — Fun</blockquote><blockquote>N: Networking Friend — Knows Everyone, Helps with Connections</blockquote><blockquote>D: Deep Talk friend — Clarifying Thinking with</blockquote><blockquote>S: Soul Friend — Shared Values, Helpful, Growth</blockquote><p>It was an exercise within a <a href="https://www.tks.world/">The Knowledge Society</a> session, and it really opened my eyes to the need for a perfect balance. The best circle of people aren’t the exact same, and when I couldn’t think of people for a couple of these spots, I knew it was time to become more intentional about building relationships within those spaces. And, also, it’s made me more conscious of the type of friend I am to the people around.</p><p>Overall, I think I’ve gotten better at choosing people within my life, and as cliche as it sounds, really understood quality over quantity. I’ve become more self-aware about who gives me energy and who drains me. I know the value my friendships add to my life, and also have been pretty good with making sure our priorities align — cause at the end of the day, I want to be around people who are equally ambitious as me.</p><p>But, my next action item is to become more intentional about how I’m maintaining my existing relationships. I want to ensure that I’m making a conscious effort to understand and connect with the people in my life beyond the surface-level friendships. Rather than simply going through the very simple motions of socializing or networking. I know that I can strengthen and deepen my relationships, to transcend how they currently are.</p><p>It’s a huge part of being intentional about people, because it’s easy to ‘choose’ the people you’re spending time with, but how can you optimize your relationships to add the most value to the both of you? I’ve taken this as a point of reflection, and have started to make it a priority to activate unique experiences as a hangout, so that I can make the best memories with those around me.</p><p>Final note from me. I hope at this point you’re not sick and tired of reading the words <em>intention</em> or <em>intentional</em>, but instead have taken something away to implement within your life. My intention behind this article was to be as authentic (with myself <em>and</em> you) as possible, all while organizing my thoughts in a manner that adds value to anyone reading this. I hope my experiences and random thoughts allow for a little bit of insight on how you can create a life of purpose for your self! :)</p><p><em>Hey, I’m Priyal, a 17-year-old who’s ambition revolves around working on solving complex problems to meaningfully contribute to the world.</em> <em>If you enjoyed my article or learned something new, feel free to subscribe to my </em><a href="https://priyaltaneja.substack.com/p/coming-soon"><strong><em>monthly newsletter</em></strong></a><em> to keep up with my progress in quantum computing exploration and an insight into everything I’ve been up to. You can also connect with me on </em><a href="https://www.linkedin.com/in/priyaltaneja/"><strong><em>LinkedIn</em></strong></a><em> and follow my </em><a href="https://medium.com/@priyaltaneja"><strong><em>Medium</em></strong></a><em> for more content! Thank you so much for reading.</em></p><p><strong><em>We’re providing opportunities for the next generation of student thinkers, inventors, and learners, to publish their thoughts, ideas, and innovation through writing.</em></strong><br><em>Our writers span from all areas of topics — from </em><a href="https://studentsxstudents.com/"><em>Growth to Tech, all the way to Future and World</em></a><em>.</em><br><em>So if you feel like you’re about to jump into a rabbit hole of reading these incredible articles, don’t worry, we feel the same way. ;)</em><br><em>That’s why </em><a href="https://studentsxstudents.com/"><em>students x students</em></a><em> is the place for getting your voice heard!</em><br><em>Sounds interesting? </em><a href="https://studentsxstudents.com/for-students-by-students-becoming-a-contributor-and-expanding-your-impact-f6da9189fa78"><em>Why not join us on this epic journey</em></a>?</p><p><a href="https://studentsxstudents.com/">students x students</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3dccc24b826a" width="1" height="1" alt=""><hr><p><a href="https://studentsxstudents.com/intentionality-it-matters-3dccc24b826a">Intentionality. It Matters.</a> was originally published in <a href="https://studentsxstudents.com/">students x students</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Changing How We Detect Diseases in Medical Images with Quanvolutional Neural Networks]]></title>
            <link>https://priyaltaneja.medium.com/changing-how-we-detect-diseases-in-medical-images-with-quanvolutional-neural-networks-e2d0f5957516?source=rss-c6847f30c07a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2d0f5957516</guid>
            <category><![CDATA[quantum-computing]]></category>
            <category><![CDATA[world]]></category>
            <dc:creator><![CDATA[Priyal Taneja]]></dc:creator>
            <pubDate>Fri, 03 Mar 2023 00:50:33 GMT</pubDate>
            <atom:updated>2023-03-18T21:21:33.064Z</atom:updated>
            <content:encoded><![CDATA[<p>Tomorrow is my friend Lia’s birthday. To wish her, I need to find the prettiest photo of her to upload to my social media platforms. I haven’t revealed how much I enjoy taking photos, so I have 10,000+ on my camera roll that I need to sift through to find the ones with Lia. I’m dreading to sit down and find a picture of her because I know it’ll take a while.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bOFbvZ7hyo-htPjsuemROQ.png" /></figure><p>Thankfully, in 2016, Apple solved my problem through streamlining the process of locating and grouping images. Now, I can head on over to my assortment of albums, where my photos are automatically sorted by people. I’ll be able to effortlessly browse through the 529 pictures of Lia, and to choose one based on my personal preferences.</p><p><strong><em>But…. how?</em></strong></p><h3>Diving Deeper into Deep Learning: Convolutional Neural Networks</h3><p>Think about how we identify who or what is around us. Currently, I’m typing this on what I know as a laptop, I’m sitting on a chair and there’s a bed behind me. It takes less than a second to identify majority of the objects around me, as my brain has been ‘trained’ to know what the names for each of these are — <em>we call this learning.</em></p><p>So, how does the little computer in our pockets sort out our images according to people who’s name it doesn’t even know?</p><p><em>*spoiler alert*</em></p><p>It’s<strong> Convolutional Neural Networks.</strong></p><p>Convolutional Neural Networks (CNNs) are a type of deep learning model — <strong>which is a subset of machine learning that involves training artificial neural networks with multiple layers to recognize patterns and extract insights from large datasets.</strong><em> </em>CNNs can analyze and classify visual data, such as images or videos…. <em>think of them like a computer’s eyes.</em></p><p>The word ‘neural’ in <em>Convolutional Neural Networks</em> is pretty significant. CNNs are a type of <em>Neural Networks </em>— which emulate the behaviour of the human brain. They work by passing information from dendrites to neurons, which then relay this information through connections between them. It’s kind of like how our brain cells communicate with each other to help us understand and interpret the world around us.</p><p><em>Here’s what the process of a CNN looks like…</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Hf7odQfDUHj2becu.gif" /></figure><p><em>…let’s break it down.</em></p><p>As you can see above, the Convolutional Neural Network model is built with multiple different layers — <em>which can be categorized as input, hidden and output layers.</em></p><p>We start off with the<strong> input layer</strong>. This is the layer that receives an image or a batch of images as an input. <strong>It’s responsible for preprocessing the input data and translating it into a format that can be processed by the subsequent layers</strong> — <em>whether this means resizing, normalization or data augmentation.</em></p><p>The input layer is typically a 3D tensor (a mathematical representation of a multi-dimensional array of data) with <em>height, width and channels</em> as the dimensions. Height and width are obviously the pixel size of the image but channels refers to the number of colour channels in the image.</p><blockquote>For example, if we were working with a 28x28 image that is black and white, our input tensor dimensions would look like: <strong>28, 28, 1</strong></blockquote><p><em>Now, we’re entering all the hidden layers, which are the layers in between the input layer and output layer and are responsible for feature extraction that is relevant to the classifications you want to make.</em></p><p>Next up, the data is sent on over to the <strong>convolutional layer.</strong> This is when the learning begins. <strong>It’s a fundamental building block of a CNN that performs feature extraction from the input images. </strong>This is done through applying a set of learnable filters, also called kernels, to the input image in order to produce output feature maps that highlight the various patterns and features present in the input.</p><p>Mathematically, to produce a feature map, a filter — which is a small matrix of weights — is put over the input image, and the dot product between the filter and the input image patch at each position is calculated, which results in a single output value for each position in the feature map.</p><p><em>Visually, it looks a little something like this…</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tgl9mGA-cWcVpinl.gif" /></figure><p>Once we’ve got our output feature map, our computer is a little more confident in the features it needs to identify in order to classify the set of images. Except, it’s still a working process.</p><p>The <strong>activation layer</strong> is next, another important part of CNNs. <strong>It introduces non-linearity into the neural network by applying a mathematical function to the output of the previous layer. </strong>This allows the CNN to expand beyond modelling only linear relationships, so that it can model complex data easily. There’s many popular activation functions, but for CNNs, ReLU and sigmoid are the most commonly used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YZFIRi95oLXpr4AyRIlYoQ.png" /><figcaption>examples of some common activation functions used</figcaption></figure><p>We now move onto the <strong>pooling layer</strong> of the CNN, which comes right after the convolutional layer. <strong>This reduces the spatial size of the input feature maps, while keeping all of its important features. </strong>Through this, we can reduce the computational cost of the network and prevent it from getting too good at recognizing the training data but not being able to work well on new data.</p><p>The pooling layer divides the input feature map into smaller rectangular regions, which are called pooling regions. Then, it computes a single output value for each region by using a pooling operation such as max pooling or average pooling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IyNSjF5yyqYxSXU9_XJypQ.png" /><figcaption>visual of what max pooling looks like</figcaption></figure><p>As we reach the end of the model, we arrive at the <strong>fully-connected layer. </strong>It’s the last of the ‘hidden layers’ and is placed after the convolutional layer, activation layer, and pooling layer. <strong>This layer is responsible for the final classification of the image.</strong></p><p>The fully connected layer receives a flattened version of the output from the previous layer as an input and then uses a set of kernels to calculate a set of output values. These output values can be interpreted as different labels, based on the task you’re trying to perform.</p><p>And, finally, we exit the hidden layers and are able to reach the final output layer in our model. It’s the final layer of a neural network and is <strong>responsible for producing the final output of the model.</strong></p><p>The output of neurons within the output layer is also compared to the ground truth labels to compute a loss value, which measures how well the model is performing on the given task. The goal of training the neural network is to minimize this loss value by adjusting the weights of the model.</p><p>That’s the inner-workings of a convolutional neural network, which is exactly what your phone uses to categorize the people and objects in your photos. The ‘eyes of our computers’ are truly so powerful and can eliminate so many manual tasks for humans.</p><h3>CNNs Improving The Medical Diagnosis Process</h3><p>I know we’ve been talking about sorting through photos of our friends and sorting pictures of cats and dogs, but the impact of convolutional neural networks extends beyond that.</p><p>Diagnosis isn’t an easy or a definitive process. Medical imaging techniques such as X-rays, CT scans, and MRI produce large amounts of data that require expert analysis to identify any potential health issues. And, interpreting medical images can also be challenging, when the abnormalities are subtle to difficult for the human eye to detect.</p><p>Currently, when you take a CT test, it takes <strong>at least 24 hours</strong> to receive your results as a radiologist has to manually view and analyze all 100+ images. I should also mention that the error rate is ~5%, which may not seem like a lot but can severely harm patients.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*sPQMU_biza7066_I" /></figure><p>Here’s where <em>convolutional neural networks</em> enter the picture, as they’ve shown great promise in improving the medical diagnosis process through a more efficient and more accurate analysis of medical images.</p><p>Using our knowledge of CNNs, we already know that they can be trained to look for certain features in medical images that are indicative of a particular disease or condition. Also, this could potentially enable earlier and more accurate diagnoses.</p><p>The only problem — <em>yes, there’s a catch</em> — is that a CNN with a fully-connected network structure uses a large amount of memory. Loads of data leads to slower computation time and greater computation power. And, depending on the number of images and classes, the layer could increase — which leads to an increase in the complexity analysis of the model. <strong>Long story short, it takes a very long time to train Convolutional Neural Networks, when working with big datasets.</strong></p><h3>Let’s Enhance it Further By Adding in the Quantum…</h3><p>This is why quantum computers exist… to solve all your big-data problems.</p><blockquote>If you’re not too familiar with quantum computing and its principles, I’d recommend giving <a href="https://medium.com/@priyaltaneja/quantum-computing-101-27b09e110ac2">this article</a> a read before you read below!</blockquote><p>Actually, I (sort-of) lied. <strong>Quanvolutional Neural Networks </strong>is a hybrid model that has both classical and quantum components, but the quantum aspects of it hold tremendous value and can fix our problem of training being slow.</p><blockquote>By the way… Quantum + Convolutional Neural Networks = Quanvolutional Neural Networks</blockquote><p>The goal behind Quanvolutional Neural Networks is the same as Convolutional Neural Networks. You’re looking to extract the most relevant features in an image, in order to determine patterns that are involved.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B3jLTfWvAC57FK7ULXLkUg.png" /><figcaption>visual of what a QNN looks like (<a href="https://pennylane.ai/qml/glossary/qcnn.html">source</a>)</figcaption></figure><p>The Quanvolutional Neural Network is built in the exact same format as a CNN, except each layer is represented as a quantum circuit… which explains why it looks a little different. But, there’s still the order of convolutional, pooling, and fully-connected layers.</p><p>Since we know that convolutional layers are responsible for most of the feature extraction from the image, it makes sense that in quanvolutional neural networks, there’s a <strong>quanvolutional layer.</strong></p><p>How this works is that the input data is translated into a quantum representation through encoding the classical data in a quantum register. The most common techniques used to do that are <em>amplitude encoding</em> and <em>qubit encoding</em>…</p><ol><li><strong>Amplitude Encoding </strong>involves mapping classical data onto the amplitudes of a quantum state. We use the input data’s binary representation to provide it with a quantum representation of its amplitude, as in quantum mechanics the state of a quantum system is described by a wave function. The amplitude is usually a complex number that determines the probability of measuring that state when observed. In this case, the classical data is translated into an amplitude within the quantum system depending on its binary value. <strong>For example, if our input data is 01, we might assign 0 as the small amplitude (small complex number with a small absolute value) and 1 as the larger amplitude (large complex number with a large absolute value).</strong></li><li><strong>Qubit Encoding</strong> involves mapping classical data onto the states of qubits in a quantum register, which is done through setting the quantum states to correspond with the binary representation of the input data.<strong> For example, let’s say that our input data is 01, in the quantum register we can represent it with the state of the first qubit as |0⟩ and the state of the second qubit as |1⟩.</strong></li></ol><p><em>Either way, you’re making the data read-able for the quantum computer.</em></p><p>Once the input state is prepared using either of these techniques, a quantum circuit applies many different quantum gates to perform the convolutional operations that we would in a CNN, except this is done through quantum gates (which are individual unitary operations) that apply a series of transformation on the quantum state. Through this, we extract the most important features of the input in a quantum context.</p><p>A common quantum gate that’s used in quanvolutional layers is the Controlled-U gate, where U is a single-qubit unitary operation. Basically, a math operation that changes the state of the system. The Controlled-U gate acts on two qubits, where the first qubit is the control qubit and the second qubit is the target qubit. If the control qubit’s state is |1⟩ then the gate applies the unitary operation to the target qubit, which indicates the data is relevant and extracts it. <strong>The quantum gates do the exact same thing our kernels did in CNNs.</strong></p><blockquote>By the way, a control qubit is used to control whether the operation is applied or not and the target qubit is where the operation is applied!</blockquote><p>Once we’ve applied the set of Controlled-U gates to each sub-register within your main quantum register, we can combine the results of the quantum states to form the output of the quanvolutional layer. We can repeat this process as many times as needed to extract all features needed… after all, quantum computers are much faster.</p><p>Through taking advantage of phenomenas such as quantum parallelism and interference through Controlled-U gates, we can create more precise feature extraction which leads to more accurate results. This is because the gate can implement more complex operations on the quantum data than a kernel can in a regular CNN.</p><p>Also, the exponential speed-up cannot be ignored.</p><p><em>For reference, if we followed everything I just mentioned, the equations for the training time needed would look like this…</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wXb038cvt5JM6pUYXO9HrA.png" /></figure><p><em>… which is a HUGE difference!</em></p><p>Anyways, once you’re done with your quanvolutional layer, you can move onto your <strong>quantum pooling layer. </strong>This is where we reduce the spatial dimensions of the input quantum data while preserving all the important features our quanvolutional layer picked out, so that our QNN can become more efficient and scalable. It’s just like a traditional pooling layer in a CNN, except this time we use a quantum circuit to extract certain statistics from the input quantum state, instead of using a classical function.</p><p>We do this through applying a series of unitary operations (<em>we mostly use Hadamard gates for this</em>) to the input quantum state of the pooling layer, and then follow it with a measurement of the output qubits in the computational basis. These results from the observation can be used to calculate the desired statistics, which really depends on the specific pooling method we’re using for our dataset.</p><blockquote><strong>If that sounds a little confusing or tricky, think of it this way:</strong> If we were trying to calculate the mean of the input quantum state, we would measure each qubit and then calculate the mean of our qubits in their classical form.</blockquote><p>Once we figure out this mean, we can construct our output state of the quantum pooling layer.</p><p>By doing this, we can achieve the model’s goal of constructing a lower-dimensional output quantum state while retaining all important features of the input data. This is important because it’s a problem that holds CNNs back from even higher accuracy values. Also, quantum pooling layers are able to extract higher-order moments of the input distribution, which allows for a more comprehensive characterization of the data than our classical pooling layers would give us.</p><p>We’ve got our quanvolutional layer and our quantum pooling layer, so of course, our <strong>quantum fully-connected layer</strong> is next. Here, our quantum fully-connected’s goal is to learn a non-linear function that maps the input quantum state to an output quantum state —<em> so that we can finally classify our images.</em></p><p>The quantum fully-connected layer is the layer in the QNN that connects all of the input qubits to output qubits, so that our model can be its final inference on which class each image belongs to. This is done through the layer applying a series of parameterized (parameters set in place during training) unitary operations to transform the input quantum state into the desired output state. The most common gates we use to do this are single-qubit rotations, two-qubit controlled gates and multi-qubit entangling gates — all of which, manipulate characteristics of the qubit state to perform the desired transformation.</p><p>Once we’ve done that, the output of the quantum fully-connected layer is typically a probability distribution over the possible output states. So that means that our output is processed to collapse the quantum states into a classical bit string.<strong> Using these probabilities, our QNN can determine which class belongs to which probability statistics so that it can accurately predict whether or not an image is or has a particular object.</strong></p><blockquote>For example, if we had a QNN that was trained to classify between cats and dogs and the probability value of the output qubit looked like [02,0.8] where 0.2 is assigned to the ‘dog’ class and 0.8 is assigned to the ‘cat’ class, the model will predict that the image contains a cat with a 80% confidence rate!</blockquote><p>Similar to Convolutional Neural Networks, our predicted outputs are compared to the true output, whether it be the accuracy or loss values of the model. Our final QNNs don’t always have to contain a quanvolutional layer, quantum pooling layer and a quantum fully-connected layer, and it’s very possible for the model to only have one of these with an entirely classical model. That depends on the dataset in question. <strong>But, regardless of how many quantum layers there are, our quantum-classical hybrid is so powerful towards enhancing the current state of Convolutional Neural Networks.</strong></p><h3>Closing Thoughts</h3><p>Without a doubt, Quanvolutional Neural Networks are still in the development phase. They require so much more time to become a 100%<br>feasible solution, as quantum computing hardware fights its limitations. But, with the <a href="https://www.scientificamerican.com/article/googles-quantum-computer-hits-key-milestone-by-reducing-errors/">recent advancements</a> in battling decoherence + error rates and finally reaching ‘step two’ of building quantum computers, the future of faster and more accurate neural networks to detect diseases in medical images isn’t far</p><p>When able to be used to its full potential, we can significantly impact medical imaging analysis, diagnosis, and treatment… <strong>and be apart of a world where diagnosis errors don’t harm patients and receiving results isn’t a long process.</strong></p><p><em>Hey, I’m Priyal, a 16-year-old who’s ambition revolves around working on solving complex problems to meaningfully contribute to the world.</em> <em>If you enjoyed my article or learned something new, feel free to subscribe to my </em><a href="https://priyaltaneja.substack.com/p/coming-soon"><strong><em>monthly newsletter</em></strong></a><em> to keep up with my progress in quantum computing exploration and an insight into everything I’ve been up to. You can also connect with me on </em><a href="https://www.linkedin.com/in/priyaltaneja/"><strong><em>LinkedIn</em></strong></a><em> and follow my </em><a href="https://medium.com/@priyaltaneja"><strong><em>Medium</em></strong></a><em> for more content! Thank you so much for reading.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2d0f5957516" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Entering The Next Era of Drug Discovery, Thanks to VQEs.]]></title>
            <link>https://priyaltaneja.medium.com/entering-the-next-era-of-drug-discovery-thanks-to-vqes-7180bfa0e9a3?source=rss-c6847f30c07a------2</link>
            <guid isPermaLink="false">https://medium.com/p/7180bfa0e9a3</guid>
            <category><![CDATA[quantum-computing]]></category>
            <dc:creator><![CDATA[Priyal Taneja]]></dc:creator>
            <pubDate>Fri, 10 Feb 2023 21:22:08 GMT</pubDate>
            <atom:updated>2023-02-10T21:38:14.755Z</atom:updated>
            <content:encoded><![CDATA[<h4>A Walkthrough of VQEs, Their Impact and an Annotated Copy of My Code</h4><blockquote><strong><em>“Why is there no cure yet?”</em></strong></blockquote><p>That’s always my first thought whenever I come across a heart-wrenching story of someone facing cancer, dementia, or any other debilitating illness without a cure. After all, these diseases have been the focus of attention for a while now. They’ve had billions of dollars and countless hours invested in the pursuit of a cure.</p><p>When I tried to find an answer for my question, I came across an alarming result; <strong>it takes a minimum of 10 years and ~2.6 billion dollars to research and develop a successful drug.</strong></p><p>Developing drugs is all about small molecules and macromolecules and the result of the interactions between them. Of course, the goal is to have interactions that don’t impose a negative reaction on our bodies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fzs2_bVJRWzAdnIu.jpg" /></figure><p>Simulating molecules is an important part of the whole drug development process, as it can help predict the behaviour and properties of potential drugs prior to being synthesized and tested in labs — <em>which saves on a whole load of time and resources. </em>It can also help us determine certain physical and chemical properties, which is key because we’re able to easily determine the best formulation and dosing regimen for the drug.</p><p><em>But..</em></p><p>..Yes, there’s a but.</p><p>Simulation is a difficult problem for our conventional computers. If you had 1 atom, you’d have to keep track of every single proton, neutron, and electron… which is do-able. Except, when the number of atoms exponentially increase, it gets pretty difficult. That’s a whole load of data, that neither us, as humans, or our computers can remember. And, inaccurate simulations that take forever to form aren’t really helpful.</p><p>Quantum computers are. They can perform simulations of molecular interactions at a much faster rate than classical computers. This allows researchers to quickly analyze potential drug candidates and identify the best options for further development —<em> which saves billions of dollars on research for drugs that may have minimal potential and all the unnecessary time.</em></p><h3>Enter Variational Quantum Eigensolvers…</h3><p><strong>A crucial part of analyzing molecules is determining the ground state of its electrons</strong> — that can provide us with information on its stability, reactivity, and binding affinity to target proteins. But, I’m sure you already guessed it. The number of possible configurations of the electrons in a molecule increase exponentially with the size of the molecule, and that’s too much data for our classical computers to analyze.</p><p>But, the key to quantum computers being this powerful tool in determining the ground state of an electron is something called a <strong>Variational Quantum Eigensolvers. </strong>VQEs are quantum algorithms for finding the lowest eigenvalue of a Hermitian operator, which represents the energy of a quantum system. And, molecules are quantum systems — <em>after all, both are viewed on an atomic scale.</em></p><p>VQEs use the <strong>variational principle</strong> (from quantum mechanics) to determine the eigenvalue of the energy of a quantum system.</p><p><em>Stick with me while I break down the variational method equation and explain some of the beautiful math behind VQEs… it’s fun I promise.</em></p><p>First, we need to know that molecules are represented in the form of a <em>matrix </em>for computers. And, given that it’s a Hermitian matrix, it’s also equal to its conjugate transpose. What we’re trying to do is <strong>find the smallest eigenvalue of this Hermitian matrix.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GaCVK4RUGnMVpVFhAYiscQ.png" /></figure><p>The main takeaway from this is that we are able to use the <strong>spectral theorem </strong>— <em>which allows us to state that the eigenvalues of the matrix must be real number. </em>Anyways, this Hermitian matrix can be used to describe the <strong>Hamiltonian</strong> of the quantum system, which specifies its total energy.</p><p>Mathematically it’s represented as…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M7xv9V8pgGuaV-Xs23Nt9g.png" /></figure><p>…where <strong>λ¡ is the Eigenvalue</strong> and <strong>|Ψ¡⟩ is the Eigenvector</strong> of the matrix.</p><p><em>The Hamiltonian can also be represented through this equation:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fhFMWJy4-q4GtdFzm1ffBg.png" /></figure><p>Now that we have two equations that are equivalent to our hamiltonian (H), we can substitute the first equation into the second.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TCKq_0elSW7H4PpXab0Zqg.png" /></figure><p>The expectation value of each observable state is given by the last equation in our rearrangement. And, since |⟨Ψ¡⟩⟨Ψ⟩|² is equal to or greater than 0 (as the eigenvalues have to be real numbers)…:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7MS0m_HtZrJLLhd4JLh5NQ.png" /></figure><p>This final equation represents the variational principle or variational method that we were talking about. It is equal or less than the eigenvalue of the Hamiltonian and tells us the expectation value of any wave function. <strong>It is the fundamental equation behind the workings of VQEs.</strong></p><h3>Let’s Code a VQE to Find the Ground State of a Triatomic Hydrogen Ion 👩🏻‍💻</h3><p><em>Feel Free to Access my </em><a href="https://github.com/priyaltaneja/Ground-State-of-H3-Using-VQE"><em>GitHub Repository</em></a><em> and See the Code in Entirety.</em></p><h4>Step One: Finding the Molecular Hamiltonian</h4><p>As usual, we’re going to start off by importing all the required libraries to ensure we have the functions needed to code this project. These are the <strong>backbones of our code so make sure all necessary libraries are imported</strong>.</p><pre># import all required libraries<br>import pennylane as qml<br>import matplotlib.pyplot as plt<br>from pennylane import numpy as np<br>from pennylane import qchem</pre><p>In order to find the ground energy level, we need to start from scratch and define the molecule that we’re working with. For this particular example, we’re going to find <strong>the ground state of an triatomic hydrogen ion (H+)</strong>, so I’ve declared each of the symbols along with the geometry of the molecule.</p><pre># define the molecule<br>symbols = [&quot;H&quot;, &quot;H&quot;, &quot;H&quot;]<br>coordinates = np.array([[0.0102,0.0442,0.0],[0.9867,1.6303,0.0],<br>                        [1.8720,-0.0085,0.0]])</pre><p><em>*The coordinates were obtained from this </em><a href="https://cccbdb.nist.gov/alldata1.asp"><em>database</em></a></p><p>And now, we finally <strong>determine the value of the Hamiltonian.</strong> At the same time, we’re also figuring out how many qubits are going to be used for this program. For the code below, <strong>the Hamiltonian value is (-0.29975061450095497) and the number of qubits needed are 6.</strong></p><pre># define the molecular hamiltonian<br>hamiltonian, qubits = qchem.molecular_hamiltonian(symbols,<br>                                                 coordinates,<br>                                                 charge = 1)<br>print (&quot;Number of qubits needed =&quot;, qubits)<br>print (&quot;The Hamiltonian is&quot;, hamiltonian)</pre><p>After this, we’re going to define an approximate ground-state which is also called the <strong>Hartree-Fock State. </strong>This is our first approximation guess towards our ground state, but isn’t actually the true value.</p><pre># determine the hartree-fock state<br>hf = qchem.hf_state(electrons = 2, orbitals = 6)<br>print (hf)</pre><p>The output of the code above is represented through the Jordan Wegner representation, and <strong>⟨110000⟩ </strong>tells us that there is one spin-up electron and one spin-down electron in the first energy state. Now, we’ll be building the circuit that will give us our expectation value with the Hartree-Fock state.</p><pre><br># calculate the expectation value<br>num_wires = qubits <br>dev = qml.device(&quot;default.qubit&quot;, wires=num_wires)<br><br>@qml.qnode(dev)<br>def exp_energy(state):<br>    qml.BasisState(np.array(state), wires=range(num_wires))<br>    return qml.expval(hamiltonian)<br><br>exp_energy(hf)</pre><p>The result of <strong>-1.24655016</strong> from <em>exp_energy(hf)</em> doesn’t provide us with the ground state but it does provide us with a minimized, lower state that we can continue iterating on to find the smallest value.</p><h4>Step Two: Prepare Trial Ground State</h4><p>Now, we’ll be defining our circuit that will de-excite the electrons through double excitation gates, which allows our system to <strong>determine a second expectation value that is lower than the first.</strong></p><p>The first <em>Double Excitation </em>gate is applied on the first element in the list of parameters and takes the electrons between the lowest energy to the intermediate level of energy. The second <em>Double Excitation</em> gate is applied on params [1] instead and takes electrons in the lowest energy level to the highest energy level.</p><pre># de-excite electrons through double excitation gates<br>def ansatz(params):<br>    qml.BasisState(hf,wires=range(num_wires))<br>    qml.DoubleExcitation(params[0], wires=[0,1,2,3])<br>    qml.DoubleExcitation(params[1],wires=[0,1,4,5])</pre><p>Here, we’ve prepared a second expectation value that can be considered a trial ground state.</p><h4>Step Three: Minimize ⟨H⟩</h4><p>Remember the<em> fundamental variational principle equation</em> we determined earlier? Here’s when it comes into play.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7MS0m_HtZrJLLhd4JLh5NQ.png" /><figcaption>brought it back as a refresher</figcaption></figure><p>This property tells us that if we find a state that minimizes the expectation value of the Hamiltonian, then that state is the ground state. So, now we’re going to move one step closer to our minimum and determine a cost function to lower the current expectation value we have.</p><pre># minimize the hamiltonian value using ritz variational principle<br>@qml.qnode(dev)<br>def cost_function(params):<br>    ansatz(params)<br>    return qml.expval(hamiltonian)<br>cost_function([0.1,0.1])</pre><p>In this case, we get an energy of <strong>-1.26796721</strong>, which is smaller than our Hartree-Fock state… so, yay. We’re progressing towards success. We’ve already found a state that is lower of what was supposed to be the ground state.</p><p>Finally, we’ll be optimizing our cost function to minimize our expectation value. This is done through optimizing quantum circuits through paneling. A reiterative process is completed with the state getting lower each time, and every 2 steps are outputted. For H+ the maximum iterations are 20, but the number can be smaller or greater depending on the molecule.</p><pre># optimize our cost function circuit to find ground-state<br>opt = qml.GradientDescentOptimizer(stepsize=0.4)<br>theta = np.array([0.0,0.0], requires_grad = True)<br><br>energy = [cost_function(theta)]<br>angle = [theta]<br>max_iterations = 20<br><br>for n in range(max_iterations):<br>    theta, prev_energy = opt.step_and_cost(cost_function, theta)<br>    <br>    energy.append(cost_function(theta))<br>    angle.append(theta)<br>    <br>    if n%2 == 0:<br>        print (f&quot;Step = {n}, Energy = {energy[-1]:.8f} Ha&quot;)<br><br># output the ground-state and the optimizing parameters<br>print (&quot;\n&quot; f&quot;Final ground energy: {energy[-1]: .8f} Ha&quot;)<br>print (&quot;\n&quot; f&quot;Final angle parameters: {theta[0]: .8f} {theta[1]: .8f}&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vmVq4JJniybT3l1jF6FpMQ.png" /><figcaption>results from the optimization circuit</figcaption></figure><p>As we can see, the energy states slowly progress lower and lower each time, and step 18 is the last value before the loop starts outputting a repetitive number. The final value converged is ~1.27 and is much lower than the Hartree-Fock state of ~1.24.</p><p>And, to end off the determination of our ground state, we’ll create a graph that will visually represent the position of the ground state.</p><pre># form a graphical representation with the ground state plotted<br>fig = plt.figure()<br>fig.set_figheight(5)<br>fig.set_figwidth(12)<br><br># full configuration interaction energy computed classically<br>E_fci = -1.27443763<br><br># add energy plot on column 1<br>ax1 = fig.add_subplot(121)<br>ax1.plot(range(n + 2), energy, &quot;go&quot;, ls=&quot;dashed&quot;)<br>ax1.plot(range(n + 2), np.full(n + 2, E_fci), color=&quot;red&quot;)<br>ax1.set_xlabel(&quot;Optimization step&quot;, fontsize=13)<br>ax1.set_ylabel(&quot;Energy (Hartree)&quot;, fontsize=13)<br>ax1.text(0.5, -1.2466, r&quot;$E_\mathrm{HF}$&quot;, fontsize=15)<br>ax1.text(0, -1.2744, r&quot;$E_\mathrm{FCI}$&quot;, fontsize=15)<br>plt.xticks(fontsize=12)<br>plt.yticks(fontsize=12)<br><br># add angle plot on column 2<br>ax2 = fig.add_subplot(122)<br>ax2.plot(range(n + 2), angle, &quot;go&quot;, ls=&quot;dashed&quot;)<br>ax2.set_xlabel(&quot;Optimization step&quot;, fontsize=13)<br>ax2.set_ylabel(&quot;Gate parameter $\\theta$ (rad)&quot;, fontsize=13)<br>plt.xticks(fontsize=12)<br>plt.yticks(fontsize=12)<br><br>plt.subplots_adjust(wspace=0.3, bottom=0.2)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2uPkuQBVJmbfyRdZ-wZKIQ.png" /></figure><h3>Closing Thoughts 💭</h3><p>We’re in a period of time where researchers are finally discovering the impact of quantum computers for drug discovery and research, which includes VQEs. They’re truly one of the most promising methods for quantum chemistry, as they have an exponential advantage over classical algorithms. Of course, limitations, such as noise, exist but the future of quantum computation in chemistry could change the way we approach drug development process.</p><p><em>Hey, I’m Priyal, a 16-year-old who’s ambition revolves around working on solving complex problems to meaningfully contribute to the world.</em> <em>If you enjoyed my article or learned something new, feel free to subscribe to my </em><a href="https://priyaltaneja.substack.com/p/coming-soon"><strong><em>monthly newsletter</em></strong></a><em> to keep up with my progress in quantum computing exploration and an insight into everything I’ve been up to. You can also connect with me on </em><a href="https://www.linkedin.com/in/priyaltaneja/"><strong><em>LinkedIn</em></strong></a><em> and follow my </em><a href="https://medium.com/@priyaltaneja"><strong><em>Medium</em></strong></a><em> for more content! Thank you so much for reading.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7180bfa0e9a3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quantum Computing 101]]></title>
            <link>https://priyaltaneja.medium.com/quantum-computing-101-27b09e110ac2?source=rss-c6847f30c07a------2</link>
            <guid isPermaLink="false">https://medium.com/p/27b09e110ac2</guid>
            <category><![CDATA[quantum-computing]]></category>
            <dc:creator><![CDATA[Priyal Taneja]]></dc:creator>
            <pubDate>Fri, 06 Jan 2023 05:23:33 GMT</pubDate>
            <atom:updated>2023-01-06T05:23:33.348Z</atom:updated>
            <content:encoded><![CDATA[<p>I remember my obsession with maze puzzles as a kid. They were the most incredible thing ever. Trying to figure out how to get to point A to point B with no obstacles along with way.</p><p>Back then, my strategy was to go through every single route I saw and whenever I’d reach a dead-end, I’d just try an alternative path. That explains why certain mazes took me hours to complete.</p><p>Think of a maze like a more high-level problem (such as our supply chain system) — except we don’t have to use my <em>time-consuming </em>strategy when we’ve got our <strong>quantum computers</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ba4vc4henC3kIF57.jpg" /><figcaption>What a Quantum Computers Looks Like</figcaption></figure><blockquote><em>Quantum computing is </em><strong><em>a way to solve problems that are too large or too complex for our conventional computers using the law of quantum mechanics</em></strong><em> </em>— which is the physics of extremely small matter.</blockquote><p>In 1965, Gordon Moore suggested that roughly every 2 years, the number of transistors (the little device that controls the flow of electric signals) on microchips will double. This is why our devices keep getting smaller and smaller — <em>think about how we went from a computer that occupied the entire room to one that fits in our pockets.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*UO3O0AcJXcKa3BGxez7cZA.png" /><figcaption>The Change in the Size of Our Computers!</figcaption></figure><p>But<strong> the second we hit the atomic level, things change… </strong>we can’t use the physics we usually do but instead have to work with <em>quantum</em> physics.</p><p><strong><em>Note:</em></strong><em> This article is written with the intention of being a very simple and basic walk-through of the emerging technology, Quantum Computing. It’s meant to expose readers to the fundamentals of QC plus its applications &amp; value, and is not meant to be technical. If you’re looking for a more specific algorithm walk-through, I’ve written a couple more articles you can check out on my Medium profile </em><a href="https://priyaltaneja.medium.com/"><em>here</em></a><em> — but if you’re simply here to learn something new, read along and I hope you enjoy! :)</em></p><h3>Bits vs. Qubits</h3><p>In order to process information to the simplest level, classical computers use something called <em>bits.</em> <strong>Bits are a binary system where everything gets translated to either a state of 0 or 1.</strong> It’s the unit of information that classical computers use to send and receive information, store data and do calculations. Basically, to do all the functions your devices perform at the moment. <strong>It’s because of this certainty that classical computers can only perform <em>one</em> operation at a time.</strong></p><p>Think about a typical on/off light switch that’s most likely on your wall. You can either turn it on <em>or</em> off. That’s exactly how bits work<em> — a value either exists in the state of 0 or 1.</em> But what if I told you to keep it in the middle of on and off? What would you classify it as —<em> is the light on or off?</em></p><p><em>Qubits</em> work in the same way. <strong>Qubits </strong>— or also known as <em>quantum bits — </em>are similar to bits as they have the ability to process information but instead of definitive states, <strong>they can exist in-between 0 and 1.</strong> This is called <strong><em>superposition</em></strong><em>…</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*9u8SB1UewVlMYEKp1cCfbw.png" /><figcaption>Classical Bits Existing in One State versus Qubits Existing in Two States at the Same Time</figcaption></figure><h3>Superposition</h3><p><strong>Superposition is what differs a bit from a qubit — </strong><em>and a classical computer vs. a quantum computer. </em>This aspect of quantum mechanics allows qubits to be in-between two states, so <strong>qubits can be in a state somewhere between 0 and 1.</strong> Since the nature of qubits isn’t definitive, you can perform <em>multiple</em> functions at a time — <em>this is why quantum computers are much faster in performing certain tasks.</em></p><h3>Representation of Qubits</h3><p>One way that we express the state of qubits is through a geometrical-representation called a <strong>bloch sphere. </strong><em>It looks like this…</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bkx85UByBukXhGQ30ko4Yg.png" /></figure><p>In quantum computing, we use linear algebra to calculate and manipulate the states, so vectors are commonly used to describe the state of a qubit — but, the main takeaway from the image above is that |Ψ<strong>⟩</strong> basically represents the state of the qubit.</p><h3>Measurement</h3><p>Superposition doesn’t exist forever though. It’s important to note that the second you <strong>measure</strong> a qubit, superposition disappears since that’s when the quantum system will collapse and the qubit will <em>pick</em> a state to be in.</p><p><strong>It will choose based on the probabilities of its superposition.</strong> <em>Not to get too mathematical but the equation looks like this…</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SzZS42rrHY7tKwcuZK1wOQ.png" /></figure><p>Each qubit has something called an <em>amplitude </em>which refers to the probability of it falling into each computational basis state — which are what ‘alpha’ (α) and ‘beta’ (β) stand for in the equation.</p><p>We have the ability to manipulate the probability of a qubit collapsing into a particular state through <strong>quantum logic gates</strong>. There are many different kinds of gates, each with a unique function, but for now it’s important to know that gates are a way to control the qubits for a desired result.</p><h3>Entanglement</h3><p>If I told you that two particles are connected, even if they were light years apart, you would probably be quick to call that a lie. Well, I don’t blame you — after all, even Albert Einstein initially rejected this idea by calling it a <em>“spooky-action-at-a-distance.”</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qCWugxYw5grcD0Vl.png" /><figcaption>Two Qubits Entangled</figcaption></figure><p><strong>Quantum entanglement is when two qubits link together in a certain way, in which no matter how far apart they are, information about one qubit will tell you something about the other qubit.</strong></p><p>My favourite way to explain this is through a story by Dr. Brian Greene at Columbia University:</p><blockquote>Pretend that you and a friend bought a pair of gloves. You place one glove inside one box and the other glove inside another box. You take one box and travel to one side of the universe. Your friend takes the other box and travels to the other side. You open your box, and find the left glove. You know immediately that your friend is going to open the box and find the right glove. You don’t need to call your friend on the telephone. Nor do you need to see inside the second box to confirm this fact. The gloves are, in a sense, entangled. One glove can tell you all you need to know about the other.</blockquote><p>The phenomena of quantum entanglement can allow us to cut down on both the necessary time and computing power to process the transfer of information between qubits.</p><h3>Applications of Quantum Computers</h3><p>Over the last few years, quantum computing has emerged to be considered as an innovative technology. Today it’s reached a stage where it can potentially solve a significant number of problems, in a way that classical computers cannot.</p><p><em>Some of the areas of problems that quantum computers can solve include:</em></p><ul><li><strong>Optimization Problems</strong>— when you’re looking for an optimal solution, you typically need an analysis of every single potential option… quantum computers (more specifically, quantum annealers) can speed up this process exponentially.</li><li><strong>Finance</strong> — quantum machine learning can handle these large amounts of data in the finance industry for real-time data insights and predictions.</li><li><strong>Cybersecurity </strong>— in order to secure data in a way that cannot be encrypted, quantum cryptography employs aspects of quantum physics.</li><li><strong>Drug Discovery </strong>— by utilizing quantum computers, we can gain better insights about shared characteristics between molecules and expedite the process of drug discovery.</li><li><strong>Data Analysis</strong> — quantum computing allows high-speed detection, analysis, integration, and diagnosis capabilities when working with huge, scattered data sets.</li></ul><h3>Current State of Quantum Computing</h3><p>There’s a reason why companies all over the world invest millions of dollars into quantum computing research but its’ potential cannot be blindsided by the limitations currently present.</p><p>Quantum computers are still in a stage where they’re unstable and not reliable. They’re prone to errors — due to the nature of quantum physics — so the computers don’t always produce the most accurate results.</p><h4>Decoherence</h4><p>One of the greatest problems in quantum computing is defined as <strong>decoherence </strong><em>— exactly where these mysterious errors come from.</em></p><p>Since qubits are extremely tiny, they’re also sensitive to compute on. This is because the external environment of the qubits can often interfere and mess-up the existing quantum states… which causes information stored by the quantum computer to be lost.</p><p><em>Some environmental factors that may cause or contribute to decoherence are:</em></p><ul><li>Changing Magnetic and Electric Fields</li><li>Radiation from Warm Objects Nearby</li><li>Interference between Qubits</li></ul><h3>Key Takeaways</h3><ol><li>Quantum computers take advantage of<em> </em><strong><em>quantum physics</em></strong><em> </em>to tackle problems that our classical computers are inefficient or incapable of solving.</li><li><strong>Superposition</strong> is what differs a qubit from a bit, as a qubit can exist in a state that is in-between 0 and 1 — rather than always being a definitive state. It disappears when <strong>measuring</strong> a qubit and the qubit will then choose one particular state to be in, which is based off its’ probability.</li><li><strong>Quantum entanglement</strong> is the idea that, when two qubits are linked, information about one will reveal information about the other, regardless of the distance between them.</li><li><strong>Decoherence</strong> refers to external factors in a qubits’ environment which can negatively impact the existing quantum systems.</li></ol><p><em>Hey, I’m Priyal, a 16-year-old driven to impact the world using emerging technologies. If you enjoyed my article or learned something new, feel free to subscribe to my </em><a href="https://priyaltaneja.substack.com/p/coming-soon"><strong><em>monthly newsletter</em></strong></a><em> to keep up with my progress in quantum computing exploration and an insight into everything I’ve been up to. You can also connect with me on </em><a href="https://www.linkedin.com/in/priyaltaneja/"><strong><em>LinkedIn</em></strong></a><em> and follow my </em><a href="https://medium.com/@priyaltaneja"><strong><em>Medium</em></strong></a><em> for more content! Thank you so much for reading.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=27b09e110ac2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimizing Database Searching with Grover’s Algorithm]]></title>
            <link>https://priyaltaneja.medium.com/optimizing-database-searching-with-grovers-algorithm-cad50a603494?source=rss-c6847f30c07a------2</link>
            <guid isPermaLink="false">https://medium.com/p/cad50a603494</guid>
            <category><![CDATA[quantum-computing]]></category>
            <dc:creator><![CDATA[Priyal Taneja]]></dc:creator>
            <pubDate>Sat, 24 Dec 2022 04:04:59 GMT</pubDate>
            <atom:updated>2023-01-12T02:21:58.941Z</atom:updated>
            <content:encoded><![CDATA[<p>Suppose that there are <strong><em>four</em></strong> doors in front of you, and you’ve been told to find the room with the ‘winning’ object.</p><p>You might choose to go through each door individually to determine whether it belongs to the winning room. Even though it’s possible that door #1 is the desired solution and you’ll only need to make one attempt to locate it, it’s not definite. The <strong>worst-case scenario</strong> is that it’s the final door, in which you’ll need to make <em>multiple</em> <em>efforts</em> instead.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*D6Cjaw7_CmU4wMhfca5ndg.png" /></figure><p>But what if there were 16 doors instead of 4, and the winning room was door 16? You would go through every single door before it to find your winning solution.</p><blockquote>That entire process can get extremely <strong>time-consuming</strong> as the number of options increases exponentially.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*Vg5kAhIE-TE0R1DjkDloNg.png" /></figure><p>The same thing applies to <strong>data sets</strong> — where the number of potential options can be much higher than 16.</p><p>Considering that we are currently living in this era of big data, <strong>the ability to quickly and efficiently search through enormous amounts of data is essential</strong>.</p><h3>A Classical Approach 📜</h3><p>What sucks is that our traditional computers use the same approach of evaluating each potential option sequentially until they identify the desired answer.</p><p><em>The code for a conventional computer’s technique resembles something like this:</em></p><pre># creating a random list<br>my_list=[1,3,5,2,4,9,5,8,0,7,6]<br><br># define an oracle and tell it the winner<br>def the_oracle(my_input):<br>    winner=7<br>    if my_input is winner:<br>        response = True<br>    else:<br>        response = False<br>    return response<br><br># figure out how many queries were made to find the winner<br>for index, trial_number in enumerate(my_list):<br>    if the_oracle(trial_number) is True:<br>        print (&#39;Winner found at index %i&#39; %index)<br>        print (&#39;%i calls to the Oracle used&#39;%(index+1))<br>        break</pre><p>If this looks like a bunch of letters and you’re unable to make out what’s happening, don’t worry.</p><p><strong>The process goes as follows:</strong></p><ul><li>The computer is given the list of numbers (in this case, these are our <em>potential</em> options)</li><li>The <strong>oracle </strong>(an unexposed operation that feeds data to another algorithm) is informed of what number is the winner and is told to output the ‘True’ response when the input is the desired option</li><li>When the winning number is discovered, the computer can also tell you how <strong>queries</strong> (a more technical term to describe the act of requesting for information) were made to find the answer</li></ul><p>As seen above, the amount of queries made by the classical computer was the number of options… in this case, it was only 10, But, whether the number of options was 256, or 50,000 — it would take that many queries to find the solution, and so on.</p><p>Due to the complexity of this problem and the ineffectiveness of this approach, <strong>O(N) </strong>refers to the amount of time that it’ll take to determine the answer — <em>where O refers to ‘on the order of’ and N refers to the length of the list</em>.</p><p>The longer the list, the more time it’ll take — and given that companies typically have millions of data sets to sift through, I’m sure the thought of this doesn’t sound too appealing.</p><h3>Lov Grover’s Quantum Approach 🔑</h3><p>In 1996, Lov Grover — a computer scientist — showed us that there is a quantum algorithm that solves this problem with <strong>O(√N)</strong> queries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Afcy5rL73vr5ua3Ecle2hQ.png" /><figcaption>Mathematical demonstration of how long a CC vs. QC would take to determine the winning solution!</figcaption></figure><blockquote>This algorithm is now referred to as <strong>Grover’s Algorithm </strong>— the key to optimizing unstructured search problems.</blockquote><p>Grover’s search algorithm is one of the first and most prominent examples that demonstrates <em>quantum advantage.</em></p><p>The difference in the number of queries may not seem significant —<em> but as the value for N increases, it becomes more visible</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PyyWukKjqi6VfV6cV7It1A.png" /><figcaption>Blue = O(N) — Red =O(√N)</figcaption></figure><p>Anyways, he proposed leveraging this trick known as<strong> amplitude amplification. </strong><em>Amplitude amplification</em> is a procedure that raises the probability amplitude of the value being searched while simultaneously lowering the other probability amplitudes. This is the key to helping quantum computers quadratically accelerate the process of solving the problem.</p><h3>Time to Code 👩🏻‍💻</h3><p><strong><em>Note:</em></strong> <em>When I was diving deeper into understanding the fundamentals of Grover’s Algorithm, this was too much to take in at once. So stay with me and let’s take it </em><strong><em>step-by-step</em></strong><em> as we learn more about the quantum mechanics, math and code behind enhancing our searching abilities. If you’d prefer to listen to an explanation of the code, I’ve also created a YouTube video that acts as a walkthrough of the code… if not, continue reading!</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FHeYGWe20yqc%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DHeYGWe20yqc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FHeYGWe20yqc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e80b7a34fec8b5aeb87c3a042b9a60b/href">https://medium.com/media/5e80b7a34fec8b5aeb87c3a042b9a60b/href</a></iframe><p><strong>The process of Grover’s algorithm can be broken done into 3 steps:</strong></p><ul><li>Initializing the quantum circuit, where it starts off in <em>uniform superposition</em> (represented by a vector; <strong>|s⟩</strong>)</li><li>Applying an <em>oracle reflection</em>, where the phase of the state |w<strong>⟩</strong> is reflected</li><li>Reversing the reflection, so that |w<strong>⟩ </strong>has the greatest amplitude and largest probability of getting chosen as the ‘winning’ answer</li></ul><h4>Step 1: Initialize the Circuit</h4><p>In this particular example, we’ll be figuring out the correct answer between 2 qubits — <em>as defined in the code below.</em></p><p><em>Since there’s 2 qubits, there’s 4 potential states (which means that N = 4):</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qB9T0SyW5zL6j3B303CozA.png" /></figure><p>The winning state we’ll be searching for today is |11<strong>⟩</strong>.</p><p>Once that’s determined, we’ll start off by coding the initialization of the quantum circuit in <strong><em>uniform superposition </em></strong><em>— a special state that we’ll consider.</em></p><pre># prepare a quantum circuit with two qubits<br>num_qubits = 2<br>grover_circuit = QuantumCircuit(num_qubits)<br><br># initialize the state<br>def initialize_s(qc,qubits):<br>    for q in qubits:<br>        qc.h(q)<br>    return qc<br><br>grover_circuit = initialize_s(grover_circuit,[0,1])<br>grover_circuit.draw()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l6fAf_v9RAgUO_FW_hLUag.png" /></figure><p><em>If we were to look at this on a graph, it would look like this:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VaeG11DsbDFF3MG-rdjFQQ.png" /><figcaption>Graphical Representation of This Problem</figcaption></figure><h4><strong>Step 2: Oracle Reflection</strong></h4><p>Now, let’s take a step back and remember the process from the classical approach. We told the oracle what our winning number was, so the same rule applies here — we need a way to ‘mark’ the winning state.</p><pre># apply controlled-Z gates as an oracle<br>grover_circuit.cz(0,1)<br>grover_circuit.draw()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NJQ-EDySlO6uAHUpQ2lm9A.png" /><figcaption>Visual Output of the Code above</figcaption></figure><p>We do so by applying a Controlled-Z gate (as the oracle reflection) after initialization, which applies a negative phase to the winning state. It’s important to note that this oracle is specific to this example of 2 qubits.</p><p><strong><em>But, how does this work…?</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MTl-wNpkbpC8tIywCzNcjA.png" /><figcaption>Visual Representation of the Options Being Evaluated in the Black Box (Oracle) and the Winning State’s Sign Being Flipped!</figcaption></figure><p>Basically, the way that the CZ gate works is that oracle will flip the sign of the winning state so that it is differentiated from the rest.</p><p>To make this easier, think of the oracle like a <em>black box</em>. The option that is being evaluated goes through this black box to be ‘tested’ if it is the winning option.</p><p>Mathematically, we can represent the way this works through functions; <em>if the input is equal to the winning number, f(x) = 1, otherwise, f(x) = 0.</em></p><p>The equation that represents the oracle’s transformations on the input is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2_z6GnSqnqkQL6o1N92U4w.png" /></figure><p>So, if |x<strong>⟩ = </strong>|w<strong>⟩</strong>, the output from the black box will be the negative value of winning state, which means the amplitude in front of |w<strong>⟩ </strong>is negative as well. All other states remain the same.</p><p><em>After the negative phase is applied, the graph looks like this:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i8i9rjTZPt-m9VVuiaFX1g.png" /><figcaption>Graphical Representation of What It Looks Like After the Negative Phase is Applied</figcaption></figure><p>Although, as a result of applying the Controlled-Z gate to winning state, <strong>the average amplitude has been lowered — </strong><em>as indicated by the dashed line in the graph above.</em></p><h4><strong>Step 3: Diffusion Operator</strong></h4><p>The final step is to reverse the previous transformation on |w<strong>⟩ </strong>(after it’s been marked) so we can increase its amplitude.</p><p>We can do this by applying a combination of <em>Hadamard</em>, <em>Pauli-Z</em>, and <em>Controlled-Z </em>gates on the qubits, as seen in the code below:</p><pre># apply diffusion operator and measure the qubits<br>grover_circuit.h([0,1])<br>grover_circuit.z([0,1])<br>grover_circuit.cz(0,1)<br>grover_circuit.h([0,1])<br>grover_circuit.measure_all()<br>grover_circuit.draw()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nwxsEfXSvH-3oXCs7a-VHA.png" /><figcaption>Visual Output of the Code above</figcaption></figure><p><em>The mathematical expression that represents this reflection is as follows:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dm3c4iLvXzXmLxMId0vQVA.png" /></figure><p>Essentially, all this operation does is reduce the probabilities of the non-winning states and increases the probability for the winning state.</p><p><em>It’ll make more sense when you see it graphically — the transformation looks like:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NMaaBdB2s1evvWpHk_tcjQ.png" /><figcaption>Graphical Representation of What It Looks Like After the Diffuser Reflection is Applied</figcaption></figure><p>Here, you can see that this transformation allows for the winning state’s amplitude to boost itself to roughly 3 times its original value, all while the <em>average</em> amplitude remains significantly lower.</p><p>To maximize the accuracy, the quantum computer will <em>repeat steps 2 and 3 several times</em> — but don’t worry, <strong>it’s still much faster than a classical computer as it’ll perform these operations around √N times.</strong></p><h3>Let’s Run the Algorithm on a Real Quantum Computer…👾</h3><p>Now comes the best part — being able to run the Grover’s algorithm we built on an actual quantum computer. IBM’s Qiskit will go ahead and find the least busy backend device where it’ll let us know whether or not the job status has been successful or not…</p><pre># run the circuit on a real quantum computer<br>provider = IBMQ.load_account()<br>provider = IBMQ.get_provider(&quot;ibm-q&quot;)<br>device = least_busy(provider.backends(filters=lambda x: int(x.configuration().n_qubits) &gt;= 3 and <br>                                   not x.configuration().simulator and x.status().operational==True))<br>print(device)<br><br>transpiled_grover_circuit = transpile(grover_circuit, device, optimization_level=3)<br>job = device.run(transpiled_grover_circuit)<br>job_monitor(job, interval=2)</pre><p><strong>…this one was a success</strong>! But, to wrap things off, we <em>have</em> to get the results from our computation to really determine how successful we were.</p><pre># get results from the computation<br>results = job.result()<br>answer = results.get_counts(grover_circuit)<br>plot_histogram(answer)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dVLDajfi4x9_frmO6LwsPA.png" /><figcaption>Graphical Representation of the Outcome of Grover’s Algorithm on 2 Qubits</figcaption></figure><p>We can see that <strong>91%</strong> of the time of running this algorithm on a real quantum computer results in the correct output, the state of |11<strong>⟩</strong>.</p><p>Even though 9% of outputs are computation errors, the results above prove a high degree of effectiveness and ultimately prove the concept of quantum advantage for this particular problem.</p><h3>Closing Thoughts 💭</h3><p>When looking into practical applications of Grover’s search algorithm, I came across its use in the <em>Travelling Salesman Problem</em> — I’ve written an article about Quantum Computing’s role in improving the supply chain &amp; route logistics, check it out <a href="https://medium.com/@priyaltaneja/how-to-solve-unsolvable-problems-within-the-supply-chain-2ce8ba8e5adb">here</a>.</p><p>Overall, in the quantum computing world, this algorithm is extremely valuable and holds great significance as it proves one of the most talked-about QC applications, <em>searching through unstructured data</em>. Its use of quantum properties speed up the execution time. When fully developed, at an even higher accuracy rate, the impact it’ll have on various industries will be outstanding to see.</p><p><em>Hey, I’m Priyal, a 16-year-old driven to impact the world using emerging technologies. If you enjoyed my article or learned something new, feel free to subscribe to my </em><a href="https://priyaltaneja.substack.com/p/coming-soon"><strong><em>monthly newsletter</em></strong></a><em> to keep up with my progress in quantum computing exploration and an insight into everything I’ve been up to. You can also connect with me on </em><a href="https://www.linkedin.com/in/priyaltaneja/"><strong><em>LinkedIn</em></strong></a><em> and follow my </em><a href="https://medium.com/@priyaltaneja"><strong><em>Medium</em></strong></a><em> for more content! Thank you so much for reading.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cad50a603494" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>