{"id":36115,"date":"2024-11-01T09:45:52","date_gmt":"2024-11-01T09:45:52","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=36115"},"modified":"2024-11-01T09:45:52","modified_gmt":"2024-11-01T09:45:52","slug":"utilizing-hugging-face-transformers-course-dialogpt-writing","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/36115\/","title":{"rendered":"Utilizing Hugging Face Transformers Course, DialoGPT Writing"},"content":{"rendered":"<p><body><\/p>\n<p>With the advancement of artificial intelligence, there has been significant innovation in the field of Natural Language Processing (NLP). In particular, deep learning-based conversational models have received a lot of attention, among which <strong>DialoGPT<\/strong> is a very popular model. In this course, we will deeply explore the concept of DialoGPT, how to utilize it, and provide implementation examples using Python.<\/p>\n<h2>1. What is DialoGPT?<\/h2>\n<p>DialoGPT (Conversational Generative Pre-trained Transformer) is a conversational model based on OpenAI&#8217;s GPT-2 model. DialoGPT has been trained to be suitable for conversations with humans, and the dataset includes dialogue logs collected from the internet. This allows the model to learn to generate responses while considering the context of previous conversations.<\/p>\n<h2>2. Hugging Face and the Transformers Library<\/h2>\n<p>Hugging Face is one of the most widely used libraries in the field of Natural Language Processing, providing various pre-trained language models. The <strong>Transformers library<\/strong> is a Python library that helps make these models easy to use. Installation can be done with the following pip command:<\/p>\n<pre><code>pip install transformers<\/code><\/pre>\n<h2>3. Installing DialoGPT<\/h2>\n<p>To use DialoGPT, you need to install the Transformers library and download the appropriate model. DialoGPT is available in various sizes such as <code>small<\/code>, <code>medium<\/code>, and <code>large<\/code>. Below is an example code using the <code>medium<\/code> model:<\/p>\n<pre><code>from transformers import AutoModelForCausalLM, AutoTokenizer\n\n# Downloading the model and tokenizer\ntokenizer = AutoTokenizer.from_pretrained(\"microsoft\/DialoGPT-medium\")\nmodel = AutoModelForCausalLM.from_pretrained(\"microsoft\/DialoGPT-medium\")<\/code><\/pre>\n<h2>4. Implementing Conversation Features<\/h2>\n<p>Now that we have downloaded the model and tokenizer, let&#8217;s implement the conversation generation feature. We will take the user&#8217;s input and generate a response based on that input.<\/p>\n<h3>4.1 Conversation Generation Code<\/h3>\n<pre><code>import torch\n\n# Initialize conversation history\nchat_history_ids = None\n\nwhile True:\n    # Take user input\n    user_input = input(\"User: \")\n\n    # Convert input from text to tokens\n    new_user_input_ids = tokenizer.encode(user_input + tokenizer.eos_token, return_tensors='pt')\n\n    # Combine previous conversation with new input\n    if chat_history_ids is not None:\n        bot_input_ids = torch.cat([chat_history_ids, new_user_input_ids], dim=-1)\n    else:\n        bot_input_ids = new_user_input_ids\n\n    # Generate response through the model\n    chat_history_ids = model.generate(bot_input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id)\n\n    # Decode the model's response to text\n    bot_response = tokenizer.decode(chat_history_ids[:, bot_input_ids.shape[-1]:][0], skip_special_tokens=True)\n\n    # Print the response\n    print(\"Bot: \", bot_response)<\/code><\/pre>\n<h3>4.2 Code Explanation<\/h3>\n<ul>\n<li><strong>torch:<\/strong> Performs tensor operations using the PyTorch library.<\/li>\n<li><strong>chat_history_ids:<\/strong> A variable that stores the context of the conversation, initially empty.<\/li>\n<li><strong>while True:<\/strong> A loop that continuously takes user input.<\/li>\n<li><strong>tokenizer.encode:<\/strong> Tokenizes the user input to convert it into a format that can be passed to the model.<\/li>\n<li><strong>model.generate:<\/strong> Generates a response through the model. Here, the maximum length is set, and the padding token ID is specified.<\/li>\n<li><strong>tokenizer.decode:<\/strong> Converts the tokens generated by the model back into a string for output.<\/li>\n<\/ul>\n<h2>5. Examples of DialoGPT Applications<\/h2>\n<p>DialoGPT can be utilized in various fields. For instance, it can be used for casual conversations with people, Q&#038;A on specific topics, customer service chatbots, and even creative activities.<\/p>\n<h3>5.1 Utilization in Creative Activities<\/h3>\n<p>We can also see example code that uses DialoGPT to assist in creative activities. For example, if you input a specific topic, it can continue to generate related stories.<\/p>\n<pre><code>def generate_story(prompt):\n    # Convert input from text to tokens\n    input_ids = tokenizer.encode(prompt + tokenizer.eos_token, return_tensors='pt')\n\n    # Generate text\n    story_ids = model.generate(input_ids, max_length=500, pad_token_id=tokenizer.eos_token_id)\n\n    # Convert the story to characters\n    story = tokenizer.decode(story_ids[0], skip_special_tokens=True)\n    return story\n\n# Example\nprompt = \"On a summer day, in the forest\"\ngenerated_story = generate_story(prompt)\nprint(generated_story)<\/code><\/pre>\n<h3>5.2 Code Explanation<\/h3>\n<ul>\n<li><strong>define the generate_story function:<\/strong> Defines a function that generates a story based on a specific topic.<\/li>\n<li><strong>input_ids:<\/strong> Tokenizes the user input.<\/li>\n<li><strong>model.generate:<\/strong> Generates a story based on the given input.<\/li>\n<li><strong>story:<\/strong> Converts the generated story to a string.<\/li>\n<\/ul>\n<h2>6. Pros and Cons of DialoGPT<\/h2>\n<h3>6.1 Advantages<\/h3>\n<ul>\n<li>It has excellent ability to understand various contexts and generate responses.<\/li>\n<li>It is trained on dialogue data collected from the internet, enabling it to handle everyday conversations well.<\/li>\n<li>Supports writing in various topics and styles.<\/li>\n<\/ul>\n<h3>6.2 Disadvantages<\/h3>\n<ul>\n<li>The generated text may not always be consistent and may contain inappropriate content.<\/li>\n<li>If the context of the conversation is lost, it may generate illogical responses.<\/li>\n<li>It may lack customization and could have limitations in generating context-appropriate responses.<\/li>\n<\/ul>\n<h2>7. Conclusion<\/h2>\n<p>In this course, we covered how to utilize DialoGPT using the Transformers library from Hugging Face. DialoGPT is a model that can be widely used as a conversational AI and creative tool, and it can be improved through various experiments and configurations for practical applications. I encourage you to use DialoGPT to create interesting and creative projects!<\/p>\n<p>I hope this course has been helpful to you. If you have any questions, please leave them in the comments.<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>With the advancement of artificial intelligence, there has been significant innovation in the field of Natural Language Processing (NLP). In particular, deep learning-based conversational models have received a lot of attention, among which DialoGPT is a very popular model. In this course, we will deeply explore the concept of DialoGPT, how to utilize it, and &hellip; <a href=\"https:\/\/atmokpo.com\/w\/36115\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Utilizing Hugging Face Transformers Course, DialoGPT Writing&#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-36115","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>Utilizing Hugging Face Transformers Course, DialoGPT Writing - \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\/36115\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Utilizing Hugging Face Transformers Course, DialoGPT Writing - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"With the advancement of artificial intelligence, there has been significant innovation in the field of Natural Language Processing (NLP). In particular, deep learning-based conversational models have received a lot of attention, among which DialoGPT is a very popular model. In this course, we will deeply explore the concept of DialoGPT, how to utilize it, and &hellip; \ub354 \ubcf4\uae30 &quot;Utilizing Hugging Face Transformers Course, DialoGPT Writing&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/36115\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:45:52+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=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/36115\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36115\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Utilizing Hugging Face Transformers Course, DialoGPT Writing\",\"datePublished\":\"2024-11-01T09:45:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36115\/\"},\"wordCount\":601,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Using Hugging Face\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/36115\/\",\"url\":\"https:\/\/atmokpo.com\/w\/36115\/\",\"name\":\"Utilizing Hugging Face Transformers Course, DialoGPT Writing - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:45:52+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36115\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/36115\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/36115\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Utilizing Hugging Face Transformers Course, DialoGPT Writing\"}]},{\"@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":"Utilizing Hugging Face Transformers Course, DialoGPT Writing - \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\/36115\/","og_locale":"ko_KR","og_type":"article","og_title":"Utilizing Hugging Face Transformers Course, DialoGPT Writing - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"With the advancement of artificial intelligence, there has been significant innovation in the field of Natural Language Processing (NLP). In particular, deep learning-based conversational models have received a lot of attention, among which DialoGPT is a very popular model. In this course, we will deeply explore the concept of DialoGPT, how to utilize it, and &hellip; \ub354 \ubcf4\uae30 \"Utilizing Hugging Face Transformers Course, DialoGPT Writing\"","og_url":"https:\/\/atmokpo.com\/w\/36115\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:45:52+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":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/36115\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/36115\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Utilizing Hugging Face Transformers Course, DialoGPT Writing","datePublished":"2024-11-01T09:45:52+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/36115\/"},"wordCount":601,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Using Hugging Face"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/36115\/","url":"https:\/\/atmokpo.com\/w\/36115\/","name":"Utilizing Hugging Face Transformers Course, DialoGPT Writing - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:45:52+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/36115\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/36115\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/36115\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Utilizing Hugging Face Transformers Course, DialoGPT Writing"}]},{"@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\/36115","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=36115"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36115\/revisions"}],"predecessor-version":[{"id":36116,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36115\/revisions\/36116"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=36115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=36115"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=36115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}