Bước 1: Thu thập dữ liệu
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.
Thu thập dữ liệu là bước quan trọng nhất để giải quyết mọi vấn đề trong công nghệ học máy có giám sát. Thuật toán phân loại văn bản của bạn chỉ có thể chất lượng dựa trên tập dữ liệu mà bạn dùng để tạo tập dữ liệu đó.
Nếu bạn không có vấn đề cụ thể nào muốn giải quyết và chỉ muốn khám phá việc phân loại văn bản nói chung, thì có rất nhiều tập dữ liệu nguồn mở có sẵn. Bạn có thể tìm thấy đường liên kết đến một số tài sản trong số đó trong kho lưu trữ GitHub của chúng tôi. Mặt khác, nếu đang giải quyết một vấn đề cụ thể, bạn sẽ phải thu thập dữ liệu cần thiết. Nhiều tổ chức cung cấp các API công khai để truy cập vào dữ liệu của họ – ví dụ: API X hoặc API NY Times. Bạn có thể tận dụng các API này để giải quyết vấn đề mà mình đang gặp phải.
Sau đây là một số điều quan trọng cần nhớ khi thu thập dữ liệu:
- Nếu bạn đang sử dụng một API công khai, hãy tìm hiểu các giới hạn của API đó trước khi sử dụng. Ví dụ: một số API đặt giới hạn về tỷ lệ bạn có thể thực hiện truy vấn.
- Bạn càng có nhiều ví dụ huấn luyện (còn gọi là mẫu trong phần còn lại của hướng dẫn này), thì càng tốt. Điều này sẽ giúp mô hình của bạn khái quát hơn.
- Hãy đảm bảo số lượng mẫu cho mỗi lớp hoặc chủ đề không thiếu cân bằng quá mức. Tức là bạn nên có số lượng mẫu tương đương trong mỗi lớp.
- Hãy đảm bảo các mẫu bao phủ đầy đủ không gian của dữ liệu đầu vào có thể có, chứ không chỉ các trường hợp phổ biến.
Trong suốt hướng dẫn này, chúng tôi sẽ sử dụng tập dữ liệu đánh giá phim trên Cơ sở dữ liệu phim trên Internet (IMDb) để minh hoạ quy trình làm việc. Tập dữ liệu này chứa các bài đánh giá phim do mọi người đăng trên trang web IMDb, cũng như các nhãn tương ứng (“tích cực” hoặc “tiêu cực”) cho biết liệu người đánh giá có thích phim hay không. Đây là một ví dụ kinh điển về một vấn đề phân tích quan điểm.
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-27 UTC."],[[["\u003cp\u003eHigh-quality data is crucial for building effective supervised machine learning text classifiers, with more training samples generally leading to better performance.\u003c/p\u003e\n"],["\u003cp\u003ePublic APIs and open-source datasets can be leveraged for data collection, but it's important to understand API limitations and ensure data balance across classes.\u003c/p\u003e\n"],["\u003cp\u003eAdequate data representation across all possible input variations is necessary, and the IMDb movie reviews dataset will be used to demonstrate text classification workflow for sentiment analysis.\u003c/p\u003e\n"],["\u003cp\u003eWhen collecting data, aim for a balanced dataset with a sufficient number of samples for each class to avoid imbalanced datasets and promote better model generalization.\u003c/p\u003e\n"]]],[],null,["# Step 1: Gather Data\n\nGathering data is the most important step in solving any supervised machine\nlearning problem. Your text classifier can only be as good as the dataset it is\nbuilt from.\n\nIf you don't have a specific problem you want to solve and are just interested\nin exploring text classification in general, there are plenty of open source\ndatasets available. You can find links to some of them in our [GitHub\nrepo](https://github.com/google/eng-edu/blob/master/ml/guides/text_classification/load_data.py).\nOn the other hand, if you are tackling a specific problem,\nyou will need to collect the necessary data. Many organizations provide public\nAPIs for accessing their data---for example, the\n[X API](https://developer.x.com/docs) or the\n[NY Times API](http://developer.nytimes.com/). You may be able to leverage\nthese APIs for the problem you are trying to solve.\n\nHere are some important things to remember when collecting data:\n\n- If you are using a public API, understand the *limitations* of the API before using them. For example, some APIs set a limit on the rate at which you can make queries.\n- The more training examples (referred to as *samples* in the rest of this guide) you have, the better. This will help your model [generalize](/machine-learning/glossary#generalization) better.\n- Make sure the number of samples for every *class* or topic is not overly [imbalanced](/machine-learning/glossary#class_imbalanced_data_set). That is, you should have comparable number of samples in each class.\n- Make sure that your samples adequately cover the *space of possible inputs*, not only the common cases.\n\nThroughout this guide, we will use the [Internet Movie Database (IMDb) movie\nreviews dataset](http://ai.stanford.edu/%7Eamaas/data/sentiment/) to illustrate\nthe workflow. This dataset contains movie reviews posted by people on the IMDb\nwebsite, as well as the corresponding labels (\"positive\" or \"negative\")\nindicating whether the reviewer liked the movie or not. This is a classic\nexample of a sentiment analysis problem."]]