사용자가 좋아하는 음식을 입력하면
비슷한 음식을 추천해 주는 음식 추천 애플리케이션을
개발하고 있다고 가정해 보겠습니다. 이 앱은 사용자가 좋아할 만한 음식을 정확히 추천하기 위해,
음식 간의 유사성을 예측할 수 있는 머신러닝(ML) 모델을 필요로 합니다.
예를 들어, “팬케이크를 좋아하신다면 크레페를 추천합니다”처럼 말이죠.
모델을 학습시키기 위해
수프,
핫도그,
샐러드,
피자,
샌드위치 등 인기 있는 5,000개의 음식 항목으로 구성된 데이터 세트를 선별합니다.
그림 1. 음식 데이터 세트에 포함된 음식 항목의 샘플.
데이터 세트에 있는 각 음식 항목을
원-핫 인코딩
으로 표현한 meal 특성을 만듭니다.
인코딩이란 모델 학습을 위해 데이터의
초기 수치적 표현을 선택하는 과정을 의미합니다.
그림 2. 수프, 핫도그, 샌드위치의 원-핫 인코딩.
각 원-핫 인코딩 벡터는 데이터 세트에 있는 음식 항목마다
하나의 항목이 포함되어 총 길이가 5,000입니다. 다이어그램의 생략 기호는 표시되지 않은
4,995개의 항목을 나타냅니다.
희소 데이터 표현의 일반적인 문제
이러한 원-핫 인코딩을 검토해 보면, 데이터 표현 방식에 다소 문제가 있다는 것을
알 수 있습니다.
가중치 수. 입력 벡터가 클수록
신경망에 필요한
가중치의 수도 많아집니다.
원-핫 인코딩에 M개의 항목이 있고, 입력 후 첫 번째 레이어에
N개의 노드가 있다면, 그 레이어에
M×N개의 가중치를 학습해야 합니다.
데이터 포인트 수. 모델의 가중치가 많을수록 효과적인 학습을 위해
더 많은 데이터가 필요합니다.
계산량. 가중치가 많을수록 모델을 학습하고 사용하는 데
더 많은 계산이 필요합니다. 따라서 하드웨어가 이를 지원하지 못할 가능성이
높습니다.
메모리양. 모델에 가중치가 많을수록, 모델을 학습하고 처리하는 가속기에
더 많은 메모리가 필요합니다. 이를 효율적으로
확장하는 것은 매우 어렵습니다.
기기 내 머신러닝(ODML)
지원의 어려움.
로컬 디바이스에서 ML 모델을 처리하지 않고 실행하려면 모델을 작게 만드는 데 집중해야 하며 가중치의 수를 줄이는 것이 중요합니다.
이 모듈에서는 이러한 문제를 해결할 수 있는 희소 데이터의 저차원 표현인
임베딩을 만드는 방법을 학습합니다.
[null,null,["최종 업데이트: 2025-05-15(UTC)"],[[["\u003cp\u003eThis module explains how to create embeddings, which are lower-dimensional representations of sparse data that address the problems of large input vectors and lack of meaningful relations between vectors in one-hot encoding.\u003c/p\u003e\n"],["\u003cp\u003eOne-hot encoding creates large input vectors, leading to a huge number of weights in a neural network, requiring more data, computation, and memory.\u003c/p\u003e\n"],["\u003cp\u003eOne-hot encoding vectors lack meaningful relationships, failing to capture semantic similarities between items, like the example of hot dogs and shawarmas being more similar than hot dogs and salads.\u003c/p\u003e\n"],["\u003cp\u003eEmbeddings offer a solution by providing dense vector representations that capture semantic relationships and reduce the dimensionality of data, improving efficiency and performance in machine learning models.\u003c/p\u003e\n"],["\u003cp\u003eThis module assumes familiarity with introductory machine learning concepts like linear regression, categorical data, and neural networks.\u003c/p\u003e\n"]]],[],null,["# Embeddings\n\n| **Estimated module length:** 45 minutes\n| **Learning objectives**\n|\n| - Visualize vector representations of word embeddings, such as [word2vec](https://wikipedia.org/wiki/Word2vec).\n| - Distinguish encoding from embedding.\n| - Describe contextual embedding.\n| **Prerequisites:**\n|\n| This module assumes you are familiar with the concepts covered in the\n| following modules:\n|\n| - [Introduction to Machine Learning](/machine-learning/intro-to-ml)\n| - [Linear regression](/machine-learning/crash-course/linear-regression)\n| - [Working with categorical data](/machine-learning/crash-course/categorical-data)\n| - [Neural networks](/machine-learning/crash-course/neural-networks)\n\nImagine you're developing a food-recommendation application, where\nusers input their favorite meals, and the app suggests similar meals\nthat they might like. You want to develop a machine learning (ML) model\nthat can predict food similarity, so your app can make high quality\nrecommendations (\"Since you like pancakes, we recommend crepes\").\n\nTo train your model, you curate a dataset of 5,000 popular\nmeal items, including ,\n,\n,\n,\nand .\n**Figure 1.** Sampling of meal items included in the food dataset.\n\nYou create a `meal` feature that contains a\n[**one-hot encoded**](/machine-learning/glossary#one-hot-encoding)\nrepresentation of each of the meal items in the dataset.\n[**Encoding**](/machine-learning/glossary#encoder) refers to the process of\nchoosing an initial numerical representation of data to train the model on.\n**Figure 2.** One-hot encodings of borscht, hot dog, and shawarma. Each one-hot encoding vector has a length of 5,000 (one entry for each menu item in the dataset). The ellipsis in the diagram represents the 4,995 entries not shown.\n\nPitfalls of sparse data representations\n---------------------------------------\n\nReviewing these one-hot encodings, you notice several problems with this\nrepresentation of the data.\n\n- **Number of weights.** Large input vectors mean a huge number of [**weights**](/machine-learning/glossary#weight) for a [**neural network**](/machine-learning/glossary#neural-network). With M entries in your one-hot encoding, and N nodes in the first layer of the network after the input, the model has to train MxN weights for that layer.\n- **Number of datapoints.** The more weights in your model, the more data you need to train effectively.\n- **Amount of computation.** The more weights, the more computation required to train and use the model. It's easy to exceed the capabilities of your hardware.\n- **Amount of memory.** The more weights in your model, the more memory that is needed on the accelerators that train and serve it. Scaling this up efficiently is very difficult.\n- **Difficulty of supporting on-device machine learning (ODML).** If you're hoping to run your ML model on local devices (as opposed to serving them), you'll need to be focused on making your model smaller, and will want to decrease the number of weights.\n\nIn this module, you'll learn how to create **embeddings**, lower-dimensional\nrepresentations of sparse data, that address these issues.\n| **Key terms:**\n|\n| - [One-hot encoding](/machine-learning/glossary#one-hot-encoding)\n| - [Neural network](/machine-learning/glossary#neural-network)\n- [Weight](/machine-learning/glossary#weight) \n[Help Center](https://support.google.com/machinelearningeducation)"]]