{"id":568,"date":"2023-02-01T14:38:53","date_gmt":"2023-02-01T11:38:53","guid":{"rendered":"https:\/\/acua.qcri.org\/blog\/?p=568"},"modified":"2023-02-01T14:38:53","modified_gmt":"2023-02-01T11:38:53","slug":"bert-for-binary-text-classification","status":"publish","type":"post","link":"https:\/\/acua.qcri.org\/blog\/bert-for-binary-text-classification\/","title":{"rendered":"Unlock the Power of BERT for Binary Text Classification"},"content":{"rendered":"<figure id=\"attachment_573\" aria-describedby=\"caption-attachment-573\" style=\"width: 626px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-573\" src=\"https:\/\/acua.qcri.org\/blog\/wp-content\/uploads\/2023\/02\/woman_computer_user.png\" alt=\"woman_computer_user\" width=\"626\" height=\"414\" srcset=\"https:\/\/acua.qcri.org\/blog\/wp-content\/uploads\/2023\/02\/woman_computer_user.png 626w, https:\/\/acua.qcri.org\/blog\/wp-content\/uploads\/2023\/02\/woman_computer_user-300x198.png 300w\" sizes=\"(max-width: 626px) 100vw, 626px\" \/><figcaption id=\"caption-attachment-573\" class=\"wp-caption-text\">Unlock the Power of BERT for Binary Text Classification<\/figcaption><\/figure>\n<p><span style=\"font-weight: 400;\">In the world of natural language processing, one of the most important tasks is binary text classification. Binary text classification is the process of classifying text into two distinct classes. For example, a binary classifier could classify an email into either spam or not.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">A new deep learning tool called BERT (Bidirectional Encoder Representations from Transformers) has emerged as a powerful tool for binary text classification. BERT is a transformer-based language model that has achieved state-of-the-art performance on many natural language processing tasks. It is based on the Transformer architecture and uses a bidirectional approach to better capture the context of words in a sentence.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Using BERT for binary text classification has many advantages. For one, it allows for the accurate and efficient classification of texts. BERT can learn to classify a text in a short amount of time with high accuracy. Additionally, it can be used to classify texts of different lengths, making it a useful tool for natural language processing tasks such as sentiment analysis, question answering, and machine translation.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In the following GitHub repository, you can find the Python code for building a binary BERT classifier. You can only change the file name to make it work for your own dataset. There are 3 general steps to follow: <\/span><\/p>\n<p><span style=\"font-weight: 400;\">STEP 1: Loading and Preprocessing the Dataset<br \/>\n<\/span><\/p>\n<p>STEP 2: Creating the BERT Model and Wrapping in Learner Object<\/p>\n<p>STEP 3: Training the BERT Model<\/p>\n<p><a href=\"https:\/\/github.com\/khuloodkhalil\/BinaryBERTClassification\/blob\/76e9e30d7cc5323c0c01b5618f4b4fd9edcb5387\/BertBinaryClassification.ipynb\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">The GitHub repository for building the binary BERT classifier.<\/span><\/a><\/p>\n<p><span style=\"font-weight: 400;\">In case you are looking for a 3 classes classification using BERT, you may refer to our previous blog post, <a href=\"https:\/\/acua.qcri.org\/blog\/demystifying-language-models-the-case-of-berts-usage-in-solving-classification-problems\/\">the use of BERT in solving classification problems<\/a>.\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the world of natural language processing, one of the most important tasks is binary text classification. Binary text classification is the process of classifying text into two distinct classes. For example, a binary classifier could classify an email into either spam or not.\u00a0 A new deep learning tool called BERT (Bidirectional Encoder Representations from&hellip; <a class=\"more-link\" href=\"https:\/\/acua.qcri.org\/blog\/bert-for-binary-text-classification\/\">Continue reading <span class=\"screen-reader-text\">Unlock the Power of BERT for Binary Text Classification<\/span><\/a><\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,12],"tags":[69,70],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.13 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Unlock the Power of BERT for Binary Text Classification - Team Acua<\/title>\n<meta name=\"description\" content=\"Using BERT for binary classification followed by a GitHub repository for a Python tutorial of 3 general steps to follow.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/acua.qcri.org\/blog\/bert-for-binary-text-classification\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Unlock the Power of BERT for Binary Text Classification - Team Acua\" \/>\n<meta property=\"og:description\" content=\"Using BERT for binary classification followed by a GitHub repository for a Python tutorial of 3 general steps to follow.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/acua.qcri.org\/blog\/bert-for-binary-text-classification\/\" \/>\n<meta property=\"og:site_name\" content=\"Team Acua\" \/>\n<meta property=\"article:published_time\" content=\"2023-02-01T11:38:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/acua.qcri.org\/blog\/wp-content\/uploads\/2023\/02\/woman_computer_user.png\" \/>\n<meta name=\"author\" content=\"Kholoud Aldous\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kholoud Aldous\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/acua.qcri.org\/blog\/bert-for-binary-text-classification\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/acua.qcri.org\/blog\/bert-for-binary-text-classification\/\"},\"author\":{\"name\":\"Kholoud Aldous\",\"@id\":\"https:\/\/acua.qcri.org\/blog\/#\/schema\/person\/84104ee571377175f3d99eb4e21e2a13\"},\"headline\":\"Unlock the Power of BERT for Binary Text Classification\",\"datePublished\":\"2023-02-01T11:38:53+00:00\",\"dateModified\":\"2023-02-01T11:38:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/acua.qcri.org\/blog\/bert-for-binary-text-classification\/\"},\"wordCount\":292,\"publisher\":{\"@id\":\"https:\/\/acua.qcri.org\/blog\/#organization\"},\"keywords\":[\"BERT\",\"Language models\"],\"articleSection\":[\"Algorithms\",\"Customer Prediction\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/acua.qcri.org\/blog\/bert-for-binary-text-classification\/\",\"url\":\"https:\/\/acua.qcri.org\/blog\/bert-for-binary-text-classification\/\",\"name\":\"Unlock the Power of BERT for Binary Text Classification - Team Acua\",\"isPartOf\":{\"@id\":\"https:\/\/acua.qcri.org\/blog\/#website\"},\"datePublished\":\"2023-02-01T11:38:53+00:00\",\"dateModified\":\"2023-02-01T11:38:53+00:00\",\"description\":\"Using BERT for binary classification followed by a GitHub repository for a Python tutorial of 3 general steps to follow.\",\"breadcrumb\":{\"@id\":\"https:\/\/acua.qcri.org\/blog\/bert-for-binary-text-classification\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/acua.qcri.org\/blog\/bert-for-binary-text-classification\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/acua.qcri.org\/blog\/bert-for-binary-text-classification\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/acua.qcri.org\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Unlock the Power of BERT for Binary Text Classification\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/acua.qcri.org\/blog\/#website\",\"url\":\"https:\/\/acua.qcri.org\/blog\/\",\"name\":\"Team Acua\",\"description\":\"Audience, Customer, and User Analytics\",\"publisher\":{\"@id\":\"https:\/\/acua.qcri.org\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/acua.qcri.org\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/acua.qcri.org\/blog\/#organization\",\"name\":\"Team Acua\",\"url\":\"https:\/\/acua.qcri.org\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/acua.qcri.org\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/acua.qcri.org\/blog\/wp-content\/uploads\/2022\/10\/cropped-cropped-logo.png\",\"contentUrl\":\"https:\/\/acua.qcri.org\/blog\/wp-content\/uploads\/2022\/10\/cropped-cropped-logo.png\",\"width\":1466,\"height\":770,\"caption\":\"Team Acua\"},\"image\":{\"@id\":\"https:\/\/acua.qcri.org\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/acua.qcri.org\/blog\/#\/schema\/person\/84104ee571377175f3d99eb4e21e2a13\",\"name\":\"Kholoud Aldous\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/acua.qcri.org\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2d623007d31bfcee2409f387825ae07d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2d623007d31bfcee2409f387825ae07d?s=96&d=mm&r=g\",\"caption\":\"Kholoud Aldous\"},\"url\":\"https:\/\/acua.qcri.org\/blog\/author\/kkaldous\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Unlock the Power of BERT for Binary Text Classification - Team Acua","description":"Using BERT for binary classification followed by a GitHub repository for a Python tutorial of 3 general steps to follow.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/acua.qcri.org\/blog\/bert-for-binary-text-classification\/","og_locale":"en_US","og_type":"article","og_title":"Unlock the Power of BERT for Binary Text Classification - Team Acua","og_description":"Using BERT for binary classification followed by a GitHub repository for a Python tutorial of 3 general steps to follow.","og_url":"https:\/\/acua.qcri.org\/blog\/bert-for-binary-text-classification\/","og_site_name":"Team Acua","article_published_time":"2023-02-01T11:38:53+00:00","og_image":[{"url":"https:\/\/acua.qcri.org\/blog\/wp-content\/uploads\/2023\/02\/woman_computer_user.png"}],"author":"Kholoud Aldous","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kholoud Aldous","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/acua.qcri.org\/blog\/bert-for-binary-text-classification\/#article","isPartOf":{"@id":"https:\/\/acua.qcri.org\/blog\/bert-for-binary-text-classification\/"},"author":{"name":"Kholoud Aldous","@id":"https:\/\/acua.qcri.org\/blog\/#\/schema\/person\/84104ee571377175f3d99eb4e21e2a13"},"headline":"Unlock the Power of BERT for Binary Text Classification","datePublished":"2023-02-01T11:38:53+00:00","dateModified":"2023-02-01T11:38:53+00:00","mainEntityOfPage":{"@id":"https:\/\/acua.qcri.org\/blog\/bert-for-binary-text-classification\/"},"wordCount":292,"publisher":{"@id":"https:\/\/acua.qcri.org\/blog\/#organization"},"keywords":["BERT","Language models"],"articleSection":["Algorithms","Customer Prediction"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/acua.qcri.org\/blog\/bert-for-binary-text-classification\/","url":"https:\/\/acua.qcri.org\/blog\/bert-for-binary-text-classification\/","name":"Unlock the Power of BERT for Binary Text Classification - Team Acua","isPartOf":{"@id":"https:\/\/acua.qcri.org\/blog\/#website"},"datePublished":"2023-02-01T11:38:53+00:00","dateModified":"2023-02-01T11:38:53+00:00","description":"Using BERT for binary classification followed by a GitHub repository for a Python tutorial of 3 general steps to follow.","breadcrumb":{"@id":"https:\/\/acua.qcri.org\/blog\/bert-for-binary-text-classification\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/acua.qcri.org\/blog\/bert-for-binary-text-classification\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/acua.qcri.org\/blog\/bert-for-binary-text-classification\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/acua.qcri.org\/blog\/"},{"@type":"ListItem","position":2,"name":"Unlock the Power of BERT for Binary Text Classification"}]},{"@type":"WebSite","@id":"https:\/\/acua.qcri.org\/blog\/#website","url":"https:\/\/acua.qcri.org\/blog\/","name":"Team Acua","description":"Audience, Customer, and User Analytics","publisher":{"@id":"https:\/\/acua.qcri.org\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/acua.qcri.org\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/acua.qcri.org\/blog\/#organization","name":"Team Acua","url":"https:\/\/acua.qcri.org\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/acua.qcri.org\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/acua.qcri.org\/blog\/wp-content\/uploads\/2022\/10\/cropped-cropped-logo.png","contentUrl":"https:\/\/acua.qcri.org\/blog\/wp-content\/uploads\/2022\/10\/cropped-cropped-logo.png","width":1466,"height":770,"caption":"Team Acua"},"image":{"@id":"https:\/\/acua.qcri.org\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/acua.qcri.org\/blog\/#\/schema\/person\/84104ee571377175f3d99eb4e21e2a13","name":"Kholoud Aldous","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/acua.qcri.org\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2d623007d31bfcee2409f387825ae07d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2d623007d31bfcee2409f387825ae07d?s=96&d=mm&r=g","caption":"Kholoud Aldous"},"url":"https:\/\/acua.qcri.org\/blog\/author\/kkaldous\/"}]}},"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/acua.qcri.org\/blog\/wp-json\/wp\/v2\/posts\/568"}],"collection":[{"href":"https:\/\/acua.qcri.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/acua.qcri.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/acua.qcri.org\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/acua.qcri.org\/blog\/wp-json\/wp\/v2\/comments?post=568"}],"version-history":[{"count":6,"href":"https:\/\/acua.qcri.org\/blog\/wp-json\/wp\/v2\/posts\/568\/revisions"}],"predecessor-version":[{"id":576,"href":"https:\/\/acua.qcri.org\/blog\/wp-json\/wp\/v2\/posts\/568\/revisions\/576"}],"wp:attachment":[{"href":"https:\/\/acua.qcri.org\/blog\/wp-json\/wp\/v2\/media?parent=568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/acua.qcri.org\/blog\/wp-json\/wp\/v2\/categories?post=568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/acua.qcri.org\/blog\/wp-json\/wp\/v2\/tags?post=568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}