<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Divish Dayal on Medium]]></title>
        <description><![CDATA[Stories by Divish Dayal on Medium]]></description>
        <link>https://medium.com/@divishdayal?source=rss-60cf7dc06e6c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4A3ndRnQ9URYZf_wchuOYw.jpeg</url>
            <title>Stories by Divish Dayal on Medium</title>
            <link>https://medium.com/@divishdayal?source=rss-60cf7dc06e6c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 11:54:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@divishdayal/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to evaluate Text Generation Models ? Metrics for Automatic Evaluation of NLP Models]]></title>
            <link>https://medium.com/data-science/how-to-evaluate-text-generation-models-metrics-for-automatic-evaluation-of-nlp-models-e1c251b04ec1?source=rss-60cf7dc06e6c------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1c251b04ec1</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[hands-on-tutorials]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Divish Dayal]]></dc:creator>
            <pubDate>Sat, 07 Nov 2020 16:12:58 GMT</pubDate>
            <atom:updated>2020-11-07T16:14:23.752Z</atom:updated>
            <content:encoded><![CDATA[<h4><a href="https://towardsdatascience.com/tagged/hands-on-tutorials">Hands-on Tutorials</a></h4><h3>How to evaluate Text Generation Models? Metrics for Automatic Evaluation of NLP Models</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ub2P_xN5vfq1ajnR" /><figcaption>Photo by <a href="https://unsplash.com/@maxcodes?utm_source=medium&amp;utm_medium=referral">Maxwell Nelson</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Text Generation is a tricky domain. Academics as well as the industry still struggle for relevant metrics for evaluation of the generative models’ qualities. Every generative task is different, having its own subtleties and peculiarities — dialog systems have different target metrics than summarisation, as does machine translation.</p><p>I will discuss the metrics that are used in NLP for the comparison of generative or extractive tasks, wherein 2 texts are to be compared. The metrics that I’ll discuss here can be applied to the following tasks:</p><ul><li>short or long-form text generation</li><li>Machine Translation</li><li>Summarisation</li><li>Chatbots and dialog systems</li><li>Question Answering</li><li>paraphrasing systems</li><li>multimedia systems like speech2text, image captioning, automatic video dubbing</li></ul><p>Firstly, let&#39;s talk about some common terms used in this post. To check evaluations in NLG, Machine-generated texts are usually evaluated against a target text(truth value). This <strong><em>target text</em></strong> is what is expected of the model to ideally generate. <strong><em>Generated text</em></strong> refers to the machine produced texts(output of the model), and <strong><em>target or reference text</em></strong> refers to the original truth value text. Some other basic terms are n-gram and bag of the words modeling which are basic NLP concepts/terms. You can read more about them online if you don’t already know them. I also present the code snippets to calculate some of these metrics in python.</p><h3>BLEU : Bilingual Evaluation Understudy Score</h3><p>BLEU and Rouge are the most popular evaluation metrics that are used to compare models in the NLG domain. Every NLG paper will surely report these metrics on the standard datasets, always. BLEU is a precision focused metric that calculates n-gram overlap of the reference and generated texts. This n-gram overlap means the evaluation scheme is word-position independent apart from n-grams’ term associations. One thing to note in BLEU — there is a brevity penalty i.e. a penalty applied when the generated text is too small compared to the target text.</p><p>Here’s the code snippet to compute BLEU using the python’s ntlk library.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f8cce3ddb9837de1457e430c9faf044/href">https://medium.com/media/2f8cce3ddb9837de1457e430c9faf044/href</a></iframe><h3>Rouge: Recall Oriented Understudy for Gisting Evaluation</h3><p>Rouge, as mentioned earlier, is another widely reported metric. It is a very common practice to report Rouge along with BLEU scores for standard tasks. It is very similar to the BLEU definition, the difference being that <strong><em>Rouge is recall focused whereas BLEU was precision focused</em></strong>. There are 3 types of Rouge: n-rouge, the most common rouge type which means n-gram overlap. eg. (2-rouge, 1-rouge for 2-grams and 1-gram respectively). Second is l-rouge which checks for Longest Common Subsequence instead of n-gram overlap. The third is s-rouge which focuses on skip grams. Standard implementations of these can be found in most ML libraries, n-rouge is most commonly used. The raw source code of n-rouge is given below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7eb6684ef4fa3a76362c52822bac0bd3/href">https://medium.com/media/7eb6684ef4fa3a76362c52822bac0bd3/href</a></iframe><h3>Perplexity</h3><p>Perplexity, a commonly used metric for evaluating the efficacy of generative models, is used as a measure of probability for a sentence to be produced by the model trained on a dataset. In information theory, perplexity refers to the power of a probability distribution to predict, or assign probabilities, to a sample. Lower the perplexity value, the better the model. Perplexity is normalized on the length of sentences.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sV80DaBOtmGSNG_pJvbUpw.png" /><figcaption>Here T is the total words in the sentence.</figcaption></figure><p>For language models, we ultimately want to check perplexity values on the test set and choose the model with the lowest value for this metric. This means — choose the probability model which assigns high probability to model/generate test set sentences.</p><p>If the model is completely dumb(worst possible), perplexity = |v| i.e. size of the vocabulary.</p><p>Perplexity is a model-dependent score. Most generative model implementations/libraries will provide it out of the box. Otherwise, you basically need these probabilities of each word in the sentence according to the specific language model to be able to compute as shown in the formula above.</p><h3>LSA: Latent Semantic Analysis</h3><p>LSA is used to calculate the semantic similarity of two texts based on the words they both contain. It uses word co-occurrence counts from a large corpus, that is pre-computed. It uses the bag of words(BOW) method for doing it, which is word-position independent. Unlike other metrics, it doesn’t punish word choice variation as much i.e this metric is lenient on “good” and “nice”, whereas rouge and bleu would not be.</p><p>Essentially, LSA is a method that uses a bag of words method to encode a sentence/document into a vector. Using these vectors, we can calculate similarity metrics(cosine) to check the similarity of the generated and target texts. A good detailed explanation about LSA metric is given <a href="https://moj-analytical-services.github.io/NLP-guidance/LSA.html">here</a>.</p><h3>METEOR: Metric for Evaluation of Translation with Explicit Ordering</h3><p>METEOR is an uncommon metric that works on word alignments. It computes one to one mapping of words in generated and reference texts. Traditionally, It uses <a href="https://wordnet.princeton.edu/">WordNet</a> or porter stemmer. Finally, it computes an F-score based on these mappings. Meteor is a relatively lesser used metric in NLG, especially since the take-off of deep learning models.</p><p>The code to calculate meteor is given <a href="http://cs.cmu.edu/~alavie/METEOR/README.html">here</a>, implemented in java by the author of the metric.</p><h3>TER : Translation Edit Rate</h3><p>TER works on the principle of conversion of the generated text to the target text. It is a measurement of the absolute dissimilarity between the strings by counting the number of operations required to transform one string into another. It is closely based on <a href="https://en.wikipedia.org/wiki/Edit_distance">Edit Distance</a> algorithm</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/341/1*dn5rJIrKwSNuJzb53DkFmg.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2278db6b20d5cd1dfed09e9769b75ae/href">https://medium.com/media/b2278db6b20d5cd1dfed09e9769b75ae/href</a></iframe><p>That is it for the list of commonly used metrics in NLG. To calculate all of the mentioned scores together, here is the code for that.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d02302a2b36e7dcfe637b362e0732dd5/href">https://medium.com/media/d02302a2b36e7dcfe637b362e0732dd5/href</a></iframe><p>I hope this helps to present an overview of the possible metrics that may be of use to you. You can read up more about them online if you need a more comprehensive explanation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1c251b04ec1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/how-to-evaluate-text-generation-models-metrics-for-automatic-evaluation-of-nlp-models-e1c251b04ec1">How to evaluate Text Generation Models ? Metrics for Automatic Evaluation of NLP Models</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unsupervised NLP : Methods and Intuitions behind working with unstructured texts]]></title>
            <link>https://medium.com/data-science/unsupervised-nlp-methods-and-intuitions-behind-working-with-unstructured-texts-b84aa4d286da?source=rss-60cf7dc06e6c------2</link>
            <guid isPermaLink="false">https://medium.com/p/b84aa4d286da</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[unsupervised-learning]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Divish Dayal]]></dc:creator>
            <pubDate>Mon, 26 Oct 2020 03:11:04 GMT</pubDate>
            <atom:updated>2020-10-27T04:39:33.049Z</atom:updated>
            <content:encoded><![CDATA[<h3>Unsupervised NLP : Methods and Intuitions behind working with unstructured texts</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pZyCh1yw_dE3ceDy" /><figcaption>Photo by <a href="https://unsplash.com/@raphaelphotoch?utm_source=medium&amp;utm_medium=referral">Raphael Schaller</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>tldr; this is a primer in the domain of unsupervised techniques in NLP and their applications. It begins with the intuition behind word vectors, their use and advancements. This evolves to the centerstage discussion about the language models in detail — introduction, active use in industry and possible applications for different use-cases.</blockquote><p>In the fledgling, yet advanced, fields of Natural Language Processing(NLP) and Natural Language Understanding(NLU) — Unsupervised learning holds an elite place. That&#39;s because it satisfies both criteria for a coveted field of science — it’s ubiquitous but it’s quite complex to understand at the same time.</p><p>I will attempt to break down my experience and knowledge in this space into simple blocks, hoping you can understand more about the field and even more so — have better and more structured intuitions about solving and dealing with NLP problems.</p><p>My work has largely been about working with unsupervised datasets, i.e. datasets with no labels or target variables. It’s often the case in the industry where you receive a business problem first, and then brainstorm and ideate over possible solutions. Sometimes, you come up with innovative datasets and labels to solve your problems. Often, the labels don’t exist and you are left to deal either with Mturkers(<em>for the uninitiated, </em><a href="https://www.mturk.com/"><em>Mturk</em></a><em> is a crowdsourced data-annotating platform</em>) or solve the problem without any labels at all, i.e. use unsupervised techniques.</p><p>Let’s dive into the two most essential, and quite ubiquitous, sub-domains of word vectors and language models. Along with introducing to the basic concepts and theory, I will include notes from my personal experience about best practices, practical and industrial applications, and the pros and cons of associated libraries.</p><h3>Word Vectors</h3><h4>Why vectors for words?</h4><p>Representation of words as a vector — array of 50–300 float values is one of the biggest leaps in NLP, also one that&#39;s the easiest to understand.</p><p>Before the now ubiquitous word vectors, the words in the vocabulary were vectorized using the traditional <a href="https://en.wikipedia.org/wiki/One-hot">one-hot vector encodings</a> as shown below. The figure shows one-hot vectors for a vocabulary containing 3 words in the sentence: ‘I love NLP’. This method is still widely used in ML algorithms like TF-IDF, and is prevalent in digital circuits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*ak1AVJCbdTJUS_WyEDG-Jg.png" /><figcaption>Image by Author: one-hot encodings: here the word “love” is represented by the vector [0, 1, 0]</figcaption></figure><p>At the turn of the last decade, word vector models came around with publications such as word2vec[1] and Glove[2]. With them, the NLP domain was imminently transformed into adopting them for virtually all possible tasks.</p><h4>How are word vectors trained?</h4><p>The word vector models come in two flavors — skip-gram model and continuous bag of words(CBOW) model, as shown in the figure below. Both of these models are fundamentally based on the same underlying principle —<strong> information about a word lies in the context it is used in</strong>. For example, the words ‘Man’ and ‘Woman’ are used in very similar contexts like ‘Man can do something’ vs. ‘Woman can do something’. These contexts, over millions of sentences and billions of tokens, generalize with the model learning that ‘Man’ and ‘Woman’ are related in their usages, while ‘Man’ is associated with ‘he/him’ and ‘Woman’ is associated with ‘she/her’. So, over large datasets, the word-vectors start to make a lot of sense based on these associations that are formed over their use in a variety of sentences.</p><p>The CBOW architecture tries to guess the current word based on the context, whereas the Skip-gram guesses surrounding words given the current word. For example, in the sentence — “climate change is affecting nature adversely.”, a CBOW model will try to predict the word <em>affecting </em>given the context, i.e the other words in the sentence. The following figure illustrates both of these methods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3U5AYmmV6otGAXPmyTZy0g.png" /><figcaption>Base Image from publication — <a href="https://arxiv.org/pdf/1301.3781.pdf">Efficient Estimation of Word Representations in Vector Space [1]</a>: Modelling variants for training word-vectors.</figcaption></figure><p>When you train such a model over billions of token over a large dataset containing web articles and so forth, what you get is a very potent representation of each word in the vocabulary in the form of a vector. These vectors can be 300 dimensions long, i.e. each word is represented by 300 real numbers. The most famous example to explain these vectors is shown in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8eExfEJvssHuX65GArc1xg.jpeg" /><figcaption>Image by Author: An example illustrating word-vectors when visualized in 2 dimensions.</figcaption></figure><p>Based on the figure, the following vector equation supposedly holds true:</p><pre>King_vec - Man_vec ~= Queen_vec - Woman_vec</pre><p>Or basically, in other words — vectors project similar relationships for those pairs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*FcWByuyPfbJZOJYzd_nm3g.png" /><figcaption>Image from publication — <a href="https://papers.nips.cc/paper/5021-distributed-representations-of-words-and-phrases-and-their-compositionality.pdf">https://papers.nips.cc/paper/5021-distributed-representations-of-words-and-phrases-and-their-compositionality.pdf</a>: Word vectors exhibiting relationships of various countries with their capitals projected in 2 dimensions</figcaption></figure><p>Word vectors can exhibit interesting characteristics useful in real-world applications. With word-vectors, machines are able to understand and process text in a more human-like way. This understanding of words, and text in general, extends to other forms of media such as speech, images, and videos which are often transformed first to text and then processed further. More on this later.</p><h4>Sub-word embeddings</h4><p>In a recent paper [3] authored in 2017, there was a huge improvement in the quality of representations of word-vectors. This new method utilized the so-called sub-word embeddings for the construction of vectors. There was a focus on the morphology of the words by breaking down a word into sub-words, or character n-grams. Let&#39;s take an example of the word “where”. It is broken down into the following n-grams taking n=3:</p><pre>where -: &lt;wh, whe, her, ere, re&gt;</pre><p>Then these sub-word vectors are combined to construct the vectors for a word. This helps in learning better associations among words in the language. Think of it as if we are learning at a more granular scale. This helps in learning phenomenon even inside the words, on their lemmas. For example, the difference between ‘cat’ and ‘cats’ is similar to other such pairs as ‘dog’ and ‘dogs’. Similarly, ‘boy’ and ‘boyfriend’ have the same relation as ‘girl’ and ‘girlfriend’. This methodology also helps in creating more meaningful representations for OOV(out of vocabulary) words that the model has not yet seen in the training set.</p><h4>How are word-vectors useful?</h4><p>I discuss the applications of word-vectors in greater detail in this other <a href="https://medium.com/swlh/nlp-all-them-features-every-feature-that-can-be-extracted-from-text-7032c0c87dee">post</a> by me. Briefly — word-vectors are useful for quick calculations, especially if computing resources are limited. Finding pre-trained word-vectors on a variety of corpora(new, web, social media like Twitter and Reddit, and so forth) is easy. You would want to use the word-vectors that are trained on a dataset closest to your application dataset. For eg., the word vectors trained on twitter dataset will be different from the ones trained on news articles.</p><p>Word vectors can be used to construct vectors for words or sentences, to use them for similarity or clustering tasks. Even easy tasks like plotting a word cloud for a dataset is a powerful method to analyze a dataset. However, the real power of word-vectors is unleashed with Language Modelling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Y4cXpLkWrcPfTVKpkD9Ow.png" /><figcaption>Image by Author: Word Cloud generated from this blog post</figcaption></figure><h3>Language Models</h3><h4>What are Language models?</h4><p>Language modeling is a primary tool for all unsupervised NLP tasks in the arsenal of ML engineers. By definition, <a href="https://en.wikipedia.org/wiki/Language_model">Wikipedia</a> defines language models aptly as :</p><blockquote>A statistical language model is a probability distribution over sequences of words.</blockquote><p>So, in simpler words — a language model is used to capture and predict the relationships between words across a sentence or a document. Fundamentally, the language model predicts the conditional probability distribution for the next word in a sentence, given by:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*b2xdQ7Swf5AYyncm8zETSA.png" /></figure><p>Using this, the probability of the occurrence of a sentence is given by:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*y5-UYRkNud0b6XL3kBc1hg.png" /></figure><p>Long story short, a Language Model is used to learn word associations in a dataset so that it can be used to predict the next word in a sentence, or the validity of a sentence — how probable is the occurrence of this sentence based on the distribution it has learned from the training dataset. So a model can tell that “Hi, how are you doing?” is a more probable English language sentence compared to something whacky like “Hi, goodnight!”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MjEMwMIqlBPX3UpAYwtsow.jpeg" /><figcaption>Image by Author: Language Models are used in phone keyboard applications to predict the next word.</figcaption></figure><p>As shown in the figure above, in one of the most obvious uses of a language model — the keyboard applications suggest the next word while we type. This is also how the auto-correct works. Let’s see how this happens in more detail using the following figure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rDO9OiJCjdKewLtzqC_T3A.jpeg" /><figcaption>Image by Author: Working Illustration of a Language Model</figcaption></figure><p>The words, or context, of the sentence are transformed into word vectors. These go as inputs into a language model, which is essentially a time-series based neural network. Finally, we get probability values across all the words in the vocabulary as to how likely a particular word is suited to be the next word to the given input context. Practically, vocabularies are huge(~300k or more) and these output probabilities are only significant enough for 10s of words whereas the rest of them have minuscule values(like 0.00001).</p><h4>Architecture</h4><p>Architecturally, Language models have two primary blocks — the encoder and the decoder. As the name suggests, an encoder is used to encode the inputs(word-vectors) using time-series Neural Network models. By time-series, I mean that the model keeps into account the positional order of words in a sentence where word_2 comes after word_1. The decoder, on the other hand, is the opposite of an encoder, which uses the output of the encoder(feature vector) to spew out words, one at a time — completing a sentence as it loops to the end. This is some deep architectural stuff, that you probably don’t need unless you are coding it yourself. Just a good to know terminologies otherwise.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yYb27OXi6GVzMTj1jygX_Q.jpeg" /><figcaption>Image by Author: Typical structure of Language Models</figcaption></figure><h4>Applications of Language Models</h4><p>What we discussed is a basic out of the box language model. Language models can be used in a variety of ways in the unsupervised context. Let’s see some of the more popular ones :</p><ul><li><strong>Vectorizing</strong> a sentence into a vector. This is a much better way of vectorizing sentences than any sort of averaging of word vectors.</li><li>Sentence/document <strong>classification</strong> tasks in a supervised setting(where you have target labels). Here, operationally — you use a pre-trained unsupervised Language Model to further train(finetune) on a supervised classification task. In the absence of any labels, you can perform <strong>clustering</strong> to segment the data for analysis.</li><li><strong>Generation</strong> tasks as we saw in the figure earlier. Sentence generation is a rising field with recent headlines by the likes of GPT-3. Generation tasks can vary from generation from scratch for tasks like ads(<a href="http://trypencil.com/">pencil</a>, <a href="http://www.persado.com/">persado</a>), games(<a href="https://play.aidungeon.io/">ai dungeons</a>), news or document summarization(<a href="http://www.agolo.com/">agolo</a>), conversational models, chatbots, keyboard/google autocompletion, question answering, and so forth. Any type of generation is possible if you have a suitable dataset as someone did for Game of Thrones <a href="https://www.vice.com/en/article/evvq3n/game-of-thrones-winds-of-winter-neural-network">here</a>. Some advanced applications use language models in multimedia settings like captioning of images, a variety of speech-to-text and text-to-speech tasks like <a href="http://alexa.amazon.com/">Alexa</a>, handwriting recognition, and so forth.</li><li><strong>Machine Translation </strong>for translating across languages has come a long way. An application like <a href="https://translate.google.com/">Google Translate</a> uses language models to convert speech to text and then translate to different languages.</li><li><strong>Information Retrieval</strong> tasks on large datasets like entity resolution, aspect-based sentiment analysis, document tagging. Some of the most powerful applications use language models in conjunction with knowledge bases.</li></ul><p>These were some of the popular ones. Any data that is sequentially consumed or generated can be modeled with a language model. Music generation using AI is one such application. There are inconceivably numerous applications out there, and it&#39;s expanding by the minute. With heavy research coming from academia and corporations, the modeling power and ability is improving rapidly. The state of the art for related tasks is pushed further with every passing major AI conference — so much so that it’s hard to keep track of the entire domain now — you have to focus on one or a few aforementioned sub-domains now.</p><h3>Few-Shot and Zero-Shot Learning</h3><p>An interesting and nascent development in AI has been the concept of few-shot learning[4]. It means that a trained model can learn a new task with only a few examples with supervised information by incorporating prior knowledge.</p><p>This is a huge step forward in the field of AI as traditionally, you need incredibly huge amounts of data for learning even simple tasks. In the context of language models, the pre-trained models like BERT and GPT-x models are trained over billions of tokens(&gt;100GB of raw text data) and even then — finetuning these models on specific tasks requires 1M+ data points. Compared to this, few-shot learners can learn new tasks using just a few points per label. This concept elevates to a whole new level with zero-shot learning where instead of data points, only metadata level information about the classes is used as input. It’s a new active area of research still in its early days. It’s a very promising field once we get metrics of accuracy acceptable to be used in the industry.</p><h4>Parameter Explosion</h4><p>There is a direct correlation between the accuracy and usefulness of AI models with the dataset and model parameter size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*ewBzgi8upWZ-Lc-PzLkj7w.png" /><figcaption>Image by Author: Various language models plotted against their parameter sizes</figcaption></figure><p>This figure shows the leading language models in the period of 2017–2020. The parameter sizes have increased by an order of magnitude every year — BERT-Large (2018)[5] has 355M parameters, GPT-2 (early 2019)[6] has 1.5B, T5 (late 2019)[7] extends further to 11B, finally GPT-3 (mid-2020)[4] has a whopping 175B.</p><p>With these, the access to research and training of these models has shifted away to the biggest corporations of the likes of Google, OpenAI, Microsoft, and Facebook. GPT-3 requires 700GB of GPU memory to train, much beyond the 10–16GB memory of normal consumer GPUs, costing over $4.6M to train on cloud Tesla V100 GPUs in parallel. The rest of us mortals are only left to use the smaller versions of these huge pre-trained models for our indifferent tasks. It’s not necessarily a bad thing and is an inevitable consequence of the advancement of AI, but it is something to ponder over and remember in the back of our minds considering the future of this elemental technology.</p><p>Looking forward to hearing from you on any critiques, discussions, or any other thoughts you would like to share with me.</p><h3>References</h3><p>[1] Mikolov, Tomas, et al. <a href="https://arxiv.org/pdf/1301.3781.pdf">Efficient estimation of word representations in vector space.</a></p><p>[2] Pennington, J., Socher, R., &amp; Manning, C. D. (2014, October). <a href="https://www.aclweb.org/anthology/D14-1162.pdf">Glove: Global vectors for word representation.</a> In Proceedings of the 2014 conference on empirical methods in natural language processing (EMNLP) (pp. 1532–1543).</p><p>[3] Bojanowski, P., Grave, E., Joulin, A., &amp; Mikolov, T. (2017). <a href="https://arxiv.org/pdf/1607.04606.pdf">Enriching word vectors with subword information.</a> Transactions of the Association for Computational Linguistics, 5, 135–146.</p><p>[4] Brown, T. B., Mann, B., Ryder, N., Subbiah, M., Kaplan, J., Dhariwal, P., … &amp; Agarwal, S. (2020). <a href="https://arxiv.org/abs/2005.14165">Language models are few-shot learners.</a> <em>arXiv preprint arXiv:2005.14165</em>.</p><p>[5] Devlin, J., Chang, M.W., Lee, K. and Toutanova, K., 2018. <a href="https://arxiv.org/abs/1810.04805">Bert: Pre-training of deep bidirectional transformers for language understanding.</a> <em>arXiv preprint arXiv:1810.04805</em>.</p><p>[6] Radford, A., Wu, J., Child, R., Luan, D., Amodei, D. and Sutskever, I., 2019. <a href="https://cdn.openai.com/better-language-models/language_models_are_unsupervised_multitask_learners.pdf">Language models are unsupervised multitask learners.</a> <em>OpenAI blog</em>, <em>1</em>(8), p.9.</p><p>[7] Raffel, C., Shazeer, N., Roberts, A., Lee, K., Narang, S., Matena, M., Zhou, Y., Li, W. and Liu, P.J., 2019. <a href="https://arxiv.org/abs/1910.10683">Exploring the limits of transfer learning with a unified text-to-text transformer.</a> <em>arXiv preprint arXiv:1910.10683</em>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b84aa4d286da" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/unsupervised-nlp-methods-and-intuitions-behind-working-with-unstructured-texts-b84aa4d286da">Unsupervised NLP : Methods and Intuitions behind working with unstructured texts</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NLP: All the Features. Every Feature That Can Be Extracted From the Text]]></title>
            <link>https://medium.com/swlh/nlp-all-them-features-every-feature-that-can-be-extracted-from-text-7032c0c87dee?source=rss-60cf7dc06e6c------2</link>
            <guid isPermaLink="false">https://medium.com/p/7032c0c87dee</guid>
            <category><![CDATA[text-classification]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[unsupervised-learning]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[Divish Dayal]]></dc:creator>
            <pubDate>Sun, 27 Sep 2020 14:06:25 GMT</pubDate>
            <atom:updated>2020-09-29T05:28:08.144Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>tldr: I will be sharing all the possible NLP features that you can extract from unstructured texts for using in downstream tasks. I also list the python libraries I prefer to use for computing these features.</blockquote><p>Text data and analysis has been one of the biggest trends and leaps of the last decade, especially the second half. This can be easily seen by the advancement of algorithms used by the tech titans in FAANG, as well as hundreds of startups that are disrupting various industries at a breakneck speed. Few of these industries have been completely transformed, while others are inevitably in the process of it. An example from personal experience — there is a huge disruption in the marketing and advertisement sector where the big agencies(like Dentsu, WPP, Publicis) are seeing a significant change in the way of doing and executing things.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6WATd2e85VuqFhkg5RQonQ.jpeg" /></figure><p>I have spent the last 3 years working with a variety of textual datasets. Primarily, I have worked with advertisement datasets, for optimization tasks as well as generation from scratch.</p><p>When the sun is brighter, you would get to work with organized and ordered datasets, otherwise, it’s all over the place from all sorts of sources. [jk, working with the latter is exciting, though quite unpredictable — literally. You never know what patterns will emerge to surprise you].</p><p>I will list down in detail, the shallow as well as deep features, that one can use as signals for downstream tasks like classifications, insights, visualizations, and so forth.</p><h3>Shallow Features</h3><p>By shallow features, I refer to the simple features that are relatively easier and simple to compute and are less compute-intensive. Also, these are directly interpretable unlike their more complex siblings discussed later.</p><h4><strong>text length counts </strong>:</h4><p>features like character length and word length are quite common to be significant in text datasets. For documents or paragraph-like data points, you can use sentence length mean and std values as features.</p><h4><strong>non-dictionary word counts</strong></h4><p>count/ratio of non-dictionary words or OOV(out of vocab) words in the text. It can be a pseudo-feature representing how formal the text is. Twitter type social media datasets will have higher ratios compared to Wikipedia articles.</p><h4><strong>readability metrics</strong></h4><p>Metrics like <a href="https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests">Flesch-Kincaid Readability Test</a> and <a href="https://en.wikipedia.org/wiki/SMOG">SMOG</a> can be used. Essentially, these are ratios of complex words(polysyllables) to the total number of words or sentences — which are hypothesized to signal how easily readable a piece fo text is.</p><h4><strong>unique word ratios</strong></h4><p>ratio of number of unique words/total words. This feature gives you a sense of word repetitions in the data points. For a deeper analysis of this type of feature, you can look into TF-IDF models.</p><h4>sentence types</h4><p>Features such as count, or boolean variable for the presence of questions, exclamations, and particular punctuations.</p><h4>emojis and hashtags</h4><p>A feature of the count or boolean for their presence in a text. Sentiments of these features can also be further used on top of these.</p><h3>Complex/Deep Features</h3><p>Now let’s look at slightly complex features. These features typically require higher machine computation resources; GPU&#39;s for large datasets(100K+ data-points). Also, these are harder and time-consuming to construct on your own, so you’ll end up using standard libraries for these. I will mention and compare the famous libraries for each of the following.</p><h4><strong>part of speech(pos)</strong></h4><p>If there’s a single feature I have used the most in my experience, it’s the Part-Of-Speech(POS) tags. They are incredibly powerful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*xtgsBtwSTfkrH7VjILDpZA.png" /><figcaption>POS illustration as visualized on spaCy’s <a href="https://spacy.io/usage/linguistic-features">Documentation website</a>.</figcaption></figure><p>A lot can be learned from what POS’s are present in a sentence. This can be extended to include the dependency features, which are the relations between the words. These end up in constructing a dependency tree for each sentence.</p><p>Practically, I often use POS to extract the relevant tags(like NOUN, VERB, ADJ). Then you can perform operations on the corresponding word-vectors(Glove/word2vec), like similarity/topic-modeling/classification. I use <a href="https://spacy.io/">spaCy</a> for this task, which is unquestionably one of the best libraries for this and other NLP tasks.</p><p>To use POS, often the best way is to generate POS tags for the sentences and then try to find patterns in the dataset yourself.</p><blockquote>Manually going through the dataset to find patterns is the most important and often under-rated task in the field.</blockquote><h4>named entity recognition(ner)</h4><p>Another related sibling of POS tagging is NER tagging. Again, spaCy is my choice for it. NER is used to identify named-entities like person names, organizations, locations, quantities, monetary values, percentages, etc. This is also a good feature that I use to filter my datasets for text generation tasks — as I don’t want the model to learn to output some of these proper noun entities.</p><h4>sentiment analysis</h4><p>Sentiments and emotions are inevitably very important underlying features of any text. The sentiment of a sentence is usually highly relevant in translating to the target variable for common classification tasks. These are also great post-processing filters for most industrial applications — you usually don’t want to show negative sentiment sentences to a client.</p><blockquote><em>Which library to use for sentiment analysis ?</em></blockquote><p>There are many libraries, models and datasets that you can use to calculate it. I usually find myself choosing one of these two — <a href="https://textblob.readthedocs.io/en/dev/">Textblob</a> and <a href="https://github.com/flairNLP/flair">Flair</a>. My decision depends on a simple evaluation, how important is this feature for my task? Textblob is a simple sentiment analyzer that uses a dictionary-based model to output 2 metrics — subjectivity and sentiment. It is CPU based and very fast because of this simpler modeling. Where it lacks is — the more complex sentences like <em>“the restaurant was great, but not enough”</em>.</p><p>On the other hand, Flair uses deep-learning based model to compute sentiments. Recently, it uses a DistilBERT model for the task. It’s reasonably accurate, though it’s quite heavy and slower to compute. You will need a GPU for any reasonable dataset size.</p><h4>Sentence Vectors</h4><p>Just as word vectors, you can represent sentences or paragraphs with vectors in the corresponding latent space. I use this technique quite often, especially in unsupervised tasks for clustering and similarity/diversity-based selection tasks. The naive way to get word vectors is averaging of non-stopword word vectors in a sentence — but it loses relevance very fast as the sentence becomes longer. My goto library for this is <a href="https://github.com/UKPLab/sentence-transformers">Sentence Transformers</a>. It is a BERT based model that&#39;s finetuned in a siamese network setting to optimize for similarity-based tasks on sentence vectors. Also, it’s faster compared to BERT. For classification tasks, the sentence vectors can be used as input to other classifiers, say Random Forests, after passing through a dimensionality reduction algorithm(like PCA).</p><p>These are all the commonly used and easily available features for textual datasets. Would love to expand on this knowledge if you can add any in the comments section. Leave any reviews here or on DMs. All the best for hacking datasets!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7032c0c87dee" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/nlp-all-them-features-every-feature-that-can-be-extracted-from-text-7032c0c87dee">NLP: All the Features. Every Feature That Can Be Extracted From the Text</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>