Passaggio 1: raccogli i dati
Mantieni tutto organizzato con le raccolte Salva e classifica i contenuti in base alle tue preferenze.
La raccolta dei dati è il passaggio più importante per risolvere qualsiasi problema di machine learning supervisionato. La qualità del classificatore di testo può essere uguale al set di dati da cui è stato creato.
Se non hai un problema specifico da risolvere e ti interessa solo esplorare la classificazione del testo in generale, hai a disposizione molti set di dati open source. Puoi trovare i link ad alcuni di questi nel nostro repository GitHub. Se invece stai affrontando un problema specifico, dovrai raccogliere i dati necessari. Molte organizzazioni forniscono API pubbliche per accedere ai dati, ad esempio l'API X o l'API NY Times. Potresti riuscire a sfruttare queste API per il problema che stai cercando di risolvere.
Di seguito sono riportati alcuni aspetti importanti da ricordare durante la raccolta dei dati:
- Se utilizzi un'API pubblica, esamina le limitazioni dell'API prima di utilizzarla. Ad esempio, alcune API impostano un limite per la frequenza con cui è possibile eseguire query.
- Maggiore è il numero di esempi di addestramento (indicati come esempi nel resto di questa guida), meglio è. In questo modo il modello può essere generalizzato meglio.
- Assicurati che il numero di campioni per ogni classe o argomento non sia eccessivamente sbilanciato. Vale a dire che dovresti avere un numero comparabile di campioni in ogni classe.
- Assicurati che i campioni coprano adeguatamente lo spazio dei possibili input, non solo i casi comuni.
In questa guida, utilizzeremo il set di dati per le recensioni dei film Internet Movie Database (IMDb) per illustrare il flusso di lavoro. Questo set di dati contiene le recensioni dei film pubblicate dagli utenti sul sito web di IMDb, nonché le etichette corrispondenti ("positiva" o "negativa") che indicano se il film è piaciuto o meno al recensore. Questo è un classico esempio di problema di analisi del sentiment.
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-07-27 UTC.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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."]]