<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Jason TC Chuang</title>
    <description>The latest articles on Forem by Jason TC Chuang (@chuangtc).</description>
    <link>https://forem.com/chuangtc</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1033437%2F43346f81-20d8-43b5-b299-dddfbe77a21c.png</url>
      <title>Forem: Jason TC Chuang</title>
      <link>https://forem.com/chuangtc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/chuangtc"/>
    <language>en</language>
    <item>
      <title>Fine Tune GPT-3 model with provided training and validation dataset</title>
      <dc:creator>Jason TC Chuang</dc:creator>
      <pubDate>Thu, 30 Mar 2023 05:58:15 +0000</pubDate>
      <link>https://forem.com/chuangtc/fine-tune-gpt-3-model-with-provided-training-and-validation-dataset-1k27</link>
      <guid>https://forem.com/chuangtc/fine-tune-gpt-3-model-with-provided-training-and-validation-dataset-1k27</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgeg3bhiy634recq1erfg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgeg3bhiy634recq1erfg.png" alt="Image description" width="800" height="359"&gt;&lt;/a&gt;&lt;br&gt;
In this tutorial, we will build our own fine-tuned GPT-3 model with provided training and validation dataset. It's doing text-summarization.&lt;/p&gt;
&lt;h2&gt;
  
  
  1. Getting OpenAI API key
&lt;/h2&gt;

&lt;p&gt;Go to &lt;a href="https://platform.openai.com/account/api-keys"&gt;https://platform.openai.com/account/api-keys&lt;/a&gt; and log in. Generate new secret key and keep it safely.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1d105sjk8obbeyklk1ah.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1d105sjk8obbeyklk1ah.png" alt="Image description" width="800" height="319"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  2. Checking the prepared training and validation data. It should include a number of pairs of prompt and completion.
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{"prompt": "Summarize the following text:Our new business production totaled $389 million of direct PVP exceeded by $75 million -- the direct PVP we produced in every year but once since 2010.\n....", "completion": "Turning to our fourth quarter 2020 results, adjusted operating income was $56 million or $0.69 per share compared with $87 million or $0.90 per share in the fourth quarter of 2019."}
{"prompt": "Summarize the following text:Overall, restaurant traffic has largely stabilized at about 5% below pre-pandemic levels led by the continued solid performance at quick service restaurants.\nDemand in U.S. retail channels also remained solid with overall category volumes in the quarter still up 15% to 20% from pre-pandemic levels....", "completion": "Specifically in the quarter, sales increased 13% to $984 million, with volume up 11% and price mix up 2%.\nDiluted earnings per share in the first quarter was $0.20, down from $0.61 in the prior year, while adjusted EBITDA including joint ventures was $123 million, down from $202 million."}
........................
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  3. Let's get started
&lt;/h2&gt;

&lt;p&gt;First, we need to install the OpenAI library:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;!pip install --upgrade openai
import os
import openai
os.environ["OPENAI_API_KEY"] = 'YOUR_API_KEY'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will pass GPT-3 model as parameters. Such as ada, curie, or davinci&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;!openai api fine_tunes.create -t "prepared_train.jsonl" -v "prepared_val.jsonl" -m ada
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It takes time to put fine-tune job in queue and train a model. Let's wait and check the status&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;!openai api fine_tunes.follow -i ft-3Wnb4hOrXU1FuQGDRfyvNWlz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After the fine-tuned model is created, wee can test our function. We will use the following prompt:&lt;/p&gt;

&lt;p&gt;Summarize the following text:During the first quarter, we maintained a very safe environment with an RIR of 0.64, which is in line with our full year 2020 performance.&lt;/p&gt;

&lt;p&gt;Use command line&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;!openai api completions.create -m ada:ft-tpisoftware-2023-03-01-00-10-20 -p "Summarize the following text:During the first quarter, we maintained a very safe environment with an RIR of 0.64, which is in line with our full year 2020 performance."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or python code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;openai.api_key = os.getenv("OPENAI_API_KEY")
openai.Completion.create(
  model="ada:ft-tpisoftware-2023-03-01-00-10-20",
  prompt="Summarize the following text:During the first quarter, we maintained a very safe environment with an RIR of 0.64, which is in line with our full year 2020 performance.",
  max_tokens=256,
  temperature=0
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sample result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;OpenAIObject text_completion id=cmpl-6p4x0eQuRB83JEWs19ssaSS5g7TKC at 0x1011ea4a0&amp;gt; JSON: {
  "choices": [
    {
      "finish_reason": "length",
      "index": 0,
      "logprobs": null,
      "text": "\nWe have been in the business of providing our customers with the best quality products and services for over 40 years."
    }
  ],
  "created": 1677631778,
  "id": "cmpl-6p4x0eQuRB83JEWs19ssaSS5g7TKC",
  "model": "ada:ft-tpisoftware-2023-03-01-00-10-20",
  "object": "text_completion",
  "usage": {
    "completion_tokens": 256,
    "prompt_tokens": 17,
    "total_tokens": 273
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Reference
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://chuangtc.com/projects/fine-tune-GPT3.php"&gt;https://chuangtc.com/projects/fine-tune-GPT3.php&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/chuangtc/ECTSum-GPT3"&gt;Github&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://platform.openai.com/docs/guides/fine-tuning"&gt;OpenAI&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>gpt3</category>
      <category>tutorial</category>
      <category>ai</category>
    </item>
    <item>
      <title>Run todo-app with React 18</title>
      <dc:creator>Jason TC Chuang</dc:creator>
      <pubDate>Sat, 25 Feb 2023 01:27:42 +0000</pubDate>
      <link>https://forem.com/chuangtc/run-todo-app-with-react-18-3n57</link>
      <guid>https://forem.com/chuangtc/run-todo-app-with-react-18-3n57</guid>
      <description>&lt;p&gt;How to run todo-app and deploy to Firebase&lt;/p&gt;

&lt;p&gt;&lt;a href="https://chuangtc.com/projects/react_todo.php" rel="noopener noreferrer"&gt;https://chuangtc.com/projects/react_todo.php&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Facebook OAuth 2.0 Login</title>
      <dc:creator>Jason TC Chuang</dc:creator>
      <pubDate>Sat, 25 Feb 2023 01:21:54 +0000</pubDate>
      <link>https://forem.com/chuangtc/facebook-oauth-20-login-4014</link>
      <guid>https://forem.com/chuangtc/facebook-oauth-20-login-4014</guid>
      <description>&lt;p&gt;In this tutorial, I’d love to share with you guys about implementing social login with Facebook for an existing Spring Boot web application, using Spring OAuth2 Client library – so your users will be able to sign in your application using their own Facebook accounts instead of application-managed credentials.&lt;/p&gt;

&lt;p&gt;Suppose that you have an existing Spring Boot project with authentication functionality already implemented using Spring Security and the user information is stored in H2 in-memory database.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://chuangtc.com/Java/spring-boot-30-facebook-login.php" rel="noopener noreferrer"&gt;https://chuangtc.com/Java/spring-boot-30-facebook-login.php&lt;/a&gt;&lt;/p&gt;

</description>
      <category>watercooler</category>
    </item>
  </channel>
</rss>
