반응형

This article is provided by...

Stop doing this on ChatGPT and get ahead of the 99% of its users | by Josep Ferrer | Geek Culture | Apr, 2023 | Medium

 

Stop doing this on ChatGPT and get ahead of the 99% of its users

Unleash the Power of AI Writing with Effective Prompts

medium.com


[0] Stop doing this on ChatGPT and get ahead of the 99% of its users

  • Unleash the Power of AI writing with Effective Prompts
  • have you ever felt frustrated with AI-generated content?
    • you think the ChatGPT output is completely horrible
    • and doesn’t satisfying your expectations?
  • getting quality output from AI writing tools
    • depends heavily on the quality of your prompts
    • by training ChatGPT
      • you can get a personal writing assistant for free!
  • time to discover The art of crafting powerful prompts
  • to make the most of this cutting-edge technology.

[1] Why the bad results?

  • The problem often lies not with the AI itself,
    • but the limitations and vagueness of the input provided.
    • instead of expecting the AI to think for you
    • you should be the one doing the thinking and guiding the AI to perform the tasks you need
  • Bad results?
    • you are feeding ChatGPT poorly written and short prompts
    • and expecting some magical output to happen
      • ”Generate a LinkedIn post about AI for my account”
      • “Suggest me some ideas to write about programming” … etc.
    • you should stop!
    • giving prompts like this, ChatGPT has to make too many decisions
      • which generates some poor output
    • Poor instructions = Poor results !!!

[2] 4 main steps to assess the prompts and results

#1. Understand your needs and requirements:

  • to order something, you first need to know what you want.
    • what you want from the AI
    • why you want it
    • how you want it delivered
  • This clarity will help you create better prompts and enhance the quality of the output.
  • start with standardizing all types of outputs you require from AI.
  • (for examples)
  • “I am starting to be active on my Twitter account – so I would like both tweet ideas and Twitter structures.”
    • Ideas to write tweets for Twitter.
    • Threads structures for Twitter.

#2. Treat AI like a digital intern:

  • imagine you’ve hired an intern
  • you wouldn’t give them only one brief explanation and expect them to do everything great at first.
    • you should provide your AI with a detailed checklist
    • explain the purpose behind the task
    • be open to clarify any doubts the AI might have.
  • “Hey ChatGPT. Write me a Twitter thread about the Google Cloud Platform” 
    • this prompt is way too vague. >> letting an AI too many decisions to make for you.
      • How many tweets do you want?
      • What writing style?
      • What subtopic should ChatGPT emphasize?
      • What is my language tone – friendly, professional..?
  • Always use AI tools to leverage your work – not to substitute you.

 


#3. Create constraints and avoid assumptions:

  • This is the key to the process.
  • To get specific and accurate output >> provide your AI with clear and well-defined information.
  1. A good contextualization
    • what kind of output do you want?
  2. A specific topic
    • with subtopics to emphasize.
  3. A specific structure
    • like how may tweets, words..
  4. A specific format for the output
    • what writing style to use, what tone..
  5. A specific list of thing to avoid
    • what you do not want to mention.

for example.....

  • Want ChatGPT to generate a Twitter Thread for me.
    • Hey ChatGPT. I am going to train you to create Twitter threads.
  • Make sure ChatGPT understands the mean by the Twitter Thread.
    • Twitter threads are a series of tweets that outline and highlight the most important ideas of a longer text or some specific topic.
  • Want ChatGPT to write with a specific topic.
    • The twitter thread will talk about Google Cloud Platform free tier services.
  • Outline what I want it to mentions for sure and what to emphasize.
    • I want you to talk about Google cloud platform environment, all its services and its utility for data science. However, you need to emphasize all these advantages are free for ever when your usage is contained within some tiers. Mention google big query and cloud functions, that are two of the most important services for analytics.

  • Specify the whole structure I want to receive from ChatGPT.
    • A first tweet with a short but concise message, letting people know what’s the thread about. It is important not to be more than 30 words, use key hashtags and convince people to read the whole thread. Emphasize the utility of the thread for them.
    • A second tweet that makes a short intro and let the reader get contextualized and understand why are they still reading the thread. It is important to keep the reader reading.
    • 4 or 5 tweets that outline and describe the most important parts of the article. These should summarise the main ideas of the topic I explained to you before.
    • A last tweet with some conclusions and letting people know why your thread is worth it.
    • A final tweet inviting them to retweet your thread and follow you.
  • Specify the format of the output I want.
    • I would like you to behave as a technology and data science writer. Use natural and engaging language. It is important to use easy-to-understand vocabulary — remember I want to break complex concepts down to everyday words.
  • A specific list of things to avoid.
    • Avoid using complex vocabulary.

#4. Iterate and refine your input:

  • if the AI generates incorrect output.
    • probably due to an issue of your input.
    • Don’t be afraid to rework your prompts.
  • to communicate with your AI machine
    • even though you use a natural language,
    • you should think you are writing a code for AI.
  • Repeat and regenerate the response as many times as you want, so you get a some good result. 

Dickie Bush's Prompt writing is an iterative game


[3] Conclusions

  • It’s not the AI that’s falling short, but rather the way we interact with it.
  • To make the most of ChatGPT and similar tools,
    • we must refine our approach
    • and focus on becoming thinkers who guide the AI in executing.
  • By following these tips and taking responsibility for the input,
    • you’ll find that AI-generated content
    • can be a valuable asset in your content creation arsenal.
  • So, let’s start crafting effective prompts and unlock the full potential of AI writing!
  • And always remember…
    • Using AI won’t make you a cheater — but not using it will leave you behind!
반응형
반응형

Hyperparameters in Deep RL with Optuna


Hyperparameters in Deep RL with Optuna

[1편 문제: Hyper-parameters]

[2편 해결: Bayesian Search]

[3편: Hyper-parameter Search with Optuna]

총 3편으로 나눠서 Deep Reinforcement Learning에서의 Hyperparameter 의 중요성과

다양한 Hyperparameter를 선택하는 Search 방법을 소개하고

Optuna 사용 방법을 익혀보겠습니다.

 


[1] Optuna

  • Bayesian search 방법이 구현된 오픈소스 Python 라이브러리
  • Bayesian 방법의 수학적인 요소에 깊은 이해가 없어도 사용 가능

Optuna


* Optuna

https://optuna.org/

 

Optuna - A hyperparameter optimization framework

Optuna is an automatic hyperparameter optimization software framework, particularly designed for machine learning. It features an imperative, define-by-run style user API.

optuna.org


[2] Start Hyper-parameter Search with Optuna

  • Deep Q-learning으로 Cart Pole environment 풀이
git clone https://github.com/Paulescu/hands-on-rl.git
  • 사용할 가상환경 지정
  • 제공하는 패키지 목록 requirements.txt를 가상환경에 설치
pip install –r requirements.txt
  • 상황에 따라서 각자 필요한 패키지 pip install 명령어로 설치
pip install mlflow
pip install jupyter
pip install optuna
pip install torch

0) 03_cart_pole/notebooks/09_hyperparameter_search.ipynb 에서 순서 제공

1) load

load_ext autoreload
autoreload 2
pylab inline
config InlineBackend.figure_format = 'svg'

2) env load

import gym
env = gym.make('CartPole-v1')

3) terminal에서 03_cart_pole 폴더로 이동

각자 환경에 맞는 디렉토리로 작성

cd ~/hands-on-rl/03_cart_pole

4) MLflow

  • ML 모델 운영화 목적 (MLOps)
  • MLFlow Tracking
    • 모델 개발 중에 필요한 모든 것을 추적
    • 많은 하이퍼-파라미터로 run하는 실험 진행 시, 매 run마다 정확한 구성을 Log
  • terminal에서 다음 명령어 실행
mlflow ui --backend-store-uri mlflow_runs/

ex. Log 예시

meta.yaml


* MLflow

mlflow

https://mlflow.org/

 

MLflow - A platform for the machine learning lifecycle

An open source platform for the end-to-end machine learning lifecycle

mlflow.org


5) MLflow Setup and URL

아래 python 파일을 run

mlflow setup

연결되면 URL 클릭 (필자의 경우 아래의 링크)

http://127.0.0.1:5000

http://127.0.0.1:5000


[3] Optimize Hyper-parameters with Optuna

  • hyperparameter sampling
  • training
  • and evaluation of RL agent

 

  • The objective function: returns the metric we want to optimize
    • 리워드 값 최대화 목표

[4] Objective function

  • Samples hyperparameters
  • trains the agent 200 episodes and evaluates it 1000 episodes
  • output is the average reward in 1000 episodes

Objective function (1)

 

  • sample_hyper_parameters()
    • samples and return the hyperparameter values
      • the range we specify
      • and the sampler used by Optuna uses(TPE default)
    • 이 함수가 정의된 코드를 확인하면
      • wide intervals or ranges of values 만 제공
      • bayesian sampling 방법은 구현하지 않아도 Optuna가 함

 

Objective function (2)
Objective function (3)

6) Optuna study object 생성

optuna object 생성

  • storage 파라미터를 로컬 sqlite file에 설정
  • 컴퓨터나 프로세스가 코드 붕괴를 run할 때 탐색을 감소시켜 중요

[5] Optimize Hyper-parameters with Optuna (con.)

7) Optuna에게 study.optimize() 로 search 시작 (100번 시도)

optuna start optimize search

 

  • perfect agent가 나온다면 평균 reward가 500점일 것
  • 그럼 hyperparameter 값들 도출 성공
agent_id = 298 is the winner
  • agent_id : 298
  • mean_reward : 500
  • optimized result with information of good hyperparameter

8) CartPole을 완벽하게 풀이하는 agent=298

cartople agent set

9) 결과 이용하여 agent 평가

agent 평가 진행하기

agent 평가
500 달성


[6] Summary

  • Deep RL에서 Hyperparameters는 중요하다
    • 좋은 hyperparameter 값을 구하기 위하여 실험
    • 똑똑한 search 전략을 사용하지 않는다면 시간 소요가 매우 크다
    • Brute-force(i.e. grid search)는 대부분의 경우에서 실현 불가능
  • Bayesian Search 방법
    • 위문제를해결하는데에가장좋은방법
    • hyperparameter에 다음에 시도할 가장 유망한 영역이 무엇인지 탐색하고 배움
    • random search보다 빠르게 수렴
  • Optuna
    • hyperparameter search에 좋은 오픈소스 라이브러리
    • bayesian search의 모든 세부 사항을 추상화하는 plug-and-play solution
    • 몇 줄의 코드로 강력한 hyperparameter 실험 파이프라인 구축

 

반응형
반응형

Hyperparameters in Deep RL with Optuna


Hyperparameters in Deep RL with Optuna

[1편 문제: Hyper-parameters]

[2편 해결: Bayesian Search]

[3편: Hyper-parameter Search with Optuna]

총 3편으로 나눠서 Deep Reinforcement Learning에서의 Hyperparameter 의 중요성과

다양한 Hyperparameter를 선택하는 Search 방법을 소개하고

Optuna 사용 방법을 익혀보겠습니다.


[1] 해결: Bayesian Search

  • to search well, remembering what you tried in the past is good
  • and use that information to decide what is best to try next

 

  • Bayesian search methods
    • keep track of past iteration results
    • to decide what are the most promising regions in the hyperparameter space to try next
  • explore the space with surrogate model(of the object function)
    • estimate of how good each hyperparameter combination is
    • as running more iterations, the algorithm updates the surrogate model
    • estimates get better and better

More Information of Efficient Hyperparameater tuning using Bayesian Optimization

https://towardsdatascience.com/a-conceptual-explanation-of-bayesian-model-based-hyperparameter-optimization-for-machine-learning-b8172278050f

 

A Conceptual Explanation of Bayesian Hyperparameter Optimization for Machine Learning

The concepts behind efficient hyperparameter tuning using Bayesian optimization

towardsdatascience.com


  • Surrogate model
    • gets good enough to point the search towards good hyperparameters
    • if the algorithm selects the hyperparameters that maximize the surrogate
      • yield good results on the true evaluation function.

estimating result of surrogate model

  • Bayesian Search
    • superior to random search
    • perfect choice to use in Deep RL
  • differ in how they build the surrogate model
  • will use Tree-structured Parzen Estimator (TPE) method.
    •  uses applying Bayes rule
    • probability of the hyperparameters given score on the object function
bayes rule in action
make two different distributions for the hyperparameters
a lower value of the objective function than the threshold
the value of the objective function is less than the threshold
 
the value of the objective function is greater than the threshold
 

 

반응형
반응형

Hyperparameters in Deep RL with Optuna


Hyperparameters in Deep RL with Optuna

[1편 문제: Hyper-parameters]

[2편 해결: Bayesian Search]

[3편: Hyper-parameter Search with Optuna]

총 3편으로 나눠서 Deep Reinforcement Learning에서의 Hyperparameter 의 중요성과

다양한 Hyperparameter를 선택하는 Search 방법을 소개하고

Optuna 사용 방법을 익혀보겠습니다.


[1] 개요: Hyper-parameters in Deep RL

  • Build a perfect agent to solve the Cart Pole environment using Deep Q
  • set of hyperparameters used
  • to become a real PRO in Reinforcement Learning
  • need to learn how to tune hyperparameters
  • with using the right tools
  • Optuna : open-source library for hyperparameters search in the Python ecosystem

[2] 문제: Hyper-parameters

Machine Learning models

1. parameters

  • numbers found AFTER training your model

2. hyperparameters

  • numbers need to set BEFORE training the model
  • exists all around ML

ex. learning rate in supervised machine learning problems

  • too low number stuck in local minima
  • too large number oscillate too much and never converge to the optimal parameters
  • Deep RL is even more challenging.

  • Deep RL problem
    • have more hyperparameters than supervised ML models
    • hyperparameters in Deep RL have a huge impact on the final training outcome

How can we find the good hyperparameters?

  • to find good hyperparameters we follow trial-and-error approach
  1. choose a set of hyperparameters
  2. train the agent
  3. evaluate the agent
  4. if we are happy with the result, we are done.
    Otherwise, we choose a new set of hp and repeat the whole process.

find good hyperparameters we follow trial-and-error approach


[3] Grid Search

  • trying all possible combinations and select the one that works best.
  • method called grid search
  • works well for many supervised ML problems
grid search

[4] Grid Search Problem

  • Deep RL problems
    • many more hyperparameters (e.g 10-20)
    • each can take many possible values
    • it creates massive grid in which to search the best combinatio
      • number of combinations grows exponentially
        • ex. 10개 hyperparameter, 1~10까지 가능하다면? grid size = 10,000,000,000
        • 한 번의 training loop이 10분이 걸린다고 해도? 10분 X 10,000,000,000 = 190,258년
        • 현실적으로 불가능!
        • 100,000개의 병렬 프로세스로 돌린다고 해도 2년..
    • 따라서 Grid search는 Deep RL 문제 풀이에는 매우 비효율적인 방법

[5] Random Search

  • instead of checking each of the 𝑁 possible hyperparameter combinations
  • randomly try a subset of them with size 𝑇
    • 𝑇 is much smaller than 𝑁
  • also train and evaluate the agent 𝑇 times

 

  • with this 𝑇 trials
    • we select the combination of hyperparameters that worked best
  • more efficient way to search and works better than Grid Search
    • speed and quality of the solution
    • but it is just spinning a roulette to decide hyperparameter
    • something more smart way needed.
반응형

+ Recent posts