{"id":36093,"date":"2024-11-01T09:45:42","date_gmt":"2024-11-01T09:45:42","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=36093"},"modified":"2024-11-01T09:45:42","modified_gmt":"2024-11-01T09:45:42","slug":"hugging-face-transformers-tutorial-preparing-dataset-for-bigbird-inference","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/36093\/","title":{"rendered":"Hugging Face Transformers Tutorial, Preparing Dataset for BigBird Inference"},"content":{"rendered":"<p><body><\/p>\n<p>\n        With the advancement of deep learning, noticeable changes are also occurring in the field of Natural Language Processing (NLP). In particular,<br \/>\n        <strong>Hugging Face<\/strong>&#8216;s Transformer library is one of the key tools that has led this change. In this course, we will take a closer look at how to prepare a dataset that can be inferred using one of the transformer models, <strong>BigBird<\/strong>.\n    <\/p>\n<h2>1. What is BigBird?<\/h2>\n<p>\n        BigBird is a transformer-based model developed by Google that is optimized for processing long texts.<br \/>\n        Existing transformer models have limitations in processing long documents due to restrictions on the length of input sequences, but<br \/>\n        BigBird was designed to overcome these limitations.<br \/>\n        BigBird can process long texts through a more efficient attention mechanism.\n    <\/p>\n<h3>1.1. Advantages of BigBird<\/h3>\n<ul>\n<li>Long sequence processing: Effectively handles long documents, overcoming the limitations of existing transformers.<\/li>\n<li>Efficiency: Reduces computation costs by decreasing the complexity of attention.<\/li>\n<li>Applicable to various NLP tasks: Can be used in various fields such as text classification, summarization, and translation.<\/li>\n<\/ul>\n<h2>2. Preparing the Dataset<\/h2>\n<p>\n        The process of preparing a dataset to use with the BigBird model is relatively simple.<br \/>\n        We need to preprocess the given data into the format required by BigBird,<br \/>\n        and we will take a look at important considerations in this process.\n    <\/p>\n<h3>2.1. Required Data Format<\/h3>\n<p>\n        The BigBird model requires text and labels (answers) as input.<br \/>\n        Input text must not exceed the model&#8217;s maximum length, and<br \/>\n        labels should be represented as integers for classification problems and as floats for regression problems.\n    <\/p>\n<h3>2.2. Loading the Dataset<\/h3>\n<p>\n        Let&#8217;s assume that the dataset is provided in CSV file format.<br \/>\n        The example code below shows how to load data from a CSV file using <code>pandas<\/code>.\n    <\/p>\n<pre><code>python\nimport pandas as pd\n\n# Load dataset\ndata = pd.read_csv('dataset.csv')\nprint(data.head())\n<\/code><\/pre>\n<h3>2.3. Data Preprocessing<\/h3>\n<p>\n        This is the process of preprocessing the data to fit the BigBird model.<br \/>\n        This process includes text cleaning, tokenization, padding, and more.<br \/>\n        Below is an example of the data preprocessing process presented in code.\n    <\/p>\n<pre><code>python\nfrom transformers import BigBirdTokenizer\n\n# Tokenization and padding\ntokenizer = BigBirdTokenizer.from_pretrained('google\/bigbird-roberta-base')\n\nmax_length = 512  # Set maximum input length\n\ndef preprocess_data(text):\n    inputs = tokenizer(\n        text,\n        max_length=max_length,\n        padding='max_length',\n        truncation=True,\n        return_tensors='pt'\n    )\n    return inputs\n\n# Perform preprocessing on the text column of the dataset\ndata['inputs'] = data['text'].apply(preprocess_data)\nprint(data['inputs'].head())\n<\/code><\/pre>\n<h2>3. Preparing the Model and Performing Inference<\/h2>\n<p>\n        Now we are ready to train the BigBird model and perform inference based on the prepared data.<br \/>\n        Hugging Face&#8217;s transformer library provides an interface that makes loading and inferring models very simple.\n    <\/p>\n<h3>3.1. Loading the BigBird Model<\/h3>\n<p>\n        We use the <code>transformers<\/code> library to load the BigBird model.<br \/>\n        The example below shows how to load the BigBird model.\n    <\/p>\n<pre><code>python\nfrom transformers import BigBirdForSequenceClassification\n\n# Load model\nmodel = BigBirdForSequenceClassification.from_pretrained('google\/bigbird-roberta-base', num_labels=2)\n<\/code><\/pre>\n<h3>3.2. Performing Inference<\/h3>\n<p>\n        We perform inference on the prepared input data using the loaded model.<br \/>\n        Below is the code showing how to perform inference with the model and check the results.\n    <\/p>\n<pre><code>python\nimport torch\n\n# Perform inference\ndef infer(inputs):\n    with torch.no_grad():\n        outputs = model(**inputs)\n    logits = outputs.logits\n    predictions = torch.argmax(logits, dim=-1)\n    return predictions\n\n# Inference on the first input of the dataset\npred = infer(data['inputs'][0])\nprint(f'Predicted label: {pred.item()}')\n<\/code><\/pre>\n<h2>4. Conclusion<\/h2>\n<p>\n        In this course, we explored the process of preparing a dataset and performing inference using Hugging Face&#8217;s BigBird model.<br \/>\n        Thanks to BigBird&#8217;s excellent performance, we can effectively handle long text data that was difficult for us to process before.<br \/>\n        Please modify and utilize the preprocessing and inference code according to your dataset for application in real projects.\n    <\/p>\n<h3>4.1. Reference Materials<\/h3>\n<ul>\n<li><a href=\"https:\/\/huggingface.co\/transformers\/\">Hugging Face Transformers Documentation<\/a><\/li>\n<li><a href=\"https:\/\/arxiv.org\/abs\/2007.08896\">BigBird Paper<\/a><\/li>\n<\/ul>\n<h3>4.2. Questions and Feedback<\/h3>\n<p>\n        If you have any questions or feedback, please leave a comment.<br \/>\n        If you would like more deep learning courses, please visit my blog.\n    <\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>With the advancement of deep learning, noticeable changes are also occurring in the field of Natural Language Processing (NLP). In particular, Hugging Face&#8216;s Transformer library is one of the key tools that has led this change. In this course, we will take a closer look at how to prepare a dataset that can be inferred &hellip; <a href=\"https:\/\/atmokpo.com\/w\/36093\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Hugging Face Transformers Tutorial, Preparing Dataset for BigBird Inference&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[108],"tags":[],"class_list":["post-36093","post","type-post","status-publish","format-standard","hentry","category---en"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Hugging Face Transformers Tutorial, Preparing Dataset for BigBird Inference - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/36093\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hugging Face Transformers Tutorial, Preparing Dataset for BigBird Inference - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"With the advancement of deep learning, noticeable changes are also occurring in the field of Natural Language Processing (NLP). In particular, Hugging Face&#8216;s Transformer library is one of the key tools that has led this change. In this course, we will take a closer look at how to prepare a dataset that can be inferred &hellip; \ub354 \ubcf4\uae30 &quot;Hugging Face Transformers Tutorial, Preparing Dataset for BigBird Inference&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/36093\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:45:42+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/36093\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36093\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Hugging Face Transformers Tutorial, Preparing Dataset for BigBird Inference\",\"datePublished\":\"2024-11-01T09:45:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36093\/\"},\"wordCount\":504,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Using Hugging Face\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/36093\/\",\"url\":\"https:\/\/atmokpo.com\/w\/36093\/\",\"name\":\"Hugging Face Transformers Tutorial, Preparing Dataset for BigBird Inference - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:45:42+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36093\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/36093\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/36093\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hugging Face Transformers Tutorial, Preparing Dataset for BigBird Inference\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Hugging Face Transformers Tutorial, Preparing Dataset for BigBird Inference - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","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:\/\/atmokpo.com\/w\/36093\/","og_locale":"ko_KR","og_type":"article","og_title":"Hugging Face Transformers Tutorial, Preparing Dataset for BigBird Inference - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"With the advancement of deep learning, noticeable changes are also occurring in the field of Natural Language Processing (NLP). In particular, Hugging Face&#8216;s Transformer library is one of the key tools that has led this change. In this course, we will take a closer look at how to prepare a dataset that can be inferred &hellip; \ub354 \ubcf4\uae30 \"Hugging Face Transformers Tutorial, Preparing Dataset for BigBird Inference\"","og_url":"https:\/\/atmokpo.com\/w\/36093\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:45:42+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/36093\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/36093\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Hugging Face Transformers Tutorial, Preparing Dataset for BigBird Inference","datePublished":"2024-11-01T09:45:42+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/36093\/"},"wordCount":504,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Using Hugging Face"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/36093\/","url":"https:\/\/atmokpo.com\/w\/36093\/","name":"Hugging Face Transformers Tutorial, Preparing Dataset for BigBird Inference - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:45:42+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/36093\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/36093\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/36093\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Hugging Face Transformers Tutorial, Preparing Dataset for BigBird Inference"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36093","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=36093"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36093\/revisions"}],"predecessor-version":[{"id":36094,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36093\/revisions\/36094"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=36093"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=36093"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=36093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}