시작하기무료로 시작하기

제품 설명 임베딩하기

온라인 리테일러가 판매하는 여러 제품의 정보가 담긴 딕셔너리 리스트 products가 제공되었어요. 소매점 웹사이트에서 시맨틱 검색을 사용할 수 있도록 각 제품의 'short_description'을 임베딩하세요.

다음은 딕셔너리 리스트 products의 미리 보기예요:

products = [
    {
        "title": "Smartphone X1",
        "short_description": "The latest flagship smartphone with AI-powered features and 5G connectivity.",
        "price": 799.99,
        "category": "Electronics",
        "features": [
            "6.5-inch AMOLED display",
            "Quad-camera system with 48MP main sensor",
            "Face recognition and fingerprint sensor",
            "Fast wireless charging"
        ]
    },
    ...
]

OpenAI 클라이언트는 이미 생성되어 client에 할당되어 있어요.

이 연습은 강의의 일부입니다

OpenAI API로 시작하는 임베딩 Introduction

강의 보기

연습 안내

  • 리스트 컴프리헨션을 사용해 products의 각 항목에서 'short_description'만 담은 리스트 product_descriptions를 만드세요.
  • 배치 처리를 사용해 각 제품의 'short_description'에 대한 임베딩을 생성하고, 입력은 text-embedding-3-small 모델에 전달하세요.
  • 각 제품의 임베딩을 response_dict에서 추출해, products의 각 항목에 'embedding'이라는 새 키로 저장하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Extract a list of product short descriptions from products
product_descriptions = [____ for product in ____]

# Create embeddings for each product description
response = ____
response_dict = response.model_dump()

# Extract the embeddings from response_dict and store in products
for i, product in ____:
    product['embedding'] = response_dict[____][____][____]
    
print(products[0].items())
코드 편집 및 실행