Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -43,16 +43,23 @@ def embed_product_data(product_data):
|
|
43 |
category_embedding = category_embedding_layer(torch.tensor([category_id]))
|
44 |
color_embedding = color_embedding_layer(torch.tensor([color_id]))
|
45 |
|
|
|
|
|
|
|
|
|
46 |
# 최종 임베딩 벡터 결합
|
47 |
product_embedding = torch.cat(
|
48 |
(text_embedding, category_embedding, color_embedding), dim=1
|
49 |
)
|
|
|
|
|
|
|
50 |
return product_embedding.detach().numpy()
|
51 |
|
52 |
# 사용자 타워: 데이터 임베딩
|
53 |
def embed_user_data(user_data):
|
54 |
# 나이, 성별, 키, 몸무게 임베딩 (임베딩 레이어)
|
55 |
-
embedding_layer = Embedding(num_embeddings=100, embedding_dim=
|
56 |
|
57 |
# 예를 들어 성별을 'M'은 0, 'F'는 1로 인코딩
|
58 |
gender_id = 0 if user_data['gender'] == 'M' else 1
|
@@ -170,7 +177,4 @@ def recommend_products_for_user(user_id, top_n=1):
|
|
170 |
# 사용자 맞춤 추천 실행
|
171 |
user_id_to_recommend = 1 # 추천할 사용자 ID
|
172 |
top_n_recommendations = 1 # 추천 상품 개수
|
173 |
-
recommended_products = recommend_products_for_user(user_id_to_recommend, top_n=top_n_recommendations)
|
174 |
-
|
175 |
-
print(f"user_embedding shape: {user_embedding.shape}")
|
176 |
-
print(f"product_embeddings shape: {product_embeddings.shape}")
|
|
|
43 |
category_embedding = category_embedding_layer(torch.tensor([category_id]))
|
44 |
color_embedding = color_embedding_layer(torch.tensor([color_id]))
|
45 |
|
46 |
+
# 모든 임베딩 벡터 차원 맞추기
|
47 |
+
category_embedding = category_embedding.view(1, -1) # 2D로 변환
|
48 |
+
color_embedding = color_embedding.view(1, -1) # 2D로 변환
|
49 |
+
|
50 |
# 최종 임베딩 벡터 결합
|
51 |
product_embedding = torch.cat(
|
52 |
(text_embedding, category_embedding, color_embedding), dim=1
|
53 |
)
|
54 |
+
|
55 |
+
print(f"Generated product_embedding shape: {product_embedding.shape}") # Debugging
|
56 |
+
|
57 |
return product_embedding.detach().numpy()
|
58 |
|
59 |
# 사용자 타워: 데이터 임베딩
|
60 |
def embed_user_data(user_data):
|
61 |
# 나이, 성별, 키, 몸무게 임베딩 (임베딩 레이어)
|
62 |
+
embedding_layer = Embedding(num_embeddings=100, embedding_dim=128) # 임의로 설정된 예시 값
|
63 |
|
64 |
# 예를 들어 성별을 'M'은 0, 'F'는 1로 인코딩
|
65 |
gender_id = 0 if user_data['gender'] == 'M' else 1
|
|
|
177 |
# 사용자 맞춤 추천 실행
|
178 |
user_id_to_recommend = 1 # 추천할 사용자 ID
|
179 |
top_n_recommendations = 1 # 추천 상품 개수
|
180 |
+
recommended_products = recommend_products_for_user(user_id_to_recommend, top_n=top_n_recommendations)
|
|
|
|
|
|