<?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 Valeriya Slovikovskaya on Medium]]></title>
        <description><![CDATA[Stories by Valeriya Slovikovskaya on Medium]]></description>
        <link>https://medium.com/@vslovik?source=rss-2b67a4da3a6d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*11g4Fhu0pSErwiZ963oYQg.jpeg</url>
            <title>Stories by Valeriya Slovikovskaya on Medium</title>
            <link>https://medium.com/@vslovik?source=rss-2b67a4da3a6d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 21:57:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vslovik/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[Fake News Detection empowered with BERT and friends]]></title>
            <link>https://medium.com/@vslovik/fake-news-detection-empowered-with-bert-and-friends-20397f7e1675?source=rss-2b67a4da3a6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/20397f7e1675</guid>
            <category><![CDATA[pre-trained-transformers]]></category>
            <category><![CDATA[natural-language-process]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[transfer-learning]]></category>
            <category><![CDATA[fake-news-detection]]></category>
            <dc:creator><![CDATA[Valeriya Slovikovskaya]]></dc:creator>
            <pubDate>Wed, 13 Nov 2019 11:13:03 GMT</pubDate>
            <atom:updated>2019-12-18T08:01:56.368Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0s1pG59ghg-YQafg0nGqjA.jpeg" /><figcaption>Photo by Mike Benson on Unsplash</figcaption></figure><h3>Fake News Detection Powered with BERT and Friends</h3><h3>Yet another transfer learning success story</h3><p>In this post, we will experiment with transfer learning from pre-trained transformers, and what we try to do is to improve the “Fake News Detection Challenge Stage 1” state-of-the-art results.</p><p>Let’s suppose we have a statement or a claim which veracity is checked or which source is trusted. How can we then detect liars about this claim in an upcoming news stream? Right, we might try to determine whether the news text is related to the claim, and, if so, to find out whether it contradicts or supports it, i.e. its stance on the subject. The Fake News Challenge Stage 1 (FNC-1) task was formulated in fact as a stance detection problem.</p><p>The data set provided in 2017 by organizers of FNC-1 Cup consists of pairs of a news article headline (as a claim), and a snippet of text taken either from the same or from another news article. Each pair in the training part of the data set is labeled with a tag attesting the relation between the headline and the snippet. The labels are ”agree”, ”disagree”, ”discuss”, and ”unrelated”. The goal of the challenge is to classify the pairs in the test data set.</p><p>The FNC-1 dataset (as well as it’s extended FNC-ARC version we use in this post) is highly unbalanced, with the vast majority of text pairs tagged as “unrelated”. (See the (Hanselowski et al., 2018) article for dataset statistics.) That means we do not expect to attain the highest classification accuracy on the “disagree” or “discuss” class.</p><p>Our first step is to obtain datasets for training and testing. Thank to (Hanselowski et al., 2018) the task is as easy as downloading four files from their GitHub repository.</p><blockquote>$ wget <a href="https://github.com/UKPLab/coling2018_fake-news-challenge/blob/master/data/fnc-1/corpora/FNC_ARC/combined_bodies_train.csv">https://github.com/UKPLab/coling2018_fake-news-challenge/blob/master/data/fnc-1/corpora/FNC_ARC/combined_stances_train.csv</a></blockquote><blockquote>$ wget <a href="https://github.com/UKPLab/coling2018_fake-news-challenge/blob/master/data/fnc-1/corpora/FNC_ARC/combined_bodies_train.csv">https://github.com/UKPLab/coling2018_fake-news-challenge/blob/master/data/fnc-1/corpora/FNC_ARC/combined_bodies_train.csv</a></blockquote><blockquote>$ wget <a href="https://github.com/UKPLab/coling2018_fake-news-challenge/blob/master/data/fnc-1/corpora/FNC_ARC/combined_bodies_train.csv">https://github.com/UKPLab/coling2018_fake-news-challenge/blob/master/data/fnc-1/corpora/FNC_ARC/combined_stances_test.csv</a></blockquote><blockquote>$ wget <a href="https://github.com/UKPLab/coling2018_fake-news-challenge/blob/master/data/fnc-1/corpora/FNC_ARC/combined_bodies_train.csv">https://github.com/UKPLab/coling2018_fake-news-challenge/blob/master/data/fnc-1/corpora/FNC_ARC/combined_bodies_test.csv</a></blockquote><p>You can also clone the repository:</p><blockquote>$ git clone <a href="https://github.com/UKPLab/coling2018_fake-news-challenge/blob/master/data/fnc-1/corpora/FNC_ARC/combined_bodies_train.csv">https://github.com/UKPLab/coling2018_fake-news-challenge</a></blockquote><p>and find the dataset in the <em>data/fnc-1/corpora/FNC_ARC</em> folder<strong>.</strong></p><p>(Hanselowski et al., 2018) paper reports the results for the original FNC-1 dataset. To obtain results for the extended dataset version follow the author&#39;s instructions: basically, what you need to do is to install python package dependencies and, choose the dataset (#4) and the model (the winning featMLP) in settings.py, and then run the training and testing commands:</p><blockquote>$ python pipeline.py -p ftrain</blockquote><blockquote>$ python pipeline.py -p ftest</blockquote><p>This way, you will get the following class-wise F1-scores: “agree”: 50.26%, <br>“disagree”: 27.22%, “discuss”: 72.43%, “unrelated”: 96.54%. And this is the top-scoring 2018 result, obtained just before the arrival of the large pre-trained Transformers. With pre-trained transformers we will easily beat it, spending few hours of computation time on, say, Nvidia Tesla Pascal P100 GPU or, alternatively, at most 1 hour on a single Cloud TPU.</p><p>Thus, our next step is to get familiar with the members of the Transformers top-scoring “dream team”: All of them, when fine-tuned, outperform all systems on all GLUE benchmark (<a href="https://gluebenchmark.com/">https://gluebenchmark.com</a>) tasks by a substantial margin.</p><p><strong>BERT</strong></p><p>BERT (Devlin et al., 2018), which stands for <strong>B</strong>idirectional <strong>E</strong>ncoder <strong>R</strong>epresentations from <strong>T</strong>ransformers, is designed to pre-train deep bidirectional representations from unlabeled text by jointly conditioning on both left and right context in all layers. BERT uses the ”masked language model” (MLM) pre-training objective, inspired by the Cloze task (Taylor, 1953). The masked language model randomly masks some of the tokens from the input, and the objective is to predict the masked word based on its context. In addition to the masked language model, BERT also uses a ”next sentence prediction” (NSP) task that jointly pre-trains text-pair representations.</p><p>For the pre-training corpus (Devlin et al., 2018) use the BooksCorpus (800M words) and English Wikipedia (2,500M words).</p><p>The self-attention mechanism in the Transformer allows BERT to model many downstream tasks — whether they involve single text or text pairs. For each task, the steps are: (1) simply plug in the task-specific inputs and outputs into<br>BERT and (2) fine-tune all the parameters end-to-end.</p><p><strong>XLNet</strong></p><p>BERT predicts all masked positions independently, meaning that during the training, it does not learn to handle dependencies between predicted masked tokens. This reduces the number of dependencies BERT learns at once, making the learning signal weaker than it could be.<br>Another problem with BERT is that the [MASK] token — which is at the center of training BERT — never appears when fine-tuning BERT on downstream tasks. That means that the [MASK] token is a source of train-test skew while<br>fine-tuning.<br>XLNet (Yang et al., 2019) incorporates a bidirectional context while avoiding the [MASK] tokens and independent predictions. It does this by introducing ”permutation language modeling”: instead of predicting the tokens in sequential order, it predicts tokens in some random order. <br>Aside from using permutation language modeling, XLNet improves upon BERT by using the Transformer XL as its base architecture.<br>Both BERT and XLNet can take the pair of text sequences as an input. To enable the model to distinguish between words in two different segments, BERT learns a segment embedding. In contrast, XLNet learns an embedding that represents whether two words are from the same segment. This embedding is used during attention computation between any two words.</p><p><strong>RoBERTa</strong></p><p>(Liu et al., 2019) found that BERT was significantly under-trained and proposed an improved recipe for training BERT models, which they call RoBERTa (Robustly optimized BERT approach), that can match or exceed the performance of all of the post-BERT methods. The recipe includes: (1) training the model longer, with bigger batches, over more data; (2) removing the ”next sentence prediction” objective; (3) training on longer sequences; and (4) dynamically changing the masking pattern applied to the training data.<br>To train RoBERTa (Liu et al., 2019) use five English-language corpora of varying sizes and domains, totaling over 160GB of uncompressed text. They also demonstrate that removing the ”next sentence prediction” loss together with segment-pair input format matches or slightly improves downstream task performance.</p><p><strong>Fake News Detection</strong></p><p>For our experiments on fine-tuning transformers on the FNC-1 task, we use the Simple Transformers (Rajapakse, 2019) wrapper around Hugging Face Transformers library (Wolf et al., 2019b).</p><p>The model implementations provided in the library are tested to ensure they match the original author implementations’ performances on various benchmarks. A list of architectures for which reference implementations and pre-trained weights are currently provided in Transformers includes BERT, XLNet, and RoBERTa, as well as DistilBERT, GPT and GPT2.</p><p>The Simple Transformers (Rajapakse, 2019) library is built on top of the Hugging Face Transformers. The idea behind it was to make it as simple as possible, abstracting a lot of the implementation details.</p><p>Thus, with Simple Transformers on the shoulders of Hugging Face Transformers, we could access pre-trained BERT, XLNet, and RoBERTa in a unified way without a lot of pre-processing coding.</p><p>Let us first prepare the data to feed into transformers:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b25bf95bdd833ed62f898864e4abe7d/href">https://medium.com/media/1b25bf95bdd833ed62f898864e4abe7d/href</a></iframe><p>Then we create the instance on the Transformer model with Simple Transformers and train it. The <em>TransformerModel </em>constructor takes two parameters: model type and model name. All available model types and model names are listed on the Simple Transformers GitHub page: <a href="https://github.com/ThilinaRajapakse/simpletransformers">https://github.com/ThilinaRajapakse/simpletransformers</a>.</p><p>We use <em>bert/bert-base-uncased, xlnet/</em>xlnet-base-cased<em>, and roberta/</em>roberta-base models. We set the learning rate to be 3e-5 for BERT and 1e-5 for XLNet and RoBERTa. (Use the validation set for the best hyper-parameters search.)</p><p>Let’s set maximum sequence length to be equal to 512 tokens: the maximum possible value to set given the parameters of pre-trained models, and the number of epoch to fine-tune the transformer to be 5.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/343fda95ab88fa89100e16925410a00a/href">https://medium.com/media/343fda95ab88fa89100e16925410a00a/href</a></iframe><p>BERT model fine-tuned, now we get predictions on the test set and evaluate fine-tuning results.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e356355e86485c324a0cccd1dd9c5d34/href">https://medium.com/media/e356355e86485c324a0cccd1dd9c5d34/href</a></iframe><p>Then we calculate averaged and class-wise F1 scores:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7dc472cd7bafe47be471f4e5da5fcfce/href">https://medium.com/media/7dc472cd7bafe47be471f4e5da5fcfce/href</a></iframe><p>After that we can calculate FNC-1 (the metric proposed by FNC-1 organizers) and print the confusion matrix:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0146877d2d5797cae7adcda6086e1163/href">https://medium.com/media/0146877d2d5797cae7adcda6086e1163/href</a></iframe><p>Let’s calculate class-wise precision and recall.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b721837014592104591fcf6c4118c1aa/href">https://medium.com/media/b721837014592104591fcf6c4118c1aa/href</a></iframe><p>You should get results, reported in Tables 1, 2, and 3 below. They show that all three models fine-tuned on the Fake News Challenge Stage 1 task outperform (Hanselowski et al., 2018) featMLP model with significant margins varying from 8 to 20% for ”related” classes. The XLNet and RoBERTa demonstrate better performance than BERT, which corresponds to our expectations; RoBERTa outperforms both BERT and XLNet, which is in line with the results reported in (Liu et al., 2019).</p><p><strong>Table 1</strong>. Performance of featMLP, BERT, XLNet, and RoBERTa on FNC-1 task</p><pre>+-----------------+----------------------------------+<br>| Score, %        |  featMLP   BERT   XLNet  RoBERTa |<br>+-----------------+----------------------------------+<br>| Accuracy        |    <strong>87.18</strong>   91.32  92.10  93.19   |<br>| FNC score       |    <strong>78.59</strong>   86.16  87.90  89.17   |<br>| F1 macro        |    <strong>61.61</strong>   72.82  76.06  78.12   |<br>| F1 agree        |    <strong>50.26</strong>   64.70  68.61  70.71   |<br>| F1 disagree     |    <strong>27.22</strong>   47.84  54.85  58.06   |<br>| F1 discuss      |    <strong>72.43</strong>   80.07  82.10  84.57   |<br>| F1 unrelated    |    <strong>96.54</strong>   98.68  98.65  99.16   |<br>+-----------------+----------------------------------+</pre><p><strong>Table 2</strong>. Confusion matrices for featMLP, BERT, XLNet, and RoBERTa</p><pre><strong>featMLP</strong>------------------------------------------------------<br>|           |   agree   | disagree  |  discuss  | unrelated |<br>-------------------------------------------------------------<br>|   agree   |   <strong>1104</strong>    |    152    |    738    |    243    |<br>-------------------------------------------------------------<br>| disagree  |    306    |    <strong>230</strong>    |    253    |    280    |<br>-------------------------------------------------------------<br>|  discuss  |    617    |    175    |   <strong>3337</strong>    |    514    |<br>-------------------------------------------------------------<br>| unrelated |    129    |    64     |    244    |   <strong>20586</strong>   | <br>-------------------------------------------------------------</pre><pre><strong>BERT</strong>----------------------------------------------------------<br>|            |  agree    |  disagree |  discuss  | unrelated |<br>--------------------------------------------------------------<br>|  agree     |   <strong>1534</strong>    |    328    |    619    |    24     |<br>--------------------------------------------------------------<br>|  disagree  |    151    |    <strong>432</strong>    |    136    |    18     |<br>--------------------------------------------------------------<br>|  discuss   |    486    |    239    |   <strong>3732</strong>    |    222    |<br>--------------------------------------------------------------<br>|  unrelated |    66     |    70     |    156    |   <strong>20759</strong>   |<br>--------------------------------------------------------------</pre><pre><strong>XLNet</strong>---------------------------------------------------------<br>|            |  agree    |  disagree |  discuss  | unrelated |<br>-------------------------------------------------------------<br>|  agree     |   <strong>1597</strong>    |    297    |    474    |    50     |<br>--------------------------------------------------------------<br>|  disagree  |    114    |    <strong>517</strong>    |    150    |    35     |<br>--------------------------------------------------------------<br>|  discuss   |    482    |    205    |   <strong>3894</strong>    |    262    |<br>--------------------------------------------------------------<br>|  unrelated |     44    |     50    |    125    |   <strong>20676</strong>   |<br>--------------------------------------------------------------</pre><pre><strong>RoBERTa</strong>-------------------------------------------------------<br>|            |  agree    |  disagree |  discuss  | unrelated |<br>--------------------------------------------------------------<br>|  agree     |   <strong>1592</strong>    |    265    |    377    |    32     |<br>--------------------------------------------------------------<br>|  disagree  |    129    |    <strong>560</strong>    |    150    |    21     |<br>--------------------------------------------------------------<br>|  discuss   |    487    |    210    |   <strong>4009</strong>    |    132    |<br>--------------------------------------------------------------<br>|  unrelated |    29     |    34     |    107    |   <strong>20838</strong>   |<br>--------------------------------------------------------------</pre><p><strong>Table 3</strong>. Precision and recall for featMLP, BERT, XLNet, RoBERTa. Every cell contains 4 results corresponding to four models respectively</p><pre>+-------------+---------------+---------------+<br>|             |  precision, % |  recall, %    |<br>+-------------+---------------+---------------+<br>|  agree      |  <strong>53</strong> 69 71 71  |  <strong>48</strong> 61 66 70  |<br>+-------------+---------------+---------------+<br>|  disagree   |  <strong>38</strong> 40 48 52  |  <strong>24</strong> 59 63 65  |<br>+-------------+---------------+---------------+<br>|  discuss    |  <strong>73</strong> 80 84 86  |  <strong>74</strong> 80 80 83  |<br>+-------------+---------------+---------------+<br>|  unrelated  |  <strong>95</strong> 99 98 99  |  <strong>98</strong> 99 99 99  |<br>+-------------+---------------+---------------+</pre><p><strong>Conclusion</strong></p><p>We substantially improved Fake News Challenge Stage 1 results, putting the task in the line of Natural Language Processing tasks that are reported to benefit from transfer learning from pre-trained transformers.</p><p><strong>References</strong></p><p>Hanselowski, A., A. PVS, B. Schiller, F. Caspelherr, D. Chaudhuri, et al. (Aug. 2018a). “A Retrospective Analysis of the Fake News Challenge Stance-Detection Task”. In: Proceedings of the 27th International Conference on Computational Linguistics. Santa Fe, New Mexico, USA: Association for Computational Linguistics, pp. 1859–1874. URL: <a href="https://www.aclweb.org/anthology/C18-1158.pdf">https://www.aclweb.org/anthology/C18–1158</a>.</p><p>Devlin, J. et al. (2018). “BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding”. In: CoRR abs/1810.04805. URL: <a href="http://arxiv.org/abs/1810.04805">http://arxiv.org/abs/1810.04805</a>.</p><p>Taylor, W. L. (1953). “Cloze Procedure”: A New Tool for Measuring Readability”. In: Journalism Bulletin 30.4, pp. 415–433. URL: <a href="https://doi.org/10.1177/107769905303000401">https://doi.org/10.1177/107769905303000401</a>.</p><p>Yang, Z., Z. Dai, et al. (2019). “XLNet: Generalized Autoregressive Pretraining for Language Understanding”. In: CoRR abs/1906.08237. URL: <a href="http://arxiv.org/abs/1906.08237">http://arxiv.org/abs/1906.08237</a>.</p><p>Liu, Y. et al. (2019). “RoBERTa: A Robustly Optimized BERT Pretraining Approach”. In: CoRR abs/1907.11692. URL: <a href="http://arxiv.org/abs/1907.11692">http://arxiv.org/abs/1907.11692</a>.</p><p>Rajapakse, T. (2019). Simple Transformers. <a href="https://github.com/ThilinaRajapakse/simpletransformers">https://github.com/ThilinaRajapakse/simpletransformers</a>.</p><p>Wolf, T. et al. (2019). “HuggingFace’s Transformers: State-of-the-art Natural Language Processing”. In: ArXiv abs/1910.03771. URL: <a href="https://github.com/huggingface/transformers">https://github.com/huggingface/transformers</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20397f7e1675" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>