<?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 Valeh Farzaliyev on Medium]]></title>
        <description><![CDATA[Stories by Valeh Farzaliyev on Medium]]></description>
        <link>https://medium.com/@valehfarzaliyev?source=rss-340042c89d45------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*kbLKuzYaY6kV9bWt</url>
            <title>Stories by Valeh Farzaliyev on Medium</title>
            <link>https://medium.com/@valehfarzaliyev?source=rss-340042c89d45------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 12:57:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@valehfarzaliyev/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[What if there is a backdoor?]]></title>
            <link>https://medium.com/@valehfarzaliyev/what-if-there-is-a-backdoor-60dc0a6ca50e?source=rss-340042c89d45------2</link>
            <guid isPermaLink="false">https://medium.com/p/60dc0a6ca50e</guid>
            <dc:creator><![CDATA[Valeh Farzaliyev]]></dc:creator>
            <pubDate>Sun, 23 Jan 2022 07:28:34 GMT</pubDate>
            <atom:updated>2022-01-23T07:28:34.151Z</atom:updated>
            <content:encoded><![CDATA[<p>We are living in a world where we believe that we have the right to keep our private information secret, do not trust third parties, yet we achieve this by trusting some institutions and/or people. This is a philosophical discussion rather than a conspiracy theory.</p><h3>The need for distrust</h3><p>Why should we trust or distrust others? That is a very hard question to answer. But, let’s approach the question using a well-understood concept in physics. In mechanics, there is a notion called equilibrium and it has two forms: stable and unstable equilibrium. Perhaps, a visual explanation would be easier to understand. Look at the two figures below. A stable equilibrium is a stronger form of equilibrium where it is hard to disrupt the system. Even, when the system is disturbed, natural laws of physics evolve the system to return its balanced position. In contrast, when the unstable equilibrium system is messed with a tiny force, the system gets destroyed. A ball on top of a hill, though is at rest and thus balanced, will move downwards upon a tiny push. However, if the ball is sitting at the bottom of the well, it will return to its original position after several oscillations once it is forced to move (of course, if we do not neglect friction).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tVAMu4bFA_OCrkT-.png" /><figcaption>Unstable equilibrium. Source: Wikipedia</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cU70yf_8mufexuOD.png" /><figcaption>Stable equilibrium. Source: Wikipedia</figcaption></figure><p>Trust has a similar property. In a closed society, if everyone trusts each other that everyone will behave honestly, this creates unstable equilibrium. Society breaks down when at least one person starts cheating or acting maliciously. Unfortunately, the world has seen such catastrophic examples. In many religions, believers are demanded to trust the exceptional capabilities of creators and it is forbidden to question them. As a result, leaders of the community can misuse the honest feelings of ordinary people to get themselves richer and/or powerful.</p><p>But, how to live with no trust at all? That is almost impossible. As human beings, we have feelings and we want to trust people we love and live a happier life. When those people betray us, we feel devastated. But if we did not trust at the beginning, maybe, we would have an unhappy and stressful life. The solution one can think of is to trust something that we do not have control over and choose our loved ones who trust that something as well. Again, religions are a good example of that. But not the only ones.</p><p>Is there deep ultimate truth (except what every religion offers) that we can build everything upon that? Like, the axiom of choice in set theory, 0 is a natural number, or the speed of light <em>c</em> is a constant, independent of the relative motion of the source. Certainly, they are useful and had a great impact on our life, scientific and technological advances. These are fundamental axioms of math and special relativity that are “obviously true”. In math, everything boils down to logic. Logic is a formal way of reasoning to evade subjective beliefs.</p><h3>Cryptography as a solution</h3><p>Let’s choose (formal) logic as the basic unquestionably true system to construct the rest of the world. We start by developing mathematics as a tool, because it helps to solve problems, such as (ac)counting. Upon observations and experiments, it is possible to devise intuitive and/or counter-intuitive theoretical scientific models and prove their correctness (under certain assumptions) using math. Moreover, we end up with a modern technologically advanced society.</p><p>Now, it is time to use this technology as a tool to help people form communities, social bonds, and ultimately civilization. This has to start from an interaction between people. Communication is a basic way of interaction. And, often, we want our conversations to be private. Not necessarily for malicious reasons, but due to distrust. It may be used by others against us if we let everyone know our secrets. For example, our medical information, financial status, love affairs, political views, etc. If communicating parties are in close contact, they can create an invisible social chamber, assuming others will not eavesdrop on their conversation. In other words, they create a secret channel or medium between themselves. For example, today, we exchange information over digital channels. The secrecy of the contents is preserved in several layers using digital and physical security solutions. Of course, they are not perfect, but, engineers are trying their best to minimize errors.</p><p>Cryptography is a branch of computer science that studies techniques of secure communication — the thing we need in a distrustful environment. Advanced math is used in cryptographic protocols which are not easily explainable for ordinary people. So they have to trust the math behind it. But, trusting math is rather achievable: learning necessary preliminaries, everyone can repeat proofs and convince themselves if the statement is true or not.</p><p>However, this doesn’t solve the trust problem. What if designers of new tools are malicious people? What if backdoors are injected into implementations? This is harder to detect. Here, the only possible solution is transparency. The design and choice of parameters rationale can or should be open access to everyone. For example, why in NIST curve coefficients are generated by hashing unexplained seeds? Because NIST is a governmental entity, it affects legal frameworks and can force private and public organizations (at least in the USA) to follow their so-called standards. If they secretly injected exploitable weakness into the cryptosystem, then the government (at least, intelligence departments) may learn our secrets without prior consent. Thus, our right to privacy is violated.</p><h3>Final thoughts</h3><p>Maybe, instead of complicating the life to make it happy place, we should accept it as the way it is. Because, learning math is not a solution for happiness, though it may bring some. And, one cannot expect everyone to be proficient in math to build unbreakable society.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60dc0a6ca50e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IBM Onlayn Kvant Kompüterində ilk sınaq]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/kvant-d%C3%BCnyas%C4%B1/ibm-onlayn-kvant-komp%C3%BCterind%C9%99-ilk-s%C4%B1naq-848fb9cc2a3a?source=rss-340042c89d45------2"><img src="https://cdn-images-1.medium.com/max/600/0*1Bnv-XKY1-lJN7Ik.png" width="600"></a></p><p class="medium-feed-snippet">IBM Onlayn Kvant Komp&#xFC;terind&#x259; Kvant D&#xFC;nyas&#x131; olaraq, sad&#x259; kvant alqoritmini test etdik, v&#x259; ideal &#x15F;&#x259;raitd&#x259; 100% n&#x259;tic&#x259; verdi!</p><p class="medium-feed-link"><a href="https://medium.com/kvant-d%C3%BCnyas%C4%B1/ibm-onlayn-kvant-komp%C3%BCterind%C9%99-ilk-s%C4%B1naq-848fb9cc2a3a?source=rss-340042c89d45------2">Continue reading on Post-Kvant Dünya »</a></p></div>]]></description>
            <link>https://medium.com/kvant-d%C3%BCnyas%C4%B1/ibm-onlayn-kvant-komp%C3%BCterind%C9%99-ilk-s%C4%B1naq-848fb9cc2a3a?source=rss-340042c89d45------2</link>
            <guid isPermaLink="false">https://medium.com/p/848fb9cc2a3a</guid>
            <category><![CDATA[informasiya]]></category>
            <category><![CDATA[kvant]]></category>
            <category><![CDATA[ibm-q-experience]]></category>
            <category><![CDATA[deutsch-jozsa-algorithm]]></category>
            <dc:creator><![CDATA[Valeh Farzaliyev]]></dc:creator>
            <pubDate>Sat, 09 Jan 2021 14:12:46 GMT</pubDate>
            <atom:updated>2021-01-09T14:12:46.962Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Kvant Kseroks Maşını]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/kvant-d%C3%BCnyas%C4%B1/kvant-kseroks-ma%C5%9F%C4%B1n%C4%B1-e9ad2eeb8a24?source=rss-340042c89d45------2"><img src="https://cdn-images-1.medium.com/max/620/0*cu61WfhU69SBka-F.jpg" width="620"></a></p><p class="medium-feed-snippet">T&#x259;bi&#x259;tin &#x259;n &#x259;h&#x259;miyy&#x259;tli qanunlar&#x131;ndan biri d&#x259; kvant informasiyas&#x131;n&#x131; &#xE7;oxaltma&#x11F;&#x131;n nam&#xFC;mk&#xFC;nl&#xFC;y&#xFC;d&#xFC;r.</p><p class="medium-feed-link"><a href="https://medium.com/kvant-d%C3%BCnyas%C4%B1/kvant-kseroks-ma%C5%9F%C4%B1n%C4%B1-e9ad2eeb8a24?source=rss-340042c89d45------2">Continue reading on Post-Kvant Dünya »</a></p></div>]]></description>
            <link>https://medium.com/kvant-d%C3%BCnyas%C4%B1/kvant-kseroks-ma%C5%9F%C4%B1n%C4%B1-e9ad2eeb8a24?source=rss-340042c89d45------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9ad2eeb8a24</guid>
            <category><![CDATA[informasiya]]></category>
            <category><![CDATA[kvant]]></category>
            <dc:creator><![CDATA[Valeh Farzaliyev]]></dc:creator>
            <pubDate>Sat, 09 Jan 2021 13:44:07 GMT</pubDate>
            <atom:updated>2021-01-09T13:44:07.780Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Kvant fizikası nədir?]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/kvant-d%C3%BCnyas%C4%B1/kvant-fizikasi-nedir-fedfe3b534c1?source=rss-340042c89d45------2"><img src="https://cdn-images-1.medium.com/max/600/1*QHIumjuQ_gupeRFp3UbBlg.jpeg" width="600"></a></p><p class="medium-feed-snippet">Kvant fizikas&#x131; i&#x15F;&#x131;&#x11F;&#x131;n kvantlarla da&#x15F;&#x131;nmas&#x131; fikiryl&#x259; elmi v&#x259; texnoloji inqilaba g&#x259;tirib &#xE7;&#x131;xarm&#x131;&#x15F; m&#xFC;asir fizika sah&#x259;sidir.</p><p class="medium-feed-link"><a href="https://medium.com/kvant-d%C3%BCnyas%C4%B1/kvant-fizikasi-nedir-fedfe3b534c1?source=rss-340042c89d45------2">Continue reading on Post-Kvant Dünya »</a></p></div>]]></description>
            <link>https://medium.com/kvant-d%C3%BCnyas%C4%B1/kvant-fizikasi-nedir-fedfe3b534c1?source=rss-340042c89d45------2</link>
            <guid isPermaLink="false">https://medium.com/p/fedfe3b534c1</guid>
            <category><![CDATA[kvant]]></category>
            <category><![CDATA[kvant-fizikası]]></category>
            <category><![CDATA[fizika]]></category>
            <dc:creator><![CDATA[Valeh Farzaliyev]]></dc:creator>
            <pubDate>Tue, 05 Jan 2021 12:17:26 GMT</pubDate>
            <atom:updated>2021-01-05T12:17:26.111Z</atom:updated>
            <cc:license>https://creativecommons.org/publicdomain/mark/1.0/</cc:license>
        </item>
        <item>
            <title><![CDATA[Deep Learning experiments on News Classification Dataset with Keras, Tensorflow and Azure ML]]></title>
            <link>https://medium.com/@valehfarzaliyev/deep-learning-experiments-on-news-classification-dataset-with-keras-tensorflow-and-azure-ml-6849c0ec6fb5?source=rss-340042c89d45------2</link>
            <guid isPermaLink="false">https://medium.com/p/6849c0ec6fb5</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[azure-ml]]></category>
            <dc:creator><![CDATA[Valeh Farzaliyev]]></dc:creator>
            <pubDate>Mon, 10 Jun 2019 03:18:10 GMT</pubDate>
            <atom:updated>2019-06-10T08:01:59.312Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*GZv5htCGCoF_XaPjGju3Ag.jpeg" /><figcaption>Headline: The Audacity Of “Nope” Or, Why A Trump Presidency Is No Surprise. <a href="https://www.huffingtonpost.com/entry/the-audacity-of-nope-or-why-a-trump-presidency_us_5847b52be4b0ca53e4b9c1c7">https://www.huffingtonpost.com/entry/the-audacity-of-nope-or-why-a-trump-presidency_us_5847b52be4b0ca53e4b9c1c7</a></figcaption></figure><p>This project has been done as course project for Neural Networks by Adil Yatkin (text processing), Sadiq Eyvazov (multimodal learning) and Valeh Farzaliyev (image processing)</p><h3>Introduction</h3><p>Classification is quite a challenging field in text mining as it requires prepossessing steps to convert unstructured data to structured information. With the increase in the number of news it has got difficult for users to access news of his interest which makes it a necessity to categories news so that it could be easily accessed. Categorization refers to grouping that allows easier navigation among articles. Internet news needs to be divided into categories. This will help users to access the news of their interest in real time without wasting any time. In this project we will classify the news according to headlines, short description and headline images.</p><h3>Data</h3><p>There are plenty of ready datasets available on the internet nowadays. We specially chose “News Category Dataset” uploaded by Rishabh Misra in Kaggle. The dataset can be found <a href="https://www.kaggle.com/rmisra/news-category-dataset">here</a>.</p><p>This dataset contains around 200,000 news headlines from the year 2012 to 2018 obtained from <a href="https://www.huffingtonpost.com/">HuffPost</a>. Each news headline has corresponding category. There are 41 different categories.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*bYrX1aRii6Im7XfE6WGseQ.png" /><figcaption>Distribution of news headlines per category.</figcaption></figure><p>In general, most of text classification examples on the internet use data with two categories such as spam email filtering or sentiment analysis (IMDB movie reviews, positive or negative). Thus, the dataset we are using is suitable to do multi-class text classification.</p><p>Here is sample news item:</p><pre><strong>{<br>    category:&quot;</strong>CRIME&quot;<strong>,<br>    headline:&quot;</strong>There Were 2 Mass Shootings In Texas Last Week, But Only 1 On TV&quot;<strong>, <br>    authors:&quot;</strong>Melissa Jeltsen&quot;<strong>,<br>    link:&quot;</strong>https://www.huffingtonpost.com/entry/texas-amanda-painter-mass-shooting_us_5b081ab4e4b0802d69caad89&quot;<strong>,<br>    short_description:&quot;</strong>She left her husband. He killed their children. Just another day in America.&quot;<strong>,<br>    date:</strong>2018-05-26<br>}<br></pre><h3>Project Overview</h3><p>The aim of this project is to classify news into categories based on their headline, short description and cover image using different neural network models. So, for the text classification, we used 4 different models where in 3 of them we used pretrained word embeddings: <strong>ELMo, Bert </strong>and <strong>NN-LM. </strong>Similarly, for image based classification we trained one simple AlexNet like CNN model and used one pretrained VGG16 features.</p><p>Later, we concatenated text and image features to train multimodal networks and compared results.</p><p>Due to huge amount of data and insufficient computation power in personal laptops, we had difficulties while training large models. For example, most common problem was to allocate big memory to store weight matrices which gave memory error as the number of parameters was at the order of billion. Therefore, we had to shrink (10K news, 5 classes) train and test size on local environment. Yet, we managed to run mentioned models on Azure Machine Learning Service with full dataset. Azure gives one Tesla K80 (12GB) under Azure ML service for free for 1 month. However, ELMo and Bert models took extremely long time even on Azure.</p><h3>Text Processing</h3><h4>Simple Word Embedding</h4><p>The simplest idea is to directly train textual input. However, length of each news headline may vary. So, it is better to use recurrent layer instead of only dense layers. Besides, we cannot give words as input to neural networks. But, most wide-spread solution is to map each word with a number using text preprocessors.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a5ea425acdc7d10f7dae37608ebbd37/href">https://medium.com/media/3a5ea425acdc7d10f7dae37608ebbd37/href</a></iframe><p>In Keras, there is an Embedding layer which associates a vector for each input given vocabulary length. Then, we add 1 LSTM and 3 Dense layers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7276e4d86a3eacf5b4b9cfee29b2371/href">https://medium.com/media/c7276e4d86a3eacf5b4b9cfee29b2371/href</a></iframe><p>That is how our model looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*bZ2EFYi1BAtRBvzx_RpNUA.png" /></figure><p>Then, we train 5 epochs with batch size 128. We have to tranform train labels to vectors using <em>to_categorical()</em> method in order to use categorical cross-entropy loss.</p><pre>history = model.fit([X_train], batch_size=128, y=to_categorical(y_train), verbose=1, validation_split=0.25, <br>          shuffle=False, epochs=5)</pre><p>Simple model gave us 98% training, 77% validation and 78% test accuracy. As it is seen, the model is overfitted</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*PaWC5e4DwBzdOl8cCeNixA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*kU0UgPI4jTkM4CxjZfySlA.png" /></figure><p>When we run same model with 200k news and 41 classes on Azure ML, we achieved 99% train, 52% validation and 40% test accuracy. Moreover, simple word embedding is not very useful. To address overfitting problem we used regularizers, dropout and hypertuning. We’ll talk about it later.</p><h4>NN-LM</h4><p>NN-LM is text embedding based on feed-forward Neural-Net Language Models with pre-built OOV. It maps text to 128-dimensional embedding vectors. It is a token based text embedding trained on English Google News 200B corpus.</p><p>NN-LM is available in tensorflow-hub. The code snippet below shows how to use it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c7df7b110854b29c3b814caf0293b67/href">https://medium.com/media/0c7df7b110854b29c3b814caf0293b67/href</a></iframe><p>Keras allows us to use custom embedding methods using Lambda layers. But there is a dimension mismatch between output of Lambda layers and the rest of network. Reshape layer in keras solves this problem.</p><p>Overall network is same as previous simple model except embedding part. That is 1 LSTM and 3 Dense layers following NN-LM embedding.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a82c3b8ba92fc61aff80032e0b80b760/href">https://medium.com/media/a82c3b8ba92fc61aff80032e0b80b760/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/1*FeFFK0-JsKRxfNilSHwAwg.png" /><figcaption>LSTM with NN-LM embedding</figcaption></figure><p>Here we trained 10 epochs using batch size 64.</p><pre>history = model.fit([X_train], batch_size=64, y=to_categorical(y_train), verbose=1, validation_split=0.25, <br>          shuffle=False, epochs=10)</pre><p>This model gave us 78% train, 76% validation and 76% test accuracy. We already have reasonable model without overfitting. We see the effect of using pre-trained embeddings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*5PeXsqzFb84Uq5ZpEXAupg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*UPwauAczYp_PRQLgzoJTkA.png" /><figcaption>LSTM with NN-LM model history</figcaption></figure><p>Accuracies dropped when we trained on full dataset: 53% train, 51% validation and 52% test. Note that, here we have 41 classes. So this result is perfectly OK for now.</p><h4><strong>ELMO</strong></h4><p>ELMo is a word representation technique proposed by <strong>AllenNLP</strong> in November 2018. Unlike traditional word embedding methods, ELMo is dynamic, meaning that ELMo embeddings change depending on the context even when the word is the same.</p><p>ELMo representations are:</p><ul><li>Contextual: The representation for each word depends on the entire context in which it is used.</li><li>Deep: The word representations combine all layers of a deep pre-trained neural network.</li><li>Character based: ELMo representations are purely character based, allowing the network to use morphological clues to form robust representations for out-of-vocabulary tokens unseen in training.</li></ul><p>See <a href="https://allennlp.org/tutorials">https://allennlp.org/tutorials</a></p><p>Usually, ELMo is used within AllenNLP framework which uses PyTorch instead of Keras. There exists small, medium and large (original) pretrained ELMo models in AllenNLP. We tested medium and large models.</p><p>AllenNLP is easy to use. First, it is required to parse input data and transform it into torch tensors.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05dd0437c10c5a3892b4b32b1c49aa67/href">https://medium.com/media/05dd0437c10c5a3892b4b32b1c49aa67/href</a></iframe><p>Then we used the model explained in tutorials, <a href="https://allennlp.org/tutorials#c17">https://allennlp.org/tutorials#c17</a>. As a result, train accuracy is 88%, validation accuracy is 82% and test accuracy is 83%.</p><p>This model performs well than previous two models. However, we were planning to train multimodal network using text and image features. But, as we used Keras (Tensorflow backend) for the image part, we realized that it would be problem. That’s why we remodeled using Keras. Similar to NN-LM, there is ELMo embedding in tensorflow-hub.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4471f9b71d82b582e1a46c2e3c0e44c/href">https://medium.com/media/b4471f9b71d82b582e1a46c2e3c0e44c/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8897def7b8ab613910e852bb8cc872e0/href">https://medium.com/media/8897def7b8ab613910e852bb8cc872e0/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/1*ZNRwlIQAR5OY5-NIbECCnw.png" /></figure><p>Unsurprisingly, we get almost same result: 88% train, 82% validation, 81% test accuracy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*y0E5nlWJjks4epLHXKkOZw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*83gEPbT2gy7RCB5fgQZO3w.png" /></figure><p>It took around 8 hours to train this model on Azure ML service (one K80 12GB gpu). Results are: 68% train, 60% validation and 59% test accuracy for 200k news and 41 classes. So far, this model has the highest accuracy.</p><h4>Overfitting on Simple Word Embedding (our base model)</h4><p>Although ELMo gives the best result, we thought that we can achieve closer result with the base model if overfitting is resolved. To do so, we used 4 different techniques: Dropout, Hypertuning and Regularization.</p><p>To save in time, each model is trained with 1000 samples. For this set of samples, simple model gives 98% train, 49% validation and 52% test accuracy. There is nearly 50% overfitting</p><p>First, we added dropout layer to the base model and trained with different dropout rates.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0030842ef5afd3ac350af84b17448b67/href">https://medium.com/media/0030842ef5afd3ac350af84b17448b67/href</a></iframe><p>Here is accuracy and loss dependence on dropout rate</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*4e7gLnnJ_gtilTdCJhiwrQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/409/1*AfpjyjfCXwEJIQkFNUO61g.png" /><figcaption>Accuracy-Dropout and Loss-Dropout graphs</figcaption></figure><p>The best dropout rate is <em>0.2</em>. Now, the difference between train and validation accuracy is 33% and test accuracy is 57%. There is a one third improvement.</p><p>Next, in fine-tuning stage, we found best learning rate to be 0.001 using the same analogy. Later, the optimizer is changed to rms_prop. In general, it is a good choice for recurrent neural networks. This change slightly dropped overfitting level to 31%.</p><p>At last, we tried L1 and L2 regularizations. The model didn’t learn at all with L1 (26% accuracy). However, L2 increased overfitting level by 8% while increasing test accuracy by ~10% after rms_prop.</p><p>Finally, combining these results, we trained the base model again on 10K news with found parameters. Remember that there was 21% difference before. Now, after 4 epochs, model achieved 82% training and 75% validation accuracy. There is only 6% difference with ELMo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*yjrd42ppIUvKmOL1NYruSw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*s9xLI05Mnb3_b9tNjrb8ZQ.png" /><figcaption>Simple Word Embedding results after dropout, hypertuning and L2 regularization.</figcaption></figure><h3>Image Processing</h3><p>Initially, images were not given in the dataset. But, we found a way to grab images from given links. But, it is obvious that it would take a lot to visit 200K links, parse HTML content and download image in meta tag. This could be done in parallel using multiple threads.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e539a4589517576f3b5315d2885c13e4/href">https://medium.com/media/e539a4589517576f3b5315d2885c13e4/href</a></iframe><p>After downloading image, here we add <em>image </em>property to original object and later save it. I wish everything was that easy. Other than it took so long and used almost all of computational resources in laptop, problems within datasets became apparent. Such that some links were broken, some of them were invalid in dataset, and some news contained cover images in gif format which is not suitable to train with other images. At the end, 56264 files downloaded out of 200853. Although specified to be 600x600 while fetching, there were images with different sizes and formats. After cleaning up unwanted files and resizing them, 49K remained. However, due to memory errors we couldn’t save final json which contained relations between image names and news items. So, we had to re-run above code do everything again. But, not to waste time again, we fetched images for 10K sample dataset.</p><h4>AlexNet</h4><p>AlexNet is the simplest common CNN model. It contains 2 CNN layers, 1 MaxPool, 2 Dense layers and Batch Normalization in between CNN layers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e7c2a630ec90092a4c1d01ecf3eb444a/href">https://medium.com/media/e7c2a630ec90092a4c1d01ecf3eb444a/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*__oGYncN-Y3vntICoJlvow.png" /><figcaption>AlexNet</figcaption></figure><p>600x600 is still big for training CNN images. We had resize them to 64x64. Before feeding input to the model, we normalized them using mean/std.</p><pre>X_train_norm = (X_train - np.mean(X_train, axis=0)) / np.std(X_train, axis=0)</pre><p>Run.</p><pre>history = model.fit(X_train_norm, batch_size=64, y=to_categorical(y_train), verbose=1, validation_split=0.10, <br>          shuffle=False, epochs=5)</pre><p>This model gives 53% train, 35% validation and 43% test accuracy. This results are unstable and differ a lot.</p><h4>VGG16</h4><p>VGG16 is a convolutional neural network model proposed by K. Simonyan and A. Zisserman from the University of Oxford in the paper “Very Deep Convolutional Networks for Large-Scale Image Recognition”. The model achieves 92.7% top-5 test accuracy in ImageNet, which is a dataset of over 14 million images belonging to 1000 classes. It was one of the famous model submitted to <a href="http://www.image-net.org/challenges/LSVRC/2014/results">ILSVRC-2014</a>. It makes the improvement over AlexNet by replacing large kernel-sized filters (11 and 5 in the first and second convolutional layer, respectively) with multiple 3×3 kernel-sized filters one after another.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*lZOmTCR4v_d6Fw_CWXPmRg.jpeg" /><figcaption>VGG16 model visualization</figcaption></figure><p>Instead of training VGG16 on our dataset, we simply used pretrained weights in Keras.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b5f7deca1cc69d139a32dbc8535eba0/href">https://medium.com/media/6b5f7deca1cc69d139a32dbc8535eba0/href</a></iframe><p><em>include_top = False</em> allows us to get features before dense layers, so output shape is 7x7x512. We use these features to train on our dataset by adding 2 Dense layers and softmax activation</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d977587cc82155f5ccc4807064b12c65/href">https://medium.com/media/d977587cc82155f5ccc4807064b12c65/href</a></iframe><pre>history = model.fit(X_train, batch_size=64, y=to_categorical(y_train), validation_split=0.10, epochs=5)</pre><p>Results: 57% train, 43% validation and 53% test accuracy.</p><p>There are several other pretrained models in Keras which are also trained on ‘imagenet’ such as InceptionResNet and ResNet. We also tried to get features from them and train same model as above. However, output size of those networks are so big and impossible to use with 10K samples. Sometimes we used 1000 or less samples, but it was illogical to make comparison and stopped using them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hzpl3MC7QO4xuyYVLQvbxQ.jpeg" /><figcaption>How to decide news classes from these images?</figcaption></figure><p>Finally, from results of AlexNet and VGG16, we see that images are not helpful alone to classify news. That is due to content of images. When we look at images, we see that there is not enough feature which can identify respective category. For example, model can learn sport news by majority of green pixels in the image, or political news by face of Donald Trump and other public faces. However, there images in other categories which contains only text or logos. Moreover, if we add context related features we can expect to increase accuracy scores.</p><h3>Multimodal Deep Learning</h3><p>As we have seen pretrained embeddings and pretrained CNN models behaved better than our naïve approaches. Therefore, we trained NN-LM + VGG16 and ELMo + VGG16 multimodal architectures.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8d72b3129029527b3fe403b71297b586/href">https://medium.com/media/8d72b3129029527b3fe403b71297b586/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*vOGJgv1Y-wwzqFlbMdHmQA.png" /><figcaption>NN-LM + VGG16</figcaption></figure><pre>history = model.fit([train_text, train_image], batch_size=64, y=to_categorical(y_image), validation_split=0.10, epochs=4)</pre><p>The result is 93% train, 57% validation and 58% test accuracy. Similarly, we get 94% train, 61% validation and 59% test accuracy with ELMo + VGG16. Clearly, adding images improved training accuracy although increasing overfitting. Thus, we cannot say that training both features together helped.</p><h3>Conclusion</h3><p>In this project we looked for advantages/disadvantages of multimodal learning. Although we got bad results, we know that this mostly originates from inconsistent data source. In addition, lack of computational resources (even AzureML) we couldn’t use more advanced models such as ResNet for image processing. However, we see that image features worsen the better performing text models.</p><p>We thank Ardi Tampuu for his fruitful discussion regarding project topic.</p><p>Check github repo for full code: <a href="https://github.com/Valeh2012/NNProject">https://github.com/Valeh2012/NNProject</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6849c0ec6fb5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>