Reti neurali: addestramento usando la retropropagazione dell'errore
Mantieni tutto organizzato con le raccolte Salva e classifica i contenuti in base alle tue preferenze.
La retropropagazione è l'algoritmo di addestramento più comune per le reti neurali. Rende fattibile la discesa del gradiente per le reti neurali multistrato. Molte librerie di codice di machine learning (come Keras) gestiscono automaticamente la retropropagazione, quindi non devi eseguire personalmente i calcoli sottostanti. Guarda il seguente video per una panoramica concettuale del funzionamento della retropropagazione:
Best practice per l'addestramento delle reti neurali
Questa sezione spiega i casi di errore della retropropagazione dell'errore e il modo più comune per regolarizzare una rete neurale.
Gradienti che svaniscono
I gradienti per i livelli della rete neurale inferiori (quelli più vicini al livello di input) possono diventare molto piccoli. Nelle reti profonde (reti con più di un livello nascosto), il calcolo di questi gradienti può comportare il prodotto di molti termini piccoli.
Quando i valori del gradiente si avvicinano a 0 per i livelli inferiori, si dice che i gradienti "svaniscono". I livelli con gradienti che svaniscono vengono addestrati molto lentamente o non vengono addestrati affatto.
La funzione di attivazione ReLU può contribuire a evitare i gradienti che svaniscono.
Gradienti esplosivi
Se i pesi di una rete sono molto grandi, i gradienti per i livelli inferiori coinvolgono i prodotti di molti termini grandi. In questo caso, puoi avere gradienti in crescita esponenziale, ovvero gradienti che diventano troppo grandi per convergere.
La normalizzazione batch può contribuire a evitare l'esplosione dei gradienti, così come la riduzione del tasso di apprendimento.
Unità ReLU morte
Quando la somma ponderata per un'unità ReLU scende al di sotto di 0, l'unità ReLU può bloccarsi. Restituisce 0, non contribuisce all'output della rete e i gradienti non possono più attraversarlo durante la retropropagazione. Con una sorgente di gradienti tagliata, l'input della ReLU potrebbe non cambiare abbastanza per riportare la somma ponderata al di sopra di 0.
La riduzione del tasso di apprendimento può contribuire a evitare che le unità ReLU si esauriscano.
Regolarizzazione del dropout
Un'altra forma di regolarizzazione, chiamata regolarizzazione con dropout, è utile per le reti neurali. Funziona "ritirando" casualmente le attivazioni delle unità in una rete per un singolo passo del gradiente. Quanto più si esclude tanto più forte è la regolarizzazione:
0,0 = nessuna regolarizzazione del dropout.
1,0 = elimina tutti i nodi. Il modello non impara nulla.
[[["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 2024-11-08 UTC."],[[["\u003cp\u003eBackpropagation is the primary training algorithm for neural networks, enabling gradient descent for multi-layer networks and often handled automatically by machine learning libraries.\u003c/p\u003e\n"],["\u003cp\u003eVanishing gradients occur when gradients in lower layers become very small, hindering their training, and can be mitigated by using ReLU activation function.\u003c/p\u003e\n"],["\u003cp\u003eExploding gradients happen when large weights cause excessively large gradients, disrupting convergence, and can be addressed with batch normalization or lowering the learning rate.\u003c/p\u003e\n"],["\u003cp\u003eDead ReLU units emerge when a ReLU unit's output gets stuck at 0, halting gradient flow, and can be avoided by lowering the learning rate or using ReLU variants like LeakyReLU.\u003c/p\u003e\n"],["\u003cp\u003eDropout regularization is a technique to prevent overfitting by randomly dropping unit activations during training, with higher dropout rates indicating stronger regularization.\u003c/p\u003e\n"]]],[],null,["[**Backpropagation**](/machine-learning/glossary#backpropagation) is the\nmost common training algorithm for neural networks.\nIt makes gradient descent feasible for multi-layer neural networks.\nMany machine learning code libraries (such as [Keras](https://keras.io/))\nhandle backpropagation automatically, so you don't need to perform any of\nthe underlying calculations yourself. Check out the following video for a\nconceptual overview of how backpropagation works: \n| To learn more about building image models, check out the [Image\n| Classification](/machine-learning/practica/image-classification) course.\n\nBest practices for neural network training\n\nThis section explains backpropagation's failure cases and the most\ncommon way to regularize a neural network.\n| **NOTE:** The backpropagation training algorithm makes use of the calculus concept of a [gradient](https://wikipedia.org/wiki/Gradient) to adjust model weights to minimize loss. Understanding and debugging the issues below usually requires some background in calculus.\n\nVanishing Gradients\n\nThe [**gradients**](/machine-learning/glossary#gradient) for the lower neural\nnetwork layers (those closer to the input layer) can become very small.\nIn [**deep networks**](/machine-learning/glossary#deep-model) (networks with\nmore than one hidden layer), computing these gradients can involve taking the\nproduct of many small terms.\n\nWhen the gradient values approach 0 for the lower layers, the gradients are\nsaid to \"vanish\". Layers with vanishing gradients train very slowly, or not\nat all.\n\nThe ReLU activation function can help prevent vanishing gradients.\n\nExploding Gradients\n\nIf the weights in a network are very large, then the gradients for the lower\nlayers involve products of many large terms. In this case you can have\nexploding gradients: gradients that get too large to converge.\n\nBatch normalization can help prevent exploding gradients, as can lowering the\nlearning rate.\n\nDead ReLU Units\n\nOnce the weighted sum for a ReLU unit falls below 0, the ReLU unit can get\nstuck. It outputs 0, contributing nothing to the network's output,\nand gradients can no longer flow through it during backpropagation. With a\nsource of gradients cut off, the input to the ReLU may not ever change enough\nto bring the weighted sum back above 0.\n\nLowering the learning rate can help keep ReLU units from dying.\n| There are also many variants of ReLU that were designed to address this specific problem, such as [LeakyReLU](https://keras.io/api/layers/activation_layers/leaky_relu/), which you may want to consider using as an activation function to prevent dead ReLU units.\n\nDropout Regularization\n\nYet another form of regularization, called\n[**dropout regularization**](/machine-learning/glossary#dropout_regularization),\nis useful for neural networks. It works by randomly \"dropping out\"\nunit activations in a network for a single gradient step.\nThe more you drop out, the stronger the regularization:\n\n- 0.0 = No dropout regularization.\n- 1.0 = Drop out all nodes. The model learns nothing.\n- Values between 0.0 and 1.0 = More useful.\n\n| **Key terms:**\n|\n| - [Backpropagation](/machine-learning/glossary#backpropagation)\n| - [Dropout regularization](/machine-learning/glossary#dropout_regularization)\n| - [Exploding gradient problem](/machine-learning/glossary#exploding-gradient-problem)\n- [Vanishing gradient problem](/machine-learning/glossary#vanishing-gradient-problem) \n[Help Center](https://support.google.com/machinelearningeducation)"]]