title: 20231101-generative-ai-for-everyone date: 2023-11-02 tags:

  • ai
  • llm

What is Generative AI

  • Supervised learning (labeling things)

  • 2010 - 2020: Large scale supervised learning

  • LLM

    • How? supervised learning (A->B) 重複預測下一個word
  • 例子

    • 寫作:rewrite for clarity
    • 閱讀:有沒有在抱怨、情緒分析
    • 聊天:聊天機器人
  • web search or LLM?

  • LLM可能會錯,但回答比較精簡

    • web search有時會得到比較好的答案,但要花時間找到你要的資訊

Generative AI Applications

  • setup
import openai
import os

openai.api_key = os.getenv("OPENAI_API_KEY")

def llm_response(prompt):
    response = openai.ChatCompletion.create(
        model='gpt-3.5-turbo',
        messages=[{'role':'user','content':prompt}],
        temperature=0
    )
    return response.choices[0].message['content']
  • classify
prompt = '''
    Classify the following review 
    as having either a positive or
    negative sentiment:

    The banana pudding was really tasty!
'''

response = llm_response(prompt)
print(response)
all_reviews = [
    'The mochi is excellent!',
    'Best soup dumplings I have ever eaten.',
    'Not worth the 3 month wait for a reservation.',
    'The colorful tablecloths made me smile!',
    'The pasta was cold.'
]

all_reviews
classifications = []
for review in all_reviews:
    prompt = f'''
        Classify the following review 
        as having either a positive or
        negative sentiment. State your answer
        as a single word, either "positive" or
        "negative":

        {review}
        '''
    response = llm_response(prompt)
    classifications.append(response)

classifications

Advance technologies: Beyond prompting

Generative AI and Business

Genetative AI and Society

Ref

  • https://www.coursera.org/learn/generative-ai-for-everyone
  • slides: https://community.deeplearning.ai/t/generative-ai-for-everyone-lecture-notes/481740