Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

397
Vistas
How to extract bias weights in Keras sequential model?

I'm running a simple feed-forward network using Keras . Having just one hidden layer I would like to make some inference regarding the relevance of each input to each output and I would like to extract the weights.

This is the model:

def build_model(input_dim, output_dim):
    n_output_layer_1 = 150
    n_output = output_dim
    model = Sequential()
    model.add(Dense(n_output_layer_1, input_dim=input_dim, activation='relu'))
    model.add(Dropout(0.25))
    model.add(Dense(n_output))

To extract the weight I wrote:

for layer in model.layers:
    weights = layer.get_weights() 


weights = np.array(weights[0])     #this is hidden to output
first = model.layers[0].get_weights() #input to hidden
first = np.array(first[0])

Unfortunately I don't get the biases columns in the matrices, which I know Keras automatically puts in it.

Do you know how to retrieve the biases weights?

Thank you in advance for your help !

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

get_weights() for a Dense layer returns a list of two elements, the first element contains the weights, and the second element contains the biases. So you can simply do:

weights = model.layers[0].get_weights()[0]
biases = model.layers[0].get_weights()[1]

Note that weights and biases are already numpy arrays.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda