식당 리뷰 임베딩하기
임베딩이 특히 잘하는 대표적인 분류 작업 중 하나가 감성 분석이에요. 이번 연습과 다음 연습에서는 임베딩을 사용해 감성 분석을 수행하는 전체 워크플로를 단계별로 진행해 볼 거예요.
reviews에는 소규모 식당 리뷰 샘플이, sentiments에는 감성 레이블이 저장되어 있어요:
sentiments = [{'label': 'Positive'},
{'label': 'Neutral'},
{'label': 'Negative'}]
reviews = ["The food was delicious!",
"The service was a bit slow but the food was good",
"The food was cold, really disappointing!"]
리뷰와 클래스 레이블을 임베딩해 zero-shot 분류 방식으로 각 리뷰의 감성을 분류해 볼 거예요.
이전에 만들었던 create_embeddings() 함수도 계속 사용하실 수 있어요.
이 연습은 강의의 일부입니다
OpenAI API로 시작하는 임베딩 Introduction
연습 안내
- 리스트 컴프리헨션을 사용해
sentiments딕셔너리의 레이블에서 클래스 설명 리스트를 만드세요. create_embeddings()함수를 사용해class_descriptions와reviews를 임베딩하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Create a list of class descriptions from the sentiment labels
class_descriptions = ____
# Embed the class_descriptions and reviews
class_embeddings = ____
review_embeddings = ____