ขั้นตอนที่ 1: รวบรวมข้อมูล
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
การรวบรวมข้อมูลเป็นขั้นตอนที่สำคัญที่สุดในการแก้ปัญหาแมชชีนเลิร์นนิงที่มีการควบคุมดูแล ตัวแยกประเภทข้อความจะใช้ได้เฉพาะชุดข้อมูลที่สร้างมาเท่านั้น
หากคุณไม่พบปัญหาเฉพาะที่ต้องการแก้ไขและเพียงแค่สนใจที่จะสำรวจการจัดประเภทข้อความโดยทั่วไป ชุดข้อมูลโอเพนซอร์สก็มีมากมายให้เลือกใช้ คุณสามารถดูลิงก์ไปยังข้อมูลบางส่วนได้ในที่เก็บของ GitHub ในทางกลับกัน หากคุณกำลังจัดการกับปัญหาเฉพาะ คุณจะต้องรวบรวมข้อมูลที่จำเป็น องค์กรหลายแห่งมี API สาธารณะสำหรับเข้าถึงข้อมูล เช่น X API หรือ NY Times API คุณอาจใช้ประโยชน์จาก API เหล่านี้เพื่อแก้ปัญหาที่คุณพยายามแก้ไขได้
ต่อไปนี้คือสิ่งสำคัญบางอย่างที่ควรจดจำเมื่อรวบรวมข้อมูล:
- หากคุณใช้ API สาธารณะ โปรดทำความเข้าใจข้อจำกัดของ API ก่อนใช้งาน เช่น API บางรายการกำหนดขีดจำกัดอัตราที่ใช้ในการค้นหาได้
- ยิ่งคุณมีตัวอย่างการฝึกมาก (หรือเรียกว่าตัวอย่างในส่วนที่เหลือของคู่มือนี้) ก็ยิ่งดี วิธีนี้จะช่วยให้โมเดลของคุณ เผยแพร่ข้อมูลทั่วไปได้ดียิ่งขึ้น
- ตรวจสอบว่าจำนวนตัวอย่างสำหรับชั้นเรียนหรือหัวข้อแต่ละรายการไม่ได้ไม่สมดุลกันมากเกินไป กล่าวคือ คุณควรมีจำนวนตัวอย่างที่คล้ายกันในแต่ละคลาส
- ตรวจสอบว่าตัวอย่างของคุณครอบคลุมพื้นที่ที่อาจอินพุตอย่างเพียงพอ ไม่ใช่แค่กรณีทั่วไป
ในคู่มือนี้ เราจะใช้ชุดข้อมูลรีวิวภาพยนตร์ของฐานข้อมูลภาพยนตร์อินเทอร์เน็ต (IMDb) เพื่ออธิบายขั้นตอนการทำงาน ชุดข้อมูลนี้มีรีวิวภาพยนตร์ที่โพสต์โดยผู้คนบนเว็บไซต์ IMDb รวมถึงป้ายกำกับที่เกี่ยวข้อง ("เชิงบวก" หรือ "เชิงลบ") ซึ่งบ่งบอกว่าผู้รีวิวชอบภาพยนตร์ดังกล่าวหรือไม่ นี่คือตัวอย่างที่คลาสสิก ของโจทย์การวิเคราะห์ความเห็น
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 UTC
[null,null,["อัปเดตล่าสุด 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."]]