<jupyter_start><jupyter_text><jupyter_code>import tensorflow as tf
import numpy as np
celsius = np.array([-40, -10, 0, 8, 15, 22, 38], dtype=float)
fahrenheit = np.array([-40, 14, 32, 46, 59, 72, 100], dtype=float)
#capa = tf.keras.layers.Dense(units=1, input_shape=[1])
#modelo = tf.keras.Sequential([capa])

oculta1 = tf.keras.layers.Dense(units=3, input_shape=[1])
oculta2 = tf.keras.layers.Dense(units=3)
salida = tf.keras.layers.Dense(units=1)
modelo = tf.keras.Sequential([oculta1, oculta2, salida])
modelo.compile(
    optimizer=tf.keras.optimizers.Adam(0.1),
    loss='mean_squared_error'
)
print("Comenzando entrenamiento...")
historial = modelo.fit(celsius, fahrenheit, epochs=1000, verbose=False)
print("Modelo entrenado!")
import matplotlib.pyplot as plt
plt.xlabel("# Epoca")
plt.ylabel("Magnitud de pérdida")
plt.plot(historial.history["loss"])
print("Hagamos una predicción!")
resultado = modelo.predict([100.0])
print("El resultado es " + str(resultado) + " fahrenheit!")
print("Variables internas del modelo")
#print(capa.get_weights())
print(oculta1.get_weights())
print(oculta2.get_weights())
print(salida.get_weights())<jupyter_output>Variables internas del modelo
[array([[-0.12656637,  0.16839124,  0.64072496]], dtype=float32), array([-3.5936892, -2.8317325,  3.670085 ], dtype=float32)]
[array([[ 1.0084509 , -0.74428594, -0.25117674],
       [ 0.76018834, -0.18859847,  0.02053964],
       [-0.9731696 , -0.84853524,  1.1058627 ]], dtype=float32), array([-3.707025 , -3.499454 ,  3.7327554], dtype=float32)]
[array([[-1.4682018 ],
       [-0.48383546],
       [ 0.87413716]], dtype=float32), array([3.588331], dtype=float32)]
{'fraction_non_alphanumeric': 0.18484848484848485, 'fraction_numerical': 0.1478787878787879, 'mean_word_length': 5.44921875, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '415150', 'license': 'MIT', 'n_tokens_mistral': 816, 'n_tokens_neox': 675, 'n_words': 114, 'path': 'red neuronal en Python y Tensorflow.ipynb', 'repo_name': '8bitcodeblue/Championify', 'size': '1650'}