Create a hotel customer reviews classification with Azure
Tags: azure, python, machinelearning
Published: 2020-01-07 07:59:26

---
title: Create a hotel customer reviews classification with Azure
published: true
description: Creating a Hotel Customer Reviews Classification with Azure Cognitive Services 
tags: azure, python, machinelearning
cover_image: https://www.idiwork.com/wp-content/uploads/102-fondo-2.jpg
---

### About 

The Experiment #102 researches about the possibilities of applying Cognitive Services and Deep Learning to understand and manage a huge amount of information from human interactions without the human intervention. We will discover if the Artificial Intelligence is capable of collect all this raw data, classify it and manage all the different situations.

## Idea

The project tries to simulate an automatic classification of comments or reviews in a business environment. Any company wants to identify critical requests as soon as possible to try to solve it before them become a big problem, regardless of the number of messages that arrive, or the language in which them were wrote, or the time that them were sent.

## Utility

For this simulation it is been chosen the case of an hotel. We will imagine that the customers have access to a mobile application in which they can leave their comments, complaints and suggestions. They can use images to illustrate their point of view or location and text messages to explain it. Due to content, the reviews will be classified as good, neutral or bad.

In this case we want to classify each comment and identify the bad, urgent and important ones to manage them quickly and, if it were necessary, report to a different human agent depends of the location (room, bar, restaurant, swimming pool, etc), who will can solve it properly.

## Process

First, we are going to create an [Azure Notebooks](https://notebooks.azure.com) project where we can set up a Notebook server. Then we will create and upload some files based on Python to deploy a Text Summarization service in an [Azure Machine Learning Workspace](https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-manage-workspace). After that, we will construct and train a simple deep neural network classification model, with [Keras](https://keras.io/models/model/) and Tensorflow, that will classify the hotel customers reviews.

Also, we will perform the integration with the [Azure Cognitive Services](https://azure.microsoft.com/en-us/services/cognitive-services/computer-vision/) along with the Azure Machine Learning. We will use Computer Vision API to collect information from pictures or photographs and Text Analytics API to extract data from human utterances.

## Advantages

The principal advantage of using Cognitive Services and Deep Learning in this case is the possibility of identifying very quickly the reviews or comments that needs to be carefully manage by a human been because of its importance or its urgency.

Even if tons and tons of messages arrive, we can be sure that the most critical messages will be identified and treated immediately and the rest of them will be classified and stored correctly.

This way a company will save money and resources and will be very much efficient attending customers’ requests.

## Architecture

![](https://www.idiwork.com/wp-content/uploads/PoC_ML_Architecture_Diagram_A-1.png)
 
We tried to simulate hotel customer inputs from different sources (01) like Social Media, this hotel reviews (02) will be send to an Artificial Intelligent for its analysis.

We used [Azure Notebooks](https://notebooks.azure.com/) with [Jupyter](https://jupyter.readthedocs.io/en/latest/index.html) to create, train and deploy the services we need. Ones of them are Containerized Services (03) we trained with Deep Learning like the Summarize Service (05) and the Classification Service (06). Others are Cognitive Services (04) we used directly from Microsoft like Computer Vision (07) and Text Analytics (08).

If you want to read more go to [this post](https://www.idiwork.com/experiment-102-architectural-diagram/).

## Step by Step

### 1. How to create an Azure Notebooks project

First, we can access this Azure Notebooks Service by visiting [https://notebooks.azure.com/](https://notebooks.azure.com/) and then, we can create a new [Azure Notebooks Project](https://notebooks.azure.com/home/projects) from “My Projects”.
 
![](https://www.idiwork.com/wp-content/uploads/StepByStep_01_01_project.gif)
 
If you want to see the whole process just go to [this post](https://www.idiwork.com/experiment-102-how-to-create-an-azure-notebooks-project-and-deploy-a-summarization-service/).

### 2. How to construct a Deep Neural Network

Keras is a Python library that allows us to construct Deep Learning models. First, we must import all needed modules and download the text analytics files from our GitHub repository. The cells of the “.ipynb” script look like this:

```py
import re
import nltk
import uuid
import os
import numpy as np
import pandas as pd
import tensorflow as tf
import keras
from keras import models, layers, optimizers, regularizers
from keras.models import Sequential
from keras.layers import Dense, Activation
from keras.utils import to_categorical

import urllib.request
data_location = './data'
base_data_url = 'https://raw.githubusercontent.com/idiWork/Experiment_102/master/resources/'
filesToDownload = ['reviews_labels.txt', 'reviews_texts.txt', 'contractions.py', 'textanalytics.py']

os.makedirs(data_location, exist_ok=True)

for file in filesToDownload:
    data_url = os.path.join(base_data_url, file)
    local_file_path = os.path.join(data_location, file)
    urllib.request.urlretrieve(data_url, local_file_path)

nltk.download('stopwords') 
nltk.download('punkt')

import sys
sys.path.append(data_location)
import textanalytics as ta
```

If you want to see the whole process just go to [this post](https://www.idiwork.com/experiment-102-how-to-construct-and-train-a-deep-neural-network-using-keras-and-deploy-the-model-as-an-azure-web-service/). 

### 3. How to deploy Azure Cognitive Services

[Computer Vision](https://azure.microsoft.com/en-us/services/cognitive-services/computer-vision/) is an [Azure Cognitive Service](https://azure.microsoft.com/en-us/services/cognitive-services/) that allow us to get information from an image. It analyzes the image environment, detects objects inside them and classifies all of them by assigning tags and labels. We can find this resource in our Azure Portal under the “AI + Machine Learning” group:
 
![](https://www.idiwork.com/wp-content/uploads/Exp102_StepByStep_03_01.gif)
 
After deploying the service, we must look and write down at the subscription key and the endpoint to integrate the service in our project.

If you want to see the whole process just go to [this post](https://www.idiwork.com/experiment-102-how-to-deploy-and-integrate-azure-cognitive-services-computer-vision-and-text-analytics/).

### 4. How to use Microsoft Flow to send alerts

We have created a very simple C# console project to simulate the reception of hotel reviews. The program makes HTTP requests to the different services we have previously deployed to collect all the information from the image and text of the review. These services include containerized services like Summarize or Classification and Cognitive Services like Computer Vision or Text Analytics.

All review data will be stored in a SQL database. This is the database definition:

```sql
CREATE TABLE [dbo].[review](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [text] [nvarchar](MAX) NULL,
    [class] [nvarchar](64) NULL,
    [sentiment] [nvarchar](64) NULL,
    [summary] [nvarchar](2048) NULL,
    [keys] [nvarchar](1024) NULL,
    [image] [nvarchar](1024) NULL,
    [captions] [nvarchar](1024) NULL,
    [categories] [nvarchar](1024) NULL,
    [tags] [nvarchar](1024) NULL,
    CONSTRAINT [PK_review] PRIMARY KEY ([id])
```

If you want to see the whole process just go to [this post](https://www.idiwork.com/experiment-102-how-to-use-microsoft-flow-to-send-an-email-when-an-event-occurs/).

To keep reading about these topics, check out the following links:

## Links

[Azure Logic Apps](https://azure.microsoft.com/en-us/services/logic-apps/)