{"id":3473,"date":"2024-09-02T17:10:21","date_gmt":"2024-09-02T17:10:21","guid":{"rendered":"https:\/\/workhouse.sweetdishy.com\/?p=3473"},"modified":"2024-09-02T17:10:22","modified_gmt":"2024-09-02T17:10:22","slug":"understanding-how-ai-translates-language","status":"publish","type":"post","link":"https:\/\/workhouse.sweetdishy.com\/index.php\/2024\/09\/02\/understanding-how-ai-translates-language\/","title":{"rendered":"Understanding How AI Translates Language"},"content":{"rendered":"\n<p id=\"Par31\">Now as we saw in Chapter\u00a01, NLP was an early focus for AI researchers. But because of the limited computer power, the capabilities were quite weak. The goal was to create rules to interpret words and sentences\u2014which turned out to be complex and not very scalable. In a way, NLP in the early years was mostly like a computer language!<\/p>\n\n\n\n<p id=\"Par32\">But over time, there evolved a general structure for it. This was critical since&nbsp;NLP&nbsp;deals with unstructured data, which can be unpredictable and difficult to interpret.<\/p>\n\n\n\n<p>Here\u2019s a general high-level look at the two key steps:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><em>Cleaning and Preprocessing the Text<\/em>: This involves using techniques like tokenization, stemming, and lemmatization to parse the text.<\/li>\n\n\n\n<li><em>Language Understanding and Generation<\/em>: This is definitely the most intensive part of the process, which often uses deep learning algorithms.<\/li>\n<\/ul>\n\n\n\n<p id=\"Par36\">In the next few sections, we\u2019ll look at the different steps in more detail.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step #1\u2014Cleaning and Preprocessing<\/h3>\n\n\n\n<p id=\"Par37\">Three things need to be done during the cleaning and preprocessing step: tokenization, stemming, and&nbsp;lemmatization.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Tokenization<\/h4>\n\n\n\n<p>Before there can be NLP, the text must be parsed and segmented into various parts\u2014a process known as\u00a0tokenization. For example, let\u2019s say we have the following sentence: \u201cJohn ate four cupcakes.\u201d You would then separate and categorize each element. Figure\u00a06-1\u00a0illustrates this tokenization.<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"Fig1\"><img decoding=\"async\" src=\"https:\/\/learning.oreilly.com\/api\/v2\/epubs\/urn:orm:book:9781484250280\/files\/images\/480660_1_En_6_Chapter\/480660_1_En_6_Fig1_HTML.jpg\" alt=\"..\/images\/480660_1_En_6_Chapter\/480660_1_En_6_Fig1_HTML.jpg\"\/><figcaption class=\"wp-element-caption\"><strong><em>Figure 6-1.<\/em><\/strong>Example of sentence tokenization<\/figcaption><\/figure>\n\n\n\n<p id=\"Par39\">All in all, kind of easy? Kind of.<\/p>\n\n\n\n<p id=\"Par40\">After tokenization, there will be normalization of the text. This will entail converting some of the text so as to make it easier for analysis, such as by changing the case to upper or lower, removing punctuation, and eliminating contractions.<\/p>\n\n\n\n<p id=\"Par41\">But this can easily lead to some problems. Suppose we have a sentence that has \u201cA.I.\u201d Should we get rid of the periods? And if so, will the computer know what \u201cA I\u201d means?<\/p>\n\n\n\n<p id=\"Par42\">Probably not.<\/p>\n\n\n\n<p id=\"Par43\">Interestingly enough, even the case of words can have a major impact on the meaning. Just look at the difference between \u201cfed\u201d and the \u201cFed.\u201d The Fed is often another name for the Federal Reserve. Or, in another case, let\u2019s suppose we have \u201cus\u201d and \u201cUS.\u201d Are we talking about the United States here?<\/p>\n\n\n\n<p>Here are some of the other issues:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><em>White Space Problem<\/em>: This is where two or more words should be one token because the words form a compound phrase. Some examples include \u201cNew York\u201d and \u201cSilicon Valley.\u201d<\/li>\n\n\n\n<li><em>Scientific Words and Phrases<\/em>: It\u2019s common for such words to have hyphens, parentheses, and Greek letters. If you strip out these characters, the system may not be able to understand the meanings of the words and phrases.<\/li>\n\n\n\n<li><em>Messy Text<\/em>: Let\u2019s face it, many documents have grammar and spelling errors.<\/li>\n\n\n\n<li><em>Sentence Splitting<\/em>: Words like \u201cMr.\u201d or \u201cMrs.\u201d can prematurely end a sentence because of the period.<\/li>\n\n\n\n<li><em>Non-important Words<\/em>: There are ones that really add little or no meaning to a sentence, like \u201cthe,\u201d \u201ca,\u201d and \u201can.\u201d To remove these, you can use a simple Stop Words filter.<\/li>\n<\/ul>\n\n\n\n<p id=\"Par50\">As you can see, it can be easy to mis-parse sentences (and in some languages, like Chinese and Japanese, things can get even more difficult with the syntax). But this can have far-ranging consequences. Since&nbsp;tokenization&nbsp;is generally the first step, a couple errors can cascade through the whole NLP process.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Stemming<\/h4>\n\n\n\n<p id=\"Par51\">Stemming&nbsp;describes the process of reducing a word to its root (or lemma), such as by removing affixes and suffixes. This has actually been effective for search engines, which involve the use of clustering to come up with more relevant results. With stemming, it\u2019s possible to find more matches as the word has a broader meaning and even to handle such things as spelling errors. And when using an AI application, it can help improve the overall understanding.<\/p>\n\n\n\n<p>Figure\u00a06-2\u00a0shows an example of stemming.<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"Fig2\"><img decoding=\"async\" src=\"https:\/\/learning.oreilly.com\/api\/v2\/epubs\/urn:orm:book:9781484250280\/files\/images\/480660_1_En_6_Chapter\/480660_1_En_6_Fig2_HTML.jpg\" alt=\"..\/images\/480660_1_En_6_Chapter\/480660_1_En_6_Fig2_HTML.jpg\"\/><figcaption class=\"wp-element-caption\"><strong><em>Figure 6-2.<\/em><\/strong>Example of stemming<\/figcaption><\/figure>\n\n\n\n<p>There are a variety of algorithms to stem words, many of which are fairly simple. But they have mixed results. According to IBM:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p id=\"Par1000\">The Porter algorithm, for example, will state that \u2018universal\u2019 has the same stem as \u2018university\u2019 and \u2018universities,\u2019 an observation that may have historical basis but is no longer semantically relevant. The Porter stemmer also does not recognize that \u2018theater\u2019 and \u2018theatre\u2019 should belong to the same stem class. For reasons such as these, Watson Explorer Engine does not use the Porter stemmer as its English stemmer.<sup>5<\/sup><\/p>\n<\/blockquote>\n\n\n\n<p id=\"Par55\">In fact, IBM has created its own proprietary&nbsp;stemmer, and it allows for significant customization.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Lemmatization<\/h4>\n\n\n\n<p id=\"Par56\">Lemmatization&nbsp;is similar to stemming. But instead of removing affixes or prefixes, there is a focus on finding similar root words. An example is \u201cbetter,\u201d which we could lemmatize to \u201cgood.\u201d This works so long as the meaning remains mostly the same. In our example, both are roughly similar, but \u201cgood\u201d has a clearer meaning. Lemmatization also may work with providing better searches or language understanding, especially with translations.<\/p>\n\n\n\n<p>Figure\u00a06-3\u00a0shows an example of lemmatization.<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"Fig3\"><img decoding=\"async\" src=\"https:\/\/learning.oreilly.com\/api\/v2\/epubs\/urn:orm:book:9781484250280\/files\/images\/480660_1_En_6_Chapter\/480660_1_En_6_Fig3_HTML.jpg\" alt=\"..\/images\/480660_1_En_6_Chapter\/480660_1_En_6_Fig3_HTML.jpg\"\/><figcaption class=\"wp-element-caption\"><strong><em>Figure 6-3.<\/em><\/strong>Example of lemmatization<\/figcaption><\/figure>\n\n\n\n<p id=\"Par58\">To effectively use lemmatization, the&nbsp;NLP&nbsp;system must understand the meanings of the words and the context. In other words, this process usually has better performance than stemming. On the other hand, it also means that the algorithms are more complicated and there are higher levels of computing power required.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step #2\u2014Understanding and Generating Language<\/h3>\n\n\n\n<p id=\"Par59\">Once the text has been put into a format that computers can process, then the NLP system must understand the overall meaning. For the most part, this is the hardest part.<\/p>\n\n\n\n<p>But over the years, researchers have developed a myriad of techniques to help out, such as the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><em>Tagging Parts of Speech (POS)<\/em>:&nbsp;This&nbsp;goes through the text and designates each word into its proper grammatical form, say nouns, verbs, adverbs, etc. Think of it like an automated version of your grade school English class! What\u2019s more, some POS systems have variations. Note that a noun has singular nouns (NN), singular proper nouns (NNP), and plural nouns (NNS).<\/li>\n\n\n\n<li><em>Chunking<\/em>: The words will then be analyzed in terms of phrases. For example, a noun phrase (NP) is a noun that acts as the subject or object to a verb.<\/li>\n\n\n\n<li><em>Named Entity Recognition<\/em>:&nbsp;This&nbsp;is identifying words that represent locations, persons, and organizations.<\/li>\n\n\n\n<li><em>Topic Modelling<\/em>:&nbsp;This&nbsp;looks for hidden patterns and clusters in the text. One of the algorithms, called Latent Dirichlet Allocation (LDA), is based on unsupervised learning approaches. That is, there will be random topics assigned, and then the computer will iterate to find matches.<\/li>\n<\/ul>\n\n\n\n<p id=\"Par65\">For many of these processes, we can use deep learning models. They can be extended to more areas of analysis\u2014to allow for seamless language understanding and generation. This is a process known as distributional semantics.<\/p>\n\n\n\n<p id=\"Par66\">With a convolutional neural network (CNN), which we learned about in Chapter\u00a04, you can find clusters of words that are translated into a feature map. This has allowed for applications like language translation, speech recognition, sentiment analysis, and Q&amp;A. In fact, the model can even do things like detect sarcasm!<\/p>\n\n\n\n<p id=\"Par67\">Yet there are some problems with CNNs. For example, the model has difficulties with text that has dependencies across large distances. But there are some ways to handle this, such as with time-delayed neural networks (TDNN) and dynamic convolutional neural networks (DCNN). These methods have shown high performance in handling sequenced data. Although, the model that has shown more success with this is the recurrent neural network (RNN), as it memorizes data.<\/p>\n\n\n\n<p id=\"Par68\">So far, we have been focused mostly on text analysis. But for there to be sophisticated NLP, we also must build voice recognition systems. We\u2019ll take a look at this in the next section.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Voice Recognition<\/h2>\n\n\n\n<p id=\"Par69\">In 1952, Bell Labs created the first&nbsp;voice recognition&nbsp;system, called Audrey (for Automatic Digit Recognition). It was able to recognize&nbsp;phonemes, which are the most basic units of sounds in a language. English, for example, has 44.<\/p>\n\n\n\n<p id=\"Par70\">Audrey could recognize the sound of a digit, from zero to nine. It was accurate for the voice of the machine\u2019s creator, HK Davis, about 90% of the time.<sup><a href=\"https:\/\/learning.oreilly.com\/library\/view\/artificial-intelligence-basics\/9781484250280\/html\/480660_1_En_6_Chapter.xhtml#Fn6\">6<\/a><\/sup>&nbsp;And for anyone else, it was 70% to 80% or so.<\/p>\n\n\n\n<p id=\"Par72\">Audrey was a major feat, especially in light of the limited computing power and memory available at the time. But the program also highlighted the major challenges with voice recognition. When we speak, our sentences can be complex and somewhat jumbled. We also generally talk fast\u2014an average of 150 words per minute.<\/p>\n\n\n\n<p id=\"Par73\">As a result, voice recognition systems improved at a glacially slow pace. In 1962, IBM\u2019s Shoebox system could recognize only 16 words, 10 digits, and 6 mathematical commands.<\/p>\n\n\n\n<p id=\"Par74\">It was not until the 1980s that there was significant progress in the technology. The key breakthrough was the use of the&nbsp;hidden Markov model (HMM), which was based on sophisticated statistics. For example, if you say the word \u201cdog,\u201d there will be an analysis of the individual sounds d, o, and g. The HMM algorithm will assign a score to each of these. Over time, the system will get better at understanding the sounds and translate them into words.<\/p>\n\n\n\n<p id=\"Par75\">While HMM was critical, it still was unable to effectively handle continuous speech. For example, voice systems were based on template matching. This involved translating sound waves into numbers, which was done by sampling. The result was that the software would measure the frequency of the intervals and store the results. But there had to be a close match. Because of this, the voice input had to be quite clear and slow. There also had to be little background noise.<\/p>\n\n\n\n<p id=\"Par76\">But by the 1990s, software developers would make strides and come out with commercial systems, such as Dragon Dictate, which could understand thousands of words in continuous speech. However, adoption was still not mainstream. Many people still found it easier to type into their computers and use the mouse. Yet there were some professions, like medicine (a popular use case with transcribing diagnosis of patients), where speech recognition found high levels of usage.<\/p>\n\n\n\n<p id=\"Par77\">With the emergence of machine learning and deep learning, voice systems have rapidly become much more sophisticated and accurate. Some of the key algorithms involve the use of the long short-term memory (LSTM), recurrent neural networks, and deep feed-forward neural networks. Google would go on to implement these&nbsp;approaches&nbsp;in Google Voice, which was available to hundreds of millions of smartphone users. And of course, we\u2019ve seen great progress with other offerings like Siri, Alexa, and Cortana.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Now as we saw in Chapter\u00a01, NLP was an early focus for AI researchers. But because of the limited computer power, the capabilities were quite weak. The goal was to create rules to interpret words and sentences\u2014which turned out to be complex and not very scalable. In a way, NLP in the early years was [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3329,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[444],"tags":[],"class_list":["post-3473","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-natural-language-processing"],"jetpack_featured_media_url":"https:\/\/workhouse.sweetdishy.com\/wp-content\/uploads\/2024\/08\/natural-language-processing.png","_links":{"self":[{"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/posts\/3473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/comments?post=3473"}],"version-history":[{"count":1,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/posts\/3473\/revisions"}],"predecessor-version":[{"id":3474,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/posts\/3473\/revisions\/3474"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/media\/3329"}],"wp:attachment":[{"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/media?parent=3473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/categories?post=3473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/tags?post=3473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}