Eco-Friendly AI Code Snippet: Resource-aware Neural Network
import numpy as np
from tensorflow.keras.models import Model
def sustainable_model(x_train, x_val):
input_layer = keras.Input(shape=(x_train.shape[1],))
model = Sequential([Dense(x_train.shape[1]//4, activation='relu', input_shape=(x_train.shape[1],))])
model.compile(loss='mean_squared_error', optimizer='adam')
return Model(inputs=input_layer, outputs=model)
This code snippet defines a simple neural network model that incorporates sustainability into its design.
Here's what it does:
- It takes into consideration computational resource usage, a major concern for energy-intensive AI models.
- The input layer size is reduced using a technique called dimensionality reduction, using
x_train.shape[1]//4instead of the full size. This reduces the computational load while preserving the model's performance to some extent. - Optimizer 'adam' is used to ensure fast and efficient model convergence.
- It compiles the model with a focus on resource efficiency during training.
- The model can then be trained and validated on smaller input datasets.
This snippet showcases a key concept in sustainable AI: designing models that are energy-efficient and computationally light.
Publicado automáticamente
Top comments (0)