{"id":36217,"date":"2024-11-01T09:46:43","date_gmt":"2024-11-01T09:46:43","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=36217"},"modified":"2024-11-01T09:46:43","modified_gmt":"2024-11-01T09:46:43","slug":"hugging-face-transformers-utilization-course-recall-precision-f1-score","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/36217\/","title":{"rendered":"Hugging Face Transformers Utilization Course, Recall, Precision, F1 Score"},"content":{"rendered":"<p><body><\/p>\n<p>\n        With the advancement of deep learning, there have been many innovations in the field of Natural Language Processing (NLP). Among them, <strong>Hugging Face<\/strong>&#8216;s transformers have become a popular tool among many researchers and developers. In this course, we will delve deeply into how to perform NLP tasks using Hugging Face transformers and the metrics for evaluating model performance, including recall, precision, and F1 score.\n    <\/p>\n<h2>1. What is Hugging Face Transformers?<\/h2>\n<p>\n        Hugging Face Transformers is an open-source library developed by <a href=\"https:\/\/huggingface.co\/\">Hugging Face<\/a> that provides easy access to a variety of pre-trained transformer models. This library includes state-of-the-art models like BERT, GPT-2, and T5, and offers a user-friendly API that helps developers easily implement NLP tasks.\n    <\/p>\n<h2>2. What are Recall, Precision, and F1 Score?<\/h2>\n<p>\n        There are several metrics that can be used to evaluate the performance of deep learning models. Here, I will explain three important metrics.\n    <\/p>\n<h3>2.1. Precision<\/h3>\n<p>\n        Precision refers to the ratio of true positives among the data predicted as positive by the model. The formula for calculating precision is as follows:\n    <\/p>\n<p>\n<strong>Precision = TP \/ (TP + FP)<\/strong>\n<\/p>\n<ul>\n<li>TP: True Positives<\/li>\n<li>FP: False Positives<\/li>\n<\/ul>\n<h3>2.2. Recall<\/h3>\n<p>\n        Recall represents the ratio of correctly predicted positives among the actual positives. The formula for calculating recall is as follows:\n    <\/p>\n<p>\n<strong>Recall = TP \/ (TP + FN)<\/strong>\n<\/p>\n<ul>\n<li>FN: False Negatives<\/li>\n<\/ul>\n<h3>2.3. F1 Score<\/h3>\n<p>\n        The F1 score is the harmonic mean of precision and recall, providing a balance between the two metrics. The formula for calculating F1 score is as follows:\n    <\/p>\n<p>\n<strong>F1 = 2 * (Precision * Recall) \/ (Precision + Recall)<\/strong>\n<\/p>\n<h2>3. Installing Hugging Face Transformers<\/h2>\n<p>\n        To use Hugging Face&#8217;s transformers library, you must first install the library. You can do this with the following command:\n    <\/p>\n<pre><code>pip install transformers<\/code><\/pre>\n<h2>4. Loading the Model and Preparing Data<\/h2>\n<p>\n        To utilize transformers, you first need to load a pre-trained model and prepare the data appropriately. For example, the following code demonstrates how to load the BERT model and prepare data as text.\n    <\/p>\n<pre><code>from transformers import BertTokenizer, BertForSequenceClassification\nimport torch\n\n# Load model and tokenizer\ntokenizer = BertTokenizer.from_pretrained('bert-base-uncased')\nmodel = BertForSequenceClassification.from_pretrained('bert-base-uncased', num_labels=2)\n\n# Sample data\ntexts = [\"I love using Hugging Face!\", \"This is a bad experience.\"]\nlabels = [1, 0]  # Positive (1), Negative (0)\n\n# Tokenize data\ninputs = tokenizer(texts, padding=True, truncation=True, return_tensors=\"pt\")\n<\/code><\/pre>\n<h2>5. Training and Evaluating the Model<\/h2>\n<p>\n        Once the model is ready, you can train the model using stochastic gradient descent. The following code shows the process of training and evaluating the model using PyTorch.\n    <\/p>\n<pre><code># Set optimizer\noptimizer = torch.optim.AdamW(model.parameters(), lr=5e-5)\n\n# Training loop\nmodel.train()\nfor epoch in range(3):\n    optimizer.zero_grad()\n    outputs = model(**inputs, labels=torch.tensor(labels))\n    loss = outputs.loss\n    loss.backward()\n    optimizer.step()\n    print(f'Epoch {epoch + 1}, Loss: {loss.item()}')\n\n# Evaluation\nmodel.eval()\nwith torch.no_grad():\n    logits = model(**inputs).logits\n    predictions = torch.argmax(logits, dim=1).numpy()\n<\/code><\/pre>\n<h2>6. Calculating Performance Evaluation Metrics<\/h2>\n<p>\n        Based on the model&#8217;s prediction results, you can calculate precision, recall, and F1 score. You can use the <code>sklearn<\/code> library for this purpose.\n    <\/p>\n<pre><code>from sklearn.metrics import precision_score, recall_score, f1_score\n\n# Calculate precision, recall, and F1 score\nprecision = precision_score(labels, predictions)\nrecall = recall_score(labels, predictions)\nf1 = f1_score(labels, predictions)\n\nprint(f'Precision: {precision:.2f}, Recall: {recall:.2f}, F1 Score: {f1:.2f}')\n<\/code><\/pre>\n<h2>7. Conclusion<\/h2>\n<p>\n        In this course, we explored the process of training NLP models using Hugging Face transformers and calculating precision, recall, and F1 score for performance evaluation. Utilize Hugging Face&#8217;s various tools and models to enhance your projects with powerful NLP capabilities.\n    <\/p>\n<h2>References<\/h2>\n<ul>\n<li><a href=\"https:\/\/huggingface.co\/docs\/transformers\/index\">Hugging Face Transformers Documentation<\/a><\/li>\n<li><a href=\"https:\/\/scikit-learn.org\/stable\/modules\/classes.html#module-sklearn.metrics\">Scikit-learn Metrics<\/a><\/li>\n<\/ul>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>With the advancement of deep learning, there have been many innovations in the field of Natural Language Processing (NLP). Among them, Hugging Face&#8216;s transformers have become a popular tool among many researchers and developers. In this course, we will delve deeply into how to perform NLP tasks using Hugging Face transformers and the metrics for &hellip; <a href=\"https:\/\/atmokpo.com\/w\/36217\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Hugging Face Transformers Utilization Course, Recall, Precision, F1 Score&#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-36217","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 Utilization Course, Recall, Precision, F1 Score - \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\/36217\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hugging Face Transformers Utilization Course, Recall, Precision, F1 Score - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"With the advancement of deep learning, there have been many innovations in the field of Natural Language Processing (NLP). Among them, Hugging Face&#8216;s transformers have become a popular tool among many researchers and developers. In this course, we will delve deeply into how to perform NLP tasks using Hugging Face transformers and the metrics for &hellip; \ub354 \ubcf4\uae30 &quot;Hugging Face Transformers Utilization Course, Recall, Precision, F1 Score&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/36217\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:46:43+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\/36217\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36217\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Hugging Face Transformers Utilization Course, Recall, Precision, F1 Score\",\"datePublished\":\"2024-11-01T09:46:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36217\/\"},\"wordCount\":424,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Using Hugging Face\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/36217\/\",\"url\":\"https:\/\/atmokpo.com\/w\/36217\/\",\"name\":\"Hugging Face Transformers Utilization Course, Recall, Precision, F1 Score - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:46:43+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36217\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/36217\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/36217\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hugging Face Transformers Utilization Course, Recall, Precision, F1 Score\"}]},{\"@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 Utilization Course, Recall, Precision, F1 Score - \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\/36217\/","og_locale":"ko_KR","og_type":"article","og_title":"Hugging Face Transformers Utilization Course, Recall, Precision, F1 Score - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"With the advancement of deep learning, there have been many innovations in the field of Natural Language Processing (NLP). Among them, Hugging Face&#8216;s transformers have become a popular tool among many researchers and developers. In this course, we will delve deeply into how to perform NLP tasks using Hugging Face transformers and the metrics for &hellip; \ub354 \ubcf4\uae30 \"Hugging Face Transformers Utilization Course, Recall, Precision, F1 Score\"","og_url":"https:\/\/atmokpo.com\/w\/36217\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:46:43+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\/36217\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/36217\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Hugging Face Transformers Utilization Course, Recall, Precision, F1 Score","datePublished":"2024-11-01T09:46:43+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/36217\/"},"wordCount":424,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Using Hugging Face"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/36217\/","url":"https:\/\/atmokpo.com\/w\/36217\/","name":"Hugging Face Transformers Utilization Course, Recall, Precision, F1 Score - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:46:43+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/36217\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/36217\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/36217\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Hugging Face Transformers Utilization Course, Recall, Precision, F1 Score"}]},{"@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\/36217","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=36217"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36217\/revisions"}],"predecessor-version":[{"id":36218,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36217\/revisions\/36218"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=36217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=36217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=36217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}