Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Tưởng tượng rằng bạn đang phát triển một ứng dụng đề xuất món ăn cho phép
người dùng nhập vào món ăn yêu thích của bản thân và ứng dụng sẽ gợi ý các món ăn tương tự
mà họ có thể thích. Bạn muốn xây dựng một mô hình học máy (ML)
có khả năng dự đoán mức độ tương đồng giữa các món ăn để ứng dụng có thể đưa ra các đề xuất
chất lượng cao ("Vì bạn thích bánh kếp, chúng tôi xin đề xuất bánh crepe").
Để huấn luyện mô hình, bạn tuyển chọn một tập dữ liệu gồm 5.000 món ăn
phổ biến, bao gồm borscht,
bánh mì kẹp xúc xích,
rau trộn,
pizza,
và shawarma.
Hình 1. Một số mẫu món ăn có trong tập dữ liệu về thực phẩm.
Bạn tạo một tính năng meal sử dụng
biểu diễn mã one-hot
cho từng món ăn trong tập dữ liệu.
Mã hoá là quá trình
chọn ra dạng biểu diễn số ban đầu cho dữ liệu nhằm phục vụ việc huấn luyện mô hình.
Hình 2. Mã one-hot cho borscht, bánh mì kẹp xúc xích và shawarma.
Mỗi vectơ của mã one-hot dài 5.000 (mỗi phần tử tương ứng với
một món ăn trong tập dữ liệu). Dấu ba chấm trong biểu đồ biểu thị
4.995 phần tử không được hiển thị.
Các lỗi khi biểu diễn dữ liệu thưa
Khi xem lại các mã one-hot, bạn sẽ nhận thấy một số vấn đề với cách
biểu diễn dữ liệu này.
Số lượng trọng số. Các vectơ đầu vào có kích thước lớn đồng nghĩa với việc
mạng nơron sẽ có
một lượng lớn trọng số.
Với M phần tử trong mã one-hot và N
nút trong lớp đầu tiên của mạng sau lớp đầu vào, mô hình sẽ phải huấn luyện
trọng số MxN chỉ riêng cho lớp đó.
Số lượng điểm dữ liệu. Mô hình của bạn càng có nhiều trọng số, thì bạn càng có nhiều dữ liệu
cần huấn luyện một cách hiệu quả.
Khối lượng tính toán. Mô hình của bạn càng có nhiều trọng số, thì bạn càng cần nhiều hoạt động tính toán
để huấn luyện và sử dụng mô hình. Tác vụ này rất dễ vượt quá khả năng xử lý của phần cứng
mà bạn có.
Dung lượng bộ nhớ. Mô hình của bạn càng có nhiều trọng số, thì các trình tăng tốc càng cần nhiều dung lượng bộ nhớ
để huấn luyện và phân phát mô hình. Việc mở rộng mô hình
một cách hiệu quả rất khó khăn.
Khó khăn khi hỗ trợ
học máy trên thiết bị (ODML).
Nếu bạn muốn chạy mô hình ML trực tiếp trên thiết bị cục bộ (thay vì phân phát từ máy chủ),
bạn sẽ cần tập trung vào việc thu nhỏ mô hình và
giảm số lượng trọng số.
Trong mô-đun này, bạn sẽ học cách tạo các mục nhúng – các biểu diễn ít chiều hơn
của dữ liệu thưa – để giải quyết các vấn đề trên.
[null,null,["Cập nhật lần gần đây nhất: 2025-05-20 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)"]]