<?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 shreyasi kalra on Medium]]></title>
        <description><![CDATA[Stories by shreyasi kalra on Medium]]></description>
        <link>https://medium.com/@shreyasikalra25?source=rss-fd7d51727a2c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*41W-bRk_caIdB_A9.</url>
            <title>Stories by shreyasi kalra on Medium</title>
            <link>https://medium.com/@shreyasikalra25?source=rss-fd7d51727a2c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 16:42:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shreyasikalra25/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[Bert Language Model]]></title>
            <link>https://medium.com/@shreyasikalra25/predict-movie-reviews-with-bert-88d8b79f5718?source=rss-fd7d51727a2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/88d8b79f5718</guid>
            <category><![CDATA[bert]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[attention]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[shreyasi kalra]]></dc:creator>
            <pubDate>Tue, 26 Feb 2019 19:24:27 GMT</pubDate>
            <atom:updated>2019-03-15T17:54:17.127Z</atom:updated>
            <content:encoded><![CDATA[<h3>BERT Language Model</h3><p>Bert is a simple yet powerful language representation model that has already obtained state-of-the-art results on eleven natural language processing tasks, resulting in 7.6% improvement for glue benchmark.</p><p><strong>BERT, Bidirectional Encoder Representation for Transformers</strong>, is designed to train deeply bidirectional representations by considering both left and right context.</p><p>Compared to all previous pre-training architectures, BERT is the first architecture that jointly fuses the left and right context in all layers. Previous state-of-the art architectures, OpenAI GPT, takes only left to right context, and ELMo, takes concatenation of independently trained left-to-right and right-to left LSTMs .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*lxd3DCwPKYkjmQb3yfy3Hw.png" /><figcaption>Pre-training Model Architectures</figcaption></figure><p>BERT is a multi-layer transformer architecture. We will discuss a little about the Transformer. Transformers are self attention models.</p><p><strong>Attention</strong> along with word embeddings are known to produce impressive results in NLP, especially for <strong>long-length sentences</strong>, but they are often used with sequential models like RNN and LSTMs. These sequential models learn cell weights based on the wights from previous cell and the current input.</p><h3><strong>TRANSFORMERS <em>: building block of BERT</em></strong></h3><p><strong>Transformers</strong> move away from the recurrent architecture and rely solely on attention resulting in increased <strong>parallelisation</strong> and <strong>reduced training time</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*abz_nltyDYtC6ThqNg4O6w.png" /><figcaption>Transformer Architecture</figcaption></figure><p>Both encoder and decoder sections of transformer are a stack of 6 identical layers of multi-head attention and feed forward sublayers. Each sublayer takes a residual connection from its previous inputs, adds it to the sub layer output and normalises it to produce final output of the sub layer. To allow for residual addition, all sub-layers produce an output of dimension 512.</p><p>The decoder has an additional sublayer which performs attention over output of encode shifted by one position. In addition to this shifting this layer is masked so that the prediction at a time step i doesn’t attend to the outputs of future time steps j, where j &gt; i.</p><p>Multi-head attention function takes input vectors query (Q) and key (K), of dimensions <em>k, </em>and value (V) vector of dimension <em>v.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/1*fo4CXnyoxAm-cWJQHB_3Gg.png" /></figure><p>All vectors Q, K, V are packed together into matrices for applying computationally optimal matrix multiplication after scaling by a factor k, to avoid vanishing gradient problem.</p><h3>BERT Pre-training</h3><p>Before we look into an example of fine tuning on a pre-trained Bert model, let’s look into the features that make BERT powerful.</p><p>BERT is trained on combined corpus from BookCorpus (800M words) and English Wikipedia (2,500M words), ignoring lists, tables and headers. Each input is a two span text sampled from the combined corpus.</p><p>BERT proposes a new pre-training objective called <strong>‘Masked Language Model’ </strong>that randomly masks 15% tokens from an input sequence and trains on the model to predict the original vocabulary id of the masked word based on it context. This approach allows the representations to fuse context from either ends.</p><p>Rather than always masking the chosen word, it masks the word 80% times with [MASK] token, 10% times with any random word and remaining 10% times with the actual word, thereby biasing the prediction towards the actual observed word.</p><p>Another pre-training feature introduced in BERT is <strong>‘Next Sentence Prediction’ </strong>that takes in a sentence-pair input, replaces the second input sentence with a random sentence for 50% of the training steps, and trains on the sentence pairs to learn sentence relationships.</p><p>Sentence pair relationship learning is need for many downstream tasks like Question Answering and Natural Language Inference.</p><p>BERT architecture is trained on two different model size.</p><p><strong>BERT</strong><em> — BASE </em>: L = 12, H = 768, A = 12</p><p><strong>BERT </strong><em>— LARGE </em>: L = 12, H = 768, A = 12</p><p><strong>L</strong>, is the umber of transformer blocks</p><p><strong>L</strong>, is the hidden size</p><p><strong>A</strong>, is the number of self-attention heads</p><h3><strong>BERT Input Representation</strong></h3><p>We will now dig deeper into BERT architecture.</p><p>Let’s start with the input format. BERT expects the tokens to be converted to lower case, tokenised using WordPiece (‘calling’ splits to [‘call’, ‘##ing’]), indexed based on vocabulary file provided by BERT.</p><p>The sentence pair is split with a separator token <strong>[SEP]</strong>. The <strong>WordPiece embeddings</strong> are added with <strong>segment embeddings</strong>, which marks the first sentence as ‘A’ and second sentence as ‘B’, and the <strong>positional embedding</strong>, for each word.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*Xdkf2eK8ZnxA8K9rlmBTQQ.png" /></figure><p>Another special classification embedding token <strong>[CLS]</strong> is added at the beginning of every input. For classification tasks the weights corresponding to this token represent the aggregated sequence. For non-classification tasks, this vector is ignored.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*onB14-5wddG6Ij6BC3t2Xw.png" /><figcaption>Task Specific Model Architecture</figcaption></figure><p>The BERT architecture can be updated at the top output layer and used for various different tasks.</p><p>The first two architecture reflect one-sentence and two-sentence classification problem. This can be seen with the segment tokens and response from [CLS].</p><p>The next two architectures are token level tasks that return a sequence of output.</p><p>Hope this brief overview of BERT is helpful in understanding the architecture and key features that make BERT so powerful. I will soon share another blog with a code walkthrough for a classification task.</p><p>Please share you views/suggestions in the comment section.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88d8b79f5718" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>