ステップ 1: データを収集する
コレクションでコンテンツを整理 必要に応じて、コンテンツの保存と分類を行います。
データの収集は、教師あり ML の問題を解決するうえで最も重要なステップです。テキスト分類器の品質は、作成元となるデータセットで決まります。
解決したい特定の問題がなく、一般的なテキスト分類の検討に関心がある場合は、オープンソースのデータセットがたくさんあります。一部へのリンクは GitHub リポジトリで確認できます。一方、特定の問題に取り組む場合は、必要なデータを収集する必要があります。多くの組織では、データにアクセスするための公開 API(X API や NY Times API など)が提供されています。解決しようとしている問題にこれらの API を利用できる場合があります。
データを収集する際は、以下の点に注意してください。
- 公開 API を使用する場合は、使用する前に API の制限事項を理解してください。たとえば、一部の API では、クエリを実行できるレートに上限が設定されています。
- トレーニング サンプル(このガイドでは以降「サンプル」と呼びます)は多ければ多いほど良いと言えます。これにより、モデルの一般化が改善されます。
- すべてのクラスまたはトピックのサンプル数の不均衡が過度にないようにします。つまり、各クラスに同数のサンプルが必要です。
- サンプルが、一般的なケースだけでなく、可能な入力のスペースを適切にカバーしていることを確認してください。
このガイドでは、Internet Movie Database(IMDb)映画レビュー データセットを使用してワークフローを示します。このデータセットには、IMDb ウェブサイトにユーザーが投稿した映画のレビューと、レビュアーが映画を高く評価したかどうかを示す対応するラベル(「ポジティブ」または「ネガティブ」)が含まれています。これは感情分析の問題の典型的な例です。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-27 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 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."]]