top of page

Automation of customer-care tickets resolution using NLP

When we call customer care, they keep on connecting with different department like technical department, billing department etc. What if they suggest some quick fixes even though they are not expert in providing solution.

Keeping this in mind, lets build a simple solution recommendation system for internet service providers based on cosine similarity of earlier questions with the present question. Higher the similarity, solution might be same. Assumption is questions with similar title, content will have similar solution.

Following steps would be required to implement solution in Python 3.0+-

1) load nlp libraries.

2) create dummy data with some questions and answers.

3) create a function that calculates cosine similarity of new ticket with all existing ticket titles.

4) show the solution/answer of the ticket that has maximum similarity with present ticket.

Step 1 - import required libraries-

import pandas as pd   
import nltk
from nltk.corpus import stopwords   
from nltk.tokenize import word_tokenize'punkt') # this is tokenizer that converts words in to tokens'stopwords') # all the stop words like verbs, prepositions etc. 

Step 2 -create a dummy dataset-

question_ans_data= pd.DataFrame()

question_ans_data['question']= ['there is no internet','no ineternet since last 2 days','net speed is slow','wrong bill','too much charge']

question_ans_data['answer']= ['restart router, check if lights blinking','technician will be sent, check lights, restart router','technician will be sent','will get back to you','will get back to you'] 

have a look at data-

Step 3- create a function ( set_con) to do text pre-processing and calculate cosine similarity between 2 strings-

def set_con(X, Y):
    X_list = word_tokenize(X)  
    Y_list = word_tokenize(Y) # convert string into word tokens
    sw = stopwords.words('english')  
    l1 =[];l2 =[]
    X_set = {w for w in X_list if not w in sw} # remove stop words
    Y_set = {w for w in Y_list if not w in sw}
    rvector = X_set.union(Y_set)  

# form a set containing keywords of both strings as pre-process step to calculate cosine similarity ( can be calculated from sklearn.matrics also)

    for w in rvector: 
        if w in X_set: l1.append(1) # create a vector 
        else: l1.append(0) 
        if w in Y_set: l2.append(1) 
        else: l2.append(0) 
    c = 0

# cosine formula

    for i in range(len(rvector)): 
            c+= l1[i]*l2[i] 
    cosine = c / float((sum(l1)*sum(l2))**0.5) 

Step 4 create a subject/title of input ticket as a string-

input_ticket= 'broadband internet not working'  # input ticket

Step 5, find similar most similar ticket title/s with existing ticket-

question_ans_data['cosine_similiarity']= [set_con(x ,input_ticket) for x in question_ans_data['question']]  # calculating cosine similarity with existing tickets

sorted_main_df=question_ans_data.sort_values(by=['cosine_similiarity'], ascending=False)

output_dataset= sorted_main_df[sorted_main_df['cosine_similiarity'] == max(sorted_main_df['cosine_similiarity'])]   # most similar tickets based on similarity of questions


So if the question is ' there is no internet', solution might be to restart router, check light . Given a large data-set with many tickets and possible solution, this can provide great help for customer care executives.

product recommendation approach in retail industry-

9 views0 comments


bottom of page