{
  "source_file": "0930",
  "source_platform": "Medium",
  "author": "Chua Chin Hon",
  "title_listed": "Detecting State-backed Twitter Trolls With Transformers",
  "keywords": "",
  "domain": "文本处理",
  "content_type": "深度技术解析",
  "is_paid_flag": "否",
  "url": "https://towardsdatascience.com/detecting-state-backed-twitter-trolls-with-transformers-5d7825945938/",
  "publish_date": "2020-09-21",
  "corpus_stage": "",
  "notes": "",
  "id": "c89b9b539eab",
  "collected_at": "2026-10-02T09:39:26",
  "title": "Detecting State-backed Twitter Trolls With Transformers | Towards Data Science",
  "body_markdown": "![Revisit consent button](../images/body-df29beacd7496220cc94.svg)\nWe value your privacy\nWe use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking \"Accept All\", you consent to our use of cookies.\nCustomise Reject All Accept All\nCustomise Consent Preferences ![](../images/body-2159bb67f3de8ad870eb.svg)\nWe use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.\nThe cookies that are categorised as \"Necessary\" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... Show more\nNecessaryAlways Active\nNecessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.\n  * Cookie\nBCTempID\n  * Duration\n10 minutes\n  * Description\nNo description available.\n\n\n  * Cookie\n__cf_bm\n  * Duration\n1 hour\n  * Description\nThis cookie, set by Cloudflare, is used to support Cloudflare Bot Management. \n\n\n  * Cookie\nAWSALBCORS\n  * Duration\n7 days\n  * Description\nAmazon Web Services set this cookie for load balancing.\n\n\n  * Cookie\n_cfuvid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to track users across sessions to optimize user experience by maintaining session consistency and providing personalized services\n\n\n  * Cookie\nli_gc\n  * Duration\n6 months\n  * Description\nLinkedin set this cookie for storing visitor's consent regarding using cookies for non-essential purposes.\n\n\n  * Cookie\n__hssrc\n  * Duration\nsession\n  * Description\nThis cookie is set by Hubspot whenever it changes the session cookie. The __hssrc cookie set to 1 indicates that the user has restarted the browser, and if the cookie does not exist, it is assumed to be a new session.\n\n\n  * Cookie\n__hssc\n  * Duration\n1 hour\n  * Description\nHubSpot sets this cookie to keep track of sessions and to determine if HubSpot should increment the session number and timestamps in the __hstc cookie.\n\n\n  * Cookie\nwpEmojiSettingsSupports\n  * Duration\nsession\n  * Description\nWordPress sets this cookie when a user interacts with emojis on a WordPress site. It helps determine if the user's browser can display emojis properly.\n\n\n  * Cookie\nBCSessionID\n  * Duration\n1 year 1 month 4 days\n  * Description\nBlueconic sets this cookie as a unique identifier for the BlueConic profile.\n\n\n  * Cookie\n_octo\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nlogged_in\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\n__Secure-YEC\n  * Duration\npast\n  * Description\nYouTube sets this cookie to stores the user's video player preferences using embedded YouTube video\n\n\n  * Cookie\n__eoi\n  * Duration\n6 months\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTGCORS\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\nlogin-status-p\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTG\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\ncsrf_token\n  * Duration\nsession\n  * Description\nNo description available.\n\n\n  * Cookie\ntoken_v2\n  * Duration\n1 day\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nD\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nPHPSESSID\n  * Duration\nsession\n  * Description\nThis cookie is native to PHP applications. The cookie stores and identifies a user's unique session ID to manage user sessions on the website. The cookie is a session cookie and will be deleted when all the browser windows are closed.\n\n\n  * Cookie\nVISITOR_PRIVACY_METADATA\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to store the user's cookie consent state for the current domain. \n\n\n  * Cookie\ncookietest\n  * Duration\nsession\n  * Description\nThe cookietest cookie is typically used to determine whether the user's browser accepts cookies, essential for website functionality and user experience.\n\n\n  * Cookie\n__Host-airtable-session\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\n__Host-airtable-session.sig\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\nm\n  * Duration\n1 year 1 month 4 days\n  * Description\nStripe sets this cookie for fraud prevention purposes. It identifies the device used to access the website, allowing the website to be formatted accordingly.\n\n\n  * Cookie\nBIGipServer*\n  * Duration\nsession\n  * Description\nMarketo sets this cookie to collect information about the user's online activity and build a profile about their interests to provide advertisements relevant to the user. \n\n\n  * Cookie\n__cfruid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to identify trusted web traffic.\n\n\n  * Cookie\n_GRECAPTCHA\n  * Duration\n6 months\n  * Description\nGoogle Recaptcha service sets this cookie to identify bots to protect the website against malicious spam attacks.\n\n\n  * Cookie\n__Secure-YNID\n  * Duration\n6 months\n  * Description\nGoogle cookie used to protect user security and prevent fraud, especially during the login process.\n\n\n  * Cookie\ncookieyes-consent\n  * Duration\n1 year\n  * Description\nCookieYes sets this cookie to remember users' consent preferences so that their preferences are respected on subsequent visits to this site. It does not collect or store any personal information about the site visitors.\n\n\nFunctional\nFunctional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.\n  * Cookie\nlidc\n  * Duration\n1 day\n  * Description\nLinkedIn sets the lidc cookie to facilitate data center selection.\n\n\n  * Cookie\nbrw\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nbrwConsent\n  * Duration\n5 minutes\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nWMF-Uniq\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nloom_anon_comment\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nloom_referral_video\n  * Duration\nsession\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nVISITOR_INFO1_LIVE\n  * Duration\n6 months\n  * Description\nA cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface.\n\n\n  * Cookie\nyt-remote-connected-devices\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nytidb::LAST_RESULT_ENTRY_KEY\n  * Duration\nNever Expires\n  * Description\nThe cookie ytidb::LAST_RESULT_ENTRY_KEY is used by YouTube to store the last search result entry that was clicked by the user. This information is used to improve the user experience by providing more relevant search results in the future.\n\n\n  * Cookie\nyt-remote-device-id\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-name\n  * Duration\nsession\n  * Description\nThe yt-remote-session-name cookie is used by YouTube to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\nyt-remote-fast-check-period\n  * Duration\nsession\n  * Description\nThe yt-remote-fast-check-period cookie is used by YouTube to store the user's video player preferences for embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-app\n  * Duration\nsession\n  * Description\nThe yt-remote-session-app cookie is used by YouTube to store user preferences and information about the interface of the embedded YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-available\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-available cookie is used to store the user's preferences regarding whether casting is available on their YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-installed\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-installed cookie is used to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\ncp_session\n  * Duration\n3 months\n  * Description\nCodepen sets this cookie for Help systems found in the website.\n\n\n  * Cookie\nloid\n  * Duration\n1 year 1 month 4 days\n  * Description\nThis cookie is set by the Reddit. The cookie enables the sharing of content from the website onto the social media platform.\n\n\nAnalytics\nAnalytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.\n  * Cookie\n__hstc\n  * Duration\n6 months\n  * Description\nHubspot set this main cookie for tracking visitors. It contains the domain, initial timestamp (first visit), last timestamp (last visit), current timestamp (this visit), and session number (increments for each subsequent session).\n\n\n  * Cookie\nhubspotutk\n  * Duration\n6 months\n  * Description\nHubSpot sets this cookie to keep track of the visitors to the website. This cookie is passed to HubSpot on form submission and used when deduplicating contacts.\n\n\n  * Cookie\n_ga\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to calculate visitor, session and campaign data and track site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognise unique visitors.\n\n\n  * Cookie\n_ga_*\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to store and count page views.\n\n\n  * Cookie\n__Host-psifi.analyticsTrace\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n__Host-psifi.analyticsTraceV2\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n_gh_sess\n  * Duration\nsession\n  * Description\nGitHub sets this cookie for temporary application and framework state between pages like what step the user is on in a multiple step form.\n\n\n  * Cookie\nYSC\n  * Duration\nsession\n  * Description\nYSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages.\n\n\n  * Cookie\najs_anonymous_id\n  * Duration\n1 year\n  * Description\nThis cookie is set by Segment to count the number of people who visit a certain site by tracking if they have visited before.\n\n\n  * Cookie\nvuid\n  * Duration\n1 year 1 month 4 days\n  * Description\nVimeo installs this cookie to collect tracking information by setting a unique ID to embed videos on the website. \n\n\nPerformance\nPerformance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.\n  * Cookie\nAWSALB\n  * Duration\n7 days\n  * Description\nAWSALB is an application load balancer cookie set by Amazon Web Services to map the session to the target.\n\n\n  * Cookie\nacq\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nacq.sig\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nptc\n  * Duration\n2 years\n  * Description\nNo description available.\n\n\nAdvertisement\nAdvertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.\n  * Cookie\nmuc_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to collect user behaviour and interaction data to optimize the website.\n\n\n  * Cookie\nguest_id_marketing\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\nguest_id_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\npersonalization_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to integrate and share features for social media and also store information about how the user uses the website, for tracking and targeting.\n\n\n  * Cookie\nguest_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor. It registers if a user is signed in to the Twitter platform and collects information about ad preferences.\n\n\n  * Cookie\nbcookie\n  * Duration\n1 year\n  * Description\nLinkedIn sets this cookie from LinkedIn share buttons and ad tags to recognize browser IDs.\n\n\n  * Cookie\n__Secure-ROLLOUT_TOKEN\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to manage feature rollout and experimentation. It helps Google control which new features or interface changes are shown to users as part of testing and staged rollouts, ensuring consistent experience for a given user during an experiment.\n\n\n  * Cookie\nyt.innertube::nextId\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nyt.innertube::requests\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nsession_tracker\n  * Duration\nsession\n  * Description\nThis cookie is set by the Reddit. This cookie is used to identify trusted web traffic. It also helps in adverstising on the website.\n\n\n  * Cookie\nedgebucket\n  * Duration\nsession\n  * Description\nReddit sets this cookie to save the information about a log-on Reddit user, for the purpose of advertisement recommendations and updating the content.\n\n\n  * Cookie\ndid\n  * Duration\n1 year\n  * Description\nArbor sets this cookie to show targeted ads to site visitors.This cookie expires after 2 months or 1 year.\n\n\nUncategorised\nOther uncategorised cookies are those that are being analysed and have not been classified into a category as yet.\nNo cookies to display.\nReject All Save My Preferences Accept All\nToggle Search[](https://towardsdatascience.com/)Toggle Mobile Navigation\n[](https://towardsdatascience.com/)\nPublish AI, ML & data-science insights to a global community of data professionals.\nSign in[Submit an Article](https://write.insightmediagroup.io)\n[Latest](https://towardsdatascience.com/latest/)[Editor's Picks](https://towardsdatascience.com/tag/editors-pick/)[Newsletter](https://towardsdatascience.com/tag/the-variable/)[ShipAI](https://towardsdatascience.com/shipai/)\n* * *\n[Write For TDS](https://towardsdatascience.com/submissions/)\n[LinkedIn](https://www.linkedin.com/company/towards-data-science/)[X](https://x.com/TDataScience)Toggle Search\n[Data Science](https://towardsdatascience.com/category/data-science/)\n# Detecting State-backed Twitter Trolls With Transformers\nA practical use case on fine tuning a Distilbert model on a custom dataset, and testing its performance against more commonly used models...\n[Chua Chin Hon](https://towardsdatascience.com/author/chuachinhon/)\nSeptember 21, 20208 min read\n### A practical use case on fine tuning a Distilbert model on a custom dataset, and testing its performance against more commonly used models like Logistic Regression and XGBoost\n![Illustration of web app by: Chua Chin Hon](../images/000.png)\nIllustration of [web app](https://github.com/chuachinhon/transformers_state_trolls_cch/tree/master/app) by: Chua Chin Hon\nWith the 2020 US election around the corner, concerns about [electoral interference](https://www.nytimes.com/2020/09/10/us/politics/russian-hacking-microsoft-biden-trump.html) by state actors via social media and other online means are back in the spotlight in a big way.\nTwitter was a major platform that Russia used to [interfere with the 2016 US election](https://en.wikipedia.org/wiki/Russian_interference_in_the_2016_United_States_elections), and few have doubts that Moscow, Beijing and others will turn to the platform yet again with new disinformation campaigns.\nThis post will outline a broad overview of of how you can build a state troll tweets detector by fine tuning a transformer model ([Distilbert](https://huggingface.co/transformers/model_doc/distilbert.html)) with a custom dataset. This builds on my [earlier project](https://github.com/chuachinhon/twitter_state_trolls_cch) using \"classic\" machine learning models and a simple bag-of-words approach to detect state troll tweets.\nI'll also compare the results from the fine tuned Distilbert model with those from a Logistic Regression and an XGBoost model, to see if a transformer model can indeed perform better in a practical use case.\nLearn this step by step with the interactive [AI and Data Scientist](https://roadmap.sh/ai-data-scientist) and [Machine Learning](https://roadmap.sh/machine-learning) roadmaps.\n**Spoiler alert:** The fine tuned transformer model performed significantly better than the Log-Reg and XGBoost models (which weren't slouches either, to be sure), and held up much better when exposed to state troll tweets from a third country. Jump ahead to Section 4 for the results.\n* * *\n## 1. GROUND TRUTH, DATA SOURCE, MODEL AND REPO\nFirst things first: How did I ascertain whose tweets are deemed the work of state influence campaigns? In this case, the ground truth is established by Twitter's election integrity team.\nThe state troll tweets used in this project are those which have been [identified by Twitter and progressively released to the public since 2018](https://transparency.twitter.com/en/reports/information-operations.html). I chose six sets of state troll tweets from Twitter - three each from China and Russia - which I cleaned up, combined and downsampled to [50,000 rows](https://github.com/chuachinhon/transformers_state_trolls_cch/blob/master/data/troll_50k.csv).\nI created an equivalent set of [50,000 rows of real tweets](https://github.com/chuachinhon/transformers_state_trolls_cch/blob/master/data/real_50k.csv) by using [Tweepy](https://www.tweepy.org/) to scrape 175 accounts, which comprise a mixture of verified users and those which I've personally checked for authenticity. The resulting combined dataset of 100,000 rows of state troll-plus-real tweets was further split into the usual train-test-validation sets in the standard proportion of 70:20:10 respectively.\nFull details are in my [notebooks](https://github.com/chuachinhon/transformers_state_trolls_cch/tree/master/notebooks), and I won't repeat them [here](https://github.com/chuachinhon/transformers_state_trolls_cch) for brevity's sake. The full repo is available here. Fine tuning was done on a [Colab Pro](https://colab.research.google.com/signup) account, and took about five-and-a-half hours.\nThe fine tuned Distilbert model is too big for Github, but I've uploaded a [copy to Dropbox](https://www.dropbox.com/sh/90h7ymog2oi5yn7/AACTuxmMTcso6aMxSmSiD8AVa) for those who just want to experiment with the model. The six raw CSV files containing state troll tweets have to be [downloaded from Twitter](https://transparency.twitter.com/en/reports/information-operations.html) if you wish to create a larger training set.\n## 2. DATA PREPARATION\nIt ought to be pointed out that key assumptions in the data cleaning and preparation process will affect the outcomes. The assumptions are necessary to keep the scope of this project practical, but if you disagree with them, feel agree to slice a different version of the data based on your own preferred cleaning rules.\nMy main data cleaning rules for this project:\n  * Exclude non-English tweets, since the working assumption is that the target audience is English-speaking. I also wanted to prevent the model from making predictions based on language.\n  * Exclude retweets.\n  * Exclude tweets which have fewer than three words after text cleaning.\n\n\nI also kept the eventual combined dataset to 100,000 rows for practical reasons. My initial attempts to fine tune Distilbert with a 600,000 rows dataset resulted in repeated crashes of the Colab notebook and/or showed extremely long and impractical run times. A more ambitious version of this project just won't be practical without access to more compute/hardware.\n## 3. FINE TUNE THE DISTILBERT MODEL WITH CUSTOM DATASET\nFor this project, I picked the[ distilbert-base-uncased model](https://huggingface.co/distilbert-base-uncased) (smaller and more manageable) and used [Hugging Face's trainer](https://huggingface.co/transformers/master/main_classes/trainer.html) for the task. I abandoned attempts to do a [hyperparameters search](https://huggingface.co/transformers/master/main_classes/trainer.html#transformers.Trainer.hyperparameter_search) after several trials which ran on for too long, and hope to return to this topic at a future date (check out the discussion [here](https://discuss.huggingface.co/t/using-hyperparameter-search-in-trainer/785/2)).\nThe steps involved are fairly straightforward, as outlined in [notebook2.0](https://github.com/chuachinhon/transformers_state_trolls_cch/blob/master/notebooks/2.0_finetune_distilbert_colab_cch.ipynb) of my repo. The code is mostly based on the excellent examples and documentation on Hugging Face [[here](https://huggingface.co/transformers/master/main_classes/trainer.html)](https://huggingface.co/transformers/master/custom_datasets.html) and here.\nThe immediate results of the fine tuning certainly look impressive:\ntext\n\n```\n'eval_accuracy': 0.9158421345191773,\n 'eval_f1': 0.9163813100629625,\n 'eval_precision': 0.9098486510199605,\n 'eval_recall': 0.9230084557187361\n```\n\nI ran a quick test against the validation set - 10,000 rows kept aside and which the model has not seen _at all_ - and the excellent classification metrics barely budged:\ntext\n\n```\n'eval_accuracy': 0.9179, \n'eval_f1': 0.9189935865811544, \n'eval_precision': 0.9178163184864012, \n'eval_recall': 0.9201738786801027\n```\n\nFor a more thorough comparison and analysis, I trained two separate Logistic Regression and XGB classifier models using the same dataset used to fine tune the Distilbert model. Let's see how they do in the same tests.\n* * *\n## 4. FINE TUNED DISTILBERT VS LOG-REG VS XGB\nThe pickled Log-Reg and XGB models are available in my repo's [\"pkl\" folder](https://github.com/chuachinhon/transformers_state_trolls_cch/tree/master/pkl). My notebooks detailing their optimisation process are available [[here](https://github.com/chuachinhon/transformers_state_trolls_cch/blob/master/notebooks/3.1_compare_xgb_cch.ipynb)](https://github.com/chuachinhon/transformers_state_trolls_cch/blob/master/notebooks/3.0_compare_logreg_cch.ipynb) and here. I won't go into the details here, except to highlight that both models scored above 0.8 during training and grid search. While clearly lower than the fine tuned Distilbert model's score, I think these two models did well enough to provide for an adequate comparison.\nThe chart below shows the detailed breakdown, via confusion matrices, of how all three models performed against the validation set (10,000 rows comprising 5,061 state troll tweets and 4,939 real tweets).\n![Image by: Chua Chin Hon](../images/001.png)\nImage by: Chua Chin Hon\nAt a glance, it's clear that the fine tuned Distilbert model (on far left) is the strongest performer, and accurately picked out more state troll and real tweets than the Log-Reg or XGB models. More significantly, the number of false positives and false negatives for the Distilbert model is about _half_ that produced by the log-reg and XGB models.\nSo while the three models' performance metrics might seem close, the gap in their classification capabilities become very stark when seen via confusion matrices that give us a better sense of how they performed in classifying thousands of tweets.\n## 4.1 ADDITIONAL TEST FOR THE 3 MODELS\nAll three models were trained on a 50–50 split of real tweets and state troll tweets from China and Russia. In reality, we don't know the actual proportion of real-versus-troll tweets on Twitter. More importantly, state troll tweets can come from any country and changes in tone, language and topics could significantly affect the classifier's ability to separate real tweets from those originating from state-backed campaigns.\nWhich of the three models would hold up better if exposed to state troll tweets from a third country? To find out, I ran a new dataset - comprising 1,000 troll tweets from Iran and 993 real tweets from American users - through the three models. This new dataset was created from an [earlier project I did on the same subject](https://github.com/chuachinhon/twitter_state_trolls_cch).\n![Image by: Chua Chin Hon](../images/002.png)\nImage by: Chua Chin Hon\nAs expected, all three classifiers saw their performance drop significantly when exposed to Iranian state troll tweets which they've not seen before.\nBut the fine tuned Distilbert model still held up decently, in my view. Not only did it correctly pick out more troll and real tweets compared to the Log-Reg or XGB model, the number of false negatives (troll tweets that the model thought were real tweets) was not excessively large.\nThis is particularly problematic with the Log-Reg model, which classified half (501 out of 1,000) of the troll tweets as real tweets when they were in fact the work of state-backed operators. The XGB model is slightly better in this area, but not by far, with the number of false negatives (468) significantly higher than the number of false positives.\nThis was a particularly pronounced [problem with the models I trained in my earlier project](https://towardsdatascience.com/using-data-science-to-uncover-state-backed-trolls-on-twitter-dc04dc749d69), meaning classifiers trained on one particular state actor's troll tweets were quite good at spotting new, unseen tweets from said state actor. But once troll tweets from another state operator is injected into the mix, the classifier's performance falters significantly.\nThe fine tuned Distilbert model doesn't overcome this problem completely, but holds up well enough to hold out hopes for a model that can \"generalise\" better. If you have enough computing resources to train a transformer model on a bigger dataset comprising state troll tweets from all the countries identified by Twitter to date, it stands to reason that said model _might_ do better in the sort of tests we've tried in this post.\nUnfortunately that's a hypothesis I'll have to test another time.\n## 5. CONCLUSION\nDetection of state influence campaigns on Twitter involves more than just the examination of the tweet text, of course. State trolls often leave bigger tell-tale signs like the (coordinated) dates of account creation, or timing of their tweets. The increasing use of photos and memes also make the detection process trickier.\nBut spotting trends and hidden structures in their tweet text will continue to be one major area of focus. And it would appear that a fine tuned transformer model can perform significantly better in this task compared to the more popular or traditional classifiers out there.\nThere are trade-offs, of course, in terms of resources and time. The hardware needed to fine tune a transformer model on, say, a million rows of tweets, is not readily available to most users, to say nothing of whether that's the most efficient way to tackle the task.\n* * *\n## 6. BONUS SECTION: WEB APP\nI tried deploying the fine tuned Distilbert model as part of a simple web app but quickly found out that free hosting accounts don't have enough disk space for pytorch installation on top of hosting the model.\nBut I've uploaded the necessary files to the repo for anyone who wants to try it out on their local machine. Just make sure to download the fine tuned model [from Dropbox](https://www.dropbox.com/sh/90h7ymog2oi5yn7/AACTuxmMTcso6aMxSmSiD8AVa) and move it to the \"app\" folder.\n![Gif by: Chua Chin Hon](../images/003.gif)\nGif by: Chua Chin Hon\nAs always, if you spot mistakes in this or any of my earlier posts, ping me at:\n  * Twitter: [Chua Chin Hon](https://medium.com/u/b3d8090c0aee?source=post_page-----aad7f2e1d0a0----------------------)\n  * LinkedIn: [www.linkedin.com/in/chuachinhon](http://www.linkedin.com/in/chuachinhon)\n\n\n## Register Now to Continue Reading\n### Unlock Towards Data Science with a Free Account\nAll articles on Towards Data Science are available to registered users. Create a free account today to access this article and thousands more.\nRegister for freeSign in to your account\n* * *\n![](../images/body-d56b810b4697a0fbf983.png)\nWritten By\n## [Chua Chin Hon](https://towardsdatascience.com/author/chuachinhon/)\n[See all from Chua Chin Hon](https://towardsdatascience.com/author/chuachinhon/)\n[Data Science](https://towardsdatascience.com/tag/data-science/)[Deep Learning](https://towardsdatascience.com/tag/deep-learning/)[Machine Learning](https://towardsdatascience.com/tag/machine-learning/)[NLP](https://towardsdatascience.com/tag/nlp/)[US Elections](https://towardsdatascience.com/tag/us-elections/)\nShare This Article\n  * [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ftowardsdatascience.com%2Fdetecting-state-backed-twitter-trolls-with-transformers-5d7825945938%2F&title=Detecting%20State-backed%20Twitter%20Trolls%20With%20Transformers)\n  * [](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Ftowardsdatascience.com%2Fdetecting-state-backed-twitter-trolls-with-transformers-5d7825945938%2F&title=Detecting%20State-backed%20Twitter%20Trolls%20With%20Transformers)\n  * [](https://x.com/share?url=https%3A%2F%2Ftowardsdatascience.com%2Fdetecting-state-backed-twitter-trolls-with-transformers-5d7825945938%2F&text=Detecting%20State-backed%20Twitter%20Trolls%20With%20Transformers)\n\n\nTowards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.\n[Write for TDS](https://towardsdatascience.com/submissions/)\n## Related Articles\n  * [![](../images/004.jpg)](https://towardsdatascience.com/beautifully-illustrated-nlp-models-from-rnn-to-transformer-80d69faf2109/)\n## [Beautifully Illustrated: NLP Models from RNN to Transformer](https://towardsdatascience.com/beautifully-illustrated-nlp-models-from-rnn-to-transformer-80d69faf2109/)\n[Deep Learning](https://towardsdatascience.com/category/artificial-intelligence/deep-learning/)\nExplaining their complex mathematical formula with working diagrams\n[Albers Uzila](https://towardsdatascience.com/author/dwiuzila/)\nOctober 11, 202211 min read\n  * [![](../images/005.jpg)](https://towardsdatascience.com/top-3-ways-your-anomaly-detection-models-can-earn-your-trust-f59072a6199c/)\n## [Top 3 Ways Your Anomaly Detection Models Can Earn Your Trust](https://towardsdatascience.com/top-3-ways-your-anomaly-detection-models-can-earn-your-trust-f59072a6199c/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nConnecting anomaly detection models results back to the original signals\n[Michaël HOARAU](https://towardsdatascience.com/author/michalhoarau/)\nMay 6, 20226 min read\n  * [![](../images/006.jpg)](https://towardsdatascience.com/data-science-career-switch-is-masters-degree-worth-it-part-2-1110c3440e4b/)\n## [Data Science Career Switch: Is Master's Degree Worth It? (Part 2)](https://towardsdatascience.com/data-science-career-switch-is-masters-degree-worth-it-part-2-1110c3440e4b/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nProgramming language to learn and three questions to ask before making a planned career switch\n[Nathan Timothy Handoko](https://towardsdatascience.com/author/nathanthandoko/)\nFebruary 26, 20225 min read\n  * [![](../images/007.jpeg)](https://towardsdatascience.com/how-to-train-test-split-kfold-vs-stratifiedkfold-281767b93869/)\n## [How to train_test_split : KFold vs StratifiedKFold](https://towardsdatascience.com/how-to-train-test-split-kfold-vs-stratifiedkfold-281767b93869/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nExplained with examples\n[Soner Yıldırım](https://towardsdatascience.com/author/sonery/)\nMay 21, 20204 min read\n  * [![](../images/body-63beb50f664a055ed739.jpg)](https://towardsdatascience.com/the-ultimate-guide-of-classification-metrics-for-model-evaluation-83e4cdf294d9/)\n## [The Ultimate Guide of Classification Metrics for Model Evaluation](https://towardsdatascience.com/the-ultimate-guide-of-classification-metrics-for-model-evaluation-83e4cdf294d9/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nCombine machine learning models with hypothesis testing. Stop pulling your hair and read this article.\n[Zijing Zhu, PhD](https://towardsdatascience.com/author/zzhu17/)\nSeptember 6, 20207 min read\n  * [![](../images/009.jpg)](https://towardsdatascience.com/how-much-math-do-you-really-need-in-data-science-821ad101d394/)\n## [How much Math do you really need in Data Science?](https://towardsdatascience.com/how-much-math-do-you-really-need-in-data-science-821ad101d394/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nWhen Enough is Enough\n[Dario Radečić](https://towardsdatascience.com/author/radecicdario/)\nDecember 3, 20194 min read\n  * [![](../images/010.png)](https://towardsdatascience.com/nlp-topic-modeling-to-identify-clusters-ca207244d04f/)\n## [NLP-Topic Modeling to identify Clusters](https://towardsdatascience.com/nlp-topic-modeling-to-identify-clusters-ca207244d04f/)\n[NLP](https://towardsdatascience.com/category/artificial-intelligence/nlp/)\nDerive Topics from Long Text\n[Gaurika Tyagi](https://towardsdatascience.com/author/tyagigaurika27/)\nJune 7, 20203 min read\n  * [![](../images/011.png)](https://towardsdatascience.com/machine-learning-illustrated-opening-black-box-models-with-shap-9e92d0400680/)\n## [Machine Learning, Illustrated: Opening Black Box Models with SHAP](https://towardsdatascience.com/machine-learning-illustrated-opening-black-box-models-with-shap-9e92d0400680/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nHow to explain any machine learning model using SHAP\n[Shreya Rao](https://towardsdatascience.com/author/shreya.rao/)\nMay 8, 20239 min read\n  * [![](../images/012.png)](https://towardsdatascience.com/interview-question-select-a-random-line-from-a-file-in-rust-c0a8cddcddfb/)\n## [Interview Question: Select a Random Line from a File (in Rust)](https://towardsdatascience.com/interview-question-select-a-random-line-from-a-file-in-rust-c0a8cddcddfb/)\n[Programming](https://towardsdatascience.com/category/programming/)\nA cool and useful algorithm explained and extended\n[Carl Kadie](https://towardsdatascience.com/author/carlmkadie/)\nSeptember 1, 202210 min read\n\n\n  * [YouTube](https://www.youtube.com/c/TowardsDataScience)\n  * [X](https://x.com/TDataScience)\n  * [LinkedIn](https://www.linkedin.com/company/towards-data-science/)\n  * [Threads](https://www.threads.net/@towardsdatascience)\n  * [Bluesky](https://bsky.app/profile/towardsdatascience.com)\n\n\n[](https://towardsdatascience.com/)\nYour home for data science and AI. The world's leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.\nSubscribe to Our Newsletter[Write For TDS](https://towardsdatascience.com/submissions/)•[About](https://towardsdatascience.com/about-towards-data-science-d691af11cc2f/)•[Advertise](https://contact.towardsdatascience.com/advertise-with-towards-data-science)•[Privacy Policy](https://towardsdatascience.com/privacy-policy/)•[Terms of Use](https://towardsdatascience.com/website-terms-of-use/)\n© Insight Media Group, LLC 2026•[The New Stack](https://thenewstack.io)•[roadmap.sh](https://roadmap.sh)•[Creator Network](https://insightmediagroup.io/creator-network)\n####  Recommended Articles \nClose\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607639/image?etag=1781250125848&width=500&height=500) Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1 ](https://towardsdatascience.com/javascript-fatigue-you-dont-need-js-to-build-chatgpt/ \"Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607930/image?etag=1782124566054&width=500&height=500) The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs ](https://towardsdatascience.com/subset-sum-problem-solved-in-linear-time-for-dense-enough-inputs/ \"The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/3660/image?etag=1780176246070&width=500&height=500) Does Your Company Have a Data Strategy? ](https://towardsdatascience.com/does-your-company-have-a-data-strategy-e8944dbec4ae/ \"Does Your Company Have a Data Strategy?\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/4970/image?etag=1780565225463&width=500&height=500) Productivity Tips, Data Career Insights, and Other Recent Must-Reads ](https://towardsdatascience.com/productivity-tips-data-career-insights-and-other-recent-must-reads-5c47eb7a2fe0/ \"Productivity Tips, Data Career Insights, and Other Recent Must-Reads\")\n\n\n",
  "metadata": {
    "title": "Detecting State-backed Twitter Trolls With Transformers | Towards Data Science",
    "description": "A practical use case on fine tuning a Distilbert model on a custom dataset, and testing its performance against more commonly used models...",
    "keywords": null,
    "author": "Chua Chin Hon",
    "og:locale": "en_US",
    "og:type": "article",
    "og:title": "Detecting State-backed Twitter Trolls With Transformers",
    "og:description": "A practical use case on fine tuning a Distilbert model on a custom dataset, and testing its performance against more commonly used models...",
    "og:url": "https://towardsdatascience.com/detecting-state-backed-twitter-trolls-with-transformers-5d7825945938/",
    "og:site_name": "Towards Data Science",
    "og:image": "https://assets.insightmediagroup.io/media/wp-content/uploads/2020/09/1cV0U-0-9NVLDqNFMTOQSKQ.png",
    "og:image:width": "3874",
    "og:image:height": "1922",
    "og:image:type": "image/png",
    "twitter:card": "summary_large_image",
    "twitter:site": "@TDataScience",
    "twitter:creator": "@TDataScience",
    "twitter:label1": "Written by",
    "twitter:data1": "Chua Chin Hon",
    "twitter:label2": "Est. reading time",
    "twitter:data2": "8 min read",
    "article:published_time": "2020-09-21T08:46:46.000Z",
    "article:modified_time": "2020-09-21T08:46:46.000Z",
    "article:author": "https://towardsdatascience.com/author/chuachinhon/"
  },
  "paywall": {
    "listed_paid": false,
    "detected": false,
    "marker": "",
    "public_only": false,
    "policy": "付费/会员内容只保留页面公开可见部分，不绕过付费墙"
  },
  "crawl": {
    "success": true,
    "status_code": 202,
    "error": ""
  },
  "code_blocks": [
    {
      "language": "txt",
      "file": "attachments/c89b9b539eab/code/block_000.txt",
      "chars": 143
    },
    {
      "language": "txt",
      "file": "attachments/c89b9b539eab/code/block_001.txt",
      "chars": 131
    }
  ],
  "images": [
    {
      "status": "http_404",
      "url": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607639/image?etag=1781250125848&width=500&height=500",
      "src": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607639/image?etag=1781250125848&width=500&height=500",
      "alt": "",
      "downloaded": false,
      "discovery": "saved_markdown",
      "retried_at": "2026-10-20T17:49:34Z"
    },
    {
      "status": "http_404",
      "url": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607930/image?etag=1782124566054&width=500&height=500",
      "src": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607930/image?etag=1782124566054&width=500&height=500",
      "alt": "",
      "downloaded": false,
      "discovery": "saved_markdown",
      "retried_at": "2026-10-20T17:49:34Z"
    },
    {
      "status": "http_404",
      "url": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/3660/image?etag=1780176246070&width=500&height=500",
      "src": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/3660/image?etag=1780176246070&width=500&height=500",
      "alt": "",
      "downloaded": false,
      "discovery": "saved_markdown",
      "retried_at": "2026-10-20T17:50:39Z"
    },
    {
      "status": "http_404",
      "url": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/4970/image?etag=1780565225463&width=500&height=500",
      "src": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/4970/image?etag=1780565225463&width=500&height=500",
      "alt": "",
      "downloaded": false,
      "discovery": "saved_markdown",
      "retried_at": "2026-10-20T17:50:39Z"
    }
  ],
  "audio": [],
  "videos": [
    {
      "url": "https://www.youtube.com/c/TowardsDataScience",
      "kind": "channel_reference",
      "status": "reference_only"
    }
  ],
  "links": [
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/latest/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/editors-pick/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/the-variable/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/shipai/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/submissions/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/data-science/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/chuachinhon/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/using-data-science-to-uncover-state-backed-trolls-on-twitter-dc04dc749d69"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/data-science/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/deep-learning/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/machine-learning/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/nlp/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/us-elections/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/beautifully-illustrated-nlp-models-from-rnn-to-transformer-80d69faf2109/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/artificial-intelligence/deep-learning/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/dwiuzila/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/top-3-ways-your-anomaly-detection-models-can-earn-your-trust-f59072a6199c/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/artificial-intelligence/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/michalhoarau/"
    },
    {
      "type": "external",
      "href": "https://write.insightmediagroup.io"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/company/towards-data-science/"
    },
    {
      "type": "external",
      "href": "https://x.com/TDataScience"
    },
    {
      "type": "external",
      "href": "https://github.com/chuachinhon/transformers_state_trolls_cch/tree/master/app"
    },
    {
      "type": "external",
      "href": "https://www.nytimes.com/2020/09/10/us/politics/russian-hacking-microsoft-biden-trump.html"
    },
    {
      "type": "external",
      "href": "https://en.wikipedia.org/wiki/Russian_interference_in_the_2016_United_States_elections"
    },
    {
      "type": "external",
      "href": "https://huggingface.co/transformers/model_doc/distilbert.html"
    },
    {
      "type": "external",
      "href": "https://github.com/chuachinhon/twitter_state_trolls_cch"
    },
    {
      "type": "external",
      "href": "https://roadmap.sh/ai-data-scientist"
    },
    {
      "type": "external",
      "href": "https://roadmap.sh/machine-learning"
    },
    {
      "type": "external",
      "href": "https://transparency.twitter.com/en/reports/information-operations.html"
    },
    {
      "type": "external",
      "href": "https://github.com/chuachinhon/transformers_state_trolls_cch/blob/master/data/troll_50k.csv"
    },
    {
      "type": "external",
      "href": "https://github.com/chuachinhon/transformers_state_trolls_cch/blob/master/data/real_50k.csv"
    },
    {
      "type": "external",
      "href": "https://www.tweepy.org/"
    },
    {
      "type": "external",
      "href": "https://github.com/chuachinhon/transformers_state_trolls_cch/tree/master/notebooks"
    },
    {
      "type": "external",
      "href": "https://github.com/chuachinhon/transformers_state_trolls_cch"
    },
    {
      "type": "external",
      "href": "https://colab.research.google.com/signup"
    },
    {
      "type": "external",
      "href": "https://www.dropbox.com/sh/90h7ymog2oi5yn7/AACTuxmMTcso6aMxSmSiD8AVa"
    },
    {
      "type": "external",
      "href": "https://huggingface.co/distilbert-base-uncased"
    },
    {
      "type": "external",
      "href": "https://huggingface.co/transformers/master/main_classes/trainer.html"
    }
  ],
  "repair_version": 2,
  "repaired_at": "2026-10-20T17:27:03Z",
  "source_url": "https://towardsdatascience.com/detecting-state-backed-twitter-trolls-with-transformers-5d7825945938/",
  "delivery_status": "unverified",
  "discovery_status": "http_403",
  "missing_reason": "源页面未重新核验:http_403；已按保留正文补采图片",
  "repair_error": "",
  "actual_video_files": [],
  "expected_saved_body_images": 4,
  "image_discovery": "saved_markdown",
  "source_body_markdown": "![Revisit consent button](https://cdn-cookieyes.com/assets/images/revisit.svg)\nWe value your privacy\nWe use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking \"Accept All\", you consent to our use of cookies.\nCustomise Reject All Accept All\nCustomise Consent Preferences ![](https://cdn-cookieyes.com/assets/images/close.svg)\nWe use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.\nThe cookies that are categorised as \"Necessary\" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... Show more\nNecessaryAlways Active\nNecessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.\n  * Cookie\nBCTempID\n  * Duration\n10 minutes\n  * Description\nNo description available.\n\n\n  * Cookie\n__cf_bm\n  * Duration\n1 hour\n  * Description\nThis cookie, set by Cloudflare, is used to support Cloudflare Bot Management. \n\n\n  * Cookie\nAWSALBCORS\n  * Duration\n7 days\n  * Description\nAmazon Web Services set this cookie for load balancing.\n\n\n  * Cookie\n_cfuvid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to track users across sessions to optimize user experience by maintaining session consistency and providing personalized services\n\n\n  * Cookie\nli_gc\n  * Duration\n6 months\n  * Description\nLinkedin set this cookie for storing visitor's consent regarding using cookies for non-essential purposes.\n\n\n  * Cookie\n__hssrc\n  * Duration\nsession\n  * Description\nThis cookie is set by Hubspot whenever it changes the session cookie. The __hssrc cookie set to 1 indicates that the user has restarted the browser, and if the cookie does not exist, it is assumed to be a new session.\n\n\n  * Cookie\n__hssc\n  * Duration\n1 hour\n  * Description\nHubSpot sets this cookie to keep track of sessions and to determine if HubSpot should increment the session number and timestamps in the __hstc cookie.\n\n\n  * Cookie\nwpEmojiSettingsSupports\n  * Duration\nsession\n  * Description\nWordPress sets this cookie when a user interacts with emojis on a WordPress site. It helps determine if the user's browser can display emojis properly.\n\n\n  * Cookie\nBCSessionID\n  * Duration\n1 year 1 month 4 days\n  * Description\nBlueconic sets this cookie as a unique identifier for the BlueConic profile.\n\n\n  * Cookie\n_octo\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nlogged_in\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\n__Secure-YEC\n  * Duration\npast\n  * Description\nYouTube sets this cookie to stores the user's video player preferences using embedded YouTube video\n\n\n  * Cookie\n__eoi\n  * Duration\n6 months\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTGCORS\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\nlogin-status-p\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTG\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\ncsrf_token\n  * Duration\nsession\n  * Description\nNo description available.\n\n\n  * Cookie\ntoken_v2\n  * Duration\n1 day\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nD\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nPHPSESSID\n  * Duration\nsession\n  * Description\nThis cookie is native to PHP applications. The cookie stores and identifies a user's unique session ID to manage user sessions on the website. The cookie is a session cookie and will be deleted when all the browser windows are closed.\n\n\n  * Cookie\nVISITOR_PRIVACY_METADATA\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to store the user's cookie consent state for the current domain. \n\n\n  * Cookie\ncookietest\n  * Duration\nsession\n  * Description\nThe cookietest cookie is typically used to determine whether the user's browser accepts cookies, essential for website functionality and user experience.\n\n\n  * Cookie\n__Host-airtable-session\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\n__Host-airtable-session.sig\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\nm\n  * Duration\n1 year 1 month 4 days\n  * Description\nStripe sets this cookie for fraud prevention purposes. It identifies the device used to access the website, allowing the website to be formatted accordingly.\n\n\n  * Cookie\nBIGipServer*\n  * Duration\nsession\n  * Description\nMarketo sets this cookie to collect information about the user's online activity and build a profile about their interests to provide advertisements relevant to the user. \n\n\n  * Cookie\n__cfruid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to identify trusted web traffic.\n\n\n  * Cookie\n_GRECAPTCHA\n  * Duration\n6 months\n  * Description\nGoogle Recaptcha service sets this cookie to identify bots to protect the website against malicious spam attacks.\n\n\n  * Cookie\n__Secure-YNID\n  * Duration\n6 months\n  * Description\nGoogle cookie used to protect user security and prevent fraud, especially during the login process.\n\n\n  * Cookie\ncookieyes-consent\n  * Duration\n1 year\n  * Description\nCookieYes sets this cookie to remember users' consent preferences so that their preferences are respected on subsequent visits to this site. It does not collect or store any personal information about the site visitors.\n\n\nFunctional\nFunctional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.\n  * Cookie\nlidc\n  * Duration\n1 day\n  * Description\nLinkedIn sets the lidc cookie to facilitate data center selection.\n\n\n  * Cookie\nbrw\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nbrwConsent\n  * Duration\n5 minutes\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nWMF-Uniq\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nloom_anon_comment\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nloom_referral_video\n  * Duration\nsession\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nVISITOR_INFO1_LIVE\n  * Duration\n6 months\n  * Description\nA cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface.\n\n\n  * Cookie\nyt-remote-connected-devices\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nytidb::LAST_RESULT_ENTRY_KEY\n  * Duration\nNever Expires\n  * Description\nThe cookie ytidb::LAST_RESULT_ENTRY_KEY is used by YouTube to store the last search result entry that was clicked by the user. This information is used to improve the user experience by providing more relevant search results in the future.\n\n\n  * Cookie\nyt-remote-device-id\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-name\n  * Duration\nsession\n  * Description\nThe yt-remote-session-name cookie is used by YouTube to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\nyt-remote-fast-check-period\n  * Duration\nsession\n  * Description\nThe yt-remote-fast-check-period cookie is used by YouTube to store the user's video player preferences for embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-app\n  * Duration\nsession\n  * Description\nThe yt-remote-session-app cookie is used by YouTube to store user preferences and information about the interface of the embedded YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-available\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-available cookie is used to store the user's preferences regarding whether casting is available on their YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-installed\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-installed cookie is used to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\ncp_session\n  * Duration\n3 months\n  * Description\nCodepen sets this cookie for Help systems found in the website.\n\n\n  * Cookie\nloid\n  * Duration\n1 year 1 month 4 days\n  * Description\nThis cookie is set by the Reddit. The cookie enables the sharing of content from the website onto the social media platform.\n\n\nAnalytics\nAnalytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.\n  * Cookie\n__hstc\n  * Duration\n6 months\n  * Description\nHubspot set this main cookie for tracking visitors. It contains the domain, initial timestamp (first visit), last timestamp (last visit), current timestamp (this visit), and session number (increments for each subsequent session).\n\n\n  * Cookie\nhubspotutk\n  * Duration\n6 months\n  * Description\nHubSpot sets this cookie to keep track of the visitors to the website. This cookie is passed to HubSpot on form submission and used when deduplicating contacts.\n\n\n  * Cookie\n_ga\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to calculate visitor, session and campaign data and track site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognise unique visitors.\n\n\n  * Cookie\n_ga_*\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to store and count page views.\n\n\n  * Cookie\n__Host-psifi.analyticsTrace\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n__Host-psifi.analyticsTraceV2\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n_gh_sess\n  * Duration\nsession\n  * Description\nGitHub sets this cookie for temporary application and framework state between pages like what step the user is on in a multiple step form.\n\n\n  * Cookie\nYSC\n  * Duration\nsession\n  * Description\nYSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages.\n\n\n  * Cookie\najs_anonymous_id\n  * Duration\n1 year\n  * Description\nThis cookie is set by Segment to count the number of people who visit a certain site by tracking if they have visited before.\n\n\n  * Cookie\nvuid\n  * Duration\n1 year 1 month 4 days\n  * Description\nVimeo installs this cookie to collect tracking information by setting a unique ID to embed videos on the website. \n\n\nPerformance\nPerformance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.\n  * Cookie\nAWSALB\n  * Duration\n7 days\n  * Description\nAWSALB is an application load balancer cookie set by Amazon Web Services to map the session to the target.\n\n\n  * Cookie\nacq\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nacq.sig\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nptc\n  * Duration\n2 years\n  * Description\nNo description available.\n\n\nAdvertisement\nAdvertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.\n  * Cookie\nmuc_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to collect user behaviour and interaction data to optimize the website.\n\n\n  * Cookie\nguest_id_marketing\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\nguest_id_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\npersonalization_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to integrate and share features for social media and also store information about how the user uses the website, for tracking and targeting.\n\n\n  * Cookie\nguest_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor. It registers if a user is signed in to the Twitter platform and collects information about ad preferences.\n\n\n  * Cookie\nbcookie\n  * Duration\n1 year\n  * Description\nLinkedIn sets this cookie from LinkedIn share buttons and ad tags to recognize browser IDs.\n\n\n  * Cookie\n__Secure-ROLLOUT_TOKEN\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to manage feature rollout and experimentation. It helps Google control which new features or interface changes are shown to users as part of testing and staged rollouts, ensuring consistent experience for a given user during an experiment.\n\n\n  * Cookie\nyt.innertube::nextId\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nyt.innertube::requests\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nsession_tracker\n  * Duration\nsession\n  * Description\nThis cookie is set by the Reddit. This cookie is used to identify trusted web traffic. It also helps in adverstising on the website.\n\n\n  * Cookie\nedgebucket\n  * Duration\nsession\n  * Description\nReddit sets this cookie to save the information about a log-on Reddit user, for the purpose of advertisement recommendations and updating the content.\n\n\n  * Cookie\ndid\n  * Duration\n1 year\n  * Description\nArbor sets this cookie to show targeted ads to site visitors.This cookie expires after 2 months or 1 year.\n\n\nUncategorised\nOther uncategorised cookies are those that are being analysed and have not been classified into a category as yet.\nNo cookies to display.\nReject All Save My Preferences Accept All\nToggle Search[](https://towardsdatascience.com/)Toggle Mobile Navigation\n[](https://towardsdatascience.com/)\nPublish AI, ML & data-science insights to a global community of data professionals.\nSign in[Submit an Article](https://write.insightmediagroup.io)\n[Latest](https://towardsdatascience.com/latest/)[Editor's Picks](https://towardsdatascience.com/tag/editors-pick/)[Newsletter](https://towardsdatascience.com/tag/the-variable/)[ShipAI](https://towardsdatascience.com/shipai/)\n* * *\n[Write For TDS](https://towardsdatascience.com/submissions/)\n[LinkedIn](https://www.linkedin.com/company/towards-data-science/)[X](https://x.com/TDataScience)Toggle Search\n[Data Science](https://towardsdatascience.com/category/data-science/)\n# Detecting State-backed Twitter Trolls With Transformers\nA practical use case on fine tuning a Distilbert model on a custom dataset, and testing its performance against more commonly used models...\n[Chua Chin Hon](https://towardsdatascience.com/author/chuachinhon/)\nSeptember 21, 20208 min read\n### A practical use case on fine tuning a Distilbert model on a custom dataset, and testing its performance against more commonly used models like Logistic Regression and XGBoost\n![Illustration of web app by: Chua Chin Hon](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/09/1cV0U-0-9NVLDqNFMTOQSKQ.png)\nIllustration of [web app](https://github.com/chuachinhon/transformers_state_trolls_cch/tree/master/app) by: Chua Chin Hon\nWith the 2020 US election around the corner, concerns about [electoral interference](https://www.nytimes.com/2020/09/10/us/politics/russian-hacking-microsoft-biden-trump.html) by state actors via social media and other online means are back in the spotlight in a big way.\nTwitter was a major platform that Russia used to [interfere with the 2016 US election](https://en.wikipedia.org/wiki/Russian_interference_in_the_2016_United_States_elections), and few have doubts that Moscow, Beijing and others will turn to the platform yet again with new disinformation campaigns.\nThis post will outline a broad overview of of how you can build a state troll tweets detector by fine tuning a transformer model ([Distilbert](https://huggingface.co/transformers/model_doc/distilbert.html)) with a custom dataset. This builds on my [earlier project](https://github.com/chuachinhon/twitter_state_trolls_cch) using \"classic\" machine learning models and a simple bag-of-words approach to detect state troll tweets.\nI'll also compare the results from the fine tuned Distilbert model with those from a Logistic Regression and an XGBoost model, to see if a transformer model can indeed perform better in a practical use case.\nLearn this step by step with the interactive [AI and Data Scientist](https://roadmap.sh/ai-data-scientist) and [Machine Learning](https://roadmap.sh/machine-learning) roadmaps.\n**Spoiler alert:** The fine tuned transformer model performed significantly better than the Log-Reg and XGBoost models (which weren't slouches either, to be sure), and held up much better when exposed to state troll tweets from a third country. Jump ahead to Section 4 for the results.\n* * *\n## 1. GROUND TRUTH, DATA SOURCE, MODEL AND REPO\nFirst things first: How did I ascertain whose tweets are deemed the work of state influence campaigns? In this case, the ground truth is established by Twitter's election integrity team.\nThe state troll tweets used in this project are those which have been [identified by Twitter and progressively released to the public since 2018](https://transparency.twitter.com/en/reports/information-operations.html). I chose six sets of state troll tweets from Twitter - three each from China and Russia - which I cleaned up, combined and downsampled to [50,000 rows](https://github.com/chuachinhon/transformers_state_trolls_cch/blob/master/data/troll_50k.csv).\nI created an equivalent set of [50,000 rows of real tweets](https://github.com/chuachinhon/transformers_state_trolls_cch/blob/master/data/real_50k.csv) by using [Tweepy](https://www.tweepy.org/) to scrape 175 accounts, which comprise a mixture of verified users and those which I've personally checked for authenticity. The resulting combined dataset of 100,000 rows of state troll-plus-real tweets was further split into the usual train-test-validation sets in the standard proportion of 70:20:10 respectively.\nFull details are in my [notebooks](https://github.com/chuachinhon/transformers_state_trolls_cch/tree/master/notebooks), and I won't repeat them [here](https://github.com/chuachinhon/transformers_state_trolls_cch) for brevity's sake. The full repo is available here. Fine tuning was done on a [Colab Pro](https://colab.research.google.com/signup) account, and took about five-and-a-half hours.\nThe fine tuned Distilbert model is too big for Github, but I've uploaded a [copy to Dropbox](https://www.dropbox.com/sh/90h7ymog2oi5yn7/AACTuxmMTcso6aMxSmSiD8AVa) for those who just want to experiment with the model. The six raw CSV files containing state troll tweets have to be [downloaded from Twitter](https://transparency.twitter.com/en/reports/information-operations.html) if you wish to create a larger training set.\n## 2. DATA PREPARATION\nIt ought to be pointed out that key assumptions in the data cleaning and preparation process will affect the outcomes. The assumptions are necessary to keep the scope of this project practical, but if you disagree with them, feel agree to slice a different version of the data based on your own preferred cleaning rules.\nMy main data cleaning rules for this project:\n  * Exclude non-English tweets, since the working assumption is that the target audience is English-speaking. I also wanted to prevent the model from making predictions based on language.\n  * Exclude retweets.\n  * Exclude tweets which have fewer than three words after text cleaning.\n\n\nI also kept the eventual combined dataset to 100,000 rows for practical reasons. My initial attempts to fine tune Distilbert with a 600,000 rows dataset resulted in repeated crashes of the Colab notebook and/or showed extremely long and impractical run times. A more ambitious version of this project just won't be practical without access to more compute/hardware.\n## 3. FINE TUNE THE DISTILBERT MODEL WITH CUSTOM DATASET\nFor this project, I picked the[ distilbert-base-uncased model](https://huggingface.co/distilbert-base-uncased) (smaller and more manageable) and used [Hugging Face's trainer](https://huggingface.co/transformers/master/main_classes/trainer.html) for the task. I abandoned attempts to do a [hyperparameters search](https://huggingface.co/transformers/master/main_classes/trainer.html#transformers.Trainer.hyperparameter_search) after several trials which ran on for too long, and hope to return to this topic at a future date (check out the discussion [here](https://discuss.huggingface.co/t/using-hyperparameter-search-in-trainer/785/2)).\nThe steps involved are fairly straightforward, as outlined in [notebook2.0](https://github.com/chuachinhon/transformers_state_trolls_cch/blob/master/notebooks/2.0_finetune_distilbert_colab_cch.ipynb) of my repo. The code is mostly based on the excellent examples and documentation on Hugging Face [[here](https://huggingface.co/transformers/master/main_classes/trainer.html)](https://huggingface.co/transformers/master/custom_datasets.html) and here.\nThe immediate results of the fine tuning certainly look impressive:\ntext\n\n```\n'eval_accuracy': 0.9158421345191773,\n 'eval_f1': 0.9163813100629625,\n 'eval_precision': 0.9098486510199605,\n 'eval_recall': 0.9230084557187361\n```\n\nI ran a quick test against the validation set - 10,000 rows kept aside and which the model has not seen _at all_ - and the excellent classification metrics barely budged:\ntext\n\n```\n'eval_accuracy': 0.9179, \n'eval_f1': 0.9189935865811544, \n'eval_precision': 0.9178163184864012, \n'eval_recall': 0.9201738786801027\n```\n\nFor a more thorough comparison and analysis, I trained two separate Logistic Regression and XGB classifier models using the same dataset used to fine tune the Distilbert model. Let's see how they do in the same tests.\n* * *\n## 4. FINE TUNED DISTILBERT VS LOG-REG VS XGB\nThe pickled Log-Reg and XGB models are available in my repo's [\"pkl\" folder](https://github.com/chuachinhon/transformers_state_trolls_cch/tree/master/pkl). My notebooks detailing their optimisation process are available [[here](https://github.com/chuachinhon/transformers_state_trolls_cch/blob/master/notebooks/3.1_compare_xgb_cch.ipynb)](https://github.com/chuachinhon/transformers_state_trolls_cch/blob/master/notebooks/3.0_compare_logreg_cch.ipynb) and here. I won't go into the details here, except to highlight that both models scored above 0.8 during training and grid search. While clearly lower than the fine tuned Distilbert model's score, I think these two models did well enough to provide for an adequate comparison.\nThe chart below shows the detailed breakdown, via confusion matrices, of how all three models performed against the validation set (10,000 rows comprising 5,061 state troll tweets and 4,939 real tweets).\n![Image by: Chua Chin Hon](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/09/1inCZUMQ9i3Wrli7PRRH2vQ.png)\nImage by: Chua Chin Hon\nAt a glance, it's clear that the fine tuned Distilbert model (on far left) is the strongest performer, and accurately picked out more state troll and real tweets than the Log-Reg or XGB models. More significantly, the number of false positives and false negatives for the Distilbert model is about _half_ that produced by the log-reg and XGB models.\nSo while the three models' performance metrics might seem close, the gap in their classification capabilities become very stark when seen via confusion matrices that give us a better sense of how they performed in classifying thousands of tweets.\n## 4.1 ADDITIONAL TEST FOR THE 3 MODELS\nAll three models were trained on a 50–50 split of real tweets and state troll tweets from China and Russia. In reality, we don't know the actual proportion of real-versus-troll tweets on Twitter. More importantly, state troll tweets can come from any country and changes in tone, language and topics could significantly affect the classifier's ability to separate real tweets from those originating from state-backed campaigns.\nWhich of the three models would hold up better if exposed to state troll tweets from a third country? To find out, I ran a new dataset - comprising 1,000 troll tweets from Iran and 993 real tweets from American users - through the three models. This new dataset was created from an [earlier project I did on the same subject](https://github.com/chuachinhon/twitter_state_trolls_cch).\n![Image by: Chua Chin Hon](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/09/1iWNfLKOAearGYcwmMCVjjg.png)\nImage by: Chua Chin Hon\nAs expected, all three classifiers saw their performance drop significantly when exposed to Iranian state troll tweets which they've not seen before.\nBut the fine tuned Distilbert model still held up decently, in my view. Not only did it correctly pick out more troll and real tweets compared to the Log-Reg or XGB model, the number of false negatives (troll tweets that the model thought were real tweets) was not excessively large.\nThis is particularly problematic with the Log-Reg model, which classified half (501 out of 1,000) of the troll tweets as real tweets when they were in fact the work of state-backed operators. The XGB model is slightly better in this area, but not by far, with the number of false negatives (468) significantly higher than the number of false positives.\nThis was a particularly pronounced [problem with the models I trained in my earlier project](https://towardsdatascience.com/using-data-science-to-uncover-state-backed-trolls-on-twitter-dc04dc749d69), meaning classifiers trained on one particular state actor's troll tweets were quite good at spotting new, unseen tweets from said state actor. But once troll tweets from another state operator is injected into the mix, the classifier's performance falters significantly.\nThe fine tuned Distilbert model doesn't overcome this problem completely, but holds up well enough to hold out hopes for a model that can \"generalise\" better. If you have enough computing resources to train a transformer model on a bigger dataset comprising state troll tweets from all the countries identified by Twitter to date, it stands to reason that said model _might_ do better in the sort of tests we've tried in this post.\nUnfortunately that's a hypothesis I'll have to test another time.\n## 5. CONCLUSION\nDetection of state influence campaigns on Twitter involves more than just the examination of the tweet text, of course. State trolls often leave bigger tell-tale signs like the (coordinated) dates of account creation, or timing of their tweets. The increasing use of photos and memes also make the detection process trickier.\nBut spotting trends and hidden structures in their tweet text will continue to be one major area of focus. And it would appear that a fine tuned transformer model can perform significantly better in this task compared to the more popular or traditional classifiers out there.\nThere are trade-offs, of course, in terms of resources and time. The hardware needed to fine tune a transformer model on, say, a million rows of tweets, is not readily available to most users, to say nothing of whether that's the most efficient way to tackle the task.\n* * *\n## 6. BONUS SECTION: WEB APP\nI tried deploying the fine tuned Distilbert model as part of a simple web app but quickly found out that free hosting accounts don't have enough disk space for pytorch installation on top of hosting the model.\nBut I've uploaded the necessary files to the repo for anyone who wants to try it out on their local machine. Just make sure to download the fine tuned model [from Dropbox](https://www.dropbox.com/sh/90h7ymog2oi5yn7/AACTuxmMTcso6aMxSmSiD8AVa) and move it to the \"app\" folder.\n![Gif by: Chua Chin Hon](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/09/17CM0DkRlFGSXXFwv8JITCw.gif)\nGif by: Chua Chin Hon\nAs always, if you spot mistakes in this or any of my earlier posts, ping me at:\n  * Twitter: [Chua Chin Hon](https://medium.com/u/b3d8090c0aee?source=post_page-----aad7f2e1d0a0----------------------)\n  * LinkedIn: [www.linkedin.com/in/chuachinhon](http://www.linkedin.com/in/chuachinhon)\n\n\n## Register Now to Continue Reading\n### Unlock Towards Data Science with a Free Account\nAll articles on Towards Data Science are available to registered users. Create a free account today to access this article and thousands more.\nRegister for freeSign in to your account\n* * *\n![](https://assets.insightmediagroup.io/media/1787657280763_838i2j.png)\nWritten By\n## [Chua Chin Hon](https://towardsdatascience.com/author/chuachinhon/)\n[See all from Chua Chin Hon](https://towardsdatascience.com/author/chuachinhon/)\n[Data Science](https://towardsdatascience.com/tag/data-science/)[Deep Learning](https://towardsdatascience.com/tag/deep-learning/)[Machine Learning](https://towardsdatascience.com/tag/machine-learning/)[NLP](https://towardsdatascience.com/tag/nlp/)[US Elections](https://towardsdatascience.com/tag/us-elections/)\nShare This Article\n  * [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ftowardsdatascience.com%2Fdetecting-state-backed-twitter-trolls-with-transformers-5d7825945938%2F&title=Detecting%20State-backed%20Twitter%20Trolls%20With%20Transformers)\n  * [](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Ftowardsdatascience.com%2Fdetecting-state-backed-twitter-trolls-with-transformers-5d7825945938%2F&title=Detecting%20State-backed%20Twitter%20Trolls%20With%20Transformers)\n  * [](https://x.com/share?url=https%3A%2F%2Ftowardsdatascience.com%2Fdetecting-state-backed-twitter-trolls-with-transformers-5d7825945938%2F&text=Detecting%20State-backed%20Twitter%20Trolls%20With%20Transformers)\n\n\nTowards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.\n[Write for TDS](https://towardsdatascience.com/submissions/)\n## Related Articles\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/10/0HiyGwoGOMI5Ao_fd-scaled.jpg)](https://towardsdatascience.com/beautifully-illustrated-nlp-models-from-rnn-to-transformer-80d69faf2109/)\n## [Beautifully Illustrated: NLP Models from RNN to Transformer](https://towardsdatascience.com/beautifully-illustrated-nlp-models-from-rnn-to-transformer-80d69faf2109/)\n[Deep Learning](https://towardsdatascience.com/category/artificial-intelligence/deep-learning/)\nExplaining their complex mathematical formula with working diagrams\n[Albers Uzila](https://towardsdatascience.com/author/dwiuzila/)\nOctober 11, 202211 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/05/061eacZdcCP-K8QFT-scaled.jpg)](https://towardsdatascience.com/top-3-ways-your-anomaly-detection-models-can-earn-your-trust-f59072a6199c/)\n## [Top 3 Ways Your Anomaly Detection Models Can Earn Your Trust](https://towardsdatascience.com/top-3-ways-your-anomaly-detection-models-can-earn-your-trust-f59072a6199c/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nConnecting anomaly detection models results back to the original signals\n[Michaël HOARAU](https://towardsdatascience.com/author/michalhoarau/)\nMay 6, 20226 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/02/0Fq_rB_XNCfhEQEdp-scaled.jpg)](https://towardsdatascience.com/data-science-career-switch-is-masters-degree-worth-it-part-2-1110c3440e4b/)\n## [Data Science Career Switch: Is Master's Degree Worth It? (Part 2)](https://towardsdatascience.com/data-science-career-switch-is-masters-degree-worth-it-part-2-1110c3440e4b/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nProgramming language to learn and three questions to ask before making a planned career switch\n[Nathan Timothy Handoko](https://towardsdatascience.com/author/nathanthandoko/)\nFebruary 26, 20225 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/05/1itAiiY0aVMrHZfW6N-0wtw-scaled.jpeg)](https://towardsdatascience.com/how-to-train-test-split-kfold-vs-stratifiedkfold-281767b93869/)\n## [How to train_test_split : KFold vs StratifiedKFold](https://towardsdatascience.com/how-to-train-test-split-kfold-vs-stratifiedkfold-281767b93869/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nExplained with examples\n[Soner Yıldırım](https://towardsdatascience.com/author/sonery/)\nMay 21, 20204 min read\n  * [![](https://towardsdatascience.com/images/fallback-image.jpg)](https://towardsdatascience.com/the-ultimate-guide-of-classification-metrics-for-model-evaluation-83e4cdf294d9/)\n## [The Ultimate Guide of Classification Metrics for Model Evaluation](https://towardsdatascience.com/the-ultimate-guide-of-classification-metrics-for-model-evaluation-83e4cdf294d9/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nCombine machine learning models with hypothesis testing. Stop pulling your hair and read this article.\n[Zijing Zhu, PhD](https://towardsdatascience.com/author/zzhu17/)\nSeptember 6, 20207 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2019/12/0CLyTlakaQOhoNsx5-scaled.jpg)](https://towardsdatascience.com/how-much-math-do-you-really-need-in-data-science-821ad101d394/)\n## [How much Math do you really need in Data Science?](https://towardsdatascience.com/how-much-math-do-you-really-need-in-data-science-821ad101d394/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nWhen Enough is Enough\n[Dario Radečić](https://towardsdatascience.com/author/radecicdario/)\nDecember 3, 20194 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/06/1njHwI4RWEKNw_cRxZhizrA.png)](https://towardsdatascience.com/nlp-topic-modeling-to-identify-clusters-ca207244d04f/)\n## [NLP-Topic Modeling to identify Clusters](https://towardsdatascience.com/nlp-topic-modeling-to-identify-clusters-ca207244d04f/)\n[NLP](https://towardsdatascience.com/category/artificial-intelligence/nlp/)\nDerive Topics from Long Text\n[Gaurika Tyagi](https://towardsdatascience.com/author/tyagigaurika27/)\nJune 7, 20203 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/05/1y-c90AFpQwXMM7WREsL5ig.png)](https://towardsdatascience.com/machine-learning-illustrated-opening-black-box-models-with-shap-9e92d0400680/)\n## [Machine Learning, Illustrated: Opening Black Box Models with SHAP](https://towardsdatascience.com/machine-learning-illustrated-opening-black-box-models-with-shap-9e92d0400680/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nHow to explain any machine learning model using SHAP\n[Shreya Rao](https://towardsdatascience.com/author/shreya.rao/)\nMay 8, 20239 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/09/18O1rD59qJ2z7s03ks4aYuQ.png)](https://towardsdatascience.com/interview-question-select-a-random-line-from-a-file-in-rust-c0a8cddcddfb/)\n## [Interview Question: Select a Random Line from a File (in Rust)](https://towardsdatascience.com/interview-question-select-a-random-line-from-a-file-in-rust-c0a8cddcddfb/)\n[Programming](https://towardsdatascience.com/category/programming/)\nA cool and useful algorithm explained and extended\n[Carl Kadie](https://towardsdatascience.com/author/carlmkadie/)\nSeptember 1, 202210 min read\n\n\n  * [YouTube](https://www.youtube.com/c/TowardsDataScience)\n  * [X](https://x.com/TDataScience)\n  * [LinkedIn](https://www.linkedin.com/company/towards-data-science/)\n  * [Threads](https://www.threads.net/@towardsdatascience)\n  * [Bluesky](https://bsky.app/profile/towardsdatascience.com)\n\n\n[](https://towardsdatascience.com/)\nYour home for data science and AI. The world's leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.\nSubscribe to Our Newsletter[Write For TDS](https://towardsdatascience.com/submissions/)•[About](https://towardsdatascience.com/about-towards-data-science-d691af11cc2f/)•[Advertise](https://contact.towardsdatascience.com/advertise-with-towards-data-science)•[Privacy Policy](https://towardsdatascience.com/privacy-policy/)•[Terms of Use](https://towardsdatascience.com/website-terms-of-use/)\n© Insight Media Group, LLC 2026•[The New Stack](https://thenewstack.io)•[roadmap.sh](https://roadmap.sh)•[Creator Network](https://insightmediagroup.io/creator-network)\n####  Recommended Articles \nClose\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607639/image?etag=1781250125848&width=500&height=500) Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1 ](https://towardsdatascience.com/javascript-fatigue-you-dont-need-js-to-build-chatgpt/ \"Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607930/image?etag=1782124566054&width=500&height=500) The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs ](https://towardsdatascience.com/subset-sum-problem-solved-in-linear-time-for-dense-enough-inputs/ \"The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/3660/image?etag=1780176246070&width=500&height=500) Does Your Company Have a Data Strategy? ](https://towardsdatascience.com/does-your-company-have-a-data-strategy-e8944dbec4ae/ \"Does Your Company Have a Data Strategy?\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/4970/image?etag=1780565225463&width=500&height=500) Productivity Tips, Data Career Insights, and Other Recent Must-Reads ](https://towardsdatascience.com/productivity-tips-data-career-insights-and-other-recent-must-reads-5c47eb7a2fe0/ \"Productivity Tips, Data Career Insights, and Other Recent Must-Reads\")\n\n\n",
  "body_base_path": "attachments/c89b9b539eab/pages/",
  "body_markdown_path": "attachments/c89b9b539eab/pages/archived-body.md",
  "local_html": "attachments/c89b9b539eab/pages/archived-body.html",
  "body_source": "prior_capture"
}