Skip to main content

Posts

Showing posts with the label deep learning

Embedding Layers in Keras and TensorFlow: A Comprehensive Guide with Code Examples and Sample Data

Embedding layers are a crucial component of deep learning models, especially for tasks involving text or categorical data. They convert sparse, high-dimensional data into dense, low-dimensional vectors, capturing the semantic relationships and reducing the computational complexity of the model. In this blog post, we will delve into the details of embedding layers in Keras and TensorFlow, providing code examples and sample data to illustrate their usage. What are Embedding Layers? Embedding layers are a type of neural network layer that maps discrete values (such as words or categories) to continuous vector representations. These vectors encode the semantic meaning and relationships between the input values, allowing the model to learn patterns and make predictions based on the input data. Implementation in Keras and TensorFlow Keras: from keras.layers import Embedding # Create an embedding layer with 10000 words and 128-dimensional vectors embedding_layer = Embedding(input_d...

Tensorflow Keras Freeze Layers / Unfreeze Layers (Python Example)

Tensorflow keras freeze / unfreeze a specific layer or multiple layers based on layer name. Freezing a layer retains current weights of a layer and does not alter when the model is trained / during model fitting. Simply put the the frozen layers are not trainable. Freezing layer is a technique predominantly used for transfer learning and fine-tuning.These are cases in which we wish to retain layer weights; as this could be an already trained model like resnet , mobilenet,etc. Or we just want to train only certain layers in the current model and not the whole model- we can freeze and unfreeze layers according to our needs and then start the fitting processing. Creating a new tensorflow model using functional api - execute the given code to generate the following model. Generated model is stored in a variable called "model". # viewing the model info # pass "show_trainable=True" # to see whether a layer is trainable model.summary(show_trainable=True) Model: ...

Tensorflow Keras Create Model Using Functional API - Single Output Regression With Multiple Dense Layers (Python Example)

Trying out tensorflow by creating simple neural network models is a good starting point to understand and to get used to various features of tensorflow and its api. Keras is used here - which sits on top of tensorflow and provides a good api layer with really good documentation.  Functional API will be demonstrated; instead of sequential API. Functional API offers more control over the model architecture, also allows creation of multi-output models, flexibility and much more. Create regression output model using Tensorflow Keras (functional api) Importing tensorflow # importing tensorflow import tensorflow as tf from tensorflow.keras.models import Model from tensorflow.keras.layers import Dense, Input Defining a function to create dense layers for convenience. Functions like these will help with creating complex layers structure and reduce confusion. # function to create dense layers def dense_layer_creator(units, name_for_layer, last_layer, activation=""): if...

Topics

Show more