skip to Main Content

GPT-3 is amazing, but parsing its results is a bit of a headache, or I’m missing something here?
For example, I’m asking GPT-3 to write something about "digital marketing" and it’s returning back some interesting stuff:

nn1. Topic: The Benefits of Digital Marketing nHeadlines: na. Unlocking the 
Potential of Digital Marketing nb. Harnessing the Power of Digital Marketing for 
Your Business nc. How to Maximize Your Return on Investment with Digital Marketing 
nd. Exploring the Benefits of a Comprehensive Digital Marketing Strategy ne. 
Leveraging Technology to Take Your Business to the Next Level with Digital Marketing  
nn2. Topic: Social Media Strategies for Effective Digital Marketing  nHeadlines:  
na. Crafting an Engaging Social Media Presence for Maximum Impact nb. How to Reach 
and Engage Your Target Audience Through Social Media Platforms  nc. Optimizing Your 
Content Strategy for Maximum Reach on Social Media Platforms   nd. Utilizing Paid 
Advertising Strategies on Social Media Platforms   ttttttt     e .Analyzing 
and Improving Performance Across Multiple Social Networksnn3. Topic: SEO Best 
Practices for Effective Digital Marketing    Headlines:     a .Understanding Search 
Engine Algorithms and Optimizing Content Accordingly    b .Developing an Effective 
SEO Strategy That Delivers Results c .Leveraging Keywords and Metadata For Maximum 
Visibility d .Exploring Advanced SEO Techniques To Increase Traffic e .Analyzing 
Performance Data To Improve Rankingsnn4Topic : Email Campaigns For Successful 
Digital Marketin g Headlines : a .Creating Compelling Email Campaigns That Drive 
Results b .Optimizing Email Deliverability For Maximum Impact c .Utilizing Automation 
Tools To Streamline Email Campaign Management d .Measuring Performance And Analyzing 
Data From Email Campaigns e .Exploring Creative Ways To Increase Open Rates On 
Emailsnn5Topic : Mobile Advertising Strategies For Effective Digita l Marketin g 
Headlines : a ..Maximizing Reach With Mobile Ads b ..Understanding User Behavior On 
Mobile Devices c ..Optimizing Ads For Different Screen Sizes d ..Leveraging Location- 
Based Targeting To Increase Relevance e ..Analyzing Performance Data From Mobile Ads

As you can see, it’s sent me back a list of topics related to "digital marketing" with some headlines (apparently from a to e). I see some line breaks and tabulation here and there. So my first reflex was to split the text on the line breaks, but it looks like the format is not equal everywhere, as there are very few line breaks in the second half of the response (which make it inaccurate).
What I’d like to do, is reformatting the output, so I can have a kind of list of topics and headlines. Something like this:

[
     {"Topic 1": ["headline 1", "headline 2","..."]},
     {"Topic 2": ["headline 1", "headline 2","..."]},
     {"Topic 3": ["headline 1", "headline 2","..."]}
]

Maybe there is a parameter to send over withing my request, but I didn’t find anything in the doc. So I guess my best bet is to reformat using regex. Here I see a pattern Topic:and Headlines: but it’s not always the case. What is consistent is the number prefixing each element (like Ì., II., 1., 2. or a., b.) but sometimes it looks like a .. (you can see that at the end of the response for example.

Any idea how to do that? (I’m using python for that, but can adapt from another language)

2

Answers


  1. Use the Edits endpoint

    If you run test.py the OpenAI API will return the following completion:

    1. Topic: The Benefits of Digital Marketing 
    Headlines: 
    
    * Unlocking the Potential of Digital Marketing 
    * Harnessing the Power of Digital Marketing for Your Business 
    * How to Maximize Your Return on Investment with Digital Marketing 
    * Exploring the Benefits of a Comprehensive Digital Marketing Strategy 
    * Leveraging Technology to Take Your Business to the Next Level with Digital Marketing
    

    test.py

    import openai
    
    openai.api_key = '<OPENAI_API_KEY>'
    
    response = openai.Edit.create(
      model = 'text-davinci-edit-001',
      input = 'nn1. Topic: The Benefits of Digital Marketing nHeadlines: na. Unlocking the Potential of Digital Marketing nb. Harnessing the Power of Digital Marketing for Your Business nc. How to Maximize Your Return on Investment with Digital Marketing nd. Exploring the Benefits of a Comprehensive Digital Marketing Strategy ne. Leveraging Technology to Take Your Business to the Next Level with Digital Marketing',
      instruction = 'Make this readable'
    )
    
    content = response['choices'][0]['text']
    
    print(content)
    
    Login or Signup to reply.
  2. You can get GPT to provide the response in JSON format you just need to train it as part of the prompt. Here is an example prompt:

    Provide a list of 3 topics related to climate change and for each topic provide 3 headlines.

    Your response should be in JSON format. Here is the expected JSON format:

        [
         {"Topic 1": ["headline 1", "headline 2","..."]},
         {"Topic 2": ["headline 1", "headline 2","..."]},
         {"Topic 3": ["headline 1", "headline 2","..."]}
    ]
    

    END PROMPT

    You might have to play around with the prompt a little bit, but I have been successful in building email parsers that return the responses in JSON.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search