summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authornavanchauhan <navanchauhan@gmail.com>2021-06-28 00:48:18 +0530
committernavanchauhan <navanchauhan@gmail.com>2021-06-28 00:48:18 +0530
commitb5c4bdce27ca7bc75c91dc28223e12ec1be2ea47 (patch)
treec0c6c27679d778b8aee9fb3c89b6b02c72a633ea /docs
parent095fc952ff5a399639deab9b5b3220d765ccaa57 (diff)
added CoreML Chatbot
Diffstat (limited to 'docs')
-rw-r--r--docs/assets/gciTales/03-regression/1.pngbin18561 -> 18561 bytes
-rw-r--r--docs/assets/posts/cheminformatics-web/postera-demo.pngbin572211 -> 983243 bytes
-rw-r--r--docs/assets/posts/cheminformatics-web/rdkit-demo.pngbin523533 -> 893061 bytes
-rw-r--r--docs/assets/posts/cheminformatics-web/webina-demo.pngbin1394971 -> 2181135 bytes
-rw-r--r--docs/assets/posts/swift-chatbot/carbon-2.pngbin0 -> 247973 bytes
-rw-r--r--docs/assets/posts/swift-chatbot/carbon-3.pngbin0 -> 94268 bytes
-rw-r--r--docs/assets/posts/swift-chatbot/carbon-4.pngbin0 -> 215477 bytes
-rw-r--r--docs/assets/posts/swift-chatbot/carbon.pngbin0 -> 188994 bytes
-rw-r--r--docs/assets/posts/swift-chatbot/create-intent.pngbin0 -> 763744 bytes
-rw-r--r--docs/assets/posts/swift-chatbot/create-tagger.pngbin0 -> 782235 bytes
-rw-r--r--docs/assets/posts/swift-chatbot/drugs-json.pngbin0 -> 549991 bytes
-rw-r--r--docs/assets/posts/swift-chatbot/intent-csv.pngbin0 -> 755977 bytes
-rw-r--r--docs/assets/posts/swift-chatbot/output.pngbin0 -> 132696 bytes
-rw-r--r--docs/feed.rss158
-rw-r--r--docs/images/04d0580b-d347-476a-232d-9568839851cd.webPlatform.pngbin1025 -> 1025 bytes
-rw-r--r--docs/images/82e24f17-2e71-90d8-67a7-587163282ebf.webPlatform.pngbin1612 -> 1612 bytes
-rw-r--r--docs/images/8c0ffe9e-b615-96cd-3e18-ab4307c859a0.webPlatform.pngbin1034 -> 1034 bytes
-rw-r--r--docs/images/9384518b-2a6c-0abc-136c-8c8faf49c71b.webPlatform.pngbin945 -> 945 bytes
-rw-r--r--docs/images/9bf4aee8-92e3-932f-5388-7731928b5692.webPlatform.pngbin786 -> 786 bytes
-rw-r--r--docs/images/9dc22996-fd1b-b2d3-3627-cef4fa224e25.webPlatform.pngbin755 -> 755 bytes
-rw-r--r--docs/images/b0cac729-56cb-2a63-7e8b-ac62a038a023.webPlatform.pngbin824 -> 824 bytes
-rw-r--r--docs/images/bb0aca46-4612-c284-055f-58850c0730bd.webPlatform.pngbin958 -> 958 bytes
-rw-r--r--docs/images/cbac5b1d-0299-9db6-3747-c7aeaaaa37d0.webPlatform.pngbin1070 -> 1070 bytes
-rw-r--r--docs/images/f1579c61-f17f-ff49-3f97-e942f202bebf.webPlatform.pngbin908 -> 908 bytes
-rw-r--r--docs/images/f400aaaa-861c-78c0-0919-07a886e57304.webPlatform.pngbin1883 -> 1883 bytes
-rw-r--r--docs/images/f7842765-fff5-aa39-9f7f-fdd3024d4056.webPlatform.pngbin902 -> 902 bytes
-rw-r--r--docs/index.html15
-rw-r--r--docs/posts/2021-06-26-Cheminformatics-On-The-Web-2021.html27
-rw-r--r--docs/posts/2021-06-27-Crude-ML-AI-Powered-Chatbot-Swift.html161
-rw-r--r--docs/posts/index.html15
30 files changed, 344 insertions, 32 deletions
diff --git a/docs/assets/gciTales/03-regression/1.png b/docs/assets/gciTales/03-regression/1.png
index e653e1c..02fe971 100644
--- a/docs/assets/gciTales/03-regression/1.png
+++ b/docs/assets/gciTales/03-regression/1.png
Binary files differ
diff --git a/docs/assets/posts/cheminformatics-web/postera-demo.png b/docs/assets/posts/cheminformatics-web/postera-demo.png
index 26b797d..bc0268f 100644
--- a/docs/assets/posts/cheminformatics-web/postera-demo.png
+++ b/docs/assets/posts/cheminformatics-web/postera-demo.png
Binary files differ
diff --git a/docs/assets/posts/cheminformatics-web/rdkit-demo.png b/docs/assets/posts/cheminformatics-web/rdkit-demo.png
index c0d41a3..a23881c 100644
--- a/docs/assets/posts/cheminformatics-web/rdkit-demo.png
+++ b/docs/assets/posts/cheminformatics-web/rdkit-demo.png
Binary files differ
diff --git a/docs/assets/posts/cheminformatics-web/webina-demo.png b/docs/assets/posts/cheminformatics-web/webina-demo.png
index 551bec8..4bfea04 100644
--- a/docs/assets/posts/cheminformatics-web/webina-demo.png
+++ b/docs/assets/posts/cheminformatics-web/webina-demo.png
Binary files differ
diff --git a/docs/assets/posts/swift-chatbot/carbon-2.png b/docs/assets/posts/swift-chatbot/carbon-2.png
new file mode 100644
index 0000000..3f05e7f
--- /dev/null
+++ b/docs/assets/posts/swift-chatbot/carbon-2.png
Binary files differ
diff --git a/docs/assets/posts/swift-chatbot/carbon-3.png b/docs/assets/posts/swift-chatbot/carbon-3.png
new file mode 100644
index 0000000..d02a85f
--- /dev/null
+++ b/docs/assets/posts/swift-chatbot/carbon-3.png
Binary files differ
diff --git a/docs/assets/posts/swift-chatbot/carbon-4.png b/docs/assets/posts/swift-chatbot/carbon-4.png
new file mode 100644
index 0000000..0c17806
--- /dev/null
+++ b/docs/assets/posts/swift-chatbot/carbon-4.png
Binary files differ
diff --git a/docs/assets/posts/swift-chatbot/carbon.png b/docs/assets/posts/swift-chatbot/carbon.png
new file mode 100644
index 0000000..2ba1a48
--- /dev/null
+++ b/docs/assets/posts/swift-chatbot/carbon.png
Binary files differ
diff --git a/docs/assets/posts/swift-chatbot/create-intent.png b/docs/assets/posts/swift-chatbot/create-intent.png
new file mode 100644
index 0000000..92413f5
--- /dev/null
+++ b/docs/assets/posts/swift-chatbot/create-intent.png
Binary files differ
diff --git a/docs/assets/posts/swift-chatbot/create-tagger.png b/docs/assets/posts/swift-chatbot/create-tagger.png
new file mode 100644
index 0000000..0e3363c
--- /dev/null
+++ b/docs/assets/posts/swift-chatbot/create-tagger.png
Binary files differ
diff --git a/docs/assets/posts/swift-chatbot/drugs-json.png b/docs/assets/posts/swift-chatbot/drugs-json.png
new file mode 100644
index 0000000..adf9348
--- /dev/null
+++ b/docs/assets/posts/swift-chatbot/drugs-json.png
Binary files differ
diff --git a/docs/assets/posts/swift-chatbot/intent-csv.png b/docs/assets/posts/swift-chatbot/intent-csv.png
new file mode 100644
index 0000000..bba4d09
--- /dev/null
+++ b/docs/assets/posts/swift-chatbot/intent-csv.png
Binary files differ
diff --git a/docs/assets/posts/swift-chatbot/output.png b/docs/assets/posts/swift-chatbot/output.png
new file mode 100644
index 0000000..121f1fd
--- /dev/null
+++ b/docs/assets/posts/swift-chatbot/output.png
Binary files differ
diff --git a/docs/feed.rss b/docs/feed.rss
index 06f953c..9a44450 100644
--- a/docs/feed.rss
+++ b/docs/feed.rss
@@ -4,8 +4,8 @@
<title>Navan's Archive</title>
<description>Rare Tips, Tricks and Posts</description>
<link>https://web.navan.dev/</link><language>en</language>
- <lastBuildDate>Sat, 26 Jun 2021 18:27:33 -0000</lastBuildDate>
- <pubDate>Sat, 26 Jun 2021 18:27:33 -0000</pubDate>
+ <lastBuildDate>Mon, 28 Jun 2021 00:47:49 -0000</lastBuildDate>
+ <pubDate>Mon, 28 Jun 2021 00:47:49 -0000</pubDate>
<ttl>250</ttl>
<atom:link href="https://web.navan.dev/feed.rss" rel="self" type="application/rss+xml"/>
@@ -2023,6 +2023,133 @@ Configure failed due to the errors above!
<item>
<guid isPermaLink="true">
+ https://web.navan.dev/posts/2021-06-27-Crude-ML-AI-Powered-Chatbot-Swift.html
+ </guid>
+ <title>
+ Making a Crude ML Powered Chatbot in Swift using CoreML
+ </title>
+ <description>
+ Writing a simple Machine-Learning powered Chatbot (or, daresay virtual personal assistant ) in Swift using CoreML.
+ </description>
+ <link>https://web.navan.dev/posts/2021-06-27-Crude-ML-AI-Powered-Chatbot-Swift.html</link>
+ <pubDate>Sun, 27 Jun 2021 23:26:00 -0000</pubDate>
+ <content:encoded><![CDATA[<h1>Making a Crude ML Powered Chatbot in Swift using CoreML</h1>
+
+<p>A chatbot/virtual assistant, on paper, looks easy to build.
+The user says something, the programs finds the best action, checks if additional input is required and sends back the output.
+To do this in Swift, I used two separate ML Models created using Apple's Create ML App.
+First is a Text Classifier to classify intent, and the other a word tagger for extracting input from the input message.
+Disclaimer: This is a very crude proof-of-concept, but it does work.</p>
+
+<h2>Text Classifier</h2>
+
+<p>I opened a CSV file and added some sample entries, with a corresponding label.</p>
+
+<p><img src="/assets/posts/swift-chatbot/intent-csv.png" alt="Screenshot of Sample Dataset" />
+<img src="/assets/posts/swift-chatbot/create-intent.png" alt="Screenshot of Create ML Text Classifier" /></p>
+
+<h2>Word Tagging</h2>
+
+<p>This is useful to extract the required variables directly from the user's input.
+This model will be only called if the intent from the classifier is a custom action.
+I created a sample JSON with only 3 examples (I know, very less, but works for a crude PoC).</p>
+
+<p><img src="/assets/posts/swift-chatbot/drugs-json.png" alt="Screenshot of Sample Dataset" />
+<img src="/assets/posts/swift-chatbot/create-tagger.png" alt="Screenshot of Create ML Text Classifier" /></p>
+
+<h2>Time to Get Swift-y</h2>
+
+<p>The initial part is easy, importing CoreML and NaturalLanguage and then initializing the models and the tagger.</p>
+
+<p><img src="/assets/posts/swift-chatbot/carbon.png" alt="Screenshot" /></p>
+
+<div class="codehilite"><pre><span></span><code><span class="kd">import</span> <span class="nc">CoreML</span>
+<span class="kd">import</span> <span class="nc">NaturalLanguage</span>
+
+<span class="kd">let</span> <span class="nv">mlModelClassifier</span> <span class="p">=</span> <span class="k">try</span> <span class="n">IntentDetection_1</span><span class="p">(</span><span class="n">configuration</span><span class="p">:</span> <span class="bp">MLModelConfiguration</span><span class="p">()).</span><span class="n">model</span>
+<span class="kd">let</span> <span class="nv">mlModelTagger</span> <span class="p">=</span> <span class="k">try</span> <span class="n">CompoundTagger</span><span class="p">(</span><span class="n">configuration</span><span class="p">:</span> <span class="bp">MLModelConfiguration</span><span class="p">()).</span><span class="n">model</span>
+
+<span class="kd">let</span> <span class="nv">intentPredictor</span> <span class="p">=</span> <span class="k">try</span> <span class="bp">NLModel</span><span class="p">(</span><span class="n">mlModel</span><span class="p">:</span> <span class="n">mlModelClassifier</span><span class="p">)</span>
+<span class="kd">let</span> <span class="nv">tagPredictor</span> <span class="p">=</span> <span class="k">try</span> <span class="bp">NLModel</span><span class="p">(</span><span class="n">mlModel</span><span class="p">:</span> <span class="n">mlModelTagger</span><span class="p">)</span>
+
+<span class="kd">let</span> <span class="nv">tagger</span> <span class="p">=</span> <span class="bp">NLTagger</span><span class="p">(</span><span class="n">tagSchemes</span><span class="p">:</span> <span class="p">[.</span><span class="n">nameType</span><span class="p">,</span> <span class="n">NLTagScheme</span><span class="p">(</span><span class="s">&quot;Apple&quot;</span><span class="p">)])</span>
+<span class="n">tagger</span><span class="p">.</span><span class="n">setModels</span><span class="p">([</span><span class="n">tagPredictor</span><span class="p">],</span> <span class="n">forTagScheme</span><span class="p">:</span> <span class="n">NLTagScheme</span><span class="p">(</span><span class="s">&quot;Apple&quot;</span><span class="p">))</span>
+</code></pre></div>
+
+<p>Now, we define a simple structure which the custom function(s) can use to access the provided input.
+It can also be used to hold additional variables.
+This custom action for our third label, uses the Word Tagger model to check for the compound in the user's message.
+If it is present then it displays the name, otherwise it tells the user that they have not provided the input.
+The latter can be replaced with a function which asks the user for the input. </p>
+
+<p><img src="/assets/posts/swift-chatbot/carbon-2.png" alt="Screenshot" /></p>
+
+<div class="codehilite"><pre><span></span><code><span class="kd">struct</span> <span class="nc">User</span> <span class="p">{</span>
+ <span class="kd">static</span> <span class="kd">var</span> <span class="nv">message</span> <span class="p">=</span> <span class="s">&quot;&quot;</span>
+<span class="p">}</span>
+
+<span class="kd">func</span> <span class="nf">customAction</span><span class="p">()</span> <span class="p">-&gt;</span> <span class="nb">String</span> <span class="p">{</span>
+ <span class="kd">let</span> <span class="nv">sampleMessage</span> <span class="p">=</span> <span class="n">User</span><span class="p">.</span><span class="n">message</span>
+ <span class="kd">var</span> <span class="nv">actionable_item</span> <span class="p">=</span> <span class="s">&quot;&quot;</span>
+ <span class="n">tagger</span><span class="p">.</span><span class="n">string</span> <span class="p">=</span> <span class="n">sampleMessage</span>
+ <span class="n">tagger</span><span class="p">.</span><span class="n">enumerateTags</span><span class="p">(</span><span class="k">in</span><span class="p">:</span> <span class="n">sampleMessage</span><span class="p">.</span><span class="n">startIndex</span><span class="p">..&lt;</span><span class="n">sampleMessage</span><span class="p">.</span><span class="n">endIndex</span><span class="p">,</span> <span class="n">unit</span><span class="p">:</span> <span class="p">.</span><span class="n">word</span><span class="p">,</span>
+ <span class="n">scheme</span><span class="p">:</span> <span class="n">NLTagScheme</span><span class="p">(</span><span class="s">&quot;Apple&quot;</span><span class="p">),</span> <span class="n">options</span><span class="p">:</span> <span class="p">.</span><span class="n">omitWhitespace</span><span class="p">)</span> <span class="p">{</span> <span class="n">tag</span><span class="p">,</span> <span class="n">tokenRange</span> <span class="k">in</span>
+ <span class="k">if</span> <span class="kd">let</span> <span class="nv">tag</span> <span class="p">=</span> <span class="n">tag</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="n">tag</span><span class="p">.</span><span class="n">rawValue</span> <span class="p">==</span> <span class="s">&quot;COMPOUND&quot;</span> <span class="p">{</span>
+ <span class="n">actionable_item</span> <span class="o">+=</span> <span class="n">sampleMessage</span><span class="p">[</span><span class="n">tokenRange</span><span class="p">]</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="k">return</span> <span class="kc">true</span>
+ <span class="p">}</span>
+ <span class="k">if</span> <span class="n">actionable_item</span> <span class="p">==</span> <span class="s">&quot;&quot;</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="s">&quot;You did not provide any input&quot;</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="s">&quot;You provided input </span><span class="si">\(</span><span class="n">actionable_item</span><span class="si">)</span><span class="s"> for performing custom action&quot;</span>
+ <span class="p">}</span>
+
+<span class="p">}</span>
+</code></pre></div>
+
+<p>Sometimes, no action needs to be performed, and the bot can use a predefined set of responses.
+Otherwise, if an action is required, it can call the custom action.</p>
+
+<p><img src="/assets/posts/swift-chatbot/carbon-3.png" alt="Screenshot" /></p>
+
+<div class="codehilite"><pre><span></span><code><span class="kd">let</span> <span class="nv">defaultResponses</span> <span class="p">=</span> <span class="p">[</span>
+ <span class="s">&quot;greetings&quot;</span><span class="p">:</span> <span class="s">&quot;Hello&quot;</span><span class="p">,</span>
+ <span class="s">&quot;banter&quot;</span><span class="p">:</span> <span class="s">&quot;no, plix no&quot;</span>
+<span class="p">]</span>
+
+<span class="kd">let</span> <span class="nv">customActions</span> <span class="p">=</span> <span class="p">[</span>
+ <span class="s">&quot;deez-drug&quot;</span><span class="p">:</span> <span class="n">customAction</span>
+<span class="p">]</span>
+</code></pre></div>
+
+<p>In the sample input, the program is updating the User.message and checking if it has a default response.
+Otherwise, it calls the custom action.</p>
+
+<p><img src="/assets/posts/swift-chatbot/carbon-4.png" alt="Screenshot" /></p>
+
+<div class="codehilite"><pre><span></span><code><span class="kd">let</span> <span class="nv">defaultResponses</span> <span class="p">=</span> <span class="p">[</span>
+ <span class="s">&quot;greetings&quot;</span><span class="p">:</span> <span class="s">&quot;Hello&quot;</span><span class="p">,</span>
+ <span class="s">&quot;banter&quot;</span><span class="p">:</span> <span class="s">&quot;no, plix no&quot;</span>
+<span class="p">]</span>
+
+<span class="kd">let</span> <span class="nv">customActions</span> <span class="p">=</span> <span class="p">[</span>
+ <span class="s">&quot;deez-drug&quot;</span><span class="p">:</span> <span class="n">customAction</span>
+<span class="p">]</span>
+</code></pre></div>
+
+<p><img src="/assets/posts/swift-chatbot/output.png" alt="Output" /></p>
+
+<p>So easy.</p>
+
+<p>If I ever release a part-2, it will either be about implementing this in Tensorflow.JS or an iOS app using SwiftUI ;)</p>
+]]></content:encoded>
+ </item>
+
+ <item>
+ <guid isPermaLink="true">
https://web.navan.dev/posts/2019-12-10-TensorFlow-Model-Prediction.html
</guid>
<title>
@@ -3342,24 +3469,21 @@ new Dics({
<pubDate>Sat, 26 Jun 2021 13:04:00 -0000</pubDate>
<content:encoded><![CDATA[<h1>Cheminformatics on the Web (2021)</h1>
-<p>Here, I have compiled a list of some tools and possible solutions.
-The web is a nice platform, it is available anywhere and just requires an internet connection.
-I, personally like static websites which don't require a server side application and can be hosted on platforms like GitHub Pages.
-Or, just open the HTML file and run it in your browser.
-No data is required to be sent to any server and your device's computational power is used.
-Even our phones have a lot of computational power now, which allows the user to run tasks on the go without needing to worry about managing dependencies.
-WebAssembly (Wasm) has made running code written for other platfroms on the web relativevly easier.
+<p>Here, I have compiled a list of some libraries and possible ideas.
+I, personally, like static websites which don't require a server side application and can be hosted on platforms like GitHub Pages.
+Or, just by opening the HTML file and running it in your browser.
+WebAssembly (Wasm) has made running code written for other platforms on the web relatively easier.
Combine Wasm with some pure JavaScript libraries, and you get a platform to quickly amp up your speed in some common tasks.</p>
<h2>RDKit</h2>
<p>RDKit bundles a minimal JavaScript Wrapper in their core RDKit suite.
-This is perfect for generating 2D Figures (HTML5 Canva/SVGs), Cannonical SMILES, Descriptors e.t.c</p>
+This is perfect for generating 2D Figures (HTML5 Canva/SVGs), Canonical SMILES, Descriptors e.t.c</p>
<h3>Substructure Matching</h3>
<p>This can be used to flag undesirable functional groups in a given compound.
-Create a simple key:value pair of name:SMARTS and use it to highlight substructure matches.
+Create a simple key:value pairs of name:SMARTS and use it to highlight substructure matches.
Thus, something like PostEra's Medicinal Chemistry Alert can be done with RDKit-JS alone.</p>
<p><img src="/assets/posts/cheminformatics-web/postera-demo.png" alt="PostEra Demo" /></p>
@@ -3379,22 +3503,22 @@ Thus, something like PostEra's Medicinal Chemistry Alert can be done with RDKit-
<p>Obviously, it takes a few hits in the time to complete the docking because the code is transpiled from C++ to Wasm.
But, the only major drawback (for now) is that it uses SharedArrayBuffer.
Due to Spectre, this feature was disabled on all browsers.
-Currently, only Chromium-based and Firefox browsers have reimplemented and renabled it.
-Hopefully, soon this will be again supported by all major browsers.</p>
+Currently, only Chromium-based and Firefox browsers have reimplemented and enabled it.
+Hopefully, soon, this will be again supported by all major browsers.</p>
<h2>Machine Learning</h2>
<p>Frameworks have now evolved enough to allow exporting models to be able to run them through JavaScript/Wasm backend.
An example task can be <strong>NER</strong> or Named-entity Recognition.
-It can be used to extract compounds or diseases from a large blob of text and then matched with external refferences.
+It can be used to extract compounds or diseases from a large blob of text and then matched with external references.
Another example is target-prediction right in the browser: <a rel="noopener" target="_blank" href="http://chembl.blogspot.com/2021/03/target-predictions-in-browser-with.html">CHEMBL - Target Prediction in Browser</a></p>
<p>CHEMBL Group is first training the model using PyTorch (A Python ML Library), then converting it to the ONNX runtime.
-A model like this can be directly implemented in Tensorflow, and then exported to be able to run with TensorFlow.js</p>
+A model like this can be directly implemented in TensorFlow, and then exported to be able to run with TensorFlow.js</p>
<h2>Cheminfo-to-web</h2>
-<p>The project aims to port chemoinformatics libraries into JavaScript via Emscripten.
+<p>The project aims to port cheminformatics libraries into JavaScript via Emscripten.
They have ported InChI, Indigo, OpenBabel, and OpenMD</p>
<h3>Kekule.js</h3>
@@ -3409,7 +3533,7 @@ They have ported InChI, Indigo, OpenBabel, and OpenMD</p>
<p>The previous machine learning examples can be packaged as browser-extensions to perform tasks on the article you are reading.
With iOS 15 bringing WebExtensions to iOS/iPadOS, the same browser extension source code can be now used on Desktop and Mobile Phones.
-You can quickly create an extenison to convert PDB codes into links to RCSB, highlight SMILES, highlight output of NER models, e.t.c</p>
+You can quickly create an extension to convert PDB codes into links to RCSB, highlight SMILES, highlight output of NER models, e.t.c</p>
<h2>Conclusion</h2>
diff --git a/docs/images/04d0580b-d347-476a-232d-9568839851cd.webPlatform.png b/docs/images/04d0580b-d347-476a-232d-9568839851cd.webPlatform.png
index 53777c6..b515ebe 100644
--- a/docs/images/04d0580b-d347-476a-232d-9568839851cd.webPlatform.png
+++ b/docs/images/04d0580b-d347-476a-232d-9568839851cd.webPlatform.png
Binary files differ
diff --git a/docs/images/82e24f17-2e71-90d8-67a7-587163282ebf.webPlatform.png b/docs/images/82e24f17-2e71-90d8-67a7-587163282ebf.webPlatform.png
index 6fe876b..3f94c60 100644
--- a/docs/images/82e24f17-2e71-90d8-67a7-587163282ebf.webPlatform.png
+++ b/docs/images/82e24f17-2e71-90d8-67a7-587163282ebf.webPlatform.png
Binary files differ
diff --git a/docs/images/8c0ffe9e-b615-96cd-3e18-ab4307c859a0.webPlatform.png b/docs/images/8c0ffe9e-b615-96cd-3e18-ab4307c859a0.webPlatform.png
index 65f9421..6c0a553 100644
--- a/docs/images/8c0ffe9e-b615-96cd-3e18-ab4307c859a0.webPlatform.png
+++ b/docs/images/8c0ffe9e-b615-96cd-3e18-ab4307c859a0.webPlatform.png
Binary files differ
diff --git a/docs/images/9384518b-2a6c-0abc-136c-8c8faf49c71b.webPlatform.png b/docs/images/9384518b-2a6c-0abc-136c-8c8faf49c71b.webPlatform.png
index 9d2b352..2b7ecef 100644
--- a/docs/images/9384518b-2a6c-0abc-136c-8c8faf49c71b.webPlatform.png
+++ b/docs/images/9384518b-2a6c-0abc-136c-8c8faf49c71b.webPlatform.png
Binary files differ
diff --git a/docs/images/9bf4aee8-92e3-932f-5388-7731928b5692.webPlatform.png b/docs/images/9bf4aee8-92e3-932f-5388-7731928b5692.webPlatform.png
index 82ed736..64095e8 100644
--- a/docs/images/9bf4aee8-92e3-932f-5388-7731928b5692.webPlatform.png
+++ b/docs/images/9bf4aee8-92e3-932f-5388-7731928b5692.webPlatform.png
Binary files differ
diff --git a/docs/images/9dc22996-fd1b-b2d3-3627-cef4fa224e25.webPlatform.png b/docs/images/9dc22996-fd1b-b2d3-3627-cef4fa224e25.webPlatform.png
index 035af6b..e247e3c 100644
--- a/docs/images/9dc22996-fd1b-b2d3-3627-cef4fa224e25.webPlatform.png
+++ b/docs/images/9dc22996-fd1b-b2d3-3627-cef4fa224e25.webPlatform.png
Binary files differ
diff --git a/docs/images/b0cac729-56cb-2a63-7e8b-ac62a038a023.webPlatform.png b/docs/images/b0cac729-56cb-2a63-7e8b-ac62a038a023.webPlatform.png
index 28edd0f..3ee2410 100644
--- a/docs/images/b0cac729-56cb-2a63-7e8b-ac62a038a023.webPlatform.png
+++ b/docs/images/b0cac729-56cb-2a63-7e8b-ac62a038a023.webPlatform.png
Binary files differ
diff --git a/docs/images/bb0aca46-4612-c284-055f-58850c0730bd.webPlatform.png b/docs/images/bb0aca46-4612-c284-055f-58850c0730bd.webPlatform.png
index 163fb7a..49d092a 100644
--- a/docs/images/bb0aca46-4612-c284-055f-58850c0730bd.webPlatform.png
+++ b/docs/images/bb0aca46-4612-c284-055f-58850c0730bd.webPlatform.png
Binary files differ
diff --git a/docs/images/cbac5b1d-0299-9db6-3747-c7aeaaaa37d0.webPlatform.png b/docs/images/cbac5b1d-0299-9db6-3747-c7aeaaaa37d0.webPlatform.png
index 571ac24..030e5fa 100644
--- a/docs/images/cbac5b1d-0299-9db6-3747-c7aeaaaa37d0.webPlatform.png
+++ b/docs/images/cbac5b1d-0299-9db6-3747-c7aeaaaa37d0.webPlatform.png
Binary files differ
diff --git a/docs/images/f1579c61-f17f-ff49-3f97-e942f202bebf.webPlatform.png b/docs/images/f1579c61-f17f-ff49-3f97-e942f202bebf.webPlatform.png
index 4bda098..7bbb309 100644
--- a/docs/images/f1579c61-f17f-ff49-3f97-e942f202bebf.webPlatform.png
+++ b/docs/images/f1579c61-f17f-ff49-3f97-e942f202bebf.webPlatform.png
Binary files differ
diff --git a/docs/images/f400aaaa-861c-78c0-0919-07a886e57304.webPlatform.png b/docs/images/f400aaaa-861c-78c0-0919-07a886e57304.webPlatform.png
index 18ba491..27272be 100644
--- a/docs/images/f400aaaa-861c-78c0-0919-07a886e57304.webPlatform.png
+++ b/docs/images/f400aaaa-861c-78c0-0919-07a886e57304.webPlatform.png
Binary files differ
diff --git a/docs/images/f7842765-fff5-aa39-9f7f-fdd3024d4056.webPlatform.png b/docs/images/f7842765-fff5-aa39-9f7f-fdd3024d4056.webPlatform.png
index 1b6ddb8..1bae893 100644
--- a/docs/images/f7842765-fff5-aa39-9f7f-fdd3024d4056.webPlatform.png
+++ b/docs/images/f7842765-fff5-aa39-9f7f-fdd3024d4056.webPlatform.png
Binary files differ
diff --git a/docs/index.html b/docs/index.html
index c220d2f..56e642e 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -45,6 +45,21 @@
<ul>
+ <li><a href="/posts/2021-06-27-Crude-ML-AI-Powered-Chatbot-Swift.html">Making a Crude ML Powered Chatbot in Swift using CoreML</a></li>
+ <ul>
+ <li>Writing a simple Machine-Learning powered Chatbot (or, daresay virtual personal assistant ) in Swift using CoreML.</li>
+ <li>Published On: 2021-06-27 23:26</li>
+ <li>Tags:
+
+ Swift,
+
+ CoreML,
+
+ NLP,
+
+ </ul>
+
+
<li><a href="/posts/2021-06-26-Cheminformatics-On-The-Web-2021.html">Cheminformatics on the Web (2021)</a></li>
<ul>
<li>Summarising Cheminformatics on the web in 2021.</li>
diff --git a/docs/posts/2021-06-26-Cheminformatics-On-The-Web-2021.html b/docs/posts/2021-06-26-Cheminformatics-On-The-Web-2021.html
index 885c7b5..3324928 100644
--- a/docs/posts/2021-06-26-Cheminformatics-On-The-Web-2021.html
+++ b/docs/posts/2021-06-26-Cheminformatics-On-The-Web-2021.html
@@ -41,24 +41,21 @@
<main>
<h1>Cheminformatics on the Web (2021)</h1>
-<p>Here, I have compiled a list of some tools and possible solutions.
-The web is a nice platform, it is available anywhere and just requires an internet connection.
-I, personally like static websites which don't require a server side application and can be hosted on platforms like GitHub Pages.
-Or, just open the HTML file and run it in your browser.
-No data is required to be sent to any server and your device's computational power is used.
-Even our phones have a lot of computational power now, which allows the user to run tasks on the go without needing to worry about managing dependencies.
-WebAssembly (Wasm) has made running code written for other platfroms on the web relativevly easier.
+<p>Here, I have compiled a list of some libraries and possible ideas.
+I, personally, like static websites which don't require a server side application and can be hosted on platforms like GitHub Pages.
+Or, just by opening the HTML file and running it in your browser.
+WebAssembly (Wasm) has made running code written for other platforms on the web relatively easier.
Combine Wasm with some pure JavaScript libraries, and you get a platform to quickly amp up your speed in some common tasks.</p>
<h2>RDKit</h2>
<p>RDKit bundles a minimal JavaScript Wrapper in their core RDKit suite.
-This is perfect for generating 2D Figures (HTML5 Canva/SVGs), Cannonical SMILES, Descriptors e.t.c</p>
+This is perfect for generating 2D Figures (HTML5 Canva/SVGs), Canonical SMILES, Descriptors e.t.c</p>
<h3>Substructure Matching</h3>
<p>This can be used to flag undesirable functional groups in a given compound.
-Create a simple key:value pair of name:SMARTS and use it to highlight substructure matches.
+Create a simple key:value pairs of name:SMARTS and use it to highlight substructure matches.
Thus, something like PostEra's Medicinal Chemistry Alert can be done with RDKit-JS alone.</p>
<p><img src="/assets/posts/cheminformatics-web/postera-demo.png" alt="PostEra Demo" /></p>
@@ -78,22 +75,22 @@ Thus, something like PostEra's Medicinal Chemistry Alert can be done with RDKit-
<p>Obviously, it takes a few hits in the time to complete the docking because the code is transpiled from C++ to Wasm.
But, the only major drawback (for now) is that it uses SharedArrayBuffer.
Due to Spectre, this feature was disabled on all browsers.
-Currently, only Chromium-based and Firefox browsers have reimplemented and renabled it.
-Hopefully, soon this will be again supported by all major browsers.</p>
+Currently, only Chromium-based and Firefox browsers have reimplemented and enabled it.
+Hopefully, soon, this will be again supported by all major browsers.</p>
<h2>Machine Learning</h2>
<p>Frameworks have now evolved enough to allow exporting models to be able to run them through JavaScript/Wasm backend.
An example task can be <strong>NER</strong> or Named-entity Recognition.
-It can be used to extract compounds or diseases from a large blob of text and then matched with external refferences.
+It can be used to extract compounds or diseases from a large blob of text and then matched with external references.
Another example is target-prediction right in the browser: <a rel="noopener" target="_blank" href="http://chembl.blogspot.com/2021/03/target-predictions-in-browser-with.html">CHEMBL - Target Prediction in Browser</a></p>
<p>CHEMBL Group is first training the model using PyTorch (A Python ML Library), then converting it to the ONNX runtime.
-A model like this can be directly implemented in Tensorflow, and then exported to be able to run with TensorFlow.js</p>
+A model like this can be directly implemented in TensorFlow, and then exported to be able to run with TensorFlow.js</p>
<h2>Cheminfo-to-web</h2>
-<p>The project aims to port chemoinformatics libraries into JavaScript via Emscripten.
+<p>The project aims to port cheminformatics libraries into JavaScript via Emscripten.
They have ported InChI, Indigo, OpenBabel, and OpenMD</p>
<h3>Kekule.js</h3>
@@ -108,7 +105,7 @@ They have ported InChI, Indigo, OpenBabel, and OpenMD</p>
<p>The previous machine learning examples can be packaged as browser-extensions to perform tasks on the article you are reading.
With iOS 15 bringing WebExtensions to iOS/iPadOS, the same browser extension source code can be now used on Desktop and Mobile Phones.
-You can quickly create an extenison to convert PDB codes into links to RCSB, highlight SMILES, highlight output of NER models, e.t.c</p>
+You can quickly create an extension to convert PDB codes into links to RCSB, highlight SMILES, highlight output of NER models, e.t.c</p>
<h2>Conclusion</h2>
diff --git a/docs/posts/2021-06-27-Crude-ML-AI-Powered-Chatbot-Swift.html b/docs/posts/2021-06-27-Crude-ML-AI-Powered-Chatbot-Swift.html
new file mode 100644
index 0000000..e4e4d1d
--- /dev/null
+++ b/docs/posts/2021-06-27-Crude-ML-AI-Powered-Chatbot-Swift.html
@@ -0,0 +1,161 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+
+ <link rel="stylesheet" href="/assets/main.css" />
+ <link rel="stylesheet" href="/assets/sakura.css" />
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Hey - Post</title>
+ <meta name="og:site_name" content="Navan Chauhan" />
+ <link rel="canonical" href="https://navanchauhan.github.io/" />
+ <meta name="twitter:url" content="https://navanchauhan.github.io/" />
+ <meta name="og:url" content="https://navanchauhan.github.io/" />
+ <meta name="twitter:title" content="Hey" />
+ <meta name="og:title" content="Hey" />
+ <meta name="description" content="Welcome to my personal fragment of the internet." />
+ <meta name="twitter:description" content="Welcome to my personal fragment of the internet. Majority of the posts should be complete." />
+ <meta name="og:description" content="Welcome to my personal fragment of the internet." />
+ <meta name="twitter:card" content="summary" />
+ <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" />
+ <link rel="manifest" href="manifest.json" />
+ <meta name="google-site-verification" content="LVeSZxz-QskhbEjHxOi7-BM5dDxTg53x2TwrjFxfL0k" />
+ <script async src="//gc.zgo.at/count.js" data-goatcounter="https://navanchauhan.goatcounter.com/count"></script>
+
+</head>
+<body>
+ <nav style="display: block;">
+|
+<a href="/">home</a> |
+<a href="/about/">about/links</a> |
+<a href="/posts/">posts</a> |
+<a href="/publications/">publications</a> |
+<a href="/repo/">iOS repo</a> |
+<a href="/feed.rss">RSS Feed</a> |
+</nav>
+
+<main>
+ <h1>Making a Crude ML Powered Chatbot in Swift using CoreML</h1>
+
+<p>A chatbot/virtual assistant, on paper, looks easy to build.
+The user says something, the programs finds the best action, checks if additional input is required and sends back the output.
+To do this in Swift, I used two separate ML Models created using Apple's Create ML App.
+First is a Text Classifier to classify intent, and the other a word tagger for extracting input from the input message.
+Disclaimer: This is a very crude proof-of-concept, but it does work.</p>
+
+<h2>Text Classifier</h2>
+
+<p>I opened a CSV file and added some sample entries, with a corresponding label.</p>
+
+<p><img src="/assets/posts/swift-chatbot/intent-csv.png" alt="Screenshot of Sample Dataset" />
+<img src="/assets/posts/swift-chatbot/create-intent.png" alt="Screenshot of Create ML Text Classifier" /></p>
+
+<h2>Word Tagging</h2>
+
+<p>This is useful to extract the required variables directly from the user's input.
+This model will be only called if the intent from the classifier is a custom action.
+I created a sample JSON with only 3 examples (I know, very less, but works for a crude PoC).</p>
+
+<p><img src="/assets/posts/swift-chatbot/drugs-json.png" alt="Screenshot of Sample Dataset" />
+<img src="/assets/posts/swift-chatbot/create-tagger.png" alt="Screenshot of Create ML Text Classifier" /></p>
+
+<h2>Time to Get Swift-y</h2>
+
+<p>The initial part is easy, importing CoreML and NaturalLanguage and then initializing the models and the tagger.</p>
+
+<p><img src="/assets/posts/swift-chatbot/carbon.png" alt="Screenshot" /></p>
+
+<div class="codehilite"><pre><span></span><code><span class="kd">import</span> <span class="nc">CoreML</span>
+<span class="kd">import</span> <span class="nc">NaturalLanguage</span>
+
+<span class="kd">let</span> <span class="nv">mlModelClassifier</span> <span class="p">=</span> <span class="k">try</span> <span class="n">IntentDetection_1</span><span class="p">(</span><span class="n">configuration</span><span class="p">:</span> <span class="bp">MLModelConfiguration</span><span class="p">()).</span><span class="n">model</span>
+<span class="kd">let</span> <span class="nv">mlModelTagger</span> <span class="p">=</span> <span class="k">try</span> <span class="n">CompoundTagger</span><span class="p">(</span><span class="n">configuration</span><span class="p">:</span> <span class="bp">MLModelConfiguration</span><span class="p">()).</span><span class="n">model</span>
+
+<span class="kd">let</span> <span class="nv">intentPredictor</span> <span class="p">=</span> <span class="k">try</span> <span class="bp">NLModel</span><span class="p">(</span><span class="n">mlModel</span><span class="p">:</span> <span class="n">mlModelClassifier</span><span class="p">)</span>
+<span class="kd">let</span> <span class="nv">tagPredictor</span> <span class="p">=</span> <span class="k">try</span> <span class="bp">NLModel</span><span class="p">(</span><span class="n">mlModel</span><span class="p">:</span> <span class="n">mlModelTagger</span><span class="p">)</span>
+
+<span class="kd">let</span> <span class="nv">tagger</span> <span class="p">=</span> <span class="bp">NLTagger</span><span class="p">(</span><span class="n">tagSchemes</span><span class="p">:</span> <span class="p">[.</span><span class="n">nameType</span><span class="p">,</span> <span class="n">NLTagScheme</span><span class="p">(</span><span class="s">&quot;Apple&quot;</span><span class="p">)])</span>
+<span class="n">tagger</span><span class="p">.</span><span class="n">setModels</span><span class="p">([</span><span class="n">tagPredictor</span><span class="p">],</span> <span class="n">forTagScheme</span><span class="p">:</span> <span class="n">NLTagScheme</span><span class="p">(</span><span class="s">&quot;Apple&quot;</span><span class="p">))</span>
+</code></pre></div>
+
+<p>Now, we define a simple structure which the custom function(s) can use to access the provided input.
+It can also be used to hold additional variables.
+This custom action for our third label, uses the Word Tagger model to check for the compound in the user's message.
+If it is present then it displays the name, otherwise it tells the user that they have not provided the input.
+The latter can be replaced with a function which asks the user for the input. </p>
+
+<p><img src="/assets/posts/swift-chatbot/carbon-2.png" alt="Screenshot" /></p>
+
+<div class="codehilite"><pre><span></span><code><span class="kd">struct</span> <span class="nc">User</span> <span class="p">{</span>
+ <span class="kd">static</span> <span class="kd">var</span> <span class="nv">message</span> <span class="p">=</span> <span class="s">&quot;&quot;</span>
+<span class="p">}</span>
+
+<span class="kd">func</span> <span class="nf">customAction</span><span class="p">()</span> <span class="p">-&gt;</span> <span class="nb">String</span> <span class="p">{</span>
+ <span class="kd">let</span> <span class="nv">sampleMessage</span> <span class="p">=</span> <span class="n">User</span><span class="p">.</span><span class="n">message</span>
+ <span class="kd">var</span> <span class="nv">actionable_item</span> <span class="p">=</span> <span class="s">&quot;&quot;</span>
+ <span class="n">tagger</span><span class="p">.</span><span class="n">string</span> <span class="p">=</span> <span class="n">sampleMessage</span>
+ <span class="n">tagger</span><span class="p">.</span><span class="n">enumerateTags</span><span class="p">(</span><span class="k">in</span><span class="p">:</span> <span class="n">sampleMessage</span><span class="p">.</span><span class="n">startIndex</span><span class="p">..&lt;</span><span class="n">sampleMessage</span><span class="p">.</span><span class="n">endIndex</span><span class="p">,</span> <span class="n">unit</span><span class="p">:</span> <span class="p">.</span><span class="n">word</span><span class="p">,</span>
+ <span class="n">scheme</span><span class="p">:</span> <span class="n">NLTagScheme</span><span class="p">(</span><span class="s">&quot;Apple&quot;</span><span class="p">),</span> <span class="n">options</span><span class="p">:</span> <span class="p">.</span><span class="n">omitWhitespace</span><span class="p">)</span> <span class="p">{</span> <span class="n">tag</span><span class="p">,</span> <span class="n">tokenRange</span> <span class="k">in</span>
+ <span class="k">if</span> <span class="kd">let</span> <span class="nv">tag</span> <span class="p">=</span> <span class="n">tag</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="n">tag</span><span class="p">.</span><span class="n">rawValue</span> <span class="p">==</span> <span class="s">&quot;COMPOUND&quot;</span> <span class="p">{</span>
+ <span class="n">actionable_item</span> <span class="o">+=</span> <span class="n">sampleMessage</span><span class="p">[</span><span class="n">tokenRange</span><span class="p">]</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="k">return</span> <span class="kc">true</span>
+ <span class="p">}</span>
+ <span class="k">if</span> <span class="n">actionable_item</span> <span class="p">==</span> <span class="s">&quot;&quot;</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="s">&quot;You did not provide any input&quot;</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="s">&quot;You provided input </span><span class="si">\(</span><span class="n">actionable_item</span><span class="si">)</span><span class="s"> for performing custom action&quot;</span>
+ <span class="p">}</span>
+
+<span class="p">}</span>
+</code></pre></div>
+
+<p>Sometimes, no action needs to be performed, and the bot can use a predefined set of responses.
+Otherwise, if an action is required, it can call the custom action.</p>
+
+<p><img src="/assets/posts/swift-chatbot/carbon-3.png" alt="Screenshot" /></p>
+
+<div class="codehilite"><pre><span></span><code><span class="kd">let</span> <span class="nv">defaultResponses</span> <span class="p">=</span> <span class="p">[</span>
+ <span class="s">&quot;greetings&quot;</span><span class="p">:</span> <span class="s">&quot;Hello&quot;</span><span class="p">,</span>
+ <span class="s">&quot;banter&quot;</span><span class="p">:</span> <span class="s">&quot;no, plix no&quot;</span>
+<span class="p">]</span>
+
+<span class="kd">let</span> <span class="nv">customActions</span> <span class="p">=</span> <span class="p">[</span>
+ <span class="s">&quot;deez-drug&quot;</span><span class="p">:</span> <span class="n">customAction</span>
+<span class="p">]</span>
+</code></pre></div>
+
+<p>In the sample input, the program is updating the User.message and checking if it has a default response.
+Otherwise, it calls the custom action.</p>
+
+<p><img src="/assets/posts/swift-chatbot/carbon-4.png" alt="Screenshot" /></p>
+
+<div class="codehilite"><pre><span></span><code><span class="kd">let</span> <span class="nv">defaultResponses</span> <span class="p">=</span> <span class="p">[</span>
+ <span class="s">&quot;greetings&quot;</span><span class="p">:</span> <span class="s">&quot;Hello&quot;</span><span class="p">,</span>
+ <span class="s">&quot;banter&quot;</span><span class="p">:</span> <span class="s">&quot;no, plix no&quot;</span>
+<span class="p">]</span>
+
+<span class="kd">let</span> <span class="nv">customActions</span> <span class="p">=</span> <span class="p">[</span>
+ <span class="s">&quot;deez-drug&quot;</span><span class="p">:</span> <span class="n">customAction</span>
+<span class="p">]</span>
+</code></pre></div>
+
+<p><img src="/assets/posts/swift-chatbot/output.png" alt="Output" /></p>
+
+<p>So easy.</p>
+
+<p>If I ever release a part-2, it will either be about implementing this in Tensorflow.JS or an iOS app using SwiftUI ;)</p>
+
+</main>
+
+
+<script src="assets/manup.min.js"></script>
+<script src="/pwabuilder-sw-register.js"></script>
+</body>
+</html> \ No newline at end of file
diff --git a/docs/posts/index.html b/docs/posts/index.html
index 119b7e6..6ee3224 100644
--- a/docs/posts/index.html
+++ b/docs/posts/index.html
@@ -48,6 +48,21 @@
<ul>
+ <li><a href="/posts/2021-06-27-Crude-ML-AI-Powered-Chatbot-Swift.html">Making a Crude ML Powered Chatbot in Swift using CoreML</a></li>
+ <ul>
+ <li>Writing a simple Machine-Learning powered Chatbot (or, daresay virtual personal assistant ) in Swift using CoreML.</li>
+ <li>Published On: 2021-06-27 23:26</li>
+ <li>Tags:
+
+ Swift,
+
+ CoreML,
+
+ NLP,
+
+ </ul>
+
+
<li><a href="/posts/2021-06-26-Cheminformatics-On-The-Web-2021.html">Cheminformatics on the Web (2021)</a></li>
<ul>
<li>Summarising Cheminformatics on the web in 2021.</li>