How to perform one hot encoding using TF learn

This recipe helps you perform one hot encoding using TF learn

Recipe Objective

This recipe explains how to perform one hot encoding in TFLayer.

Learn How to Build a Multi Class Text Classification Model using BERT

One Hot Encoding

Its syntax is: tflearn.layers.core.one_hot_encoding (target, n_classes, on_value=1.0, off_value=0.0, name='OneHotEncoding')
where its arguments are target which is the labels placeholder, n_classes which is total number of classes, on_value which is a scalar defining the on-value, off_value which is a scalar defining the off-value and, name which is a name for this layer (optional).
One Hot Encoding transform numeric labels into a binary vector.

def One_Hot_Encoding(t, n, on=1.0, off=0.0, Name="OneHotEncoding"):

    with tf.name_scope(Name):
      if t.dtype != dtypes.int64:
          t = standard_ops.to_int64(t)

       t = standard_ops.one_hot(t, n, on_value=on, off_value=off)

    tf.add_to_collection(tf.GraphKeys.LAYER_TENSOR + '/' + Name, t)

    return t

What Users are saying..

profile image

Jingwei Li

Graduate Research assistance at Stony Brook University
linkedin profile url

ProjectPro is an awesome platform that helps me learn much hands-on industrial experience with a step-by-step walkthrough of projects. There are two primary paths to learn: Data Science and Big Data.... Read More

Relevant Projects

Build Regression (Linear,Ridge,Lasso) Models in NumPy Python
In this machine learning regression project, you will learn to build NumPy Regression Models (Linear Regression, Ridge Regression, Lasso Regression) from Scratch.

Detectron2 Object Detection and Segmentation Example Python
Object Detection using Detectron2 - Build a Dectectron2 model to detect the zones and inhibitions in antibiogram images.

Build a Review Classification Model using Gated Recurrent Unit
In this Machine Learning project, you will build a classification model in python to classify the reviews of an app on a scale of 1 to 5 using Gated Recurrent Unit.

Build a Face Recognition System in Python using FaceNet
In this deep learning project, you will build your own face recognition system in Python using OpenCV and FaceNet by extracting features from an image of a person's face.

Ecommerce product reviews - Pairwise ranking and sentiment analysis
This project analyzes a dataset containing ecommerce product reviews. The goal is to use machine learning models to perform sentiment analysis on product reviews and rank them based on relevance. Reviews play a key role in product recommendation systems.

MLOps AWS Project on Topic Modeling using Gunicorn Flask
In this project we will see the end-to-end machine learning development process to design, build and manage reproducible, testable, and evolvable machine learning models by using AWS

MLOps Project on GCP using Kubeflow for Model Deployment
MLOps using Kubeflow on GCP - Build and deploy a deep learning model on Google Cloud Platform using Kubeflow pipelines in Python

Deep Learning Project for Beginners with Source Code Part 1
Learn to implement deep neural networks in Python .

Learn Hyperparameter Tuning for Neural Networks with PyTorch
In this Deep Learning Project, you will learn how to optimally tune the hyperparameters (learning rate, epochs, dropout, early stopping) of a neural network model in PyTorch to improve model performance.

Time Series Classification Project for Elevator Failure Prediction
In this Time Series Project, you will predict the failure of elevators using IoT sensor data as a time series classification machine learning problem.