{"id":36165,"date":"2024-11-01T09:46:18","date_gmt":"2024-11-01T09:46:18","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=36165"},"modified":"2024-11-01T09:46:18","modified_gmt":"2024-11-01T09:46:18","slug":"transfomer-utilization-course-on-hugging-face-setting-up-the-pegasus-library-and-loading-pre-trained-models","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/36165\/","title":{"rendered":"Transfomer Utilization Course on Hugging Face, Setting Up the PEGASUS Library and Loading Pre-trained Models"},"content":{"rendered":"<p><body><\/p>\n<p>Recent innovations in the field of Natural Language Processing (NLP) have been made possible by advancements in deep learning models. In particular, the <strong>Transformers<\/strong> library developed by Hugging Face has become a symbol of this progress. In this course, we will cover in detail the library setup and how to load pretrained models necessary to perform text summarization tasks using the PEGASUS model.<\/p>\n<h2>1. What is the Hugging Face Transformers Library?<\/h2>\n<p>The Hugging Face Transformers library is a Python library that provides pretrained models for various NLP tasks. This library particularly offers a variety of models (BERT, GPT-2, RoBERTa, T5, etc.) based on the transformer architecture. PEGASUS is one of the models based on this transformer architecture, primarily designed for text summarization.<\/p>\n<h2>2. Introduction to the PEGASUS Model<\/h2>\n<p>PEGASUS (Pre-trained Text-to-Text Transfer Transformer) is a model developed by Google, optimized for extracting important information from natural language documents and summarizing them. The core idea of the PEGASUS model is to mask randomly selected sentences from the input document and perform pre-training by predicting the masked sentences. During this process, the model learns to understand the overall context of the text and identify important information.<\/p>\n<h3>2.1. Advantages of the PEGASUS Model<\/h3>\n<ul>\n<li>Excellent text summarization performance<\/li>\n<li>Can be trained with less data using pretrained models<\/li>\n<li>Usable in various languages and domains<\/li>\n<\/ul>\n<h2>3. Environment Setup<\/h2>\n<p>To use the PEGASUS model, you first need to install the necessary libraries. This process primarily requires the installation of the <code>transformers<\/code> and <code>torch<\/code> libraries. Below is the installation method.<\/p>\n<pre><code>pip install transformers torch<\/code><\/pre>\n<h3>3.1. Importing Necessary Libraries<\/h3>\n<p>Once the installation is complete, import the necessary libraries as follows.<\/p>\n<pre><code>import torch\nfrom transformers import PegasusForConditionalGeneration, PegasusTokenizer<\/code><\/pre>\n<h2>4. Loading the PEGASUS Model<\/h2>\n<p>Now it&#8217;s time to load the PEGASUS model and tokenizer. The PEGASUS model can be easily loaded from Hugging Face&#8217;s model hub.<\/p>\n<pre><code>model_name = \"google\/pegasus-xsum\"\n\n# Load tokenizer and model\ntokenizer = PegasusTokenizer.from_pretrained(model_name)\nmodel = PegasusForConditionalGeneration.from_pretrained(model_name)<\/code><\/pre>\n<h3>4.1 Preparing the Text to Summarize<\/h3>\n<p>To use the model, you need to prepare the text to be summarized. The code below defines a sample text.<\/p>\n<pre><code>sample_text = \"Natural language processing is a field of computer science that deals with the interaction between computers and human language. It researches how to understand and process human language.\"<\/code><\/pre>\n<h3>4.2 Tokenizing Text and Summarization<\/h3>\n<p>After tokenizing the text using the tokenizer, set the batch size and perform the summarization.<\/p>\n<pre><code># Text encoding\ninputs = tokenizer(sample_text, return_tensors=\"pt\", max_length=512, truncation=True)\n\n# Generate summary\nsummary_ids = model.generate(inputs[\"input_ids\"], num_beams=4, max_length=50, early_stopping=True)\n\n# Decode summary\nsummary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)\nprint(\"Summary:\", summary)<\/code><\/pre>\n<h2>5. Analyzing Summary Results<\/h2>\n<p>Let&#8217;s check the summary results generated from the code above. The generated summary should concisely convey the most important information from the original document. Potential issues that may arise in this process include incorrect sentence formation or missing information. To address these issues, the quantity and quality of the training data are crucially important.<\/p>\n<h2>6. Conclusion<\/h2>\n<p>Through this course, we learned how to perform text summarization using the PEGASUS model. The PEGASUS model is a powerful pretrained natural language processing model that has established itself as an effective summarization tool. We also confirmed that we can easily load and use the model through the Hugging Face Transformers library.<\/p>\n<p>In future courses, we will cover how to fine-tune the PEGASUS model to adjust it for specific domains, and how to improve performance by adjusting various hyperparameters. The world of NLP is vast and offers a range of application possibilities. Continue to learn and research to develop even more effective models.<\/p>\n<footer>\n<p>\u00a9 2023 Blog Author<\/p>\n<\/footer>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recent innovations in the field of Natural Language Processing (NLP) have been made possible by advancements in deep learning models. In particular, the Transformers library developed by Hugging Face has become a symbol of this progress. In this course, we will cover in detail the library setup and how to load pretrained models necessary to &hellip; <a href=\"https:\/\/atmokpo.com\/w\/36165\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Transfomer Utilization Course on Hugging Face, Setting Up the PEGASUS Library and Loading Pre-trained Models&#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-36165","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>Transfomer Utilization Course on Hugging Face, Setting Up the PEGASUS Library and Loading Pre-trained Models - \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\/36165\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Transfomer Utilization Course on Hugging Face, Setting Up the PEGASUS Library and Loading Pre-trained Models - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Recent innovations in the field of Natural Language Processing (NLP) have been made possible by advancements in deep learning models. In particular, the Transformers library developed by Hugging Face has become a symbol of this progress. In this course, we will cover in detail the library setup and how to load pretrained models necessary to &hellip; \ub354 \ubcf4\uae30 &quot;Transfomer Utilization Course on Hugging Face, Setting Up the PEGASUS Library and Loading Pre-trained Models&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/36165\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:46:18+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\/36165\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36165\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Transfomer Utilization Course on Hugging Face, Setting Up the PEGASUS Library and Loading Pre-trained Models\",\"datePublished\":\"2024-11-01T09:46:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36165\/\"},\"wordCount\":511,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Using Hugging Face\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/36165\/\",\"url\":\"https:\/\/atmokpo.com\/w\/36165\/\",\"name\":\"Transfomer Utilization Course on Hugging Face, Setting Up the PEGASUS Library and Loading Pre-trained Models - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:46:18+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36165\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/36165\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/36165\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Transfomer Utilization Course on Hugging Face, Setting Up the PEGASUS Library and Loading Pre-trained Models\"}]},{\"@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":"Transfomer Utilization Course on Hugging Face, Setting Up the PEGASUS Library and Loading Pre-trained Models - \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\/36165\/","og_locale":"ko_KR","og_type":"article","og_title":"Transfomer Utilization Course on Hugging Face, Setting Up the PEGASUS Library and Loading Pre-trained Models - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Recent innovations in the field of Natural Language Processing (NLP) have been made possible by advancements in deep learning models. In particular, the Transformers library developed by Hugging Face has become a symbol of this progress. In this course, we will cover in detail the library setup and how to load pretrained models necessary to &hellip; \ub354 \ubcf4\uae30 \"Transfomer Utilization Course on Hugging Face, Setting Up the PEGASUS Library and Loading Pre-trained Models\"","og_url":"https:\/\/atmokpo.com\/w\/36165\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:46:18+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\/36165\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/36165\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Transfomer Utilization Course on Hugging Face, Setting Up the PEGASUS Library and Loading Pre-trained Models","datePublished":"2024-11-01T09:46:18+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/36165\/"},"wordCount":511,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Using Hugging Face"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/36165\/","url":"https:\/\/atmokpo.com\/w\/36165\/","name":"Transfomer Utilization Course on Hugging Face, Setting Up the PEGASUS Library and Loading Pre-trained Models - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:46:18+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/36165\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/36165\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/36165\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Transfomer Utilization Course on Hugging Face, Setting Up the PEGASUS Library and Loading Pre-trained Models"}]},{"@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\/36165","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=36165"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36165\/revisions"}],"predecessor-version":[{"id":36166,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36165\/revisions\/36166"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=36165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=36165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=36165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}