<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Iman Codes</title>
    <link>https://iman.codes/</link>
    <description>sometimes it&#39;s fun</description>
    <pubDate>Sun, 05 Apr 2026 17:06:32 +0000</pubDate>
    <item>
      <title>WriteAs Comments - Talkyard</title>
      <link>https://iman.codes/writeas-comments-talkyard?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[Might be a little silly to have a blog post about implementing comments on WriteAs when this blog itself doesn’t have comments implemented, but I thought I’d put it up here anyway. I have no idea how Javascript works so I only managed to get comments up on my personal blog thanks to various resources, specifically by Dino.&#xA;&#xA;But, it&#39;s code and should probably go up on the code blog!&#xA;&#xA;I wanted a lightweight, privacy-focused commenting system and didn&#39;t want to wait for Remark.as to be open for non-paying Write.as users. Also, I didn&#39;t want to pay through the nose for a system that will probably get like, 2 comments total over the lifetime of my blog. Plus I didn&#39;t want to host it myself, because it&#39;d probably be more of a hassle than it&#39;s worth!&#xA;&#xA;I tried out a couple options that were recommended on the Write.as discussion forums but in the end, I went with Talkyard.&#xA;&#xA;!--more--&#xA;&#xA;Getting the Javascript up and running was way easier when I could refer to Dino&#39;s implementation of Hyvor Talk, but it did take some finagling, since I don&#39;t really know what I&#39;m doing.&#xA;&#xA;A lot of the implementation methods for Write.as comments involved placing a code snippet at the bottom of each post, often with the Write.as signature function to make things easier - but that would also put comments onto pinned posts, which is sometimes not what you&#39;re going for. But Dino&#39;s code for Hyvor Talk was pretty elegant - it would automatically insert the code at the bottom of each post, eliminating the need to manually copy and paste it each time or use the signature function. He also had a way to exclude your pinned posts - that part would be manual, but one has way fewer pinned posts than regular blog posts!&#xA;&#xA;Anyway, something that I managed to do specifically for Talkyard is take the post slug and use it as the Talkyard ID. This means that as long as I don&#39;t change my post slug, I can automatically port my comments if I change the post title or domain name! Which is super convenient since I&#39;ll probably move off the writeas.com domain at some point for the personal blog - I just haven&#39;t committed yet.&#xA;&#xA;I think the script is relatively readable so I&#39;ve just copied and pasted it below:&#xA;&#xA;var currentURL = window.location.href;&#xA;var isAboutPage = /\/about$/i.test(currentURL);&#xA;var isArchivePage = /\/archive$/i.test(currentURL);&#xA;&#xA;var element = document.querySelector(&#39;meta[property=&#34;og:url&#34;]&#39;);&#xA;var content = element &amp;&amp; element.getAttribute(&#34;content&#34;);&#xA;var postSlug = content.split(&#39;/&#39;).pop();&#xA;&#xA;var talkyardServerUrl = &#39;server URL here&#39;;&#xA;&#xA;var talkyardDiv = &#39;brhrbrdiv class=&#34;talkyard-comments&#34; data-discussion-id=&#34;talkyardID&#34;/div&#39;&#xA;&#xA;talkyardDiv = talkyardDiv.replace(&#34;talkyardID&#34;, postSlug);&#xA;&#xA;if (document.getElementById(&#34;post-body&#34;) &amp;&amp; !isArchivePage &amp;&amp; !isAboutPage) {&#xA;    document.getElementsByTagName(&#34;article&#34;)[0].insertAdjacentHTML(&#39;beforeend&#39;, talkyardDiv );&#xA;}&#xA;&#xA;// src: https://c1.ty-cdn.net/-/talkyard-comments.min.js&#xA;&#xA;Looking at it now, I realize I haven&#39;t excluded my (empty) tags page from here, so maybe I&#39;ll do that... eventually... As an aside, I do like Write.as but there is a lot of manual work for some stuff. Its primary focus is writing and I appreciate it a lot, because it minimizes all the distractions that come from other blogging platforms! But that means it doesn&#39;t have a lot of stuff that comes out-of-box from other platforms too (see: this whole post about putting comments up lol).&#xA;&#xA;But moving on, I also customized the CSS for Talkyard to match my personal blog. That&#39;s actually why I haven&#39;t implemented it on this code blog, even though Talkyard allows you to put it on as many sites as you&#39;d like - the theming would clash completely! My personal blog is very bright and pink, while this one is cool blues. The default theme would&#39;ve actually been acceptable on the code blog, but as of now, without learning a whole lot more about Javascript and CSS, I don&#39;t think I&#39;d be able to have two separate themes.&#xA;&#xA;Talkyard says, on its CSS and Javascript page customization page:&#xA;&#xA;  We&#39;ll give you a simpler way to choose colors, later.&#xA;&#xA;so we&#39;ll see if that comes to fruition! My theming was a complete hack job, so I&#39;m looking forward to... not having it be a complete hack job, lol. And that&#39;s why I won&#39;t be sharing the CSS here.&#xA;&#xA;When I tested things out, it seemed to work really nicely. There’s some moderation features, which will be nice if I ever need that (hopefully not!). &#xA;&#xA;Anyway, hopefully this post will help me in the future, or if I’m really lucky, someone else trying to set up Talkyard on their own Write.as blog, haha.&#xA;&#xA;#javascript #css]]&gt;</description>
      <content:encoded><![CDATA[<p>Might be a little silly to have a blog post about implementing comments on WriteAs when this blog itself doesn’t have comments implemented, but I thought I’d put it up here anyway. I have no idea how Javascript works so I only managed to get comments up on my <a href="https://write.as/iman/" rel="nofollow">personal blog</a> thanks to <a href="https://discuss.write.as/t/adding-comments-to-your-blog/1146/16" rel="nofollow">various</a> <a href="https://discuss.write.as/t/installing-a-write-as-theme/4117/3" rel="nofollow">resources</a>, specifically by <a href="https://journal.dinobansigan.com/" rel="nofollow">Dino</a>.</p>

<p>But, it&#39;s code and should probably go up on the code blog!</p>

<p>I wanted a lightweight, privacy-focused commenting system and didn&#39;t want to wait for Remark.as to be open for non-paying Write.as users. Also, I didn&#39;t want to pay through the nose for a system that will probably get like, 2 comments total over the lifetime of my blog. Plus I didn&#39;t want to host it myself, because it&#39;d probably be more of a hassle than it&#39;s worth!</p>

<p>I tried out a couple options that were recommended on the Write.as discussion forums but in the end, I went with <a href="https://forum.talkyard.io/blog-comments" rel="nofollow">Talkyard</a>.</p>



<p>Getting the Javascript up and running was way easier when I could refer to Dino&#39;s implementation of Hyvor Talk, but it did take some finagling, since I don&#39;t really know what I&#39;m doing.</p>

<p>A lot of the implementation methods for Write.as comments involved placing a code snippet at the bottom of each post, often with the Write.as signature function to make things easier – but that would also put comments onto pinned posts, which is sometimes not what you&#39;re going for. But Dino&#39;s code for Hyvor Talk was pretty elegant – it would automatically insert the code at the bottom of each post, eliminating the need to manually copy and paste it each time or use the signature function. He also had a way to exclude your pinned posts – that part would be manual, but one has way fewer pinned posts than regular blog posts!</p>

<p>Anyway, something that I managed to do specifically for Talkyard is take the post slug and use it as the Talkyard ID. This means that as long as I don&#39;t change my post slug, I can automatically port my comments if I change the post title or domain name! Which is super convenient since I&#39;ll probably move off the writeas.com domain at some point for the personal blog – I just haven&#39;t committed yet.</p>

<p>I think the script is relatively readable so I&#39;ve just copied and pasted it below:</p>

<pre><code>var currentURL = window.location.href;
var isAboutPage = /\/about$/i.test(currentURL);
var isArchivePage = /\/archive$/i.test(currentURL);

var element = document.querySelector(&#39;meta[property=&#34;og:url&#34;]&#39;);
var content = element &amp;&amp; element.getAttribute(&#34;content&#34;);
var postSlug = content.split(&#39;/&#39;).pop();

var talkyardServerUrl = &#39;server URL here&#39;;

var talkyardDiv = &#39;&lt;br&gt;&lt;hr&gt;&lt;br&gt;&lt;div class=&#34;talkyard-comments&#34; data-discussion-id=&#34;talkyardID&#34;&gt;&lt;/div&gt;&#39;

talkyardDiv = talkyardDiv.replace(&#34;talkyardID&#34;, postSlug);


if (document.getElementById(&#34;post-body&#34;) &amp;&amp; !isArchivePage &amp;&amp; !isAboutPage) {
    document.getElementsByTagName(&#34;article&#34;)[0].insertAdjacentHTML(&#39;beforeend&#39;, talkyardDiv );
}

// src: https://c1.ty-cdn.net/-/talkyard-comments.min.js
</code></pre>

<p>Looking at it now, I realize I haven&#39;t excluded my (empty) tags page from here, so maybe I&#39;ll do that... eventually... As an aside, I do like Write.as but there is a lot of manual work for some stuff. Its primary focus is <em>writing</em> and I appreciate it a lot, because it minimizes all the distractions that come from other blogging platforms! But that means it doesn&#39;t have a lot of stuff that comes out-of-box from other platforms too (see: this whole post about putting comments up lol).</p>

<p>But moving on, I also customized the CSS for Talkyard to match my personal blog. That&#39;s actually why I haven&#39;t implemented it on this code blog, even though Talkyard allows you to put it on as many sites as you&#39;d like – the theming would clash completely! My personal blog is very bright and pink, while this one is cool blues. The default theme would&#39;ve actually been acceptable on the code blog, but as of now, without learning a whole lot more about Javascript and CSS, I don&#39;t think I&#39;d be able to have two separate themes.</p>

<p>Talkyard says, on its CSS and Javascript page customization page:</p>

<blockquote><p>We&#39;ll give you a simpler way to choose colors, later.</p></blockquote>

<p>so we&#39;ll see if that comes to fruition! My theming was a complete hack job, so I&#39;m looking forward to... not having it be a complete hack job, lol. And that&#39;s why I won&#39;t be sharing the CSS here.</p>

<p>When I tested things out, it seemed to work really nicely. There’s some moderation features, which will be nice if I ever need that (hopefully not!).</p>

<p>Anyway, hopefully this post will help me in the future, or if I’m really lucky, someone else trying to set up Talkyard on their own Write.as blog, haha.</p>

<p><a href="https://iman.codes/tag:javascript" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">javascript</span></a> <a href="https://iman.codes/tag:css" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">css</span></a></p>
]]></content:encoded>
      <guid>https://iman.codes/writeas-comments-talkyard</guid>
      <pubDate>Sun, 26 Feb 2023 17:45:34 +0000</pubDate>
    </item>
    <item>
      <title>How is it 2023 already?</title>
      <link>https://iman.codes/how-is-it-2023-already?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[Well, I guess it was another year of no code blogging. As with my last post, which I just re-read, I didn’t do much for my personal projects (or at least, I didn’t finish any… I can’t be the only one with a million WIPs that never get finished). And again, I’m in yet another new role! &#xA;&#xA;In terms of code accomplishments, I would say the majority are actually “side projects” that I did at work but weren’t relevant to my day job. Specifically, I spent a lot of time re-learning R Shiny and made some pretty sweet dashboards, if I do say so myself. I’m actually using some of that knowledge for a personal project right now - I’m hoping I actually get that done so I can blog about it!&#xA;&#xA;Anyway, job rambling under the cut:&#xA;&#xA;!--more--&#xA;&#xA;My last job seemed promising (I sound so naive in my last post) but man did it ever crash and burn. You know how they say people don’t leave bad jobs, they leave bad managers? Yeah. That was me. I would’ve probably been happier had I stayed and learned how the hell web dev worked. I was extremely competent at what they wanted me to do, but it also still wasn’t data science.&#xA;&#xA;Plus, I didn’t do any talks last year, which was probably one of my biggest disappointments. I think getting halfway through the year and realizing it just wasn’t going to happen was when it hit me that the job wasn’t the right spot for me. I’m an introvert and I hate talking to people, but I am good at doing talks and I like sharing knowledge! And doing talks is good for the career!&#xA;&#xA;So once again, I am optimistic that my new role will be more fulfilling. I’m willing to do a lot of non-data-science bullshit, but I just don’t want to dread opening my laptop every morning. So far so good? It’s much better aligned to my interests, the manager came highly recommended by multiple people, and a colleague from this team actually tried to recruit me last year around this time but for obvious reasons, I couldn’t do anything.&#xA;&#xA;So far, I’m the one yelling about code reusability and “why aren’t we using GitHub?!?!?!” which is… interesting, since I’m not a real developer. But I am on the product team, so I guess it works?&#xA;&#xA;Once again, I hope that we can only go up from here, but I ended my last post on the same note, and it definitely went way, way, waaaay down. I guess at least I really learned how to compartmentalize work and personal lives, and I got very good at closing my laptop at 5pm? &#xA;&#xA;meta]]&gt;</description>
      <content:encoded><![CDATA[<p>Well, I guess it was another year of no code blogging. As with my last post, which I just re-read, I didn’t do much for my personal projects (or at least, I didn’t finish any… I can’t be the only one with a million WIPs that never get finished). And again, I’m in yet another new role!</p>

<p>In terms of code accomplishments, I would say the majority are actually “side projects” that I did at work but weren’t relevant to my day job. Specifically, I spent a lot of time re-learning R Shiny and made some pretty sweet dashboards, if I do say so myself. I’m actually using some of that knowledge for a personal project right now – I’m hoping I actually get that done so I can blog about it!</p>

<p>Anyway, job rambling under the cut:</p>



<p>My last job seemed promising (I sound so naive in my last post) but man did it ever crash and burn. You know how they say people don’t leave bad jobs, they leave bad managers? Yeah. That was me. I would’ve probably been happier had I stayed and learned how the hell web dev worked. I was extremely competent at what they wanted me to do, but it also still wasn’t data science.</p>

<p>Plus, I didn’t do any talks last year, which was probably one of my biggest disappointments. I think getting halfway through the year and realizing it just wasn’t going to happen was when it hit me that the job wasn’t the right spot for me. I’m an introvert and I hate talking to people, but I am good at doing talks and I like sharing knowledge! And doing talks is good for the career!</p>

<p>So once again, I am optimistic that my new role will be more fulfilling. I’m willing to do a lot of non-data-science bullshit, but I just don’t want to dread opening my laptop every morning. So far so good? It’s much better aligned to my interests, the manager came highly recommended by multiple people, and a colleague from this team actually tried to recruit me last year around this time but for obvious reasons, I couldn’t do anything.</p>

<p>So far, I’m the one yelling about code reusability and “why aren’t we using GitHub?!?!?!” which is… interesting, since I’m not a real developer. But I am on the product team, so I guess it works?</p>

<p>Once again, I hope that we can only go up from here, but I ended my last post on the same note, and it definitely went way, way, waaaay down. I guess at least I really learned how to compartmentalize work and personal lives, and I got very good at closing my laptop at 5pm?</p>

<p><a href="https://iman.codes/tag:meta" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">meta</span></a></p>
]]></content:encoded>
      <guid>https://iman.codes/how-is-it-2023-already</guid>
      <pubDate>Sat, 11 Feb 2023 04:04:15 +0000</pubDate>
    </item>
    <item>
      <title>Yet Another New Year</title>
      <link>https://iman.codes/yet-another-new-year?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[It&#39;s 2022, and I feel like everyone is just tired. I haven&#39;t been code-blogging as much because it feels like most of my personal code projects (and well, just about every kind of personal project) fell to the wayside as I focused (or more accurately, hyper-fixated) on the continuous impending feeling of doom as our governments and leaders prioritize the nebulous &#34;economy&#34; instead of human lives (which, surprise, fuel the economy! you don&#39;t get an economy if all the humans are dead!).&#xA;&#xA;But this is a code blog and this is a new year post, so let&#39;s instead talk about my various accomplishments from 2021 instead.&#xA;&#xA;Last year, code-wise, I:&#xA;&#xA;started this blog! &#xA;did the 2021 WiDS datathon! &#xA;got reorged into a new role, and then found me a new role that is better suited to my strengths and capabilities &#xA;played around with Django&#xA;started working on spaced repetition system for my Korean learning for funsies, which ended up being more a &#34;how to learn to make GUIs&#34; than actually learning any Korean&#xA;did two talks at work, Linguistics 101 for NLPers and one about lessons learned when productionizing the 7 models that my team built &#xA;&#xA;I guess this is a pretty okay list. I could&#39;ve done more, I could&#39;ve done less, but I got through 2021, and one could consider than the greatest achievement, so... I&#39;m happy about it.&#xA;&#xA;!--more--I&#39;m happy that I have this blog, and I&#39;m happy I did the datathon. I&#39;m hoping to do this year&#39;s datathon as well, but we&#39;ll see how life goes!&#xA;&#xA;With the new role, I&#39;m still at the bank! I got reorged mid-2021 because of my NLP experience and Linguistics minor - it was supposed to be a role where I would focus on NLP technology within the bank. However, it ended up as a team of data scientists trying to do web dev for a chatbot, taking over an existing code base that was poorly documented at best. I have zero knowledge of JavaScript or TypeScript or anything else that was being used, but programming languages are easy to pick up - I could read the code. The problem for me was that I had no web dev knowledge. I was floundering - like what the hell is a POST request? What&#39;s an end point? These are pretty basic concepts but my previous experience never needed me to know about these things.&#xA;&#xA;Of course, I vaguely know about them now, but honestly, it&#39;s not my jam. This is why we have specialties! It&#39;s like how I knew I didn&#39;t want to do civil engineering (buildings? foundations? boring) in school, but I was so fascinated with my choice of engineering physics (rocket science? nuclear physics? fluid dynamics? give me more of that good stuff). And of course, now I&#39;m in a software engineering field, so y&#39;know. You end up doing things you didn&#39;t think about before, but it&#39;s still something I found interesting and something I worked to be good at. &#xA;&#xA;Anyway, I quickly learned that it wasn&#39;t the right reorg for me, and luckily someone internally was looking for someone like me around the time I was looking to find a better place, so it all worked out. I&#39;m quite happy about it! I did do a few external interviews through the year to see how things looked outside the bank, but I&#39;m actually quite happy to stay here. It&#39;s not perfect, but what company is?&#xA;&#xA;Django was interesting to look at because it did touch on the various web-dev-y things I was tasked with learning at work. I was actually hoping to use it to hook into the spaced repetition system that I was playing around with, but I&#39;ll be honest. Web things are just a pain in the ass to me. I don&#39;t understand it, and I don&#39;t want to put the work into understanding it because there are way more interesting (to me) things to work on!&#xA;&#xA;But the SRS thing I was working on was pretty fun! I&#39;m hoping to expand it with a &#34;proper&#34; (or at least functional) GUI at some point this year! I also don&#39;t understand how GUIs work (and making things look &#34;pretty&#34; is the worst thing you could ask me to do - I&#39;m so bad at it), but it&#39;s cool to see how things come together.&#xA;&#xA;I&#39;m hoping to continue doing talks at work in 2022. Doing the linguistics talk 3 times last year was a lot, but I guess I&#39;m really good at it now. People have also asked for more in-depth linguistics/NLP topics, so I&#39;d love to find time to create those as well. Work-specific talks, I suppose, will depend on the work I&#39;m doing, but I&#39;m optimistic that I&#39;ll have some useful stuff eventually, though maybe not this year!&#xA;&#xA;Anyway, it&#39;s a new year, and although it&#39;s already kinda crappy, hopefully we can go up from here. &#xA;&#xA;meta]]&gt;</description>
      <content:encoded><![CDATA[<p>It&#39;s 2022, and I feel like everyone is just <em>tired</em>. I haven&#39;t been code-blogging as much because it feels like most of my personal code projects (and well, just about every kind of personal project) fell to the wayside as I focused (or more accurately, hyper-fixated) on the continuous impending feeling of doom as our governments and leaders prioritize the nebulous “economy” instead of human lives (which, surprise, fuel the economy! you don&#39;t get an economy if all the humans are dead!).</p>

<p>But this is a code blog and this is a new year post, so let&#39;s instead talk about my various accomplishments from 2021 instead.</p>

<p>Last year, code-wise, I:</p>
<ul><li>started this blog!</li>
<li>did the <a href="https://iman.codes/tag:wids2021" rel="nofollow">2021 WiDS datathon</a>!</li>
<li>got reorged into a new role, and then found me a new role that is better suited to my strengths and capabilities</li>
<li>played around with Django</li>
<li>started working on spaced repetition system for my Korean learning for funsies, which ended up being more a “how to learn to make GUIs” than actually learning any Korean</li>
<li>did two talks at work, <a href="https://iman.codes/linguistics-101-for-nlpers" rel="nofollow">Linguistics 101 for NLPers</a> and one about lessons learned when productionizing the 7 models that my team built</li></ul>

<p>I guess this is a pretty okay list. I could&#39;ve done more, I could&#39;ve done less, but I got through 2021, and one could consider than the greatest achievement, so... I&#39;m happy about it.</p>

<p>I&#39;m happy that I have this blog, and I&#39;m happy I did the datathon. I&#39;m hoping to do this year&#39;s datathon as well, but we&#39;ll see how life goes!</p>

<p>With the new role, I&#39;m still at the bank! I got reorged mid-2021 because of my NLP experience and Linguistics minor – it was supposed to be a role where I would focus on NLP technology within the bank. However, it ended up as a team of data scientists trying to do web dev for a chatbot, taking over an existing code base that was poorly documented at best. I have zero knowledge of JavaScript or TypeScript or anything else that was being used, but programming languages are easy to pick up – I could read the code. The problem for me was that I had no web dev knowledge. I was floundering – like what the hell is a POST request? What&#39;s an end point? These are pretty basic concepts but my previous experience never needed me to know about these things.</p>

<p>Of course, I vaguely know about them now, but honestly, it&#39;s not my jam. This is why we have specialties! It&#39;s like how I knew I didn&#39;t want to do civil engineering (buildings? foundations? <em>boring</em>) in school, but I was so fascinated with my choice of engineering physics (rocket science? nuclear physics? fluid dynamics? give me more of that good stuff). And of course, now I&#39;m in a software engineering field, so y&#39;know. You end up doing things you didn&#39;t think about before, but it&#39;s still something I found interesting and something I worked to be good at.</p>

<p>Anyway, I quickly learned that it wasn&#39;t the right reorg for me, and luckily someone internally was looking for someone like me around the time I was looking to find a better place, so it all worked out. I&#39;m quite happy about it! I did do a few external interviews through the year to see how things looked outside the bank, but I&#39;m actually quite happy to stay here. It&#39;s not perfect, but what company is?</p>

<p>Django was interesting to look at because it did touch on the various web-dev-y things I was tasked with learning at work. I was actually hoping to use it to hook into the spaced repetition system that I was playing around with, but I&#39;ll be honest. Web things are just a pain in the ass to me. I don&#39;t understand it, and I don&#39;t want to put the work into understanding it because there are way more interesting (to me) things to work on!</p>

<p>But the SRS thing I was working on was pretty fun! I&#39;m hoping to expand it with a “proper” (or at least functional) GUI at some point this year! I also don&#39;t understand how GUIs work (and making things look “pretty” is the worst thing you could ask me to do – I&#39;m so bad at it), but it&#39;s cool to see how things come together.</p>

<p>I&#39;m hoping to continue doing talks at work in 2022. Doing the linguistics talk 3 times last year was a lot, but I guess I&#39;m really good at it now. People have also asked for more in-depth linguistics/NLP topics, so I&#39;d love to find time to create those as well. Work-specific talks, I suppose, will depend on the work I&#39;m doing, but I&#39;m optimistic that I&#39;ll have some useful stuff eventually, though maybe not this year!</p>

<p>Anyway, it&#39;s a new year, and although it&#39;s already kinda crappy, hopefully we can go up from here.</p>

<p><a href="https://iman.codes/tag:meta" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">meta</span></a></p>
]]></content:encoded>
      <guid>https://iman.codes/yet-another-new-year</guid>
      <pubDate>Thu, 06 Jan 2022 18:57:01 +0000</pubDate>
    </item>
    <item>
      <title>Linguistics 101 for NLPers</title>
      <link>https://iman.codes/linguistics-101-for-nlpers?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[Somewhat recently, I made a little presentation on introductory linguistic concepts for my team at work, since we&#39;re an NLP group. I&#39;ve always thought that people working in natural language processing should have a deeper understanding of linguistics. Because I have a minor in linguistics, I suppose I&#39;m somewhat more qualified than the average bear to speak about linguistics!&#xA;&#xA;I wrote out an extensive set of notes, so it was kind of perfectly suited to adapt this presentation for my blog, especially because I ended up cutting some content when I did this presentation a second time for a larger group. Luckily, I didn&#39;t have to cut any content when I was asked to do this a third time, haha. But I&#39;m quite tired of doing this presentation now, at least in the near future, which makes a blog post the perfect delivery format!&#xA;&#xA;(And although I say I &#34;recently&#34; did my talks, the third time was back in July! This post has been in my drafts for many, many months, as it was actually a lot more work to convert than I had anticipated.)&#xA;&#xA;Due to a) my comparatively shallow understanding of linguistics (vs. someone who majored in linguistics/has a PhD/etc.), and b) and the time distance from when I received my minor to now; as well as 1) the target audience of my talk, and 2) the time limitation I had for the talk itself; this will be a very gross oversimplification of linguistic concepts. Please refer to an actual linguistics textbook if you&#39;re interested in learning more.&#xA;&#xA;But now that I&#39;ve given you this disclaimer, let&#39;s get into it!&#xA;&#xA;!--more--First of all, when I first created my presentation, I referenced Kevin Duh&#39;s Linguistics 101 slides from his 2019 Intro to NLP course for both structure and concepts that would be most relevant to NLPers. He&#39;s a senior research scientist and associate research professor at Johns Hopkins University. If you&#39;d like to take a look at his slides, you can click this link!&#xA;&#xA;But if you&#39;d like to follow along with my slides, you can find them here - this &#34;adaptation&#34; of my talk follows them quite closely, although the post does stand on its own!&#xA;&#xA;So what is linguistics anyway? You can consider it the scientific study of language. It focuses on the analysis and understanding of languages, in all their myriad forms.&#xA;&#xA;There&#39;s a variety of linguistic research areas, including (but not limited to):&#xA;&#xA;sociolinguistics (the study of language usage in society, such as how language varies across time/geography/cultures/etc.)&#xA;developmental linguistics (language acquisition, especially in children, but also including things like second or more language acquisition in adults, or heritage language learners)&#xA;neurolinguistics (how language interacts with the brain)&#xA;clinical linguistics (applied linguistics in a clinical setting, for example: speech language pathology, speech-related disorders, swallowing disorders, etc.)&#xA;translation (how a source language maps to a target language)&#xA;computational linguistics (the computational modelling of natural language)&#xA;&#xA;One could consider that computational linguistics is the closest to the natural language processing. However, I think (and other, more qualified people also think) that there are differences! &#xA;&#xA;Computational linguistics is focused on using computational methods to solve the scientific problems of linguistics. Natural language processing is more focused on solving engineering problems, or the creation of tools with which to perform language processing tasks. They are very similar, and can draw on one another, but they have different goals in the end.&#xA;&#xA;You can see how these fields all can have overlap and aren&#39;t neatly bucketed (as I&#39;ll probably say often in this post).&#xA;&#xA;There are also the major sub-disciplines in linguistics including:&#xA;&#xA;historical (how language changes over time)&#xA;phonetics and phonology (the sounds of language)&#xA;writing systems (the representation of language in physical media)&#xA;morphology (the structure of words)&#xA;syntax (the structure of sentences)&#xA;semantics (the meanings of words and sentences)&#xA;pragmatics (the meanings in context)&#xA;&#xA;It&#39;s not an exhaustive list, but you can kind of treat this as a&#34;table of contents&#34; for the rest of my post &#xA;&#xA;But the very first concept I want to cover is:&#xA;&#xA;Language is not writing!&#xA;&#xA;We are concerned with natural language which is a language that has not been constructed with intentionality. Most of us speak natural languages. A constructed language, of course, is one that was created. Esperanto is probably one of most famous constructed languages, and it even is the only one with native speakers. A nerdier take on constructed languages would be Tolkien&#39;s Elvish languages, or Klingon.&#xA;&#xA;The important thing to note is that natural languages are spoken or signed. &#xA;&#xA;Note that “signed” is mentioned! Sign languages have as much richness and diversity as spoken languages - you can have music in sign language! In fact, I have been to a sign language concert! I&#39;m not an expert, or even knowledgeable at all, about sign language, so I&#39;ll leave it to someone else to cover, ahaha.&#xA;&#xA;One can pick up listening and speaking in a language without formal instruction, especially in the case of children. However, one must be taught to read and write. In fact, the need to teach reading/writing is why literacy rates of a population is tracked. Literacy rates can be used as a an analogue for various socioeconomic measures.&#xA;&#xA;Something like the systematic simplification of Chinese characters in the 50s was done to promote literacy rates. There’s also the creation of Hangul, the Korean alphabet, in the 1400s, to promote literacy rates. It replaced classical Chinese characters as well as other phonetic systems that were in use at the time. Of course, there were other reasons as well, but that&#39;s outside the scope of this blog post.&#xA;&#xA;There are about 7000 living languages (which are languages which are still in use today), and among them, about 4000 have a developed writing system. However, this doesn’t account for those writing systems actually being used by the native speakers (for various reasons, such as being a construction for the purposes of research, or due to low literacy rates, the low prestige of the language, or other social factors).&#xA;&#xA;Phonetics&#xA;&#xA;Since we&#39;re talking about language being spoken, let&#39;s talk about how these sounds are produced. &#xA;&#xA;diagram of the vocal tract&#xA;figcaptionVocal Tract - Image from a href=&#34;https://commons.wikimedia.org/wiki/File:Tract.svg&#34;Wikimedia Commons/a/figcaption&#xA;&#xA;This image shows the vocal tract, which is the part of the body that produces sounds that we use in language. Some of the &#34;places of articulation,&#34; or parts of the vocal tract which move to produce sounds, are shown on the diagram.&#xA;&#xA;And if we want to discuss the actual sounds themselves in writing?&#xA;&#xA;Welcome to the International Phonetic Alphabet!&#xA;&#xA;To be honest, this part is actually easier to explain in a presentation, when one can hear all the sounds I make. &#xA;&#xA;If you click the link, you&#39;ll be taken to a page which has charts for different sounds that are produced in various languages.&#xA;&#xA;IPA Pulmonic Consonant ChartfigcaptionIPA Pulmonic Consonant Chart - Image from International Phonetic Association/figcaption&#xA;&#xA;In the pulmonic consonant chart (pulmonic referring to using the lungs and thus how air flows in the vocal tract), there are sometimes two items in a single cell. This is because one is &#34;voiced&#34; while the other is &#34;unvoiced&#34; - this refers to whether or not the vocal chords vibrate when making this sound. For example, if you say the [p] as in &#34;pat&#34; and the [b] as in &#34;bat,&#34; you can place your hand against your throat and feel the slight difference in the initial consonant.&#xA;&#xA;Those two consonants are called &#34;bilabial&#34; consonants, which means that it uses both the lips. You can see at the top of the chart for all the various places of articulation, which can be considered to be the &#34;place&#34; at which a sound is produced. The left side of the chart is what we call the manner of articulation, or how the sound is produced. For example, [p] and [b] are plosives or stops, which means that they are produced through the stopping of airflow.&#xA;&#xA;We can compare [p] and [b] to [m], which is another bilabial consonant - however, it&#39;s a nasal consonant, which means that it is produced when air flows through the nasal cavity. If you say &#34;pat,&#34; &#34;bat,&#34; and &#34;mat,&#34; you can get a better feel for these differences.&#xA;&#xA;IPA Vowel ChartfigcaptionIPA Vowel Chart - Image from International Phonetic Association/figcaption&#xA;&#xA;We also have vowels and an accompanying vowel chart! This chart has a bit of a unique shape, because it roughly corresponds to the space inside the mouth. The left side labels are to explain how “open” or “closed” the airway is by the tongue, or how close to the top or bottom the tongue is, whereas the top labels indicate how far forward the tongue is.&#xA;&#xA;Vowels are a bit harder to understand without hearing them, so I won&#39;t try to give written examples. If you&#39;d like to hear the vowel sounds, the Wikipedia article on vowels has some audio samples!&#xA;&#xA;I think vowels are a bit harder to learn and understand because it&#39;s all about open space in the mouth, compared to consonants which have more physical anchors.&#xA;&#xA;Not all sounds are present in all languages, and there are more charts that pulmonic consonants and vowels! If we&#39;re not used to hearing these sounds, we can have a hard time identifying them, let alone producing or conceptualizing them.&#xA;&#xA;This leads into another aspect of phonetics and phonology, which deals with how we hear and perceive sounds in languages. This affects &#34;accents,&#34; or how people speak languages. &#xA;&#xA;If we can’t produce a sound without conscious thought, we’re unlikely to be able to use that when we speak. If a native speaker of one language learns a language with sounds that are not part of their native language, they&#39;ll default to the closest approximation that they know.  For example, I can’t reliably produce the French [ʁ] (as in the French verb “rester”) and instead will default to [ɹ] (as in the English verb “to rest”).&#xA;&#xA;Most children, if they learn a language early enough, will have what’s considered a “native level” accent. For example, one could consider my English to be a native level Standard Canadian English accent. My Cantonese accent, however, would not be considered native-level, even though that’s technically my first language.&#xA;&#xA;Conversely, a “native-level” accent is possible (though extremely difficult for most language learners) to achieve as an adult learner of a language depending on multiple factors, such as similarity to the “native” language and amount of interaction with the target language.&#xA;&#xA;There’s a lot of social aspects tied up in accents, especially if we consider that some people think they speak “without an accent.” You’ll notice that I said that my accent would be Standard Canadian English. Some accents would be considered to be “accentless” because they are more “standard” pronunciations but this is more a function of the social prestige that a “native-like” accent confers. English has many accents due to the spread of where it’s an official language and the number of people who learn it as a second language. &#xA;&#xA;Also note that accents and dialects can be related, but don’t need to be! They are different things. Dialects are ways of speaking as well, but more in word choice and word meaning. We all speak with a dialect, and there’s a lot of social issues tied up in dialects too, which I&#39;ll touch on later.&#xA;&#xA;Writing Systems&#xA;&#xA;Now if we move onto how to represent a language visually, we get into writing systems. Here&#39;s a table showing one way to classify different writing systems - and there are many different ways to categorize them!&#xA;&#xA;| Type            | Single Symbol Representation                                                | Language Example   | Written Example |&#xA;|-----------------|-----------------------------------------------------------------------------|--------------------|-----------------|&#xA;| Logographic     | Word, morpheme, or syllable                                                 | Chinese characters | 语素文字                |&#xA;| Syllabary       | Syllable                                                                    | Japanese hiragana  |   おんじ                |&#xA;| Featural System | Distinctive feature of a segment                                            | Korean hangul      |  자질문자               |&#xA;| Alphabet        | Consonant or vowel                                                          | Latin alphabet     |  Alphabet               |&#xA;| Abjad           | Consonant                                                                   | Arabic alphabet    | الأبجد                |&#xA;| Abugida         | Consonant with specific vowel,  modifying symbols representing other vowels | Indian Devanagari  | आबूगीदा                |&#xA;&#xA;Logographic writing systems are where each symbol represents a single morpheme (which we’ll discuss when I get to the morphology part). Many logograms are required to write all the words in a language, but because the logograms’ meanings are inherent to the symbol, it can be used across multiple languages. We can see this for example in how the different Chinese languages all use Chinese characters, the use of Chinese characters in Japanese, as well as previous usage of Chinese characters in other languages such as Korean or Vietnamese before they switched to other systems. We also use logograms such as Arabic numerals or various other symbols like the @ sign or currency symbols like the $ sign.&#xA;&#xA;Syllabaries have each symbol representing a single syllable, and a true syllabary will have no systematic visual similarity between syllables with similar sounds.&#xA;&#xA;Featural systems are interesting in that symbols don’t represent a phonetic element but rather a feature that can be combined to make a syllable. A feature can represent something like the place of articulation or voicing, as well. It’s a bit like a combination of a syllabary and an alphabet.&#xA;&#xA;Alphabets, which we use in English, are where each symbol represents a consonant or a vowel – however, as you may be able to infer from the discussion on phonetics and dialects, English’s use of the alphabet is particularly fun because the sounds don’t map particularly well to the alphabet. Tune in later for my TED Talk on why English is a messed up language.&#xA;&#xA;Abjads, also known as a consonantaries, leaves readers to infer an appropriate vowel. Their symbols represent a consonant sound. However, most modern abjads are so-called “impure abjads” which include characters or diacritics for vowels, or both.&#xA;&#xA;Abugidas are also known as alphasyllabaries because they share similar features to both an alphabet and a syllabary. Each symbol represents a consonant-vowel pair, and there’s visual similarities between characters that share the same consonant or vowel.&#xA;&#xA;Writing systems aren’t entirely self-contained so I’m sure you can see how there’s crossover between these classifications, as well as why there would be multiple ways of classifying them.&#xA;&#xA;Morphology&#xA;&#xA;Morphology is the study of the structure and content of word forms. If you love words, morphology is the place for you!&#xA;&#xA;One important concept is that of the morpheme, which is the smallest possible meaningful unit in a language. For example, if we have the word dogs, its morphemes are dog and the suffix s. Free morphemes like dog can function independently, but bound morphemes like s only appear as parts of other words.&#xA;&#xA;Further to that, we have derivational bound morphemes, which change the original word&#39;s meaning or class. For example:&#xA;&#xA;establishment (noun) = establish (verb) + ment&#xA;happiness (noun) = happy (adj) + ness&#xA;&#xA;There are also inflectional bound morphemes, which change the tense, mood, or other aspects, but the meaning or class stays the same. For example:&#xA;&#xA;walked = walk + ed&#xA;undo = un + do&#xA;taller = tall + er&#xA;&#xA;Of course, there&#39;s more ways to make words than simply cobbling pieces together. A few other ways for English include:&#xA;&#xA;alternation: goose -  geese&#xA;reduplication: choo-choo, putt-putt, fifty-fifty, win-win&#xA;&#xA;There are many other morphological processes, too!&#xA;&#xA;In NLP, stemming or lemmatization can be considered to be morphological processes. In that situation, we&#39;re typically trying to get the smallest useful part of the word for our situations, not necessarily the base morphemes.&#xA;&#xA;We also have morphological topography, which is a way to classify languages based on how they form words, or their morphological structures. This is important because while my examples above were in English (due to it being the language of this post!), the many languages of the world have many different ways to form words.&#xA;&#xA;Analytic languages are those with an almost 1:1 ratio of morphemes to words. Vietnamese is considered to be an analytic language. There&#39;s also isolating languages (not to be confused with a language isolate, which is a different concept!), which are very related to analytic languages, and for the purpose of this post, you can consider them to be the same.&#xA;&#xA;Then we get into synthetic languages, which affix dependent morphemes to root morphemes to create new words. These can be broken down even further.&#xA;&#xA;Fusional languages are those where the morphemes are not easily distinguishable from themselves. Take this French example of the verb &#34;to like&#34; - aimer - and conjugating it in the first person singular:&#xA;&#xA;present tense: j&#39;aime&#xA;imparfait: j&#39;aimais&#xA;passé composé: j&#39;ai aimé&#xA;passé simple: j&#39;aimai&#xA;&#xA;Not so easy to point out the base morpheme, or even the dependent morphemes, is it? I&#39;ve even chosen a regular verb (it&#39;s one of the first you learn when you&#39;re learning French!) and that&#39;s not counting how it&#39;s conjugated in second or third person. Irregular verbs get even more fun.&#xA;&#xA;Next we have agglutinative languages, where words contain several morphemes - essentially, the words are formed through agglutination, which is the act of adding morphemes to each other without changing the spelling/phonetics. Each morpheme represents a single meaning, and is clearly demarcated. For example, in Japanese, we can have the verb &#34;to eat&#34; - 食べる - and conjugate it:&#xA;&#xA;past tense: 食べた&#xA;polite paste tense:　食べました&#xA;negative:　食べなかった&#xA;polite negative: 食べませんでした&#xA;&#xA;Here we can see that 食べ is the root, た indicates past tense, and polite forms have a ま in them (although Japanese politeness is also outside the scope of this post). &#xA;&#xA;There are also polysynthetic languages, which you can consider to be a language where words are formed that are whole sentences in other languages.&#xA;&#xA;You can also see that languages don’t neatly fall into these categories either. English is typically considered a fusional language, but it has many analytic characteristics. In the French example, we can still mostly see the root morpheme “aim-” and in Japanese, there’s some changing of the morphemes, especially seen in the polite forms.&#xA;&#xA;Syntax&#xA;&#xA;Syntax is a very important part of linguistics, but it&#39;s honestly my least favourite part, so I apologize if this section is sparser on details haha. It&#39;s a really deep topic and there are various different grammatical models in the study of syntax, but I&#39;ll only be covering some superficial parts (although this whole thing is a very superficial intro to linguistics anyway!).&#xA;&#xA;Essentially, syntax is the part of linguistics that focuses on the rules and structures of how sentences are constructed - you could consider it to be the &#34;grammar&#34; part of linguistics.&#xA;&#xA;We have various syntactic structures, such as:&#xA;&#xA;parts of speech (nouns, adjectives, prepositions, etc.)&#xA;sequence of subject (S), object (O), and verb (V)&#xA;agreement&#xA;phrase structure&#xA;&#xA;We&#39;re all familiar with the parts of speech, especially because in NLP, we&#39;ll sometimes do part of speech tagging. But what exactly are they? Essentially they&#39;re categories of words and their function in a language.&#xA;&#xA;We also have open classes, which includes nouns and adjectives, which we can compare with closed classes, which includes pronouns and prepositions. The primary difference between the two is that a part of speech in an open class is one that typically accepts new words, but those in closed classes very rarely have items added to them.&#xA;&#xA;Classes also vary between languages. In some languages, there’s no difference between adjectives and adverbs.&#xA;&#xA;One fun part of speech that I particularly like are ideophones! They are words that evoke a sensory perception through their sound. In English, ideophones are less used than in other languages like Japanese. Typically what we’d consider “sound effects” are ideophones – mostly onomatopoeia such as “tick-tock,” “vroom,” or “boing.” However, in Japanese, ideophones are much more common, including ones for smiling [ニコニコ], something sparkling [キラキラ] or even silence [シーン].&#xA;&#xA;Ideophones are closely linked to the linguistic research area of sound symbolism, &#xA;which is the idea that sounds, or phonemes, carry meaning. It&#39;s a really cool area of research, in my opinion!&#xA;&#xA;There is also word order in syntax, and that is pretty much what it says on the tin: the correct order for words to be arranged in order to make a grammatical sentence. Consider the following two English sentences:&#xA;&#xA;Iman (subject) baked (verb) bread (object)&#xA;Baked (verb) Iman (subject) bread (object)&#xA;&#xA;The second one is an ungrammatical sentence (denoted by the asterisk), because English is a subject-object-verb (SVO) language. In the world&#39;s languages, approximately 35% are SVO, ~44% are SOV, and ~29% are VSO. The other combinations are very rare.&#xA;&#xA;Word order can be more or less free depending on the language and still be considered “correct” or “grammatical.” For example, not all SVO languages require all sentences to be SVO.&#xA;&#xA;Languages also require agreement to be grammatical, and there are different kinds of agreement.&#xA;&#xA;English requires subject-verb agreement:&#xA;&#xA;he eats cookies&#xA;they eat cookies&#xA;&#xA;French requires gender agreement:&#xA;&#xA;il est heureux (he is happy)&#xA;elle est heuruese (she is happy)&#xA;&#xA;German requires case agreement:&#xA;&#xA;der gute Mann (the good man - nominative case)&#xA;der guten Mann(e)s (of the good man - genitive case)&#xA;&#xA;Cases are a way to categorize certain parts of speech based on their grammatical function within a phrase, clause, or sentence. The nominative case marks the subject of a sentence, while the genitive case marks a word as modifying another word (typically a noun).&#xA;&#xA;Finally, we come to phrase structure. This is one way to explain a language’s syntax – the concept was introduced by Noam Chomsky, a very famous linguist sometimes called “the father of modern linguistics.” Phrase structure breaks down sentences into their constituent parts (also known as syntactic categories) which includes parts of speech and phrasal categories (noun phrase, verb phrase, prepositional phrase, adjective phrase etc.).&#xA;&#xA;This dendrogram/tree structure is one way to represent phrase structure rules. The sentence is also a famous sentence from Chomsky which shows how a sentence can be syntactically sound but meaningless semantically. However, I do have a sentence showing a syntactically and semantically sound sentence... &#xA;&#xA;Please look forward to my next talk, English is a Garbage Language*.&#xA;&#xA;If you actually want to understand this sentence, the Wikipedia article has a pretty good explanation!&#xA;&#xA;Anyway, phrase structure is very important in the history of NLP. This sort of grammar was the basis of many systems in the heyday of symbolic NLP, meaning they were rules based on grammars and grammar theories, like context-free grammar, transformational grammar, or generative grammar. Starting in the 1990’s, we saw this rule-based way of performing NLP start to decline with the advent of statistical methods that we probably are more familiar with. But I’ll talk a bit more about this later.&#xA;&#xA;Semantics &#xA;&#xA;You can have semantics in other fields, but in linguistics, it’s concerned with the meanings of words, phrases, sentences, or even larger units.&#xA;&#xA;There&#39;s a lot of different semantic theories and ways to study semantics, but here is a sample of them:&#xA;&#xA;Conceptual semantics aims to provide a characterization of conceptual elements through how a person understands a sentence, or an explanatory semantic representation. “Explanatory” in this case means it deals with the most underlying structure and that it has predictive power, independent of the language. &#xA;&#xA;Conceptual semantics breaks lexical concepts into categories called “semantic primes” or “semantic primitives,” which can be understood as a sort of “syntax of meaning.” They represent words or phrases that can’t be broken down further and their meaning is learned through practice, such as quantifiers like “one,” “two,” or “many.” Through this, we can also see how syntax and semantics are quite related.&#xA;&#xA;Compositional semantics relates to how meanings are determined through the meanings of units and the construction of sentences through syntax rules - essentially, how do sentence meanings arise from word meaning? Take our earlier buffalo sentence, for example – all the words “sound” the same but have different meanings. The composition of the sentence gives us a way to understand it.&#xA;&#xA;Lexical semantics is concerned with the meanings of lexical units and how they correlate to the syntax of a language. Lexical units includes words, affixes, and even compound words or phrases.&#xA;&#xA;One concept in lexical semantics is that of the semantic network. It represents semantic relationships in a network and is a form of knowledge representation. &#xA;&#xA;As you might be able to infer from this example, a semantic network is a directed or undirected graph where the vertices represent concepts and the edges represent semantic relations between the concepts. If this sounds familiar, it’s because WordNet is a semantic network, and you may have used that in your NLP before.&#xA;&#xA;But let&#39;s go into the basics of &#34;words mean things&#34; which is kinda the basis of semantics.&#xA;&#xA;If you came across this building, what would you understand this to be?&#xA;&#xA;Well, the sign says “store” – that&#39;s a building that sells items. And “poutine” – those are fries covered in cheese curds and gravy. So this is probably some sort of establishment that sells poutine!&#xA;&#xA;figcaptionPhoto ©Mark Bahensky/figcaption&#xA;How would you feel if you went in and there was maple syrup? And nothing is being sold, it’s just maple syrup all over the shelves for you to look at. You&#39;d be pretty confused and concerned that I didn’t even know how to name things, right?&#xA;&#xA;Anyway, it’s kind of like this typographic attack where a model misclassifies the picture of an apple as an iPod, which I find absolutely hilarious.&#xA;&#xA;This also leads into our next topic:&#xA;&#xA;Pragmatics&#xA;&#xA;Pragmatics can be understood to be the meaning of language in context. The key difference between this and semantics is that semantics is concerned with what the sentence itself means, while pragmatics takes the overall context of the utterance, including the surrounding sentences, the culture, the tone, etc.&#xA;&#xA;Here&#39;s a quick example:&#xA;&#xA;  Q: Can I go the the bathroom?&#xA;&#xA;The question here asks, based on our shared understanding of English, for permission to go to the bathroom. We can answer it thusly:&#xA;&#xA;  A1: Yes, go ahead.&#xA;&#xA;This answer understands the request for permission implicitly – it’s how we phrase questions in English, after all. But let&#39;s consider a different, equally correct answer:&#xA;&#xA;  A2: I don&#39;t know, can you?&#xA;&#xA;This decides to interpret the question willfully obtusely, as in “is it physically possible for me to go to the bathroom.” &#xA;&#xA;Pragmatic rules are rarely noticed, but when they’re broken like this, it’s quite obvious, and can also be quite frustrating and obnoxious. &#xA;&#xA;They also enable us to understand ambiguous sentences. Take this sentence for example:&#xA;&#xA;  I&#39;m going to the bank.&#xA;&#xA;I did this presentation internally to my colleagues, and look at that, we all work at a financial institution! So because that is our shared context, everyone would tend to assume I mean a bank branch - some sort of building that contains ATMs, tellers, safety deposit boxes, financial advisors... However, if I were standing next to a river, a location where I find myself surprising frequently, I might actually mean the river bank.&#xA;&#xA;Code switching is also another concept covered by pragmatics, and one can code switch between two languages, or between two registers or forms of a single language. This &#34;switch&#34; is when the two languages or forms are mixed together in the same conversation or sentence.&#xA;&#xA;As a personal example, when I’m speaking to my family, I’ll code switch when referring to my paternal grandparents – “I’m going to see 嫲嫲 and 爺爺 tomorrow.” I’ll also code-switch when speaking to my grandparents, mostly because my Cantonese is really bad. They’ll ask me a question in Cantonese, “rubyrb食咗飯未呀?/rbrtHave you eaten yet?/rt/ruby” I’ll respond with something like, “rubyrb我食咗/rbrtI&#39;ve eaten/rt/ruby steak rubyrb同/rbrtand/rt/ruby mashed potato.” Steak has a Cantonese word – 牛扒– and so does mashed potatoes – 薯蓉 – but I think of western food in my western language. You may have noticed that in my code switched sentence, I used the singular form of mashed potatoes. That’s because Cantonese is a language that pluralizes words differently than English, so even when I code switch into English, I’ll use similar grammatical rules as Cantonese. &#xA;&#xA;A more common form of code-switching for the monoglots among us is between different registers, forms, or dialects. We all code switch in this way - I certainly speak differently to my work colleagues than I do with my friends, for example. As work colleagues, I’ll probably say something like, “hey, I made cookies, they’re on the usual table,” while with friends, I might say something like “eat your damn cookies and be happy about it.” You can hopefully see the difference between my phrasing, even though the meaning of both sentences are roughly equivalent!&#xA;&#xA;If you remember back when I was talking about accents, I mentioned that they’re related to dialects but not necessarily. You might have inferred here that dialects are more about word choice than the actual way that sounds are produced, although there are also pronunciation differences with dialects. As with accents, everyone speaks with their own dialect (also known as an idiolect) and no one lacks a dialect, no matter what you may be told. &#xA;&#xA;There’s a certain social prestige if you speak with a dialect that’s considered neutral or &#34;standard,&#34; much like how being “accentless” confers a certain prestige. I&#39;m no social scientist, either, but &#34;professional&#34; settings have expectations of which dialects are acceptable and which are not, which I imagine contributes to the prestige of certain dialects.&#xA;&#xA;This all brings me to my favourite topic: translation and translation theory! I&#39;m bundling this into the pragmatics section, because as I hope I&#39;ll be able to illustrate, translation depends heavily on context!&#xA;&#xA;Consider the following media or situations where translation might be necessary:&#xA;&#xA;medical documents&#xA;simultaneous interpretation at the UN&#xA;Oscar-award winning movie subtitles&#xA;Brooklyn 99 dubbing&#xA;&#xA;The way you would translate for each of these situations would be different – you could translate all of these the same way, but it’d be pretty weird to get a medical document in the same style as a comedy.&#xA;&#xA;I’d also like to point out here that my third point is ambiguous! Are the subtitles award winning? Is the movie? Who knows! Welcome to pragmatics!&#xA;&#xA;I’ll cover two theories that are important in translation, polysystem theory, and equivalence theory but of course, this is not an exhaustive and in-depth exploration of these topics. Also, I’m not an expert, I just like this stuff. There’s a lot of other ways and theories to approach translation!&#xA;&#xA;So first, equivalence theory - this is something that states that the translation makes the reader of a translation (target reader) understand the same meaning and react the same way as the original language (source reader). But what does this mean in practice?&#xA;&#xA;Consider the Oscar-award winning movie Parasite. Have you seen it? (I haven’t, but I really should watch it.)&#xA;&#xA;In this scene, the translator changed “Seoul National University” to “Oxford.” The translator himself said, &#34;The first time I did the translation, I did write out SNU but we ultimately decided to change it because it&#39;s a very funny line, and in order for humor to work, people need to understand it immediately.&#34;&#xA;&#xA;A “direct” translation, keeping the institutions the same, would convey the same meaning, but it wouldn’t have the same immediate emotional response from a viewer. The average English speaker likely isn&#39;t familiar with Korea, and they would more immediately associate ”Oxford” with “prestigious university” than “Seoul National University.” Once you think about it, you could probably understand that SNU is a famous academic institution, but that “once you think about it” is the key here – if the target audience doesn’t understand something in the same amount of time that the source audience does, it is a potential failing of the translation, especially as subtitles have limited time on screen.&#xA;&#xA;Plus it’s often said that “if you need to explain a joke, then it’s not funny.” Now that I’ve explained this joke, I hope it remains funny when you watch Parasite.&#xA;&#xA;For another example, let&#39;s consider Beowulf! This is an Old English poem that’s also one of the most translated pieces of work in the world. It starts with “Hwæt!” and in the 2020 Beowulf translation by Maria Dahvana Headley, it is translated as “Bro!” Other translations have used “Behold!” and “Lo!” and “What ho!” but for a modern translation for modern readers, ”Bro!” provides the sort of immediate equivalence and a more seamless integration into the work (although you certainly can disagree with this choice).&#xA;&#xA;This translation interprets Beowulf as a sort of bragging, over-the-top, urban legend where it’s been embellished so many times over the years. You can consider it kind of like the guy at the bar who always tells his story about the huge fish he caught once - every time you hear it, the fish is bigger than the last time. So this sort of “Bro!” opening provides a very similar emotional feel to a modern reader.&#xA;&#xA;I also am going to present this one image without comment, since I think it&#39;s funny and relevant:&#xA;&#xA;Next we have polysystem theory, which is very related to equivalence theory! Essentially, literary works are part of the social, cultural, literary, and historical systems in which they were created, and to translate a work, one must remove it from those source systems and transplant it into the target systems.&#xA;&#xA;So these are all a bunch of nice words, but what does this actually mean? This doesn’t even have to be about different languages, so let’s use some English examples for now.&#xA;&#xA;I say something like, “what kind of cake should I bake?” you might assume that I’m asking for general opinions. However, if I said this at work, with the context of coming to the office and understanding that I brought in baked goods regularly for everyone to eat, you would understand that I’m asking about what my coworkers want to eat next. My point here is that these are systems which that my coworkers would be familiar with – the office is a social/cultural system, and there&#39;s the historical context of previously eating muffins. As a random reader, I had to explain all these things, or &#34;translate&#34; what I meant. This would involve rephrasing my question or adding more context to the question itself, as I’ve done here.&#xA;&#xA;Since I’m talking a lot about context here, we can also talk about high and low context cultures. This is a continuum of how explicit one needs to be when communicating. So when we’re talking about languages, generally English is a low context language because we prefer to have more information up front. You could also characterize a lower context language by how direct it is. Asian languages like Chinese or Japanese tend to be considered higher context because you rely more on shared experiences, traditions, and societal expectations to communicate. In these languages, you can communicate the same amount of information in fewer words. &#xA;&#xA;Even within English-speaking “culture,” we can vary between whether we’re higher or lower context. If you have an “inside joke” with your friends, that’s a higher context! Or, just refer back to my earlier example about my cake.&#xA;&#xA;Also here&#39;s another fun English example.:&#xA;&#xA;figcaptionComic by a href=&#34;https://twitter.com/thejenkinscomic/status/1351179836602146820&#34;The Jenkins/a/figcaption&#xA;&#xA;  When the violin repeats what the piano has just played, it cannot make the same sounds and it can only approximate the same chords. It can, however, make recognizably the same &#34;music,&#34; the same air. But it can do so only when it is as faithful to the self-logic of the violin as it is to the self-logic of the piano. &#xA;    Language too is an instrument and each language has its own logic. I believe that the process of rendering from language to language is better conceived as a &#34;transposition&#34; than as a &#34;translation,&#34; for &#34;translation&#34; implies a series of word-for-word equivalents that do not exist across language boundaries any more than piano sounds exist in the violin. &#xA;    -- citeJohn Ciardi (The Inferno, 1954 Translation) /cite&#xA;&#xA;I particularly like this quote from a translator of The Inferno, because it’s such a good metaphor for translation and I think that it fits well into polysystem theory.&#xA; &#xA;Polysystem theory also addresses the cultural expectations of a work in its target language. We have certain expectations of how works should be written – poetry reads differently than modern literature reads differently than harlequin romance reads differently than legal document reads differently than marketing brochures. If you translate a fantasy novel in the same way as a divorce proceeding, you’re going to confuse a lot of people. &#xA;&#xA;Essentially, the context and expectations of a target language, with respect to the culture and even the specific target audience, is going to have an effect on your translation. This has come to the fore in English language media because now we are able to get foreign language media almost simultaneously with the source language. This article talks about translation considerations in TV shows and movies and it&#39;s a very good take on what makes a &#34;good&#34; translation.&#xA;&#xA;And since this is technically supposed to be a discussion of linguistics for those of us who work in NLP, let&#39;s talk about machine translation as well!&#xA;&#xA;Machine translation (MTL) can be a helpful tool in translation! But the keywords here are &#34;can&#34; and &#34;tool.&#34; There are uses for machine translation but it&#39;s still limited. I, and (I hope) most machine translation researchers, would advise against using machine translation for everything.&#xA;&#xA;First of all, the language pair matters! When actual translators were asked to evaluate machine translation results, they ranked MTL providers like so:&#xA;&#xA;|Language pair| 1st preference | 2nd preference | 3rd preference | 4th preference|&#xA;|-----|-----|-----|-----|-----|&#xA;|EN =  DE| DeepL| Microsoft| Amazon| Google|&#xA;|EN =  FR| Microsoft| DeepL| Google| Amazon|&#xA;|EN =  RU| Google| Amazon| Microsoft| DeepL|&#xA;&#xA;Generally the more similar a language pair is to one another, the better results you get. Hopefully that’s self-explanatory with all of the fun linguistics concepts I went over already!&#xA;&#xA;Second of all, the purpose of your translation matters! If you’re going to try and use it for marketing, maybe use a real human. If it’s a low-stakes internal use, yeah I mean maybe, go for it if no one’s gonna complain and it gets the job done. &#xA;&#xA;Thirdly, the source document matters! Is this a literary work? Maybe reconsider - think of all the metaphors that&#39;ll get truly lost in translation. Is this a short instruction manual? Potentially fine, if it has a regular and expected structure, and you&#39;re sure that you have enough training examples for a good result. And I still wouldn&#39;t suggest machine translating an instruction manual for distribution to one&#39;s clients.&#xA;&#xA;So this is a bunch of words to say that machine translation is a tool. So as long as you use it properly, you’re fine. You wouldn&#39;t use a rice cooker in place of a wood chipper, would you? &#xA;&#xA;At the end of the day, translation is difficult even for humans. A machine would struggle to translate a line such as, “your dog looks sick,” but so would a human without appropriate context. Is this the vet? My dog is probably sick in the medical sense. Is this a guy on the street who means my dog looks cool? Is this a person seeing my dog throw up as I’m walking her? Knowing my dog, she ate too much grass because she’s dumb sometimes.&#xA;&#xA;But if you work in AI, machine translation has a lot of cool stuff going on in terms of technology! So I imagine that’s also great. I have no idea about the state of machine translation research but a quick search told me that it sounds cool.&#xA;&#xA;We may think of machine translation as something that’s a sleek and modern field, but its origins can be traced back to the 9th century Arabic cryptography Al-Kindi who developed techniques for systemic language translation.&#xA;&#xA;What we think of for “machine translation” with computers can potentially be said to have started in the 50’s, such as with the Georgetown experiment, which was the first public demonstration of machine translation, where over 60 Russian sentences were translated automatically into English. This used the symbolic methods, like the phrase structure grammar that I talked about earlier.&#xA;&#xA;Then we had the so-called “statistical revolution,” thanks in part to the computing power increase due to Moore’s Law. Many of the initial successes of statistical methods in NLP were in machine translation. These methods include things like decision trees and hidden Markov models, which hopefully sound familiar!&#xA;&#xA;More recently, NLP has increasingly used neural models, especially in the field of machine translation, and that’s where the predominant machine translation research community is right now, although statistical methods are still used! &#xA;&#xA;Lessons for NLPers&#xA;&#xA;I assembled some quick takeaways for my talk audience, and I think it works better in a talk setting, but here they are anyway.&#xA;&#xA;Not all NLP is text data&#xA;&#xA;My work group predominantly works with text data, and I imagine many other people who focus on NLP work mostly with text. There’s other groups who work with voice data, and I would love to see how they approach it, because there’s a lot of cool stuff phonologically – but my intuition is that phonetics and phonology isn&#39;t taken into account, and I also suspect the same happens with sign languages. Sign languages are a 3D language involving the space around the person signing and facial expressions and a whole lot of other things. There are all sorts of considerations when you move outside of text data, even computationally, so I think it&#39;s good to keep linguistic concepts in mind.&#xA;&#xA;But I want to re-emphasize that language encompasses spoken word and visual media, so there’s so much to consider and so much research to be done.&#xA;&#xA;Preprocessing results in a loss of information&#xA;&#xA;Stemming or lemmatization results in the loss of morphological structure, which in a fusional language like English, contains valuable information. Removing stop words removes syntactic information. Lower-casing all words removes morphological characteristics - think back to that &#34;Buffalo&#34; sentence! Bag of words representation destroys any syntactic structure, creating n-grams can create confusion in the syntactic structure while trying to capture aspects of that structure...&#xA;&#xA;Generally anything that simplifies the way we present language will result in a loss of information. Sometimes we don’t need all this information though! Sometimes it truly is unnecessary in the task we’re doing. But I think it’s good to keep in mind when creating a preprocessing and feature engineering pipeline about what sort of information we do want to keep and what’s truly unnecessary, which is very dependent on both our data and the task we’re working on.&#xA;&#xA;Different languages are different&#xA;&#xA;This is a bit of a dumb point to write out, but I think many people understand multiple languages. Even if you haven’t thought about it, you’re casually aware of the differences in different languages, especially after getting through the rest of this post! &#xA;&#xA;Plus, I&#39;m a Canadian so it&#39;s important for me to note that Canada is officially bilingual. Sooner or later, a Canadian data scientist will come across French in the data. We all have different approaches to dealing with this, but techniques that work on English data won’t necessarily work on French data. And working on a data set that contains both languages has other complexities. French and English are relatively easy to distinguish from each other for a speaker who knows English or French, but a machine doesn’t know either!&#xA;&#xA;Now throw in our increasingly global society with languages that aren’t related to others, like Korean, or those with different writing systems, like Japanese, or with sound features that aren’t produced in the language we’re familiar with, like the tones in Cantonese. And then let’s throw in code switching on top of all of that!&#xA;&#xA;Languages are hard, but that&#39;s also what makes them so fun and interesting.&#xA;&#xA;Language is complex but also follows rules&#xA;&#xA;Something that always bothered me about “modern” NLP, meaning the statistical and neural methods, was that we don’t encode rules into our models and systems. &#xA;&#xA;However, language follows rules! When we learn a second language, we are taught all of the grammar rules, as well as the various exceptions to these rules. However, nowadays we don’t typically teach the machines these rules. We kind of treat them like children where they learn from implication.&#xA;&#xA;It’s not easy, but if we work with natural language, we should consider these various rules. Doing this requires more specialized knowledge of syntactic structures, morphological topography, and various other concepts. It’s certainly not necessary in every case, and it may not feel “machine learning”-y because it involves rules, and apparently we all hate rule-based systems in DS/ML/AI, but I think a hybrid system would create a more robust model in the end. And there’s actually quite a bit of interest in creating these hybrid systems. &#xA;&#xA;There’s are some researchers who think linguistics and NLP should draw on one another, and one quote that I particularly like is from Tal Linzen, an associate professor of linguistics and data science at NYU: &#xA;&#xA;  Linguists are best positioned to define the standards of linguistic competence that natural language technology should aspire to.&#xA;&#xA;Anyway, I hope this blog post has given you some things to think about, either in your work or in your everyday life! A final reminder that I’m not really an expert, I just know a little bit more than the average person off the street, and I really like languages haha.&#xA;&#xA;Also I know that the majority of this is unsourced, so please don&#39;t use it in any formal settings ahaha. And I definitely cribbed knowledge from places and I didn&#39;t think to note from where, which was totally a mistake.&#xA;&#xA;#datascience #nlp #linguistics]]&gt;</description>
      <content:encoded><![CDATA[<p>Somewhat recently, I made a little presentation on introductory linguistic concepts for my team at work, since we&#39;re an NLP group. I&#39;ve always thought that people working in natural language processing should have a deeper understanding of linguistics. Because I have a minor in linguistics, I suppose I&#39;m somewhat more qualified than the average bear to speak about linguistics!</p>

<p>I wrote out an extensive set of notes, so it was kind of perfectly suited to adapt this presentation for my blog, especially because I ended up cutting some content when I did this presentation a second time for a larger group. Luckily, I didn&#39;t have to cut any content when I was asked to do this a third time, haha. But I&#39;m quite tired of doing this presentation now, at least in the near future, which makes a blog post the perfect delivery format!</p>

<p>(And although I say I “recently” did my talks, the third time was back in July! This post has been in my drafts for many, many months, as it was actually a lot more work to convert than I had anticipated.)</p>

<p>Due to a) my comparatively shallow understanding of linguistics (vs. someone who majored in linguistics/has a PhD/etc.), and b) and the time distance from when I received my minor to now; as well as 1) the target audience of my talk, and 2) the time limitation I had for the talk itself; this will be a very gross oversimplification of linguistic concepts. Please refer to an actual linguistics textbook if you&#39;re interested in learning more.</p>

<p>But now that I&#39;ve given you this disclaimer, let&#39;s get into it!</p>

<p>First of all, when I first created my presentation, I referenced Kevin Duh&#39;s Linguistics 101 slides from his 2019 Intro to NLP course for both structure and concepts that would be most relevant to NLPers. He&#39;s a senior research scientist and associate research professor at Johns Hopkins University. If you&#39;d like to take a look at his slides, you can <a href="https://kevinduh.github.io/nlp-course/assets/lectures/04-Linguistics101.pdf" rel="nofollow">click this link!</a></p>

<p>But if you&#39;d like to follow along with my slides, you can <a href="https://1drv.ms/b/s!AuWQIZuxtcjGqlBm0rQcKGGd5h7r?e=76lExj" rel="nofollow">find them here</a> – this “adaptation” of my talk follows them quite closely, although the post does stand on its own!</p>

<p>So what is linguistics anyway? You can consider it the scientific study of language. It focuses on the analysis and understanding of languages, in all their myriad forms.</p>

<p>There&#39;s a variety of linguistic research areas, including (but not limited to):</p>
<ul><li><strong>sociolinguistics</strong> (the study of language usage in society, such as how language varies across time/geography/cultures/etc.)</li>
<li><strong>developmental linguistics</strong> (language acquisition, especially in children, but also including things like second or more language acquisition in adults, or heritage language learners)</li>
<li><strong>neurolinguistics</strong> (how language interacts with the brain)</li>
<li><strong>clinical linguistics</strong> (applied linguistics in a clinical setting, for example: speech language pathology, speech-related disorders, swallowing disorders, etc.)</li>
<li><strong>translation</strong> (how a source language maps to a target language)</li>
<li><strong>computational linguistics</strong> (the computational modelling of natural language)</li></ul>

<p>One could consider that computational linguistics is the closest to the natural language processing. However, I think (and other, more qualified people also think) that there are differences!</p>

<p>Computational linguistics is focused on using computational methods to solve the scientific problems of linguistics. Natural language processing is more focused on solving engineering problems, or the creation of tools with which to perform language processing tasks. They are very similar, and can draw on one another, but they have different goals in the end.</p>

<p>You can see how these fields all can have overlap and aren&#39;t neatly bucketed (as I&#39;ll probably say often in this post).</p>

<p>There are also the major sub-disciplines in linguistics including:</p>
<ul><li><strong>historical</strong> (how language changes over time)</li>
<li><strong>phonetics and phonology</strong> (the sounds of language)</li>
<li><strong>writing systems</strong> (the representation of language in physical media)</li>
<li><strong>morphology</strong> (the structure of words)</li>
<li><strong>syntax</strong> (the structure of sentences)</li>
<li><strong>semantics</strong> (the meanings of words and sentences)</li>
<li><strong>pragmatics</strong> (the meanings in context)</li></ul>

<p>It&#39;s not an exhaustive list, but you can kind of treat this as a”table of contents” for the rest of my post</p>

<p>But the very first concept I want to cover is:</p>

<h3 id="language-is-not-writing" id="language-is-not-writing">Language is not writing!</h3>

<p>We are concerned with <em>natural language</em> which is a language that has not been constructed with intentionality. Most of us speak natural languages. A constructed language, of course, is one that was created. Esperanto is probably one of most famous constructed languages, and it even is the only one with native speakers. A nerdier take on constructed languages would be Tolkien&#39;s Elvish languages, or Klingon.</p>

<p>The important thing to note is that natural languages are <strong>spoken</strong> or <strong>signed</strong>.</p>

<p>Note that “signed” is mentioned! Sign languages have as much richness and diversity as spoken languages – you can have music in sign language! In fact, I have been to a sign language concert! I&#39;m not an expert, or even knowledgeable at all, about sign language, so I&#39;ll leave it to someone else to cover, ahaha.</p>

<p>One can pick up listening and speaking in a language without formal instruction, especially in the case of children. However, one must be taught to read and write. In fact, the need to teach reading/writing is why literacy rates of a population is tracked. Literacy rates can be used as a an analogue for various socioeconomic measures.</p>

<p>Something like the systematic simplification of Chinese characters in the 50s was done to promote literacy rates. There’s also the creation of Hangul, the Korean alphabet, in the 1400s, to promote literacy rates. It replaced classical Chinese characters as well as other phonetic systems that were in use at the time. Of course, there were other reasons as well, but that&#39;s outside the scope of this blog post.</p>

<p>There are about 7000 living languages (which are languages which are still in use today), and among them, about 4000 have a developed writing system. However, this doesn’t account for those writing systems actually being used by the native speakers (for various reasons, such as being a construction for the purposes of research, or due to low literacy rates, the low prestige of the language, or other social factors).</p>

<h3 id="phonetics" id="phonetics">Phonetics</h3>

<p>Since we&#39;re talking about language being spoken, let&#39;s talk about how these sounds are produced.</p>

<p><img src="https://i.snap.as/6xTjJtMB.png" alt="diagram of the vocal tract"/>
<figcaption>Vocal Tract – Image from <a href="https://commons.wikimedia.org/wiki/File:Tract.svg" rel="nofollow">Wikimedia Commons</a></figcaption></p>

<p>This image shows the vocal tract, which is the part of the body that produces sounds that we use in language. Some of the “places of articulation,” or parts of the vocal tract which move to produce sounds, are shown on the diagram.</p>

<p>And if we want to discuss the actual sounds themselves in writing?</p>

<p>Welcome to the <a href="https://www.internationalphoneticassociation.org/IPAcharts/IPA_chart_orig/IPA_charts_E.html" rel="nofollow">International Phonetic Alphabet</a>!</p>

<p>To be honest, this part is actually easier to explain in a presentation, when one can hear all the sounds I make.</p>

<p>If you click the link, you&#39;ll be taken to a page which has charts for different sounds that are produced in various languages.</p>

<p><img src="https://i.snap.as/9ca9uqzt.jpeg" alt="IPA Pulmonic Consonant Chart"/><figcaption>IPA Pulmonic Consonant Chart – Image from <a href="https://www.internationalphoneticassociation.org/IPAcharts/IPA_chart_orig/IPA_charts_E_img.html" rel="nofollow">International Phonetic Association</a></figcaption></p>

<p>In the pulmonic consonant chart (pulmonic referring to using the lungs and thus how air flows in the vocal tract), there are sometimes two items in a single cell. This is because one is “voiced” while the other is “unvoiced” – this refers to whether or not the vocal chords vibrate when making this sound. For example, if you say the [p] as in “pat” and the [b] as in “bat,” you can place your hand against your throat and feel the slight difference in the initial consonant.</p>

<p>Those two consonants are called “bilabial” consonants, which means that it uses both the lips. You can see at the top of the chart for all the various places of articulation, which can be considered to be the “place” at which a sound is produced. The left side of the chart is what we call the manner of articulation, or how the sound is produced. For example, [p] and [b] are plosives or stops, which means that they are produced through the stopping of airflow.</p>

<p>We can compare [p] and [b] to [m], which is another bilabial consonant – however, it&#39;s a nasal consonant, which means that it is produced when air flows through the nasal cavity. If you say “pat,” “bat,” and “mat,” you can get a better feel for these differences.</p>

<p><img src="https://i.snap.as/FrwhHZm1.jpeg" alt="IPA Vowel Chart"/><figcaption>IPA Vowel Chart – Image from <a href="https://www.internationalphoneticassociation.org/IPAcharts/IPA_chart_orig/IPA_charts_E_img.html" rel="nofollow">International Phonetic Association</a></figcaption></p>

<p>We also have vowels and an accompanying vowel chart! This chart has a bit of a unique shape, because it roughly corresponds to the space inside the mouth. The left side labels are to explain how “open” or “closed” the airway is by the tongue, or how close to the top or bottom the tongue is, whereas the top labels indicate how far forward the tongue is.</p>

<p>Vowels are a bit harder to understand without hearing them, so I won&#39;t try to give written examples. If you&#39;d like to hear the vowel sounds, the <a href="https://en.wikipedia.org/wiki/Vowel#Audio_samples" rel="nofollow">Wikipedia article on vowels</a> has some audio samples!</p>

<p>I think vowels are a bit harder to learn and understand because it&#39;s all about open space in the mouth, compared to consonants which have more physical anchors.</p>

<p>Not all sounds are present in all languages, and there are more charts that pulmonic consonants and vowels! If we&#39;re not used to hearing these sounds, we can have a hard time identifying them, let alone producing or conceptualizing them.</p>

<p>This leads into another aspect of phonetics and phonology, which deals with how we hear and perceive sounds in languages. This affects “accents,” or how people speak languages.</p>

<p>If we can’t produce a sound without conscious thought, we’re unlikely to be able to use that when we speak. If a native speaker of one language learns a language with sounds that are not part of their native language, they&#39;ll default to the closest approximation that they know.  For example, I can’t reliably produce the French [ʁ] (as in the French verb “rester”) and instead will default to [ɹ] (as in the English verb “to rest”).</p>

<p>Most children, if they learn a language early enough, will have what’s considered a “native level” accent. For example, one could consider my English to be a native level Standard Canadian English accent. My Cantonese accent, however, would not be considered native-level, even though that’s technically my first language.</p>

<p>Conversely, a “native-level” accent is possible (though extremely difficult for most language learners) to achieve as an adult learner of a language depending on multiple factors, such as similarity to the “native” language and amount of interaction with the target language.</p>

<p>There’s a lot of social aspects tied up in accents, especially if we consider that some people think they speak “without an accent.” You’ll notice that I said that my accent would be Standard Canadian English. Some accents would be considered to be “accentless” because they are more “standard” pronunciations but this is more a function of the social prestige that a “native-like” accent confers. English has many accents due to the spread of where it’s an official language and the number of people who learn it as a second language.</p>

<p>Also note that accents and dialects can be related, but don’t need to be! They are different things. Dialects are ways of speaking as well, but more in word choice and word meaning. We all speak with a dialect, and there’s a lot of social issues tied up in dialects too, which I&#39;ll touch on later.</p>

<h3 id="writing-systems" id="writing-systems">Writing Systems</h3>

<p>Now if we move onto how to represent a language visually, we get into writing systems. Here&#39;s a table showing one way to classify different writing systems – and there are many different ways to categorize them!</p>

<table>
<thead>
<tr>
<th><strong>Type</strong></th>
<th><strong>Single Symbol Representation</strong></th>
<th><strong>Language Example</strong></th>
<th><strong>Written Example</strong></th>
</tr>
</thead>

<tbody>
<tr>
<td>Logographic</td>
<td>Word, morpheme, or syllable</td>
<td>Chinese characters</td>
<td>语素文字</td>
</tr>

<tr>
<td>Syllabary</td>
<td>Syllable</td>
<td>Japanese hiragana</td>
<td>おんじ</td>
</tr>

<tr>
<td>Featural System</td>
<td>Distinctive feature of a segment</td>
<td>Korean hangul</td>
<td>자질문자</td>
</tr>

<tr>
<td>Alphabet</td>
<td>Consonant or vowel</td>
<td>Latin alphabet</td>
<td>Alphabet</td>
</tr>

<tr>
<td>Abjad</td>
<td>Consonant</td>
<td>Arabic alphabet</td>
<td>الأبجد</td>
</tr>

<tr>
<td>Abugida</td>
<td>Consonant with specific vowel,  modifying symbols representing other vowels</td>
<td>Indian Devanagari</td>
<td>आबूगीदा</td>
</tr>
</tbody>
</table>

<p>Logographic writing systems are where each symbol represents a single morpheme (which we’ll discuss when I get to the morphology part). Many logograms are required to write all the words in a language, but because the logograms’ meanings are inherent to the symbol, it can be used across multiple languages. We can see this for example in how the different Chinese languages all use Chinese characters, the use of Chinese characters in Japanese, as well as previous usage of Chinese characters in other languages such as Korean or Vietnamese before they switched to other systems. We also use logograms such as Arabic numerals or various other symbols like the @ sign or currency symbols like the $ sign.</p>

<p>Syllabaries have each symbol representing a single syllable, and a true syllabary will have no systematic visual similarity between syllables with similar sounds.</p>

<p>Featural systems are interesting in that symbols don’t represent a phonetic element but rather a feature that can be combined to make a syllable. A feature can represent something like the place of articulation or voicing, as well. It’s a bit like a combination of a syllabary and an alphabet.</p>

<p>Alphabets, which we use in English, are where each symbol represents a consonant or a vowel – however, as you may be able to infer from the discussion on phonetics and dialects, English’s use of the alphabet is particularly fun because the sounds don’t map particularly well to the alphabet. Tune in later for my TED Talk on why English is a messed up language.</p>

<p>Abjads, also known as a consonantaries, leaves readers to infer an appropriate vowel. Their symbols represent a consonant sound. However, most modern abjads are so-called “impure abjads” which include characters or diacritics for vowels, or both.</p>

<p>Abugidas are also known as alphasyllabaries because they share similar features to both an alphabet and a syllabary. Each symbol represents a consonant-vowel pair, and there’s visual similarities between characters that share the same consonant or vowel.</p>

<p>Writing systems aren’t entirely self-contained so I’m sure you can see how there’s crossover between these classifications, as well as why there would be multiple ways of classifying them.</p>

<h3 id="morphology" id="morphology">Morphology</h3>

<p>Morphology is the study of the structure and content of word forms. If you love words, morphology is the place for you!</p>

<p>One important concept is that of the morpheme, which is the smallest possible meaningful unit in a language. For example, if we have the word <em>dogs</em>, its morphemes are <em>dog</em> and the suffix <em>s</em>. Free morphemes like <em>dog</em> can function independently, but bound morphemes like <em>s</em> only appear as parts of other words.</p>

<p>Further to that, we have derivational bound morphemes, which change the original word&#39;s meaning or class. For example:</p>
<ul><li>establishment (noun) = establish (verb) + ment</li>
<li>happiness (noun) = happy (adj) + ness</li></ul>

<p>There are also inflectional bound morphemes, which change the tense, mood, or other aspects, but the meaning or class stays the same. For example:</p>
<ul><li>walked = walk + ed</li>
<li>undo = un + do</li>
<li>taller = tall + er</li></ul>

<p>Of course, there&#39;s more ways to make words than simply cobbling pieces together. A few other ways for English include:</p>
<ul><li>alternation: goose –&gt; geese</li>
<li>reduplication: choo-choo, putt-putt, fifty-fifty, win-win</li></ul>

<p>There are many other morphological processes, too!</p>

<p>In NLP, stemming or lemmatization can be considered to be morphological processes. In that situation, we&#39;re typically trying to get the smallest useful part of the word for our situations, not necessarily the base morphemes.</p>

<p>We also have morphological topography, which is a way to classify languages based on how they form words, or their morphological structures. This is important because while my examples above were in English (due to it being the language of this post!), the many languages of the world have many different ways to form words.</p>

<p>Analytic languages are those with an almost 1:1 ratio of morphemes to words. Vietnamese is considered to be an analytic language. There&#39;s also isolating languages (not to be confused with a <em>language isolate</em>, which is a different concept!), which are very related to analytic languages, and for the purpose of this post, you can consider them to be the same.</p>

<p>Then we get into synthetic languages, which affix dependent morphemes to root morphemes to create new words. These can be broken down even further.</p>

<p>Fusional languages are those where the morphemes are not easily distinguishable from themselves. Take this French example of the verb “to like” – aimer – and conjugating it in the first person singular:</p>
<ul><li>present tense: j&#39;aime</li>
<li>imparfait: j&#39;aimais</li>
<li>passé composé: j&#39;ai aimé</li>
<li>passé simple: j&#39;aimai</li></ul>

<p>Not so easy to point out the base morpheme, or even the dependent morphemes, is it? I&#39;ve even chosen a regular verb (it&#39;s one of the first you learn when you&#39;re learning French!) and that&#39;s not counting how it&#39;s conjugated in second or third person. Irregular verbs get even more fun.</p>

<p>Next we have agglutinative languages, where words contain several morphemes – essentially, the words are formed through agglutination, which is the act of adding morphemes to each other without changing the spelling/phonetics. Each morpheme represents a single meaning, and is clearly demarcated. For example, in Japanese, we can have the verb “to eat” – 食べる – and conjugate it:</p>
<ul><li>past tense: 食べた</li>
<li>polite paste tense:　食べました</li>
<li>negative:　食べなかった</li>
<li>polite negative: 食べませんでした</li></ul>

<p>Here we can see that 食べ is the root, た indicates past tense, and polite forms have a ま in them (although Japanese politeness is also outside the scope of this post).</p>

<p>There are also polysynthetic languages, which you can consider to be a language where words are formed that are whole sentences in other languages.</p>

<p>You can also see that languages don’t neatly fall into these categories either. English is typically considered a fusional language, but it has many analytic characteristics. In the French example, we can still mostly see the root morpheme “aim-” and in Japanese, there’s some changing of the morphemes, especially seen in the polite forms.</p>

<h3 id="syntax" id="syntax">Syntax</h3>

<p>Syntax is a very important part of linguistics, but it&#39;s honestly my least favourite part, so I apologize if this section is sparser on details haha. It&#39;s a really deep topic and there are various different grammatical models in the study of syntax, but I&#39;ll only be covering some superficial parts (although this whole thing is a very superficial intro to linguistics anyway!).</p>

<p>Essentially, syntax is the part of linguistics that focuses on the rules and structures of how sentences are constructed – you could consider it to be the “grammar” part of linguistics.</p>

<p>We have various syntactic structures, such as:</p>
<ul><li>parts of speech (nouns, adjectives, prepositions, etc.)</li>
<li>sequence of subject (S), object (O), and verb (V)</li>
<li>agreement</li>
<li>phrase structure</li></ul>

<p>We&#39;re all familiar with the parts of speech, especially because in NLP, we&#39;ll sometimes do part of speech tagging. But what exactly are they? Essentially they&#39;re categories of words and their function in a language.</p>

<p>We also have open classes, which includes nouns and adjectives, which we can compare with closed classes, which includes pronouns and prepositions. The primary difference between the two is that a part of speech in an open class is one that typically accepts new words, but those in closed classes very rarely have items added to them.</p>

<p>Classes also vary between languages. In some languages, there’s no difference between adjectives and adverbs.</p>

<p>One fun part of speech that I particularly like are ideophones! They are words that evoke a sensory perception through their sound. In English, ideophones are less used than in other languages like Japanese. Typically what we’d consider “sound effects” are ideophones – mostly onomatopoeia such as “tick-tock,” “vroom,” or “boing.” However, in Japanese, ideophones are much more common, including ones for smiling [ニコニコ], something sparkling [キラキラ] or even silence [シーン].</p>

<p>Ideophones are closely linked to the linguistic research area of sound symbolism,
which is the idea that sounds, or phonemes, carry meaning. It&#39;s a really cool area of research, in my opinion!</p>

<p>There is also word order in syntax, and that is pretty much what it says on the tin: the correct order for words to be arranged in order to make a grammatical sentence. Consider the following two English sentences:</p>
<ul><li>Iman (subject) baked (verb) bread (object)</li>
<li>*Baked (verb) Iman (subject) bread (object)</li></ul>

<p>The second one is an ungrammatical sentence (denoted by the asterisk), because English is a subject-object-verb (SVO) language. In the world&#39;s languages, approximately 35% are SVO, ~44% are SOV, and ~29% are VSO. The other combinations are very rare.</p>

<p>Word order can be more or less free depending on the language and still be considered “correct” or “grammatical.” For example, not all SVO languages require all sentences to be SVO.</p>

<p>Languages also require agreement to be grammatical, and there are different kinds of agreement.</p>

<p>English requires subject-verb agreement:</p>
<ul><li>he eats cookies</li>
<li>they eat cookies</li></ul>

<p>French requires gender agreement:</p>
<ul><li>il est heureux (he is happy)</li>
<li>elle est heuruese (she is happy)</li></ul>

<p>German requires case agreement:</p>
<ul><li>der gute Mann (the good man – nominative case)</li>
<li>der guten Mann(e)s (of the good man – genitive case)</li></ul>

<p>Cases are a way to categorize certain parts of speech based on their grammatical function within a phrase, clause, or sentence. The nominative case marks the subject of a sentence, while the genitive case marks a word as modifying another word (typically a noun).</p>

<p>Finally, we come to phrase structure. This is one way to explain a language’s syntax – the concept was introduced by Noam Chomsky, a very famous linguist sometimes called “the father of modern linguistics.” Phrase structure breaks down sentences into their constituent parts (also known as syntactic categories) which includes parts of speech and phrasal categories (noun phrase, verb phrase, prepositional phrase, adjective phrase etc.).</p>

<p><img src="https://i.snap.as/B2ZNnmLL.png" alt=""/></p>

<p>This dendrogram/tree structure is one way to represent phrase structure rules. The sentence is also a famous sentence from Chomsky which shows how a sentence can be syntactically sound but meaningless semantically. However, I do have a sentence showing a syntactically and semantically sound sentence...</p>

<p><img src="https://i.snap.as/gmYzCGGG.png" alt=""/></p>

<p>Please look forward to my next talk, <em>English is a Garbage Language</em>.</p>

<p>If you actually want to understand this sentence, <a href="https://en.wikipedia.org/wiki/Buffalo_buffalo_Buffalo_buffalo_buffalo_buffalo_Buffalo_buffalo" rel="nofollow">the Wikipedia article</a> has a pretty good explanation!</p>

<p>Anyway, phrase structure is very important in the history of NLP. This sort of grammar was the basis of many systems in the heyday of symbolic NLP, meaning they were rules based on grammars and grammar theories, like context-free grammar, transformational grammar, or generative grammar. Starting in the 1990’s, we saw this rule-based way of performing NLP start to decline with the advent of statistical methods that we probably are more familiar with. But I’ll talk a bit more about this later.</p>

<h3 id="semantics" id="semantics">Semantics</h3>

<p>You can have semantics in other fields, but in linguistics, it’s concerned with the meanings of words, phrases, sentences, or even larger units.</p>

<p>There&#39;s a lot of different semantic theories and ways to study semantics, but here is a sample of them:</p>

<p>Conceptual semantics aims to provide a characterization of conceptual elements through how a person understands a sentence, or an <em>explanatory semantic representation</em>. “Explanatory” in this case means it deals with the most underlying structure and that it has predictive power, independent of the language.</p>

<p>Conceptual semantics breaks lexical concepts into categories called “semantic primes” or “semantic primitives,” which can be understood as a sort of “syntax of meaning.” They represent words or phrases that can’t be broken down further and their meaning is learned through practice, such as quantifiers like “one,” “two,” or “many.” Through this, we can also see how syntax and semantics are quite related.</p>

<p>Compositional semantics relates to how meanings are determined through the meanings of units and the construction of sentences through syntax rules – essentially, how do sentence meanings arise from word meaning? Take our earlier buffalo sentence, for example – all the words “sound” the same but have different meanings. The composition of the sentence gives us a way to understand it.</p>

<p>Lexical semantics is concerned with the meanings of lexical units and how they correlate to the syntax of a language. Lexical units includes words, affixes, and even compound words or phrases.</p>

<p>One concept in lexical semantics is that of the semantic network. It represents semantic relationships in a network and is a form of knowledge representation.</p>

<p><img src="https://i.snap.as/Ta7ZYZ3L.png" alt=""/></p>

<p>As you might be able to infer from this example, a semantic network is a directed or undirected graph where the vertices represent concepts and the edges represent semantic relations between the concepts. If this sounds familiar, it’s because WordNet is a semantic network, and you may have used that in your NLP before.</p>

<p>But let&#39;s go into the basics of “words mean things” which is kinda the basis of semantics.</p>

<p>If you came across this building, what would you understand this to be?</p>

<p><img src="https://i.snap.as/dmHml7zm.png" alt=""/></p>

<p>Well, the sign says “store” – that&#39;s a building that sells items. And “poutine” – those are fries covered in cheese curds and gravy. So this is probably some sort of establishment that sells poutine!</p>

<p><img src="https://i.snap.as/9t8b9Hm6.jpeg" alt=""/>
<figcaption>Photo ©<a href="https://capitalcurrent.ca/climate-change-remains-amongst-causes-for-concern-for-canadian-maple-farmers-despite-record-breaking-2019/l" rel="nofollow">Mark Bahensky</a></figcaption>
How would you feel if you went in and there was maple syrup? And nothing is being sold, it’s just maple syrup all over the shelves for you to look at. You&#39;d be pretty confused and concerned that I didn’t even know how to name things, right?</p>

<p><img src="https://i.snap.as/u1WJ27fz.png" alt=""/></p>

<p>Anyway, it’s kind of like this typographic attack where a model misclassifies the picture of an apple as an iPod, which I find absolutely hilarious.</p>

<p>This also leads into our next topic:</p>

<h3 id="pragmatics" id="pragmatics">Pragmatics</h3>

<p>Pragmatics can be understood to be the meaning of language in context. The key difference between this and semantics is that semantics is concerned with what the sentence itself means, while pragmatics takes the overall context of the utterance, including the surrounding sentences, the culture, the tone, etc.</p>

<p>Here&#39;s a quick example:</p>

<blockquote><p>Q: Can I go the the bathroom?</p></blockquote>

<p>The question here asks, based on our shared understanding of English, for permission to go to the bathroom. We can answer it thusly:</p>

<blockquote><p>A1: Yes, go ahead.</p></blockquote>

<p>This answer understands the request for permission implicitly – it’s how we phrase questions in English, after all. But let&#39;s consider a different, equally correct answer:</p>

<blockquote><p>A2: I don&#39;t know, <em>can</em> you?</p></blockquote>

<p>This decides to interpret the question willfully obtusely, as in “is it physically possible for me to go to the bathroom.”</p>

<p>Pragmatic rules are rarely noticed, but when they’re broken like this, it’s quite obvious, and can also be quite frustrating and obnoxious.</p>

<p>They also enable us to understand ambiguous sentences. Take this sentence for example:</p>

<blockquote><p>I&#39;m going to the bank.</p></blockquote>

<p>I did this presentation internally to my colleagues, and look at that, we all work at a financial institution! So because that is our shared context, everyone would tend to assume I mean a bank branch – some sort of building that contains ATMs, tellers, safety deposit boxes, financial advisors... However, if I were standing next to a river, a location where I find myself surprising frequently, I might actually mean the river bank.</p>

<p>Code switching is also another concept covered by pragmatics, and one can code switch between two languages, or between two registers or forms of a single language. This “switch” is when the two languages or forms are mixed together in the same conversation or sentence.</p>

<p>As a personal example, when I’m speaking to my family, I’ll code switch when referring to my paternal grandparents – “I’m going to see 嫲嫲 and 爺爺 tomorrow.” I’ll also code-switch when speaking to my grandparents, mostly because my Cantonese is really bad. They’ll ask me a question in Cantonese, “<ruby>食咗飯未呀?<rt>Have you eaten yet?</rt></ruby>” I’ll respond with something like, “<ruby>我食咗<rt>I&#39;ve eaten</rt></ruby> steak <ruby>同<rt>and</rt></ruby> mashed potato.” Steak has a Cantonese word – 牛扒– and so does mashed potatoes – 薯蓉 – but I think of western food in my western language. You may have noticed that in my code switched sentence, I used the singular form of mashed potatoes. That’s because Cantonese is a language that pluralizes words differently than English, so even when I code switch into English, I’ll use similar grammatical rules as Cantonese.</p>

<p>A more common form of code-switching for the monoglots among us is between different registers, forms, or dialects. We all code switch in this way – I certainly speak differently to my work colleagues than I do with my friends, for example. As work colleagues, I’ll probably say something like, “hey, I made cookies, they’re on the usual table,” while with friends, I might say something like “eat your damn cookies and be happy about it.” You can hopefully see the difference between my phrasing, even though the meaning of both sentences are roughly equivalent!</p>

<p>If you remember back when I was talking about accents, I mentioned that they’re related to dialects but not necessarily. You might have inferred here that dialects are more about word choice than the actual way that sounds are produced, although there are also pronunciation differences with dialects. As with accents, everyone speaks with their own dialect (also known as an idiolect) and no one lacks a dialect, no matter what you may be told.</p>

<p>There’s a certain social prestige if you speak with a dialect that’s considered neutral or “standard,” much like how being “accentless” confers a certain prestige. I&#39;m no social scientist, either, but “professional” settings have expectations of which dialects are acceptable and which are not, which I imagine contributes to the prestige of certain dialects.</p>

<p>This all brings me to my favourite topic: translation and translation theory! I&#39;m bundling this into the pragmatics section, because as I hope I&#39;ll be able to illustrate, translation depends heavily on context!</p>

<p>Consider the following media or situations where translation might be necessary:</p>
<ul><li>medical documents</li>
<li>simultaneous interpretation at the UN</li>
<li>Oscar-award winning movie subtitles</li>
<li>Brooklyn 99 dubbing</li></ul>

<p>The way you would translate for each of these situations would be different – you could translate all of these the same way, but it’d be pretty weird to get a medical document in the same style as a comedy.</p>

<p>I’d also like to point out here that my third point is ambiguous! Are the subtitles award winning? Is the movie? Who knows! Welcome to pragmatics!</p>

<p>I’ll cover two theories that are important in translation, polysystem theory, and equivalence theory but of course, this is not an exhaustive and in-depth exploration of these topics. Also, I’m not an expert, I just like this stuff. There’s a lot of other ways and theories to approach translation!</p>

<p>So first, equivalence theory – this is something that states that the translation makes the reader of a translation (target reader) understand the same meaning and react the same way as the original language (source reader). But what does this mean in practice?</p>

<p><img src="https://i.snap.as/n82eG33R.png" alt=""/></p>

<p>Consider the Oscar-award winning movie Parasite. Have you seen it? (I haven’t, but I really should watch it.)</p>

<p>In this scene, the translator changed “Seoul National University” to “Oxford.” <a href="https://www.korea.net/NewsFocus/Culture/view?articleId=171974&amp;pageIndex=1" rel="nofollow">The translator himself said</a>, “The first time I did the translation, I did write out SNU but we ultimately decided to change it because it&#39;s a very funny line, and in order for humor to work, people need to understand it immediately.”</p>

<p>A “direct” translation, keeping the institutions the same, would convey the same meaning, but it wouldn’t have the same immediate emotional response from a viewer. The average English speaker likely isn&#39;t familiar with Korea, and they would more immediately associate ”Oxford” with “prestigious university” than “Seoul National University.” Once you think about it, you could probably understand that SNU is a famous academic institution, but that “once you think about it” is the key here – if the target audience doesn’t understand something in the same amount of time that the source audience does, it is a potential failing of the translation, especially as subtitles have limited time on screen.</p>

<p>Plus it’s often said that “if you need to explain a joke, then it’s not funny.” Now that I’ve explained this joke, I hope it remains funny when you watch Parasite.</p>

<p>For another example, let&#39;s consider Beowulf! This is an Old English poem that’s also one of the most translated pieces of work in the world. It starts with “Hwæt!” and in the 2020 Beowulf translation by Maria Dahvana Headley, it is translated as “Bro!” Other translations have used “Behold!” and “Lo!” and “What ho!” but for a modern translation for modern readers, ”Bro!” provides the sort of immediate equivalence and a more seamless integration into the work (although you certainly can disagree with this choice).</p>

<p>This translation interprets Beowulf as a sort of bragging, over-the-top, urban legend where it’s been embellished so many times over the years. You can consider it kind of like the guy at the bar who always tells his story about the huge fish he caught once – every time you hear it, the fish is bigger than the last time. So this sort of “Bro!” opening provides a very similar emotional feel to a modern reader.</p>

<p>I also am going to present this one image without comment, since I think it&#39;s funny and relevant:</p>

<p><img src="https://i.snap.as/1I6Apwt6.png" alt=""/></p>

<p>Next we have polysystem theory, which is very related to equivalence theory! Essentially, literary works are part of the social, cultural, literary, and historical systems in which they were created, and to translate a work, one must remove it from those source systems and transplant it into the target systems.</p>

<p>So these are all a bunch of nice words, but what does this actually mean? This doesn’t even have to be about different languages, so let’s use some English examples for now.</p>

<p>I say something like, “what kind of cake should I bake?” you might assume that I’m asking for general opinions. However, if I said this at work, with the context of coming to the office and understanding that I brought in baked goods regularly for everyone to eat, you would understand that I’m asking about what my coworkers want to eat next. My point here is that these are systems which that my coworkers would be familiar with – the office is a social/cultural system, and there&#39;s the historical context of previously eating muffins. As a random reader, I had to explain all these things, or “translate” what I meant. This would involve rephrasing my question or adding more context to the question itself, as I’ve done here.</p>

<p>Since I’m talking a lot about context here, we can also talk about high and low context cultures. This is a continuum of how explicit one needs to be when communicating. So when we’re talking about languages, generally English is a low context language because we prefer to have more information up front. You could also characterize a lower context language by how direct it is. Asian languages like Chinese or Japanese tend to be considered higher context because you rely more on shared experiences, traditions, and societal expectations to communicate. In these languages, you can communicate the same amount of information in fewer words.</p>

<p>Even within English-speaking “culture,” we can vary between whether we’re higher or lower context. If you have an “inside joke” with your friends, that’s a higher context! Or, just refer back to my earlier example about my cake.</p>

<p>Also here&#39;s another fun English example.:</p>

<p><img src="https://i.snap.as/xYI79GWf.png" alt=""/>
<figcaption>Comic by <a href="https://twitter.com/thejenkinscomic/status/1351179836602146820" rel="nofollow">The Jenkins</a></figcaption></p>

<blockquote><p>When the violin repeats what the piano has just played, it cannot make the same sounds and it can only approximate the same chords. It can, however, make recognizably the same “music,” the same air. But it can do so only when it is as faithful to the self-logic of the violin as it is to the self-logic of the piano.</p>

<p>Language too is an instrument and each language has its own logic. I believe that the process of rendering from language to language is better conceived as a “transposition” than as a “translation,” for “translation” implies a series of word-for-word equivalents that do not exist across language boundaries any more than piano sounds exist in the violin.</p>

<p>— <cite>John Ciardi (The Inferno, 1954 Translation) </cite></p></blockquote>

<p>I particularly like this quote from a translator of The Inferno, because it’s such a good metaphor for translation and I think that it fits well into polysystem theory.</p>

<p>Polysystem theory also addresses the cultural expectations of a work in its target language. We have certain expectations of how works should be written – poetry reads differently than modern literature reads differently than harlequin romance reads differently than legal document reads differently than marketing brochures. If you translate a fantasy novel in the same way as a divorce proceeding, you’re going to confuse a lot of people.</p>

<p>Essentially, the context and expectations of a target language, with respect to the culture and even the specific target audience, is going to have an effect on your translation. This has come to the fore in English language media because now we are able to get foreign language media almost simultaneously with the source language. <a href="https://theconversation.com/squid-game-why-you-shouldnt-be-too-hard-on-translators-169968" rel="nofollow">This article</a> talks about translation considerations in TV shows and movies and it&#39;s a very good take on what makes a “good” translation.</p>

<p>And since this is technically supposed to be a discussion of linguistics for those of us who work in NLP, let&#39;s talk about machine translation as well!</p>

<p>Machine translation (MTL) can be a helpful tool in translation! But the keywords here are “can” and “tool.” There are uses for machine translation but it&#39;s still limited. I, and (I hope) most machine translation researchers, would advise against using machine translation for everything.</p>

<p>First of all, the language pair matters! When actual translators were asked to evaluate machine translation results, they ranked MTL providers like so:</p>

<table>
<thead>
<tr>
<th><strong>Language pair</strong></th>
<th><strong>1st preference</strong></th>
<th><strong>2nd preference</strong></th>
<th><strong>3rd preference</strong></th>
<th><strong>4th preference</strong></th>
</tr>
</thead>

<tbody>
<tr>
<td>EN =&gt; DE</td>
<td>DeepL</td>
<td>Microsoft</td>
<td>Amazon</td>
<td>Google</td>
</tr>

<tr>
<td>EN =&gt; FR</td>
<td>Microsoft</td>
<td>DeepL</td>
<td>Google</td>
<td>Amazon</td>
</tr>

<tr>
<td>EN =&gt; RU</td>
<td>Google</td>
<td>Amazon</td>
<td>Microsoft</td>
<td>DeepL</td>
</tr>
</tbody>
</table>

<p>Generally the more similar a language pair is to one another, the better results you get. Hopefully that’s self-explanatory with all of the fun linguistics concepts I went over already!</p>

<p>Second of all, the purpose of your translation matters! If you’re going to try and use it for marketing, maybe use a real human. If it’s a low-stakes internal use, yeah I mean maybe, go for it if no one’s gonna complain and it gets the job done.</p>

<p>Thirdly, the source document matters! Is this a literary work? Maybe reconsider – think of all the metaphors that&#39;ll get truly lost in translation. Is this a short instruction manual? Potentially fine, if it has a regular and expected structure, and you&#39;re sure that you have enough training examples for a good result. And I still wouldn&#39;t suggest machine translating an instruction manual for distribution to one&#39;s clients.</p>

<p>So this is a bunch of words to say that machine translation is a tool. So as long as you use it properly, you’re fine. You wouldn&#39;t use a rice cooker in place of a wood chipper, would you?</p>

<p>At the end of the day, translation is difficult even for humans. A machine would struggle to translate a line such as, “your dog looks sick,” but so would a human without appropriate context. Is this the vet? My dog is probably sick in the medical sense. Is this a guy on the street who means my dog looks cool? Is this a person seeing my dog throw up as I’m walking her? Knowing my dog, she ate too much grass because she’s dumb sometimes.</p>

<p>But if you work in AI, machine translation has a lot of cool stuff going on in terms of technology! So I imagine that’s also great. I have no idea about the state of machine translation research but a quick search told me that it sounds cool.</p>

<p>We may think of machine translation as something that’s a sleek and modern field, but its origins can be traced back to the 9th century Arabic cryptography Al-Kindi who developed techniques for systemic language translation.</p>

<p>What we think of for “machine translation” with computers can potentially be said to have started in the 50’s, such as with the Georgetown experiment, which was the first public demonstration of machine translation, where over 60 Russian sentences were translated automatically into English. This used the symbolic methods, like the phrase structure grammar that I talked about earlier.</p>

<p>Then we had the so-called “statistical revolution,” thanks in part to the computing power increase due to Moore’s Law. Many of the initial successes of statistical methods in NLP were in machine translation. These methods include things like decision trees and hidden Markov models, which hopefully sound familiar!</p>

<p>More recently, NLP has increasingly used neural models, especially in the field of machine translation, and that’s where the predominant machine translation research community is right now, although statistical methods are still used!</p>

<h3 id="lessons-for-nlpers" id="lessons-for-nlpers">Lessons for NLPers</h3>

<p>I assembled some quick takeaways for my talk audience, and I think it works better in a talk setting, but here they are anyway.</p>

<h4 id="not-all-nlp-is-text-data" id="not-all-nlp-is-text-data">Not all NLP is text data</h4>

<p>My work group predominantly works with text data, and I imagine many other people who focus on NLP work mostly with text. There’s other groups who work with voice data, and I would love to see how they approach it, because there’s a lot of cool stuff phonologically – but my intuition is that phonetics and phonology isn&#39;t taken into account, and I also suspect the same happens with sign languages. Sign languages are a 3D language involving the space around the person signing and facial expressions and a whole lot of other things. There are all sorts of considerations when you move outside of text data, even computationally, so I think it&#39;s good to keep linguistic concepts in mind.</p>

<p>But I want to re-emphasize that language encompasses spoken word and visual media, so there’s so much to consider and so much research to be done.</p>

<h4 id="preprocessing-results-in-a-loss-of-information" id="preprocessing-results-in-a-loss-of-information">Preprocessing results in a loss of information</h4>

<p>Stemming or lemmatization results in the loss of morphological structure, which in a fusional language like English, contains valuable information. Removing stop words removes syntactic information. Lower-casing all words removes morphological characteristics – think back to that “Buffalo” sentence! Bag of words representation destroys any syntactic structure, creating n-grams can create confusion in the syntactic structure while trying to capture aspects of that structure...</p>

<p>Generally anything that simplifies the way we present language will result in a loss of information. Sometimes we don’t need all this information though! Sometimes it truly is unnecessary in the task we’re doing. But I think it’s good to keep in mind when creating a preprocessing and feature engineering pipeline about what sort of information we do want to keep and what’s truly unnecessary, which is very dependent on both our data and the task we’re working on.</p>

<h4 id="different-languages-are-different" id="different-languages-are-different">Different languages are different</h4>

<p>This is a bit of a dumb point to write out, but I think many people understand multiple languages. Even if you haven’t thought about it, you’re casually aware of the differences in different languages, especially after getting through the rest of this post!</p>

<p>Plus, I&#39;m a Canadian so it&#39;s important for me to note that Canada is officially bilingual. Sooner or later, a Canadian data scientist will come across French in the data. We all have different approaches to dealing with this, but techniques that work on English data won’t necessarily work on French data. And working on a data set that contains both languages has other complexities. French and English are relatively easy to distinguish from each other for a speaker who knows English or French, but a machine doesn’t know either!</p>

<p>Now throw in our increasingly global society with languages that aren’t related to others, like Korean, or those with different writing systems, like Japanese, or with sound features that aren’t produced in the language we’re familiar with, like the tones in Cantonese. And then let’s throw in code switching on top of all of that!</p>

<p>Languages are <em>hard</em>, but that&#39;s also what makes them so fun and interesting.</p>

<h4 id="language-is-complex-but-also-follows-rules" id="language-is-complex-but-also-follows-rules">Language is complex but also follows rules</h4>

<p>Something that always bothered me about “modern” NLP, meaning the statistical and neural methods, was that we don’t encode rules into our models and systems.</p>

<p>However, language follows rules! When we learn a second language, we are taught all of the grammar rules, as well as the various exceptions to these rules. However, nowadays we don’t typically teach the machines these rules. We kind of treat them like children where they learn from implication.</p>

<p>It’s not easy, but if we work with natural language, we should consider these various rules. Doing this requires more specialized knowledge of syntactic structures, morphological topography, and various other concepts. It’s certainly not necessary in every case, and it may not feel “machine learning”-y because it involves rules, and apparently we all hate rule-based systems in DS/ML/AI, but I think a hybrid system would create a more robust model in the end. And there’s actually quite a bit of interest in creating these hybrid systems.</p>

<p>There’s are some researchers who think linguistics and NLP should draw on one another, and one quote that I particularly like is from Tal Linzen, an associate professor of linguistics and data science at NYU:</p>

<blockquote><p>Linguists are best positioned to define the standards of linguistic competence that natural language technology should aspire to.</p></blockquote>

<p>Anyway, I hope this blog post has given you some things to think about, either in your work or in your everyday life! A final reminder that I’m not really an expert, I just know a little bit more than the average person off the street, and I really like languages haha.</p>

<p>Also I know that the majority of this is unsourced, so please don&#39;t use it in any formal settings ahaha. And I definitely cribbed knowledge from places and I didn&#39;t think to note from where, which was totally a mistake.</p>

<p><a href="https://iman.codes/tag:datascience" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">datascience</span></a> <a href="https://iman.codes/tag:nlp" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">nlp</span></a> <a href="https://iman.codes/tag:linguistics" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">linguistics</span></a></p>
]]></content:encoded>
      <guid>https://iman.codes/linguistics-101-for-nlpers</guid>
      <pubDate>Tue, 19 Oct 2021 19:31:49 +0000</pubDate>
    </item>
    <item>
      <title>WiDS 2021 Datathon - Lessons Learned</title>
      <link>https://iman.codes/wids-2021-datathon-lessons-learned?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[Well, I perhaps didn&#39;t do as much as I wanted to after my last post. Life sneaks up on you sometimes, y&#39;know? I had a surprisingly busy mid-Feb till now, and even now I&#39;m more focused on other stuff, both work and personal. The Women in Data Science Conference is long over! But I do have some things I learned and thought it&#39;d be a good to have a final summary post.&#xA;&#xA;!--more--Something that I found was that it was very weird to have my data split by hospital ID. I know that probably happens in other applications, but in my work life, it&#39;d be really weird to have, for example, all the clients in one city in the training data and then all the clients from another city for prediction purposes. I especially find it weird because it&#39;s not like hospital locations change over time (or at least, not quickly!) so I don&#39;t really know why it was split up like this. Location is also a very important factor in health, so that&#39;s why this is my biggest complaint haha.&#xA;&#xA;I also have to say that I&#39;m not a big fan of datathon optimizing towards the best scores - I don&#39;t think this gets us anywhere in real life. Is it really worth tuning parameters for hours for the incremental gain? Or rather, should we be tuning parameters without the input of a subject matter expert? At work, I work on lower-stakes models, but we still work very closely with our business partners, aka the subject matter experts! If I were building a healthcare model, I&#39;d be asking the medical professionals - what&#39;s the risk to a patient of a false positive? A false negative? Do the results even make sense? Can we explain what&#39;s going on in the model?&#xA;&#xA;Perfection (getting the highest scores) also feels so artificial and &#34;school project&#34;-like. I hated this attitude in school and hate it in my professional life too, because good enough is GOOD ENOUGH and perfection is not a good character trait. Perfection is not attainable, and not a true reflection of the messy nature of human lives, so I don&#39;t think we should try to get the &#34;best&#34; models out their either. The effort spent on creating such perfect models could be better spent collecting more data or cleaning the current data or anything to do with the data, which I think would lead to better real-world results rather than an arbitrary number.&#xA;&#xA;I think that the quest for the highest score also leans more towards the more sophisticated techniques, which tend to be less explainable!! In a high-stakes setting like healthcare, I think this is unacceptable. As in my first post, we saw how a completely transparent basic equation discriminated against Blacks and how it took so many years for people to think, &#34;hey wait maybe this is bad actually?&#34; - institutionalizing this in black box models that are difficult to explain don&#39;t help this situation at all!&#xA;&#xA;I suppose all of this (my ranting about getting the Highest Score mostly) may not hold true for research or cutting-edge AI tech companies, but at the end of the day, you still need to sell your product, the model, to an end user who may or may not be as tech-savvy as yourself. I&#39;m always asking, &#34;What are you actually going to do with that model?&#34; At least, that&#39;s my poorly educated opinion, haha.&#xA;&#xA;Also something that I realized when working on this: proper pipelining is so important. I&#39;m still learning to do this properly too, but I didn&#39;t realize how good I had it at work now that we&#39;ve built a more functional pipeline. It&#39;s hard for me to explain but it felt so awkward and clunky to have to read in my train and predict sets and then do all my processing on them, and the code was very messy, being stored all in one notebook. And as a datathon, this work isn&#39;t going to be productionized so there&#39;s no incentive to create a &#34;pipeline.&#34; I did try and write my code to be reusable, but I had no reason to create a functional structure to my code, so it&#39;s just... there.&#xA;&#xA;Anyway, I suppose with all my complaints out of the way, I can talk about the good things I learned haha.&#xA;&#xA;It was interesting to work on healthcare data, although I&#39;m still unsure about someone without a healthcare background doing so. I learned so many random things about diabetes and different measurements just so I could understand what was going on!&#xA;&#xA;I also got to play with the Explainable Boosting Model and the Interpretable ML package. That was pretty fun to noodle around with.&#xA;&#xA;I generally enjoyed working on this data and everything, and I think it was a good experience overall! I think I&#39;m just too focused on making things useful in the real world, haha. It&#39;s a good thing that I work in the industry!&#xA;&#xA;#wids2021 #datascience]]&gt;</description>
      <content:encoded><![CDATA[<p>Well, I perhaps didn&#39;t do as much as I wanted to after my last post. Life sneaks up on you sometimes, y&#39;know? I had a surprisingly busy mid-Feb till now, and even now I&#39;m more focused on other stuff, both work and personal. The Women in Data Science Conference is long over! But I do have some things I learned and thought it&#39;d be a good to have a final summary post.</p>

<p>Something that I found was that it was very weird to have my data split by hospital ID. I know that probably happens in other applications, but in my work life, it&#39;d be really weird to have, for example, all the clients in one city in the training data and then all the clients from another city for prediction purposes. I especially find it weird because it&#39;s not like hospital locations change over time (or at least, not quickly!) so I don&#39;t really know why it was split up like this. Location is also a very important factor in health, so that&#39;s why this is my biggest complaint haha.</p>

<p>I also have to say that I&#39;m not a big fan of datathon optimizing towards the best scores – I don&#39;t think this gets us anywhere in real life. Is it really worth tuning parameters for hours for the incremental gain? Or rather, should we be tuning parameters without the input of a subject matter expert? At work, I work on lower-stakes models, but we still work very closely with our business partners, aka the subject matter experts! If I were building a healthcare model, I&#39;d be asking the medical professionals – what&#39;s the risk to a patient of a false positive? A false negative? Do the results even make sense? Can we explain what&#39;s going on in the model?</p>

<p>Perfection (getting the highest scores) also feels so artificial and “school project”-like. I hated this attitude in school and hate it in my professional life too, because good enough is GOOD ENOUGH and perfection is not a good character trait. Perfection is not attainable, and not a true reflection of the messy nature of human lives, so I don&#39;t think we should try to get the “best” models out their either. The effort spent on creating such perfect models could be better spent collecting more data or cleaning the current data or anything to do with the data, which I think would lead to better real-world results rather than an arbitrary number.</p>

<p>I think that the quest for the highest score also leans more towards the more sophisticated techniques, which tend to be less explainable!! In a high-stakes setting like healthcare, I think this is unacceptable. As in my first post, we saw how a completely transparent basic equation discriminated against Blacks and how it took <em>so many years</em> for people to think, “hey wait maybe this is bad actually?” – institutionalizing this in black box models that are difficult to explain don&#39;t help this situation at all!</p>

<p>I suppose all of this (my ranting about getting the Highest Score mostly) may not hold true for research or cutting-edge AI tech companies, but at the end of the day, you still need to sell your product, the model, to an end user who may or may not be as tech-savvy as yourself. I&#39;m always asking, “What are you actually going to do with that model?” At least, that&#39;s my poorly educated opinion, haha.</p>

<p>Also something that I realized when working on this: proper pipelining is so important. I&#39;m still learning to do this properly too, but I didn&#39;t realize how good I had it at work now that we&#39;ve built a more functional pipeline. It&#39;s hard for me to explain but it felt so awkward and clunky to have to read in my train and predict sets and then do all my processing on them, and the code was very messy, being stored all in one notebook. And as a datathon, this work isn&#39;t going to be productionized so there&#39;s no incentive to create a “pipeline.” I did try and write my code to be reusable, but I had no reason to create a functional structure to my code, so it&#39;s just... there.</p>

<p>Anyway, I suppose with all my complaints out of the way, I can talk about the good things I learned haha.</p>

<p>It was interesting to work on healthcare data, although I&#39;m still unsure about someone without a healthcare background doing so. I learned so many random things about diabetes and different measurements just so I could understand what was going on!</p>

<p>I also got to play with the Explainable Boosting Model and the Interpretable ML package. That was pretty fun to noodle around with.</p>

<p>I generally enjoyed working on this data and everything, and I think it was a good experience overall! I think I&#39;m just too focused on making things useful in the real world, haha. It&#39;s a good thing that I work in the industry!</p>

<p><a href="https://iman.codes/tag:wids2021" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">wids2021</span></a> <a href="https://iman.codes/tag:datascience" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">datascience</span></a></p>
]]></content:encoded>
      <guid>https://iman.codes/wids-2021-datathon-lessons-learned</guid>
      <pubDate>Tue, 06 Apr 2021 22:29:15 +0000</pubDate>
    </item>
    <item>
      <title>WiDS Datathon 2021 - Still Going</title>
      <link>https://iman.codes/wids-datathon-2021-still-going?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[I know I said in my last post that I&#39;d keep the blog updated, so here I am doing just that.&#xA;&#xA;I don&#39;t have too much to say though - I&#39;ve tried a few things that didn&#39;t improve the performance much, but I did try a lot of things that made it worse! Learning from failure is still learning though, haha. &#xA;&#xA;I did find that I preferred using EBM to xgboost, even though xgboost is my go-to at work. Not sure if it&#39;s just because I didn&#39;t really have the patience to do xgboost &#34;properly&#34; in my spare time or not, but hey, if it means I can focus on the things that are important to me, I&#39;m okay with that. Especially since this is something I&#39;m noodling around with when I have the time after work.&#xA;&#xA;(I&#39;ve also not had as much spare time recently since my new desk is finally ready to be picked up, and I&#39;ve had to clean up so much stuff so it&#39;ll actually fit where I want it to. I never realized working from home full-time would mean my place would get so much messier.)&#xA;&#xA;Anyway, some of the things that I tried out:&#xA;&#xA;recalculating BMI from the weight/height - I think I mentioned this in an earlier post but I actually didn&#39;t do it until after my first submission hahaha whoops&#xA;KNN missing value imputation&#xA;binning various numeric continuous variables (e.g. age)&#xA;creating new features from BMI such as an obesity indicator or body fat percentage (type 2 diabetes seems to be linked to obesity)&#xA;&#xA;I&#39;m currently trying to see if there&#39;s a good way to get my hospital IDs back in, since I think location is so important for a geographically diverse dataset. A patient would theoretically be local to the hospital they&#39;re sent to, and the lifestyle of someone in NYC would be different than someone in SoCal would be different than the lifestyle of an Albertan, and that affects disease incidence!&#xA;&#xA;But we&#39;ll see how that goes haha.&#xA;&#xA;#wids2021 #datascience]]&gt;</description>
      <content:encoded><![CDATA[<p>I know I said in my last post that I&#39;d keep the blog updated, so here I am doing just that.</p>

<p>I don&#39;t have too much to say though – I&#39;ve tried a few things that didn&#39;t improve the performance much, but I did try a lot of things that made it worse! Learning from failure is still learning though, haha.</p>

<p>I did find that I preferred using EBM to xgboost, even though xgboost is my go-to at work. Not sure if it&#39;s just because I didn&#39;t really have the patience to do xgboost “properly” in my spare time or not, but hey, if it means I can focus on the things that are important to me, I&#39;m okay with that. Especially since this is something I&#39;m noodling around with when I have the time after work.</p>

<p>(I&#39;ve also not had as much spare time recently since my new desk is finally ready to be picked up, and I&#39;ve had to clean up so much stuff so it&#39;ll actually fit where I want it to. I never realized working from home full-time would mean my place would get so much <em>messier</em>.)</p>

<p>Anyway, some of the things that I tried out:</p>
<ul><li>recalculating BMI from the weight/height – I think I mentioned this in an earlier post but I actually didn&#39;t do it until after my first submission hahaha whoops</li>
<li>KNN missing value imputation</li>
<li>binning various numeric continuous variables (e.g. age)</li>
<li>creating new features from BMI such as an obesity indicator or body fat percentage (type 2 diabetes seems to be linked to obesity)</li></ul>

<p>I&#39;m currently trying to see if there&#39;s a good way to get my hospital IDs back in, since I think location is so important for a geographically diverse dataset. A patient would theoretically be local to the hospital they&#39;re sent to, and the lifestyle of someone in NYC would be different than someone in SoCal would be different than the lifestyle of an Albertan, and that affects disease incidence!</p>

<p>But we&#39;ll see how that goes haha.</p>

<p><a href="https://iman.codes/tag:wids2021" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">wids2021</span></a> <a href="https://iman.codes/tag:datascience" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">datascience</span></a></p>
]]></content:encoded>
      <guid>https://iman.codes/wids-datathon-2021-still-going</guid>
      <pubDate>Sun, 07 Feb 2021 16:37:33 +0000</pubDate>
    </item>
    <item>
      <title>WiDS 2021 Datathon - Generating the Submission</title>
      <link>https://iman.codes/wids-2021-datathon-generating-the-submission?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[Not sure what to say here. I shoved everything into a notebook and trained a model with all the work that I did, and then generated a submission file!&#xA;&#xA;For reference, here&#39;s my final model performance:&#xA;&#xA;Final Model Performance&#xA;&#xA;(I want to note that hospital ID made such a big difference in the performance of my model, and having to drop that column was such a loss for me! I&#39;m so disappointed that the train and predict sets were split in this manner!)&#xA;&#xA;Anyway, my first submission to the datathon gave me an AUC of 0.83715. In datathon terms, I&#39;m ranked 207 at the time of submission! Which is actually kinda good for a first pass. In the real world, I&#39;d probably be pretty happy with this haha. I&#39;d move to comparing the true/false positives/negatives since this is for healthcare, and there are probably more serious implications of false negatives! In the real world, this is also the point where I&#39;d talk to the subject matter expert (probably a doctor) about the results and ask them if it makes sense.&#xA;&#xA;Global feature importance for final model&#xA;&#xA;That&#39;s where the explainable model comes in. At work, I&#39;ve used SHAP which is quite similar, but it&#39;s explaining the model after the fact. It&#39;s still better than, &#34;well, that&#39;s what the model learned from the data,&#34; though, haha. This is where we can go through what the model learned overall, as well as a few randomly selected patients, to see if everything makes sense from an expert&#39;s point of view. At work, we went even further to discuss the implications of our results on clients and to analyze what, if anything, our work meant to their work.&#xA;&#xA;Then, if everyone&#39;s satisfied with the work, I&#39;d move towards putting this model into production, so that it can benefit more people. The results would be proven to be useful and coherent, so then we could move towards getting the results into people&#39;s hands. I suppose in this case, it&#39;d be nurses who input various patient values into the model to see if the patient may be diabetic, allowing them to adjust care if needed.&#xA;&#xA;But since this is a datathon and not the real world, I&#39;m going to continue to finagle with this data and modelling. I got to play a bit with InterpretML and the EBM, so I&#39;m going to go to back and try to squeeze all that extra juice out to see how high I can get into the rankings haha. This probably will involve me using good ol&#39; xgboost, which at least can be explained after the fact with some ease. I may also go back to do some more feature cleaning or engineering or even see if I have the patience to do the imputation methods I didn&#39;t want to wait for earlier haha.&#xA;&#xA;I&#39;ll keep the blog updated with my progress!&#xA;&#xA;#datascience #wids2021]]&gt;</description>
      <content:encoded><![CDATA[<p>Not sure what to say here. I shoved everything into a notebook and trained a model with all the work that I did, and then generated a submission file!</p>

<p>For reference, here&#39;s my final model performance:</p>

<p><img src="https://i.snap.as/zfLpGiu4.png" alt="Final Model Performance"/></p>

<p>(I want to note that hospital ID made such a big difference in the performance of my model, and having to drop that column was such a loss for me! I&#39;m so disappointed that the train and predict sets were split in this manner!)</p>

<p>Anyway, my first submission to the datathon gave me an AUC of 0.83715. In datathon terms, I&#39;m ranked 207 at the time of submission! Which is actually kinda good for a first pass. In the real world, I&#39;d probably be pretty happy with this haha. I&#39;d move to comparing the true/false positives/negatives since this is for healthcare, and there are probably more serious implications of false negatives! In the real world, this is also the point where I&#39;d talk to the subject matter expert (probably a doctor) about the results and ask them if it makes sense.</p>

<p><img src="https://i.snap.as/yOeNJNgb.png" alt="Global feature importance for final model"/></p>

<p>That&#39;s where the explainable model comes in. At work, I&#39;ve used SHAP which is quite similar, but it&#39;s explaining the model after the fact. It&#39;s still better than, “well, that&#39;s what the model learned from the data,” though, haha. This is where we can go through what the model learned overall, as well as a few randomly selected patients, to see if everything makes sense from an expert&#39;s point of view. At work, we went even further to discuss the implications of our results on clients and to analyze what, if anything, our work meant to their work.</p>

<p>Then, if everyone&#39;s satisfied with the work, I&#39;d move towards putting this model into production, so that it can benefit more people. The results would be proven to be useful and coherent, so then we could move towards getting the results into people&#39;s hands. I suppose in this case, it&#39;d be nurses who input various patient values into the model to see if the patient may be diabetic, allowing them to adjust care if needed.</p>

<p>But since this is a datathon and not the real world, I&#39;m going to continue to finagle with this data and modelling. I got to play a bit with InterpretML and the EBM, so I&#39;m going to go to back and try to squeeze all that extra juice out to see how high I can get into the rankings haha. This probably will involve me using good ol&#39; xgboost, which at least can be explained after the fact with some ease. I may also go back to do some more feature cleaning or engineering or even see if I have the patience to do the imputation methods I didn&#39;t want to wait for earlier haha.</p>

<p>I&#39;ll keep the blog updated with my progress!</p>

<p><a href="https://iman.codes/tag:datascience" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">datascience</span></a> <a href="https://iman.codes/tag:wids2021" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">wids2021</span></a></p>
]]></content:encoded>
      <guid>https://iman.codes/wids-2021-datathon-generating-the-submission</guid>
      <pubDate>Sat, 30 Jan 2021 22:48:10 +0000</pubDate>
    </item>
    <item>
      <title>WiDS Datathon 2021 - Hyperparameter Tuning</title>
      <link>https://iman.codes/wids-datathon-2021-hyperparameter-tuning?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[This is a really short post since I didn&#39;t actually tune too many hyperparameters of the Explainable Boosting Model. In fact, I don&#39;t think there were actually too many that I wanted to tune anyway haha. Plus, hyperparameter tuning in an explainable model felt weird to me, but I didn&#39;t get much sleep last night so my words aren&#39;t great right now haha.&#xA;&#xA;Anyway, I used Bayesian Optimization to tune the minimum samples in a leaf as well as the maximum leaves. I didn&#39;t run it too much, and then I got something that gave me a slightly higher AUC! Huzzah!&#xA;&#xA;It&#39;s convenient because I also had this tweet retweeted onto my timeline today - it feels so true that initial data prep has much more of a difference on how the model performs than parameter tuning or even picking more &#34;sophisticated&#34; models.&#xA;&#xA;I have a draft post going that I&#39;ll clean up and post once this is all done about &#34;lessons learned&#34; since I have so many thoughts about this that don&#39;t belong in my nice little &#34;workflow&#34; type posts haha. I&#39;ve realized that there&#39;s a pretty big difference between a datathon to get perfection vs how I work in the real world, after all.&#xA;&#xA;#datascience #wids2021]]&gt;</description>
      <content:encoded><![CDATA[<p>This is a really short post since I didn&#39;t actually tune too many hyperparameters of the Explainable Boosting Model. In fact, I don&#39;t think there were actually too many that I wanted to tune anyway haha. Plus, hyperparameter tuning in an explainable model felt weird to me, but I didn&#39;t get much sleep last night so my words aren&#39;t great right now haha.</p>

<p>Anyway, I used Bayesian Optimization to tune the minimum samples in a leaf as well as the maximum leaves. I didn&#39;t run it too much, and then I got something that gave me a slightly higher AUC! Huzzah!</p>

<p>It&#39;s convenient because I also had <a href="https://twitter.com/fchollet/status/1353422914071142400" rel="nofollow">this tweet</a> retweeted onto my timeline today – it feels so true that initial data prep has much more of a difference on how the model performs than parameter tuning or even picking more “sophisticated” models.</p>

<p>I have a draft post going that I&#39;ll clean up and post once this is all done about “lessons learned” since I have so many thoughts about this that don&#39;t belong in my nice little “workflow” type posts haha. I&#39;ve realized that there&#39;s a pretty big difference between a datathon to get perfection vs how I work in the real world, after all.</p>

<p><a href="https://iman.codes/tag:datascience" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">datascience</span></a> <a href="https://iman.codes/tag:wids2021" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">wids2021</span></a></p>
]]></content:encoded>
      <guid>https://iman.codes/wids-datathon-2021-hyperparameter-tuning</guid>
      <pubDate>Sat, 30 Jan 2021 02:25:31 +0000</pubDate>
    </item>
    <item>
      <title>WiDS Datathon 2021 - Feature Selection</title>
      <link>https://iman.codes/wids-datathon-2021-feature-selection?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[So, now that I&#39;ve done the initial work in exploring the data and some data cleaning/preprocessing, it&#39;s time to actually do modelling type things. Not that I&#39;ve been skimping on modelling, but it&#39;s the Serious Modelling now!&#xA;&#xA;First of all, I&#39;ve simply been tossing all the features into a model and hoping for the best. However, we have a lot of features in here, and I&#39;m not sure if it&#39;s all relevant information! In fact, I&#39;m pretty sure a doctor might not know if it&#39;s relevant, unless it&#39;s something like glucose which is key to diagnosing diabetes. The beauty of machine learning is that it&#39;s supposed to learn and reveal those unknown relationships and patterns that humans can&#39;t spot.&#xA;&#xA;But, that means there&#39;s probably a lot of noise in this data. Do we really need to keep some of those other disease indicators? Who knows! Not me. But that&#39;s why we do feature selection - we can remove the features that seem to be making the performance worse, or at least seem to be irrelevant.&#xA;&#xA;I&#39;m going to use Boruta for this. It was originally implemented in R but is available in Python too. The gist of it, as I understand it, is that Boruta pits &#34;shadow features&#34; against the actual features, and if the shadow features are more important than the true features, it means the actual ones aren&#39;t as useful. These shadow features are the true features but randomized. Boruta also runs iteratively, and each time a true feature has a higher importance than a shadow feature, Boruta becomes more and more confident that it&#39;s a relevant feature.&#xA;&#xA;I probably didn&#39;t explain that very well, but hopefully I got the point across... there are much better articles out there that go into how it works haha. I&#39;m just here to use it! &#xA;&#xA;I did end up having to one-hot encode my categorical variables for this, since Boruta uses a Random Forest base (or rather, any tree-based model - I&#39;ve used it with xgboost at work, too). &#xA;&#xA;Not much to say here except I let it run for 100 iterations and in the end, I got 153 confirmed features, 50 rejected features, and 5 tentative features. Which is great! Now I know what to drop and what to keep. By the way, tentative features means that Boruta isn&#39;t quite sure if they&#39;re relevant or not, so then it&#39;s up to the data scientist. In my case, 3 of the 5 were pairs of a min/max, so I put those with their accepted or rejected counterparts. The final ones were first hour bilirubin, which were like almost 90% missing, so I discarded that. Finally, some categoricals were accepted and some were not. I&#39;m on the fence about whether to keep all of them, or to simply take the informative ones. I&#39;ll think about it and come back to it later, I guess.&#xA;&#xA;#datascience #wids2021 ]]&gt;</description>
      <content:encoded><![CDATA[<p>So, now that I&#39;ve done the initial work in exploring the data and some data cleaning/preprocessing, it&#39;s time to actually do modelling type things. Not that I&#39;ve been skimping on modelling, but it&#39;s the Serious Modelling now!</p>

<p>First of all, I&#39;ve simply been tossing all the features into a model and hoping for the best. However, we have a lot of features in here, and I&#39;m not sure if it&#39;s all relevant information! In fact, I&#39;m pretty sure a doctor might not know if it&#39;s relevant, unless it&#39;s something like glucose which is key to diagnosing diabetes. The beauty of machine learning is that it&#39;s supposed to learn and reveal those unknown relationships and patterns that humans can&#39;t spot.</p>

<p>But, that means there&#39;s probably a lot of noise in this data. Do we really need to keep some of those other disease indicators? Who knows! Not me. But that&#39;s why we do feature selection – we can remove the features that seem to be making the performance worse, or at least seem to be irrelevant.</p>

<p>I&#39;m going to use <a href="https://www.jstatsoft.org/article/view/v036i11" rel="nofollow">Boruta</a> for this. It was originally implemented in R but is available in Python too. The gist of it, as I understand it, is that Boruta pits “shadow features” against the actual features, and if the shadow features are more important than the true features, it means the actual ones aren&#39;t as useful. These shadow features are the true features but randomized. Boruta also runs iteratively, and each time a true feature has a higher importance than a shadow feature, Boruta becomes more and more confident that it&#39;s a relevant feature.</p>

<p>I probably didn&#39;t explain that very well, but hopefully I got the point across... there are much better articles out there that go into how it works haha. I&#39;m just here to use it!</p>

<p>I did end up having to one-hot encode my categorical variables for this, since Boruta uses a Random Forest base (or rather, any tree-based model – I&#39;ve used it with xgboost at work, too).</p>

<p>Not much to say here except I let it run for 100 iterations and in the end, I got 153 confirmed features, 50 rejected features, and 5 tentative features. Which is great! Now I know what to drop and what to keep. By the way, tentative features means that Boruta isn&#39;t quite sure if they&#39;re relevant or not, so then it&#39;s up to the data scientist. In my case, 3 of the 5 were pairs of a min/max, so I put those with their accepted or rejected counterparts. The final ones were first hour bilirubin, which were like almost 90% missing, so I discarded that. Finally, some categoricals were accepted and some were not. I&#39;m on the fence about whether to keep all of them, or to simply take the informative ones. I&#39;ll think about it and come back to it later, I guess.</p>

<p><a href="https://iman.codes/tag:datascience" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">datascience</span></a> <a href="https://iman.codes/tag:wids2021" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">wids2021</span></a></p>
]]></content:encoded>
      <guid>https://iman.codes/wids-datathon-2021-feature-selection</guid>
      <pubDate>Fri, 29 Jan 2021 20:24:20 +0000</pubDate>
    </item>
    <item>
      <title>WiDS Datathon 2021 - Preprocessing</title>
      <link>https://iman.codes/wids-datathon-2021-preprocessing?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[I had a lot of grand plans for preprocessing data. And then I remembered that I&#39;m using my tiny little Surface Pro.&#xA;&#xA;Anyway, I did do some stuff here, and I did a bunch of research (aka googling terms and reading papers), so I guess it wasn&#39;t all a loss haha.&#xA;&#xA;I don&#39;t actually get to do too much of this at work. Or rather, the data I work with is very different than the datathon dataset, so I don&#39;t use the techniques here, since it wouldn&#39;t be appropriate. So it was kind of fun to do something I hadn&#39;t done in a while!&#xA;&#xA;!--more--The first thing I wanted to do was fix up some of the categorical variables. Luckily, the Explainable Boosting Model takes categorical features in directly, so I mostly had to clean up the missing values. Some, like ethnicity, already had an &#34;Other/Unknown&#34; category, so that was an easy fix! Others, like gender, did not. &#xA;&#xA;For this situation, I kind of just... shoved everything into an &#34;other&#34; column. Not that I didn&#39;t want to impute this data, but the only two categorical columns with missing values were gender and ICU admit source. I wish I had doctor knowledge for the latter, and the former - well, I figured if it&#39;s missing, it might be for a reason? I won&#39;t get into gender discussion, and there&#39;s the whole thing where the data dictionary says the gender here is the &#34;genotypical sex&#34; (in which case, why not name the column that?) - but regardless, there weren&#39;t that many missing and I figured it&#39;d be safest (patient-wise) to keep it as unknown.&#xA;&#xA;Also, in general, I&#39;m kind of uncomfortable imputing medical information. To me it&#39;s kind of weird... especially since some of the columns here are like 80-90% missing! Is it really worth keeping if you&#39;re going to train on like 90% made-up information?&#xA;&#xA;Of course, I&#39;m not the only one with this issue, so I did look up a couple papers on how others imputed medical data and how it worked out for them. In this paper, they say:&#xA;&#xA;&#34;In cases where it is not possible to have the complete-case dataset, researchers  should be aware of this potential impact, use different imputation methods for  predictive modeling, and discuss the resulting interpretations with medical experts or compare to the medical knowledge when choosing the imputation method that yields the most reasonable interpretations.&#34;&#xA;&#xA;Which honestly, yes, if I were working on this in the real world, I would absolutely be consulting with an actual expert on what&#39;s reasonable here. &#xA;&#xA;I also came across A Safe-Region Imputation Method for Handling Medical Data with Missing Values by Shu-Fen Huang and Ching-Hsue Cheng. Their method sounded pretty reasonable and had good results, and I really wanted to try it out, but uh. Let&#39;s be honest here. I&#39;m not smart enough to implement this, especially not if I&#39;m only working on this for a couple hours after work.&#xA;&#xA;So those two papers led me to want to try KNN and missForest, but uh. Then I tried running the code. And it turns out I also don&#39;t have the patience to actually have it run on my Surface Pro, because it kept going to sleep while I was trying to run things. I gave up on this train of thought, which is unfortunate because I did want to compare things. Ah well.&#xA;&#xA;Bonus - now I don&#39;t need to one-hot encode my categoricals?&#xA;&#xA;Anyway, what I did instead was fill in the missing values from least to most missing with the mean or median and if there was an improvement to the AUC, I kept it and moved to the next feature.&#xA;&#xA;But first, going back to categoricals, I also wanted to collapse the hospital IDs, as I said in my exploration post. I came across this paper and wanted to try it out. I&#39;m ... probably doing it incorrectly since I don&#39;t want to dedicate too much time to it, but I thought I&#39;d give it a try anyway.&#xA;&#xA;The key sentence here is &#34;...only urban districts are used as categorical predictor in a regression model to  explain the monthly  rent, and districts are potentially fused (without further restrictions)...&#34; - so I took the hospital IDs, one-hot encoded them, and then fit them to lasso and plotted out the path.&#xA;&#xA;It worked out, kinda!&#xA;&#xA;Hospital ID coefficient paths (LASSO)&#xA;&#xA;Emphasis on the kinda.&#xA;&#xA;Anyway, I thought I&#39;d bin up these coefficients to see how to collapse the hospital IDs, since I clearly wouldn&#39;t be able to do it by looking at the paths haha.&#xA;&#xA;Here&#39;s a few of my bin attempts, in histogram form:&#xA;&#xA;Hospital ID - 20 bins&#xA;&#xA;Hospital ID - 50 bins&#xA;&#xA;Hospital ID - 0.025 bin size&#xA;&#xA;Hospital ID - 0.05 bin size&#xA;&#xA;(Ignore that I&#39;m bad at labelling my plots - the bottom two are actually 0.025 and 0.05 respectively)&#xA;&#xA;Anyway, based on these, I decided to go with bin sizes of 0.025. It kind of seemed the most reasonable!&#xA;&#xA;So I mapped these bin assignments back to the hospital ID (made a new column called &#34;hospitalbin&#34; and dropped &#34;hospitalid&#34; essentially) and then trained a new &#34;baseline&#34; model to see how that affected the AUC. I also made sure all my categoricals were being treated as categoricals instead of continuous.&#xA;&#xA;(Also, I considered binning age, but I like keeping age as a continuous variable for the most part - I think this is a Me thing, and I may do it later to see if I can get improvements in the AUC for generating actual predictions).&#xA;&#xA;Oh - and in this whole process, I also discovered that I could drop ICU ID - it&#39;s linked to specific hospitals, and covered by the ICU Type column. Just wanted to mention it for my own sake.&#xA;&#xA;Baseline model performance with Hospital IDs binned&#xA;&#xA;And would you look at that - I already get a slight improvement over the &#34;just shove everything in&#34; model shown in the last post! That had an AUC of 0.8567 for reference.&#xA;&#xA;Feature importance for baseline binned model&#xA;&#xA;Plus we can even see here that hospital bins are important! Woo! Go team! Feature engineering isn&#39;t a lie!&#xA;&#xA;The unfortunate thing about this though, is that the submission set uses completely different hospital IDs so this work amounted to nothing, whoops. But hey, it would&#39;ve been nice to use it for a proxy for location!&#xA;&#xA;So then I continued onto doing my whole &#34;mean or median or 0s&#34; missing value imputation test run. I only did it this long and convoluted way because, well, I have time, I wasn&#39;t doing the fancy methods I actually wanted to try out, and I might as well do something that I wouldn&#39;t do at work. At work, all the missing values are 0&#39;s because I work with financial data - if a client doesn&#39;t have a product, it&#39;ll usually be a missing value, and that&#39;s definitely a 0! Although it&#39;d be nice if someone imputed me some more money into my bank account some days hahaha.&#xA;&#xA;It took a while to run (yay, loops!) but I did it so it regularly told me what was going on so I didn&#39;t get frustrated with it haha. I won&#39;t share it since it&#39;s kinda boring and probably not very important to see. I also cleaned it up a bit - if a min value was dropped but the corresponding max value used median, then I set both of them to be median.&#xA;&#xA;Oh, and one last thing that I did - I checked to make sure the min values were actually smaller than the max values, and if not, I swapped them. I got the idea from the 3rd place solution notebook in the 2020 WiDS Datathon, although they did it slightly differently (filled with NA if the min value was smaller than the max).&#xA;&#xA;After all this work - there wasn&#39;t even an improvement in the AUC. I won&#39;t show you, and it wasn&#39;t that bad, but it wasn&#39;t an increase haha. But that&#39;s what future steps are for haha.&#xA;&#xA;#datascience #wids2021]]&gt;</description>
      <content:encoded><![CDATA[<p>I had a lot of grand plans for preprocessing data. And then I remembered that I&#39;m using my tiny little Surface Pro.</p>

<p>Anyway, I <em>did</em> do some stuff here, and I did a bunch of research (aka googling terms and reading papers), so I guess it wasn&#39;t all a loss haha.</p>

<p>I don&#39;t actually get to do too much of this at work. Or rather, the data I work with is very different than the datathon dataset, so I don&#39;t use the techniques here, since it wouldn&#39;t be appropriate. So it was kind of fun to do something I hadn&#39;t done in a while!</p>

<p>The first thing I wanted to do was fix up some of the categorical variables. Luckily, the Explainable Boosting Model takes categorical features in directly, so I mostly had to clean up the missing values. Some, like ethnicity, already had an “Other/Unknown” category, so that was an easy fix! Others, like gender, did not.</p>

<p>For this situation, I kind of just... shoved everything into an “other” column. Not that I didn&#39;t want to impute this data, but the only two categorical columns with missing values were gender and ICU admit source. I wish I had doctor knowledge for the latter, and the former – well, I figured if it&#39;s missing, it might be for a reason? I won&#39;t get into gender discussion, and there&#39;s the whole thing where the data dictionary says the gender here is the “genotypical sex” (in which case, why not name the column that?) – but regardless, there weren&#39;t that many missing and I figured it&#39;d be safest (patient-wise) to keep it as unknown.</p>

<p>Also, in general, I&#39;m kind of uncomfortable imputing medical information. To me it&#39;s kind of weird... especially since some of the columns here are like 80-90% missing! Is it really worth keeping if you&#39;re going to train on like 90% made-up information?</p>

<p>Of course, I&#39;m not the only one with this issue, so I did look up a couple papers on how others imputed medical data and how it worked out for them. In <a href="https://www.medrxiv.org/content/10.1101/2020.06.06.20124347v1.full.pdf" rel="nofollow">this paper</a>, they say:</p>

<p>“In cases where it is not possible to have the complete-case dataset, researchers  should be aware of this potential impact, use different imputation methods for  predictive modeling, and discuss the resulting interpretations with medical experts or compare to the medical knowledge when choosing the imputation method that yields the most reasonable interpretations.”</p>

<p>Which honestly, yes, if I were working on this in the real world, I would absolutely be consulting with an actual expert on what&#39;s reasonable here.</p>

<p>I also came across <a href="https://www.mdpi.com/2073-8994/12/11/1792/pdf" rel="nofollow"><em>A Safe-Region Imputation Method for Handling Medical Data with Missing Values</em></a> by Shu-Fen Huang and Ching-Hsue Cheng. Their method sounded pretty reasonable and had good results, and I really wanted to try it out, but uh. Let&#39;s be honest here. I&#39;m not smart enough to implement this, especially not if I&#39;m only working on this for a couple hours after work.</p>

<p>So those two papers led me to want to try KNN and missForest, but uh. Then I tried running the code. And it turns out I also don&#39;t have the patience to actually have it run on my Surface Pro, because it kept going to sleep while I was trying to run things. I gave up on this train of thought, which is unfortunate because I did want to compare things. Ah well.</p>

<p>Bonus – now I don&#39;t need to one-hot encode my categoricals?</p>

<p>Anyway, what I did instead was fill in the missing values from least to most missing with the mean or median and if there was an improvement to the AUC, I kept it and moved to the next feature.</p>

<p>But first, going back to categoricals, I also wanted to collapse the hospital IDs, as I said in my exploration post. I came across <a href="https://projecteuclid.org/euclid.aoas/1294167814" rel="nofollow">this paper</a> and wanted to try it out. I&#39;m ... probably doing it incorrectly since I don&#39;t want to dedicate too much time to it, but I thought I&#39;d give it a try anyway.</p>

<p>The key sentence here is “...only urban districts are used as categorical predictor in a regression model to  explain the monthly  rent, and districts are potentially fused (without further restrictions)...” – so I took the hospital IDs, one-hot encoded them, and then fit them to lasso and plotted out the path.</p>

<p>It worked out, kinda!</p>

<p><img src="https://i.snap.as/3cx2rIb5.png" alt="Hospital ID coefficient paths (LASSO)"/></p>

<p>Emphasis on the <em>kinda</em>.</p>

<p>Anyway, I thought I&#39;d bin up these coefficients to see how to collapse the hospital IDs, since I clearly wouldn&#39;t be able to do it by looking at the paths haha.</p>

<p>Here&#39;s a few of my bin attempts, in histogram form:</p>

<p><img src="https://i.snap.as/bmCgktXx.png" alt="Hospital ID - 20 bins"/></p>

<p><img src="https://i.snap.as/3WsnQhkf.png" alt="Hospital ID - 50 bins"/></p>

<p><img src="https://i.snap.as/XT6JZuD8.png" alt="Hospital ID - 0.025 bin size"/></p>

<p><img src="https://i.snap.as/CvB0w0Om.png" alt="Hospital ID - 0.05 bin size"/></p>

<p>(Ignore that I&#39;m bad at labelling my plots – the bottom two are actually 0.025 and 0.05 respectively)</p>

<p>Anyway, based on these, I decided to go with bin sizes of 0.025. It kind of seemed the most reasonable!</p>

<p>So I mapped these bin assignments back to the hospital ID (made a new column called “hospital<em>bin” and dropped “hospital</em>id” essentially) and then trained a new “baseline” model to see how that affected the AUC. I also made sure all my categoricals were being treated as categoricals instead of continuous.</p>

<p>(Also, I considered binning age, but I like keeping age as a continuous variable for the most part – I think this is a Me thing, and I may do it later to see if I can get improvements in the AUC for generating actual predictions).</p>

<p>Oh – and in this whole process, I also discovered that I could drop ICU ID – it&#39;s linked to specific hospitals, and covered by the ICU Type column. Just wanted to mention it for my own sake.</p>

<p><img src="https://i.snap.as/3MOuYLb6.png" alt="Baseline model performance with Hospital IDs binned"/></p>

<p>And would you look at that – I already get a slight improvement over the “just shove everything in” model shown in the last post! That had an AUC of 0.8567 for reference.</p>

<p><img src="https://i.snap.as/gKRuMu49.png" alt="Feature importance for baseline binned model"/></p>

<p>Plus we can even see here that hospital bins are important! Woo! Go team! Feature engineering isn&#39;t a lie!</p>

<p>The unfortunate thing about this though, is that the submission set uses completely different hospital IDs so this work amounted to nothing, whoops. But hey, it would&#39;ve been nice to use it for a proxy for location!</p>

<p>So then I continued onto doing my whole “mean or median or 0s” missing value imputation test run. I only did it this long and convoluted way because, well, I have time, I wasn&#39;t doing the fancy methods I actually wanted to try out, and I might as well do something that I wouldn&#39;t do at work. At work, all the missing values are 0&#39;s because I work with financial data – if a client doesn&#39;t have a product, it&#39;ll usually be a missing value, and that&#39;s definitely a 0! Although it&#39;d be nice if someone imputed me some more money into my bank account some days hahaha.</p>

<p>It took a while to run (yay, loops!) but I did it so it regularly told me what was going on so I didn&#39;t get frustrated with it haha. I won&#39;t share it since it&#39;s kinda boring and probably not very important to see. I also cleaned it up a bit – if a min value was dropped but the corresponding max value used median, then I set both of them to be median.</p>

<p>Oh, and one last thing that I did – I checked to make sure the min values were actually smaller than the max values, and if not, I swapped them. I got the idea from the 3rd place solution notebook in the 2020 WiDS Datathon, although they did it slightly differently (filled with NA if the min value was smaller than the max).</p>

<p>After all this work – there wasn&#39;t even an improvement in the AUC. I won&#39;t show you, and it wasn&#39;t that bad, but it wasn&#39;t an increase haha. But that&#39;s what future steps are for haha.</p>

<p><a href="https://iman.codes/tag:datascience" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">datascience</span></a> <a href="https://iman.codes/tag:wids2021" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">wids2021</span></a></p>
]]></content:encoded>
      <guid>https://iman.codes/wids-datathon-2021-preprocessing</guid>
      <pubDate>Thu, 28 Jan 2021 17:45:00 +0000</pubDate>
    </item>
  </channel>
</rss>