{"id":272,"date":"2018-06-04T18:18:30","date_gmt":"2018-06-04T18:18:30","guid":{"rendered":"http:\/\/freedville.com\/blog\/?p=272"},"modified":"2019-04-12T14:01:20","modified_gmt":"2019-04-12T14:01:20","slug":"cognitive-classification-and-what-it-can-do-for-you","status":"publish","type":"post","link":"https:\/\/freedville.com\/blog\/2018\/06\/04\/cognitive-classification-and-what-it-can-do-for-you\/","title":{"rendered":"Cognitive classification and what it can do for you"},"content":{"rendered":"<p><strong>Introduction<\/strong><br \/>\nCognitive technology allows you to process a lot of information quickly &#8211; this is one of the key benefits of the technology. Instead of humans spending hours sorting through information looking for relevant or action-worthy details, cognitive algorithms can surface interesting nuggets in seconds or minutes. In this post I&#8217;ll explore one of the key cognitive techniques &#8211; called &#8216;classification&#8217; &#8211; and various ways you can apply it to your problem domain.<\/p>\n<p><strong>What is classification?<\/strong><br \/>\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/Classification\">Wikipedia defines classification<\/a> as &#8220;a process related to categorization, the process in which ideas and objects are recognized, differentiated, and understood&#8221;.&nbsp; You can think about classification as &#8220;given an input, which output class does it most resemble?&#8221;<\/p>\n<figure id=\"attachment_278\" aria-describedby=\"caption-attachment-278\" style=\"width: 700px\" class=\"wp-caption alignnone\"><img decoding=\"async\" loading=\"lazy\" class=\"size-large wp-image-278\" src=\"http:\/\/freedville.com\/blog\/wp-content\/uploads\/2018\/06\/ThinkerWithClassification-700x328.png\" alt=\"Example of classification where the input is a diamond and the possible classification targets are square and circle\" width=\"700\" height=\"328\" srcset=\"https:\/\/freedville.com\/blog\/wp-content\/uploads\/2018\/06\/ThinkerWithClassification-700x328.png 700w, https:\/\/freedville.com\/blog\/wp-content\/uploads\/2018\/06\/ThinkerWithClassification-300x140.png 300w, https:\/\/freedville.com\/blog\/wp-content\/uploads\/2018\/06\/ThinkerWithClassification-768x360.png 768w, https:\/\/freedville.com\/blog\/wp-content\/uploads\/2018\/06\/ThinkerWithClassification.png 850w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><figcaption id=\"caption-attachment-278\" class=\"wp-caption-text\">Classification example &#8211; The Thinker from https:\/\/commons.wikimedia.org\/wiki\/File:The_Thinker,_Auguste_Rodin.jpg.<\/figcaption><\/figure>\n<p>There are several different ways you might want to classify your information, here are just a few:<\/p>\n<ul>\n<li><strong>Topic<\/strong>: Is this text about sports or cooking? Is this a legal text or a fictional story? Is this an image of a cat or a dog? Watson <a href=\"https:\/\/www.ibm.com\/watson\/services\/natural-language-classifier\/\">Natural Language Classifier<\/a> is an example solution that helps you answer &#8220;where does this belong?&#8221;<\/li>\n<li><strong>Emotion and\/or sentiment<\/strong>: Is the speaker happy, sad, or angry? Are they positive, negative, or neutral towards a subject? Watson <a href=\"https:\/\/www.ibm.com\/watson\/services\/tone-analyzer\/\">Tone Analyzer<\/a> can help answer &#8220;how does this user feel?&#8221;<\/li>\n<li><strong>Intent<\/strong>: What is the speaker trying to accomplish? This is an underpinning of conversational systems like <a href=\"https:\/\/www.ibm.com\/watson\/services\/conversation\/\">Watson Assistant<\/a> which help determine a user&#8217;s goal.<\/li>\n<\/ul>\n<p>As you can see above, classification can work on a variety of input modalities including images and short or long text. We interchangeably refer to these categories as &#8216;classes&#8217;. The <a href=\"https:\/\/www.ibm.com\/watson\/products-services\/\">Watson product and services catalog<\/a>&nbsp;includes several classifier tools including pre-built classifiers like <a href=\"https:\/\/www.ibm.com\/watson\/services\/tone-analyzer\/\">Tone Analyzer<\/a> and train-your-own classifiers like <a href=\"https:\/\/www.ibm.com\/watson\/services\/natural-language-classifier\/\">Natural Language Classifier<\/a>.<\/p>\n<p>Update: See this post with <a href=\"https:\/\/medium.com\/ibm-watson\/cognitive-classification-of-text-and-what-it-can-do-for-you-514378af1e08\">specific focus on Natural Language Classifier<\/a>.<\/p>\n<p><strong>Machine learning classification techniques<\/strong><\/p>\n<p>Machine learning (ML) classifiers are a &#8220;no code&#8221; way to implement classification.&nbsp; You need only to provide the classes (categories) and examples, and a black box can handle the rest.&nbsp; You may have experience with personal email spam filters.&nbsp; Every time you take an email and &#8220;mark as spam&#8221;, you are giving an additional training data to a classifier with at least two categories (&#8220;spam&#8221; and &#8220;not spam&#8221;).<\/p>\n<p>Machine learning classifiers work well over a wide range of input data.&nbsp; They work best when classifications have distinct boundaries and a large number of ways to be expressed.&nbsp; Email is a great example &#8211; there are probably trillions of emails that could be described as spam or not-spam, clearly distinct classifications.<\/p>\n<p>Training an ML classifier requires a &#8220;representational set&#8221; of training data.&nbsp; If we can provide an accurate sample of data that looks like the broader set, we can train on that smaller sample, giving us much quicker results.&nbsp; Some email spam\/not-spam training systems have you get started with just 20 spam and not-spam messages &#8211; a far cry from the thousands of emails that might be sitting in your inbox right now, or the trillions that exist world-wide.&nbsp; Enterprise-grade classifiers are trained on subsets as well, just larger subsets.&nbsp; Using an accurate, representational subset is important because machine learning models learn only from example, thus your training set needs to supply all the examples the model needs to learn.<\/p>\n<p>You can try out some pre-trained ML classifiers provided by Natural Language Understanding in the <a href=\"https:\/\/natural-language-understanding-demo.ng.bluemix.net\/\">NLU demo service<\/a>.&nbsp; I tried providing the stirring <a href=\"http:\/\/www.abrahamlincolnonline.org\/lincoln\/speeches\/gettysburg.htm\">Gettysburg Address<\/a> to the&nbsp;<a href=\"https:\/\/natural-language-understanding-demo.ng.bluemix.net\/\">NLU demo service<\/a> and it provided the results below.&nbsp; Be sure to test out the service with your own input data as well.<\/p>\n<figure id=\"attachment_274\" aria-describedby=\"caption-attachment-274\" style=\"width: 700px\" class=\"wp-caption alignnone\"><img decoding=\"async\" loading=\"lazy\" class=\"size-large wp-image-274\" src=\"http:\/\/freedville.com\/blog\/wp-content\/uploads\/2018\/06\/NLU-category-700x219.png\" alt=\"Results from using NLU to classify the textual content in the Gettysburg Address\" width=\"700\" height=\"219\" srcset=\"https:\/\/freedville.com\/blog\/wp-content\/uploads\/2018\/06\/NLU-category-700x219.png 700w, https:\/\/freedville.com\/blog\/wp-content\/uploads\/2018\/06\/NLU-category-300x94.png 300w, https:\/\/freedville.com\/blog\/wp-content\/uploads\/2018\/06\/NLU-category-768x240.png 768w, https:\/\/freedville.com\/blog\/wp-content\/uploads\/2018\/06\/NLU-category.png 1600w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><figcaption id=\"caption-attachment-274\" class=\"wp-caption-text\">NLU categorical classification example<\/figcaption><\/figure>\n<figure id=\"attachment_275\" aria-describedby=\"caption-attachment-275\" style=\"width: 700px\" class=\"wp-caption alignnone\"><img decoding=\"async\" loading=\"lazy\" class=\"size-large wp-image-275\" src=\"http:\/\/freedville.com\/blog\/wp-content\/uploads\/2018\/06\/NLU-Emotion-700x209.png\" alt=\"Results from using NLU to classify the emotional content in the Gettysburg Address\" width=\"700\" height=\"209\" srcset=\"https:\/\/freedville.com\/blog\/wp-content\/uploads\/2018\/06\/NLU-Emotion-700x209.png 700w, https:\/\/freedville.com\/blog\/wp-content\/uploads\/2018\/06\/NLU-Emotion-300x90.png 300w, https:\/\/freedville.com\/blog\/wp-content\/uploads\/2018\/06\/NLU-Emotion-768x229.png 768w, https:\/\/freedville.com\/blog\/wp-content\/uploads\/2018\/06\/NLU-Emotion.png 1628w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><figcaption id=\"caption-attachment-275\" class=\"wp-caption-text\">NLU emotional analysis example<\/figcaption><\/figure>\n<p>This is a pretty good default classification for a historical eulogy broadly considered the turning point in the American Civil War.&nbsp; Built-in classifiers like the ones used in Natural Language Classification are good for quickly classifying a large amount of data.<\/p>\n<p>When you need to define your own target classes, you can train your own model.&nbsp; One example of this kind of activity is training a conversational chatbot, for instance using <a href=\"https:\/\/www.ibm.com\/watson\/services\/conversation\/\">Watson Assistant<\/a>.&nbsp; Chatbots are based on discovering user intents from their utterances, for instance &#8220;I want to change my password&#8221; has a different intent from &#8220;I need to cancel my order&#8221; or &#8220;How do I get a loyalty card?&#8221;.&nbsp; The beginning of training a chatbot by matching utterances to intents is a classification problem.&nbsp;&nbsp;<a href=\"https:\/\/www.ibm.com\/watson\/services\/conversation\/\">Watson Assistant<\/a>&nbsp;includes some common intents (and training data) such as eCommerce and customer care, however you can define your own as well.&nbsp; As before, conversational training involves gathering exemplary sample data for each of your target classes.<\/p>\n<p><strong>Rules-based classification techniques<\/strong><\/p>\n<p>Classification does not always require machine learning &#8211; sometimes a simple rule is enough to get the job done.&nbsp; Using rules-based classification is important when you have clear insights\/rules that you need applied and you don&#8217;t want to leave anything to chance.&nbsp; For example:<\/p>\n<ul>\n<li>The first three characters of a product code may tell you the manufacturer<\/li>\n<li>A swear word filterer has a limited set of words that must always be flagged<\/li>\n<li>A form always contains certain information in precise coordinates (ex: <a href=\"https:\/\/www.irs.gov\/pub\/irs-pdf\/f1040.pdf\">US tax form 1040<\/a>)<\/li>\n<li>Use document metadata to find the author name rather than inferring it from the text body<\/li>\n<\/ul>\n<p>Rules-based classifiers work well when the number of significant input variations is finite.&nbsp; In each example above a definite rule can be identified quickly without a need for a machine learning model to infer it.<\/p>\n<p><strong>Ensemble models<\/strong><\/p>\n<p>Ensemble modeling is a great way to get the benefits of multiple models.&nbsp; In classification we can use ensemble classifiers to get the best out of both machine learning and rules-based techniques.&nbsp; By running multiple models sequentially or in parallel we can get superior results.<\/p>\n<ul>\n<li>When classifying document types, we use the machine learning model unless the first nine words are &#8220;Form 1040 Department of the Treasury\u2014Internal Revenue Service&#8221;<\/li>\n<li>When classifying email, we use the machine learning classifier first.&nbsp; Then we use a rule check if the sender is on a known whitelist or blacklist.<\/li>\n<li>When classifying text for obscenity, we let the machine learning analysis run first and then double-check against our rules list of known swear words.<\/li>\n<\/ul>\n<p>We can even run multiple classifiers in parallel, &#8220;competing&#8221; against one another, and then use a resolution mechanism such as voting to decide which result we want to use.<\/p>\n<p>As alluded in the examples above, one important reason to use ensembles is to take advantage of additional context.&nbsp; In the email classification mechanism we use a machine learning model on the email subject + body and then use rules on the sender&#8217;s address.&nbsp; When classifying text you may be able to get better insight by including aspect of the user&#8217;s profile.&nbsp; For instance when classifying my <a href=\"https:\/\/twitter.com\/andrewrfreed\">Twitter activity<\/a> you might start with the default assumption that each tweet is about technology, since my profile tells you I tweet about technology.&nbsp; When accuracy is paramount in your classification, use all the context that is available to you.<\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<p>Classification is intended to help you organize objects and information.&nbsp; Cognitive technologies allow you to do this classification quickly and in many cases with no coding required.&nbsp; For best classification results you need to understand your inputs and whether they have a finite or infinite number of significant differences.&nbsp; Use machine learning when you want to train by example and use rules when you have finite, clearly defined rules available.&nbsp; You can combine multiple classification techniques in an ensemble to get the best results, particularly when there is additional content that cannot be directly fed into a classifier.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Cognitive technology allows you to process a lot of information quickly &#8211; this is one of the key benefits of the technology. Instead of humans spending hours sorting through information looking for relevant or&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[9,2,5],"_links":{"self":[{"href":"https:\/\/freedville.com\/blog\/wp-json\/wp\/v2\/posts\/272"}],"collection":[{"href":"https:\/\/freedville.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/freedville.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/freedville.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/freedville.com\/blog\/wp-json\/wp\/v2\/comments?post=272"}],"version-history":[{"count":9,"href":"https:\/\/freedville.com\/blog\/wp-json\/wp\/v2\/posts\/272\/revisions"}],"predecessor-version":[{"id":405,"href":"https:\/\/freedville.com\/blog\/wp-json\/wp\/v2\/posts\/272\/revisions\/405"}],"wp:attachment":[{"href":"https:\/\/freedville.com\/blog\/wp-json\/wp\/v2\/media?parent=272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freedville.com\/blog\/wp-json\/wp\/v2\/categories?post=272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freedville.com\/blog\/wp-json\/wp\/v2\/tags?post=272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}