summaryrefslogtreecommitdiff
path: root/posts/2019-12-22-Fake-News-Detector
diff options
context:
space:
mode:
Diffstat (limited to 'posts/2019-12-22-Fake-News-Detector')
-rw-r--r--posts/2019-12-22-Fake-News-Detector/index.html4
1 files changed, 2 insertions, 2 deletions
diff --git a/posts/2019-12-22-Fake-News-Detector/index.html b/posts/2019-12-22-Fake-News-Detector/index.html
index 4f1197c..3ffb14a 100644
--- a/posts/2019-12-22-Fake-News-Detector/index.html
+++ b/posts/2019-12-22-Fake-News-Detector/index.html
@@ -1,4 +1,4 @@
-<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"/><meta name="og:site_name" content="Navan Chauhan"/><link rel="canonical" href="https://navanchauhan.github.io/posts/2019-12-22-Fake-News-Detector"/><meta name="twitter:url" content="https://navanchauhan.github.io/posts/2019-12-22-Fake-News-Detector"/><meta name="og:url" content="https://navanchauhan.github.io/posts/2019-12-22-Fake-News-Detector"/><title>Building a Fake News Detector with Turicreate | Navan Chauhan</title><meta name="twitter:title" content="Building a Fake News Detector with Turicreate | Navan Chauhan"/><meta name="og:title" content="Building a Fake News Detector with Turicreate | Navan Chauhan"/><meta name="description" content="In this tutorial we will build a fake news detecting app from scratch, using Turicreate for the machine learning model and SwiftUI for building the app"/><meta name="twitter:description" content="In this tutorial we will build a fake news detecting app from scratch, using Turicreate for the machine learning model and SwiftUI for building the app"/><meta name="og:description" content="In this tutorial we will build a fake news detecting app from scratch, using Turicreate for the machine learning model and SwiftUI for building the app"/><meta name="twitter:card" content="summary"/><link rel="stylesheet" href="/styles.css" type="text/css"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><link rel="shortcut icon" href="/images/favicon.png" type="image/png"/><link rel="alternate" href="/feed.rss" type="application/rss+xml" title="Subscribe to Navan Chauhan"/><meta name="twitter:image" content="https://navanchauhan.github.io/images/logo.png"/><meta name="og:image" content="https://navanchauhan.github.io/images/logo.png"/></head><head><script>var _paq=window._paq=window._paq||[];_paq.push(['trackPageView']),_paq.push(['enableLinkTracking']),function(){var a='https://navanspi.duckdns.org:6969/analytics/';_paq.push(['setTrackerUrl',a+'matomo.php']),_paq.push(['setSiteId','2']);var e=document,t=e.createElement('script'),p=e.getElementsByTagName('script')[0];t.type='text/javascript',t.async=!0,t.src=a+'matomo.js',p.parentNode.insertBefore(t,p)}();</script></head><head><script src="https://www.googletagmanager.com/gtag/js?id=UA-108635191-1v"></script><script>window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag('js', new Date());gtag('config', 'UA-108635191-1');</script></head><body class="item-page"><header><div class="wrapper"><a class="site-name" href="/">Navan Chauhan</a><nav><ul><li><a href="/about">About Me</a></li><li><a class="selected" href="/posts">Posts</a></li><li><a href="/publications">Publications</a></li><li><a href="/assets/résumé.pdf">Résumé</a></li><li><a href="https://navanchauhan.github.io/repo">Repo</a></li></ul></nav></div></header><div class="wrapper"><article><div class="content"><span class="reading-time">7 minute read</span><span class="reading-time">Created on December 22, 2019</span><span class="reading-time">Last modified on June 1, 2020</span><h1>Building a Fake News Detector with Turicreate</h1><p><strong>In this tutorial we will build a fake news detecting app from scratch, using Turicreate for the machine learning model and SwiftUI for building the app</strong></p><p>Note: These commands are written as if you are running a jupyter notebook.</p><h2>Building the Machine Learning Model</h2><h3>Data Gathering</h3><p>To build a classifier, you need a lot of data. George McIntire (GH: @joolsa) has created a wonderful dataset containing the headline, body and wheter it is fake or real. Whenever you are looking for a dataset, always try searching on Kaggle and GitHub before you start building your own</p><h3>Dependencies</h3><p>I used a Google Colab instance for training my model. If you also plan on using Google Colab then I reccomend choosing a GPU Instance (It is Free) This allows you to train the model on the GPU. Turicreat is built on top of Apache's MXNet Framework, for us to use GPU we need to install a CUDA compatible MXNet package.</p><pre><code><div class="highlight"><span></span><span class="nt">!pip</span><span class="na"> install turicreate</span>
+<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"/><meta name="og:site_name" content="Navan Chauhan"/><link rel="canonical" href="https://navanchauhan.github.io/posts/2019-12-22-Fake-News-Detector"/><meta name="twitter:url" content="https://navanchauhan.github.io/posts/2019-12-22-Fake-News-Detector"/><meta name="og:url" content="https://navanchauhan.github.io/posts/2019-12-22-Fake-News-Detector"/><title>Building a Fake News Detector with Turicreate | Navan Chauhan</title><meta name="twitter:title" content="Building a Fake News Detector with Turicreate | Navan Chauhan"/><meta name="og:title" content="Building a Fake News Detector with Turicreate | Navan Chauhan"/><meta name="description" content="In this tutorial we will build a fake news detecting app from scratch, using Turicreate for the machine learning model and SwiftUI for building the app"/><meta name="twitter:description" content="In this tutorial we will build a fake news detecting app from scratch, using Turicreate for the machine learning model and SwiftUI for building the app"/><meta name="og:description" content="In this tutorial we will build a fake news detecting app from scratch, using Turicreate for the machine learning model and SwiftUI for building the app"/><meta name="twitter:card" content="summary"/><link rel="stylesheet" href="/styles.css" type="text/css"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><link rel="shortcut icon" href="/images/favicon.png" type="image/png"/><link rel="alternate" href="/feed.rss" type="application/rss+xml" title="Subscribe to Navan Chauhan"/><meta name="twitter:image" content="https://navanchauhan.github.io/images/logo.png"/><meta name="og:image" content="https://navanchauhan.github.io/images/logo.png"/></head><head><script>var _paq=window._paq=window._paq||[];_paq.push(['trackPageView']),_paq.push(['enableLinkTracking']),function(){var a='https://navanspi.duckdns.org:6969/analytics/';_paq.push(['setTrackerUrl',a+'matomo.php']),_paq.push(['setSiteId','2']);var e=document,t=e.createElement('script'),p=e.getElementsByTagName('script')[0];t.type='text/javascript',t.async=!0,t.src=a+'matomo.js',p.parentNode.insertBefore(t,p)}();</script></head><head><script src="https://www.googletagmanager.com/gtag/js?id=UA-108635191-1v"></script><script>window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag('js', new Date());gtag('config', 'UA-108635191-1');</script></head><body class="item-page"><header><div class="wrapper"><a class="site-name" href="/">Navan Chauhan</a><nav><ul><li><a href="/about">About Me</a></li><li><a class="selected" href="/posts">Posts</a></li><li><a href="/publications">Publications</a></li><li><a href="/assets/résumé.pdf">Résumé</a></li><li><a href="https://navanchauhan.github.io/repo">Repo</a></li></ul></nav></div></header><div class="wrapper"><article><div class="content"><span class="reading-time">7 minute read</span><span class="reading-time">Created on December 22, 2019</span><span class="reading-time">Last modified on September 15, 2020</span><h1>Building a Fake News Detector with Turicreate</h1><p><strong>In this tutorial we will build a fake news detecting app from scratch, using Turicreate for the machine learning model and SwiftUI for building the app</strong></p><p>Note: These commands are written as if you are running a jupyter notebook.</p><h2>Building the Machine Learning Model</h2><h3>Data Gathering</h3><p>To build a classifier, you need a lot of data. George McIntire (GH: @joolsa) has created a wonderful dataset containing the headline, body and whether it is fake or real. Whenever you are looking for a dataset, always try searching on Kaggle and GitHub before you start building your own</p><h3>Dependencies</h3><p>I used a Google Colab instance for training my model. If you also plan on using Google Colab then I recommend choosing a GPU Instance (It is Free) This allows you to train the model on the GPU. Turicreate is built on top of Apache's MXNet Framework, for us to use GPU we need to install a CUDA compatible MXNet package.</p><pre><code><div class="highlight"><span></span><span class="nt">!pip</span><span class="na"> install turicreate</span>
<span class="na">!pip uninstall -y mxnet</span>
<span class="na">!pip install mxnet-cu100==1.4.0.post0</span>
</div></code></pre><p>If you do not wish to train on GPU or are running it on your computer, you can ignore the last two lines</p><h3>Downloading the Dataset</h3><pre><code><div class="highlight"><span></span><span class="nt">!wget</span><span class="na"> -q &quot;https</span><span class="p">:</span><span class="nc">//github.com/joolsa/fake_real_news_dataset/raw/master/fake_or_real_news.csv.zip&quot;</span>
@@ -39,7 +39,7 @@
</div></code></pre><h3>Exporting the Model</h3><pre><code><div class="highlight"><span></span><span class="n">model_name</span> <span class="o">=</span> <span class="s1">&#39;FakeNews&#39;</span>
<span class="n">coreml_model_name</span> <span class="o">=</span> <span class="n">model_name</span> <span class="o">+</span> <span class="s1">&#39;.mlmodel&#39;</span>
<span class="n">exportedModel</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">export_coreml</span><span class="p">(</span><span class="n">coreml_model_name</span><span class="p">)</span>
-</div></code></pre><p><strong>Note: To download files from Google Volab, simply click on the files section in the sidebar, right click on filename and then click on downlaod</strong></p><p><a href="https://colab.research.google.com/drive/1onMXGkhA__X2aOFdsoVL-6HQBsWQhOP4">Link to Colab Notebook</a></p><h2>Building the App using SwiftUI</h2><h3>Initial Setup</h3><p>First we create a single view app (make sure you check the use SwiftUI button)</p><p>Then we copy our .mlmodel file to our project (Just drag and drop the file in the XCode Files Sidebar)</p><p>Our ML Model does not take a string directly as an input, rather it takes bag of words as an input. DescriptionThe bag-of-words model is a simplifying representation used in NLP, in this text is represented as a bag of words, without any regatd of grammar or order, but noting multiplicity</p><p>We define our bag of words function</p><pre><code><div class="highlight"><span></span><span class="kd">func</span> <span class="nf">bow</span><span class="p">(</span><span class="n">text</span><span class="p">:</span> <span class="nb">String</span><span class="p">)</span> <span class="p">-&gt;</span> <span class="p">[</span><span class="nb">String</span><span class="p">:</span> <span class="nb">Double</span><span class="p">]</span> <span class="p">{</span>
+</div></code></pre><p><strong>Note: To download files from Google Colab, simply click on the files section in the sidebar, right click on filename and then click on download</strong></p><p><a href="https://colab.research.google.com/drive/1onMXGkhA__X2aOFdsoVL-6HQBsWQhOP4">Link to Colab Notebook</a></p><h2>Building the App using SwiftUI</h2><h3>Initial Setup</h3><p>First we create a single view app (make sure you check the use SwiftUI button)</p><p>Then we copy our .mlmodel file to our project (Just drag and drop the file in the XCode Files Sidebar)</p><p>Our ML Model does not take a string directly as an input, rather it takes bag of words as an input. DescriptionThe bag-of-words model is a simplifying representation used in NLP, in this text is represented as a bag of words, without any regard for grammar or order, but noting multiplicity</p><p>We define our bag of words function</p><pre><code><div class="highlight"><span></span><span class="kd">func</span> <span class="nf">bow</span><span class="p">(</span><span class="n">text</span><span class="p">:</span> <span class="nb">String</span><span class="p">)</span> <span class="p">-&gt;</span> <span class="p">[</span><span class="nb">String</span><span class="p">:</span> <span class="nb">Double</span><span class="p">]</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nv">bagOfWords</span> <span class="p">=</span> <span class="p">[</span><span class="nb">String</span><span class="p">:</span> <span class="nb">Double</span><span class="p">]()</span>
<span class="kd">let</span> <span class="nv">tagger</span> <span class="p">=</span> <span class="bp">NSLinguisticTagger</span><span class="p">(</span><span class="n">tagSchemes</span><span class="p">:</span> <span class="p">[.</span><span class="n">tokenType</span><span class="p">],</span> <span class="n">options</span><span class="p">:</span> <span class="mi">0</span><span class="p">)</span>