04.11 프롬프트 엔지니어링의 끝이 보인다!

2024. 4. 12. 00:36프로젝트/빵맛집 추천서비스 웹배포

 

01 피드백 전, 프롬프트 엔지니어링 과정 (결과가 썩 맘에 들지 않음)


- "Please exclude the '\n' character from the output" 추가 -> 제거

- "Characteristics:" 이게 특성 이름으로 랜덤으로 잡힌다. -> 제거

- "Print it in a single line." 추가 : \n의 제거가 목적이다.

- Output 축소를 위해 예시 형식의 간소화 {"A" : "+10"} -> 적용이 안돼서 제거

- "Exclude zero score." -> output 축소를 위해 추가

- import time, import random 모듈 추가로 대기 시간을 더한다.

- "Please separate the output characteristic values for each review with commas." (예시와 겹침) 제거

- "Please ensure to output the Meaningful scores." -> 제, 예시의 깨찰빵이 모두 출력

- Output Rules 추가하고 예시 구문을 여기로 통합한다.

- '깨찰빵'이라는 특정 명칭의 예시 대신 "bread name"으로 변경했다.

- 개행(\n)문자를 추가 -> 문단을 분류하는 기능을 추가했지만 결과가 같아서 삭제했다.

- 숫자만 출력해 추가 -> 01-1을 참고하기. 결과가 좋지 않아서 제거했다.

- 1번 뒤에 "모든 유의미한 데이터 출력하시오."를 zero score 조건과 상충하여 삭제했다.

- "예시는 다음 형식과 같다." 를 ouput 조건으로 통합했다.

- **Print the values corresponding to the attributes in order, excluding the attribute names.** 숨어있던 충돌조건을 삭제했다.

 

# 결과 프롬프트 더보기 클릭

더보기
system_prompt = "From now on, you must do three things: 1) Analyze the keywords in the bakery reviews in detail and assign integer scores ranging from -10 to +10 for all 25 characteristics. 2) 'Overall review sentiment score': Provide the overall sentiment score of the entire review text, ranging from -1 to 1, rounded to one decimal place. Closer to 1 indicates more positive, and closer to -1 indicates more negative. 3) 'Unique menu item name': If there is a unique menu item specific to the store, output text as an exception at the end. If not, output 'None'. Conditions: 1) First, check if there are keywords related to the characteristic, if yes, assign True. 2) If True, assign scores closer to -10 for negative sentiments and closer to +10 for positive sentiments. 3) The higher the emotional intensity, the higher the score assigned, and vice versa, assign lower scores in stages. 4) The less emotion, the closer the score is to 0. 5) When the score is 0, double-check to ensure accuracy. 6) The 'Pets' keyword must be related to the 'customer's' 'pet'. Wild animals do not qualify. 7) 'Waiting' refers to the time customers spend waiting. 8) Distinctly identify the 'subject' of 'tastes good'. 9) If there are keywords related to 'waiting', definitely evaluate the score. 10) The word '맛집' is very important to me. 11) Infer and judge similar languages. 12) Anything served in a cup is considered a 'beverage'. 13) Be aware that there are various types of 'bread'. 14) Characteristics that are unrelated or indeterminable are scored as 0. 15) 'View' is highly related to the 'scenery' characteristic. 16) Do not compare with other reviews, only use the content of the given review as the basis for scoring. 17) Judgments must be based solely on keywords in the review. 18) Do not provide any further explanation, only scores. 19) 'Desserts' are also included in 'bread'. 20) Distinctly identify the sentence's subject. Characteristics: 'The bread is delicious', 'The beverage is delicious', 'Vegan', 'No senior zone', 'No kids zone', 'Pets are allowed', 'Uses whole wheat', 'Nice view', 'Good atmosphere', 'Friendly', 'The store is clean', 'The restroom is clean', 'Parking available', 'The store is spacious', 'Plenty of seats', 'The seating is comfortable', 'There is a special menu', 'Photogenic', 'The music is good', 'Reservation is possible', 'Unique concept', 'The interior is beautiful', 'Good value for money', 'There is a wait', 'Good for health'. Additional score to be outputted: 'Overall review sentiment score', 'Unique menu item name' Output Rules: 1) Examples are as follows: 'The bread is delicious' : '+9', 'The beverage is delicious' : '+3', 'Vegan' : '+3', 'No senior zone' : '-2', 'No kids zone' : '0', 'Pets are allowed' : '+7', 'Uses whole wheat' : '-5', 'Nice view' : '-5', 'Good atmosphere' : '+2', 'Friendly' : '+7', 'The store is clean' : '0', 'The restroom is clean' : '-1', 'Parking available' : '-1', 'The store is spacious' : '-7', 'Plenty of seats' : '+9', 'The seating is comfortable' : '+3', 'There is a special menu' : '+3', 'Photogenic' : '-2', 'The music is good' : '0', 'Reservation is possible' : '+7', 'Unique concept' : '-5', 'The interior is beautiful' : '+2', 'Good value for money' : '+9', 'There is a wait' : '+3', 'Good for health' : '+3'. Additional score to be outputted: 'Overall review sentiment score' : '+0.5', 'Unique menu item name' : 'bread name' 2) Make outputs as JSON format. 3) Print it in a single line. 4) Exclude zero score."

 

01-1 번외: 숫자만 나오게 하기+json 도전!! fail


1. 목적: 대용량의 데이터를 제한된 예산 안에서 원하는 결과를 본다.

2. 최대한 숫자만 나오게 활용하면서 제외되는 데이터가 없어야 한다.

3. 3.5 모델은 json 형식으로 출력하는 게 맞다고 판단했다.

4. 모델이 헷갈릴 수 있는 bread name은 형태소 분석을 통해 추출 -> 프롬프트내 제거

 

# 전체 프롬프트 더보기 클릭

더보기
system_prompt = "From now on, you must do two things: 1) Analyze the keywords in the bakery reviews in detail and assign integer scores ranging from -10 to +10 for all 25 characteristics. 2) 'Overall review sentiment score': Provide the overall sentiment score of the entire review text, ranging from -1 to 1, rounded to one decimal place. Closer to 1 indicates more positive, and closer to -1 indicates more negative. Conditions: 1) First, check if there are keywords related to the characteristic, if yes, assign True. 2) If True, assign scores closer to -10 for negative sentiments and closer to +10 for positive sentiments. 3) The higher the emotional intensity, the higher the score assigned, and vice versa, assign lower scores in stages. 4) The less emotion, the closer the score is to 0. 5) When the score is 0, double-check to ensure accuracy. 6) The 'Pets' keyword must be related to the 'customer's' 'pet'. Wild animals do not qualify. 7) 'Waiting' refers to the time customers spend waiting. 8) Distinctly identify the 'subject' of 'tastes good'. 9) If there are keywords related to 'waiting', definitely evaluate the score. 10) The word '맛집' is very important to me. 11) Infer and judge similar languages. 12) Anything served in a cup is considered a 'beverage'. 13) Be aware that there are various types of 'bread'. 14) Characteristics that are unrelated or indeterminable are scored as 0. 15) 'View' is highly related to the 'scenery' characteristic. 16) Do not compare with other reviews, only use the content of the given review as the basis for scoring. 17) Judgments must be based solely on keywords in the review. 18) 'Desserts' are also included in 'bread'. 19) Distinctly identify the sentence's subject. Characteristics: 'The bread is delicious', 'The beverage is delicious', 'Vegan', 'No senior zone', 'No kids zone', 'Pets are allowed', 'Uses whole wheat', 'Nice view', 'Good atmosphere', 'Friendly', 'The store is clean', 'The restroom is clean', 'Parking available', 'The store is spacious', 'Plenty of seats', 'The seating is comfortable', 'There is a special menu', 'Photogenic', 'The music is good', 'Reservation is possible', 'Unique concept', 'The interior is beautiful', 'Good value for money', 'There is a wait', 'Good for health'. Additional score to be outputted: 'Overall review sentiment score' Output Rules: 1) Examples are as follows: 'Characteristics' : [+n,+n,+n,-n,0,+n,-n,-n,+n,+n,0,-n,-n,-n,+n,+n,+n,-n,0,+n,-n,+n,+n,+n,+n] Additional score to be outputted: 'Overall review sentiment score' : '+0.5' 2) Make outputs as JSON format. 3) Do not provide any further explanation."

 

# "다음과 같은 형식으로 출력해줘" 변경 결과 더보기 클릭

더보기
'Characteristics' : [+n,+n,+n,-n,0,+n,-n,-n,+n,+n,0,-n,-n,-n,+n,+n,+n,-n,0,+n,-n,+n,+n,+n,+n] Additional score to be outputted: 'Overall review sentiment score' : '+0.5'

 

# 결과: 리뷰내용을 분석하지 않은 판단 결과로 이 프롬프트는 쓸 수 없다 판단했다.

 

02 토큰 계산


- 10개의 리뷰 텍스트 input, output의 단가가 0.15달러였다.

- 13만건의 데이터를 진행한다면 130달러가 나올 예정이다.

 

03 전처리 추가


- N, K사 데이터에 중복 데이터가 존재했고, 전처리 후 약 10만건의 데이터 셋이 만들어졌다.

 

04 PPT, 스크립트 완성


 

05 프롬프트 피드백 적용 후, 답이 보인다.


# 피드백
- openai api 대체할 무료 사이트 알려주셨다.
- 프롬프트 구조화를 시도해보록 한다.
- 프롬프트 너무 길다. -> 줄글로 길다. -> 구조화.
- 프롬프트가 너무 길다는 건, 구조화를 했으면 좋겠다는 말이다.
- 3개 데이터의 정확도 확인 -> 5개 보고 -> 7개 정확하면 -> 10개씩 보고 -> 덩어리 단위로 숫자를 늘리며 보는데 어느 순간 멍청해지는 대답을 할 때가 있다. 그럼 그전 개수까지 끊어서 반복하면 된다.
- 데이터 덩어리가 들어왔을 때, 어느 순간 정확도가 떨어지는 갯수가 있다고 한다.
- 리뷰 원문이랑 결과를 사람이 비교해보는 작업이 꼭 필요하다.
- 비용이 나와도 좋은 방향이 어떻겠는가? -> JSON 추천
- 150만원은 회사에게 큰 돈이 아니다. 모든 구를 추천하는거보다 소수의 구에 집중하는게 어떨까.
- 점수의 최고점을 100점으로 바꾸는게 어떤가? 5단위 숫자가 그래도 잘 먹힌다.
- 그래도 숫자에 약한 gpt라는 점을 인지한다.
- 긍부정 지수를 0, 1로 나눈다. (이건 타튜터님 자료 참고)
- 해시 학습은 지금 아닌거 같고 현재 프로젝트 과정에 집중한다.

 

# 결과

1. 기존 -1~1점인 긍부정 점수를 N과 P로 나눈다.

- 전체적으로 추천인지 비추천인지를 0/1로 나눴는데 output의 가성비를 위해서 zero score를 제외하고 출력할 것이기 때문에 문자형으로 변경했다. -> 만족스럽다.

2. 중복으로 판단되는 문장 3개(3/4/8번)를 제거했다.

(3) The higher the emotional intensity, the higher the score assigned, and vice versa, assign lower scores in stages.

- 감정지수가 높을수록 높은 점수를 부여하고, 낮을수록 낮은 점수를 단계별로 판단해서 부여해. 중복으로 제거한다.

(4) The less emotion, the closer the score is to 0.

- 감정이 적을수록 0에 가까운 점수를 부여해. 중복으로 제거한다.

(8) Distinctly identify the 'subject' of 'tastes good'.

- '맛있다'는 텍스트의 '주어'를 구분해. 중복으로 제거한다.

3. zero score 를 직관적으로 0 또는 '0'으로 변경한다.

 

# 전체 프롬프트 더보기 클릭

더보기
system_prompt = "From now on, you must do three things: 1) Analyze the keywords in the bakery reviews in detail and assign integer scores ranging from -100 to +100 for all 25 characteristics. 2) 'Positive-Negative score': Assign 'P' if the entire review text is positive, and 'N' if it is negative. 3) 'Unique menu item name': If there is a unique menu item specific to the store, output text as an exception at the end. If not, output 'None'. Conditions: 1) First, check if there are keywords related to the characteristic, if yes, assign True. 2) If True, assign scores closer to -100 for negative sentiments and closer to +100 for positive sentiments. 3) When the score is 0, double-check to ensure accuracy. 4) The 'Pets' keyword must be related to the 'customer's' 'pet'. Wild animals do not qualify. 5) 'Waiting' refers to the time customers spend waiting. 6) If there are keywords related to 'waiting', definitely evaluate the score. 7) The word '맛집' is very important to me. 8) Infer and judge similar languages. 9) Anything served in a cup is considered a 'beverage'. 10) Be aware that there are various types of 'bread'. 11) Characteristics that are unrelated or indeterminable are scored as 0. 12) 'View' is highly related to the 'scenery' characteristic. 13) Do not compare with other reviews, only use the content of the given review as the basis for scoring. 14) Judgments must be based solely on keywords in the review. 15) Do not provide any further explanation, only scores. 16) 'Desserts' are also included in 'bread'. 17) Distinctly identify the sentence's subject. Characteristics: 'The bread is delicious', 'The beverage is delicious', 'Vegan', 'No senior zone', 'No kids zone', 'Pets are allowed', 'Uses whole wheat', 'Nice view', 'Good atmosphere', 'Friendly', 'The store is clean', 'The restroom is clean', 'Parking available', 'The store is spacious', 'Plenty of seats', 'The seating is comfortable', 'There is a special menu', 'Photogenic', 'The music is good', 'Reservation is possible', 'Unique concept', 'The interior is beautiful', 'Good value for money', 'There is a wait', 'Good for health'. Additional score to be outputted: 'Positive-Negative score', 'Unique menu item name' Output Rules: 1) Examples are as follows 'The bread is delicious' : '+98', 'The beverage is delicious' : '+32', 'Vegan' : '+3', 'No senior zone' : '-23', 'No kids zone' : '0', 'Pets are allowed' : '+75', 'Uses whole wheat' : '-51', 'Nice view' : '-5', 'Good atmosphere' : '+27', 'Friendly' : '+70', 'The store is clean' : '100', 'The restroom is clean' : '-100', 'Parking available' : '-16', 'The store is spacious' : '-7', 'Plenty of seats' : '+99', 'The seating is comfortable' : '+35', 'There is a special menu' : '+31', 'Photogenic' : '-2', 'The music is good' : '0', 'Reservation is possible' : '+70', 'Unique concept' : '-54', 'The interior is beautiful' : '+26', 'Good value for money' : '+94', 'There is a wait' : '+36', 'Good for health' : '+1'. Additional score to be outputted: 'Positive-Negative score' : 'P', 'Unique menu item name' : 'bread name' 2) Make outputs as JSON format. 3) Print it in a single line. 4) Exclude '0' score"

 

# 실험 1. 튜터님의 조언대로 점수 폭을 크게 높이니 정확도가 높아진 점수가 보인다.

but 출력 데이터의 길이가 너무 길다.

 

# 실험 2. 출력하지 않고도 함수로 대체할 수 있는 0값을 제거하기 위한 작업을 했다.

- zero 스코어를 제거하고자 하는데 긍부정 지수에 0이 중복되니 P/N 값으로 변경했다.

- 'Exclude zero score' 를 추가했다.

but temperature = 0이어도 랜덤으로 길게 나오는 출력값이 보인다.

 

# 실험 3. zero 구문을 0 또는 "0"과 같이 직관적으로 변경한다.

- 0값을 부여할 때 

- '0'값을 부여할 때

# 결과: 앞으로 더 많은 결과들이 필요하겠지만 일단 '0'으로 정했고 꾸준한 결과 여부를 확인할 것이다.

 

05-1 번외: Characteristics 설명과 Output rules를 통합한다.


- 결과: Characteristics output rules 분류는 실패했다.

- 이유: 프롬프트 내 "반복학습"이 중요하다는 걸 깨달았다.

 

# 반복 학습이 안됐다면 컬럼을 자체 생성한하는 문제를 발견했다.