임베딩 고도화
이전에 상품 정보를 임베딩할 때는 상품의 'short_description'만 임베딩할 수 있었기 때문에, 유의미한 정보가 일부만 반영되었어요. 이번 연습에서는 더 많은 정보를 담기 위해 'title', 'short_description', 'category', 'features'를 함께 임베딩해 볼 거예요.
다음은 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"
]
},
...
]
여러 특성을 하나의 문자열로 합칠 때는 다음 구조를 따라야 해요:
Title: <product title>
Description: <product description>
Category: <product category>
Features: <feature 1>; <feature 2>; <feature 3>; ...
이 연습은 강의의 일부입니다
OpenAI API로 시작하는 임베딩 Introduction
연습 안내
create_product_text()라는 함수를 정의해title,short_description,category,features데이터를 원하는 형식의 하나의 문자열로 결합하세요.create_product_text()를 사용해products의 각 상품 특성을 결합하고, 결과를 리스트에 저장하세요.product_texts의 텍스트를 임베딩하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Define a function to combine the relevant features into a single string
def create_product_text(product):
return f"""Title: {____}
Description: {____}
Category: {____}
Features: {____}"""
# Combine the features for each product
product_texts = [____ for product in ____]
# Create the embeddings from product_texts
product_embeddings = ____