You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: site/it/README.md
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,8 @@ To volunteer to write or review community translations, contact the
20
20
21
21
Alcune parole fanno parte di un vocabolario tecnico inglese e pertanto non hanno una traduzione naturale. Per favore *non* traducete le seguenti parole:
" <a target=\"_blank\" href=\"https://www.tensorflow.org/tutorials/customization/autodiff\"><img src=\"https://www.tensorflow.org/images/tf_logo_32px.png\" />Visualizza su TensorFlow.org</a>\n",
73
+
" </td>\n",
74
+
" <td>\n",
75
+
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/docs/blob/master/site/it/tutorials/customization/autodiff.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Esegui in Google Colab</a>\n",
76
+
" </td>\n",
77
+
" <td>\n",
78
+
" <a target=\"_blank\" href=\"https://github.com/tensorflow/docs/blob/master/site/it/tutorials/customization/autodiff.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />Visualizza il sorgente su GitHub</a>\n",
79
+
" </td>\n",
80
+
" <td>\n",
81
+
" <a href=\"https://storage.googleapis.com/tensorflow_docs/docs/site/it/tutorials/customization/autodiff.ipynb\"><img src=\"https://www.tensorflow.org/images/download_logo_32px.png\" />Scarica il notebook</a>\n",
82
+
" </td>\n",
83
+
"</table>"
84
+
]
85
+
},
86
+
{
87
+
"cell_type": "markdown",
88
+
"metadata": {
89
+
"id": "gw8qUkhemiPf",
90
+
"colab_type": "text"
91
+
},
92
+
"source": [
93
+
"Note: La nostra comunità di Tensorflow ha tradotto questi documenti. Poichè questa traduzioni della comunità sono *best-effort*, non c'è garanzia che questa sia un riflesso preciso e aggiornato della [documentazione ufficiale in inglese](https://www.tensorflow.org/?hl=en).\n",
94
+
"Se avete suggerimenti per migliorare questa traduzione, mandate per favore una pull request al repository Github [tensorflow/docs](https://github.com/tensorflow/docs).\n",
95
+
"Per proporsi come volontari alla scrittura o alla review delle traduzioni della comunità contattate la [mailing list docs@tensorflow.org](https://groups.google.com/a/tensorflow.org/forum/#!forum/docs)."
96
+
]
97
+
},
98
+
{
99
+
"cell_type": "markdown",
100
+
"metadata": {
101
+
"colab_type": "text",
102
+
"id": "vDJ4XzMqodTy"
103
+
},
104
+
"source": [
105
+
"Nel tutorial precedente abbiamo introdotto i `Tensori` e le loro operazioni. In questo tutorial copriremo la [differenziazione automatica](https://en.wikipedia.org/wiki/Automatic_differentiation), una tecnica importante per ottimizare i modelli di machine learning."
"TensorFlow fornisce l'API [tf.GradientTape](https://www.tensorflow.org/api_docs/python/tf/GradientTape) per la differenziazione automatica che calcola il gradiente di una computazione rispetto alle sue variabili in input. Tensorflow \"registra\" tutte le operazioni eseguite dentro il contesto di un `tf.GradientTape` su un \"tape\". Tensorflow quindi usa quel \"tape\" e i gradienti associati con ogni operazione registrata per calcolare il gradiente di una computazione \"registrata\" utilizzando l'[accumulazione inversa](https://en.wikipedia.org/wiki/Automatic_differentiation).\n",
148
+
"\n",
149
+
"Per esempio:"
150
+
]
151
+
},
152
+
{
153
+
"cell_type": "code",
154
+
"metadata": {
155
+
"colab_type": "code",
156
+
"id": "bAFeIE8EuVIq",
157
+
"colab": {}
158
+
},
159
+
"source": [
160
+
"x = tf.ones((2, 2))\n",
161
+
"\n",
162
+
"with tf.GradientTape() as t:\n",
163
+
" t.watch(x)\n",
164
+
" y = tf.reduce_sum(x)\n",
165
+
" z = tf.multiply(y, y)\n",
166
+
"\n",
167
+
"# Derivative of z with respect to the original input tensor x\n",
168
+
"dz_dx = t.gradient(z, x)\n",
169
+
"for i in [0, 1]:\n",
170
+
" for j in [0, 1]:\n",
171
+
" assert dz_dx[i][j].numpy() == 8.0"
172
+
],
173
+
"execution_count": 0,
174
+
"outputs": []
175
+
},
176
+
{
177
+
"cell_type": "markdown",
178
+
"metadata": {
179
+
"colab_type": "text",
180
+
"id": "N4VlqKFzzGaC"
181
+
},
182
+
"source": [
183
+
"Puoi anche richiedere i gradienti dell'output rispetto ai valori intermedi calcolati in un contesto \"registrato\" di `tf.GradientTape`."
184
+
]
185
+
},
186
+
{
187
+
"cell_type": "code",
188
+
"metadata": {
189
+
"colab_type": "code",
190
+
"id": "7XaPRAwUyYms",
191
+
"colab": {}
192
+
},
193
+
"source": [
194
+
"x = tf.ones((2, 2))\n",
195
+
"\n",
196
+
"with tf.GradientTape() as t:\n",
197
+
" t.watch(x)\n",
198
+
" y = tf.reduce_sum(x)\n",
199
+
" z = tf.multiply(y, y)\n",
200
+
"\n",
201
+
"# Use the tape to compute the derivative of z with respect to the\n",
202
+
"# intermediate value y.\n",
203
+
"dz_dy = t.gradient(z, y)\n",
204
+
"assert dz_dy.numpy() == 8.0"
205
+
],
206
+
"execution_count": 0,
207
+
"outputs": []
208
+
},
209
+
{
210
+
"cell_type": "markdown",
211
+
"metadata": {
212
+
"colab_type": "text",
213
+
"id": "ISkXuY7YzIcS"
214
+
},
215
+
"source": [
216
+
"Di default, le risorse tenute da un GradientTape sono rilasciate non appena il metodo GradientTape.gradient() è chiamato. Per calcolare multipli gradienti sullo stesso calcolo, crea un `persistent` gradient tape. Questo da la possibilità di fare chiamate multiple del metodo `gradient()` non appena le risorse sono rilasciate quando l'oggetto tape è liberato dal garbage collector. Per esempio:"
217
+
]
218
+
},
219
+
{
220
+
"cell_type": "code",
221
+
"metadata": {
222
+
"colab_type": "code",
223
+
"id": "zZaCm3-9zVCi",
224
+
"colab": {}
225
+
},
226
+
"source": [
227
+
"x = tf.constant(3.0)\n",
228
+
"with tf.GradientTape(persistent=True) as t:\n",
229
+
" t.watch(x)\n",
230
+
" y = x * x\n",
231
+
" z = y * y\n",
232
+
"dz_dx = t.gradient(z, x) # 108.0 (4*x^3 at x = 3)\n",
233
+
"dy_dx = t.gradient(y, x) # 6.0\n",
234
+
"del t # Drop the reference to the tape"
235
+
],
236
+
"execution_count": 0,
237
+
"outputs": []
238
+
},
239
+
{
240
+
"cell_type": "markdown",
241
+
"metadata": {
242
+
"colab_type": "text",
243
+
"id": "6kADybtQzYj4"
244
+
},
245
+
"source": [
246
+
"### Flusso di controllo della registrazione\n",
247
+
"\n",
248
+
"Poichè i \"tape\" registrano operazione nel momento in cui le eseugono, il flusso di controllo Python (usando `if` e `while` per esempio) è gestito naturalmente:"
249
+
]
250
+
},
251
+
{
252
+
"cell_type": "code",
253
+
"metadata": {
254
+
"colab_type": "code",
255
+
"id": "9FViq92UX7P8",
256
+
"colab": {}
257
+
},
258
+
"source": [
259
+
"def f(x, y):\n",
260
+
" output = 1.0\n",
261
+
" for i in range(y):\n",
262
+
" if i > 1 and i < 5:\n",
263
+
" output = tf.multiply(output, x)\n",
264
+
" return output\n",
265
+
"\n",
266
+
"def grad(x, y):\n",
267
+
" with tf.GradientTape() as t:\n",
268
+
" t.watch(x)\n",
269
+
" out = f(x, y)\n",
270
+
" return t.gradient(out, x)\n",
271
+
"\n",
272
+
"x = tf.convert_to_tensor(2.0)\n",
273
+
"\n",
274
+
"assert grad(x, 6).numpy() == 12.0\n",
275
+
"assert grad(x, 5).numpy() == 12.0\n",
276
+
"assert grad(x, 4).numpy() == 4.0\n"
277
+
],
278
+
"execution_count": 0,
279
+
"outputs": []
280
+
},
281
+
{
282
+
"cell_type": "markdown",
283
+
"metadata": {
284
+
"colab_type": "text",
285
+
"id": "DK05KXrAAld3"
286
+
},
287
+
"source": [
288
+
"### Gradienti di ordine superiore\n",
289
+
"\n",
290
+
"Le operazioni dentro il gestore di contesto di `GradientTape` sono registrati per la differenziazione automatica. Se i gradienti sono calcolati nello stesso contesto, allora anche il calcolo del gradiente è registrato. Come risultato, la stessa API funziona per gradienti di ordine superiore. Per esempio:"
291
+
]
292
+
},
293
+
{
294
+
"cell_type": "code",
295
+
"metadata": {
296
+
"colab_type": "code",
297
+
"id": "cPQgthZ7ugRJ",
298
+
"colab": {}
299
+
},
300
+
"source": [
301
+
"x = tf.Variable(1.0) # Create a Tensorflow variable initialized to 1.0\n",
302
+
"\n",
303
+
"with tf.GradientTape() as t:\n",
304
+
" with tf.GradientTape() as t2:\n",
305
+
" y = x * x * x\n",
306
+
" # Compute the gradient inside the 't' context manager\n",
307
+
" # which means the gradient computation is differentiable as well.\n",
308
+
" dy_dx = t2.gradient(y, x)\n",
309
+
"d2y_dx2 = t.gradient(dy_dx, x)\n",
310
+
"\n",
311
+
"assert dy_dx.numpy() == 3.0\n",
312
+
"assert d2y_dx2.numpy() == 6.0"
313
+
],
314
+
"execution_count": 0,
315
+
"outputs": []
316
+
},
317
+
{
318
+
"cell_type": "markdown",
319
+
"metadata": {
320
+
"colab_type": "text",
321
+
"id": "4U1KKzUpNl58"
322
+
},
323
+
"source": [
324
+
"## Passi successivi\n",
325
+
"\n",
326
+
"In questo tutorial abbiamo coperto il calcolo di gradienti in TensorFlow. Con questo abbiamo abbastanza primitive richieste per costruire e addestrare reti neurali."
0 commit comments