[Tensorflow+natural language processing+LSTM] Practice of building an intelligent chat customer service robot
AD |
Need source code and dataset,please like and follow the comments section after favorites,leave a message,private message~~~Natural language processing technology is the foundation of intelligent customer service application. In the process of natural language processing,word segmentation is the first step
Need source code and dataset,please like and follow the comments section after favorites,leave a message,private message~~~
Natural language processing technology is the foundation of intelligent customer service application. In the process of natural language processing,word segmentation is the first step. This process is usually based on statistical theory. The refinement of word segmentation can improve the language processing ability of intelligent customer service. Statistical word segmentation and Markov model are common methods,but they are slightly inferior in the recognition accuracy of unusual words,and the accuracy directly affects the accuracy of word segmentation results,Diverse participles help identify formal irrationality
Natural language processing technology is an important link in intelligent customer service,and it is also a key factor that determines the quality of intelligent customer service applications and the efficiency of problem handling. To create intelligent customer service,the system usually conducts a lot of learning first to enrich the language knowledge base,and improves the system's processing ability by combining various typical cases. The intelligent customer service system focuses on three parts:
one: Knowledge base improvement
two: Service satisfaction
3: Self learning ability to handle unknown scenarios
Compared to traditional manual customer service,intelligent customer service applications generally have the following advantages
We can provide two4-hour uninterrupted online service.
Possess the ability to continuously learn independently.
Fast processing speed,high processing efficiency,
Can handle short-term high-capacity service requests.
Cost advantage.
The basic framework of the process from user questions to response output is shown in the following figure
Gensim
NLTK
SpaCy
TensorFlowTensorFlow is a dataflow programming based system,which is widely used in the implementation of graphics classification,audio processing,recommendation system,natural language processing and other scenarios. It provides four versions based on Python language: CPU version(tensorflow),GPU accelerated version(tensorflow gpu),and daily compiled version(tf slightly,tf slightly gpu)
Theano
Keras
Intelligent customer service systems rely on professional data and are closely related to artificial intelligence technologies such as natural processing and understanding. In the process of solving user business demands,it is inevitable to use user inquiries and unsolvable problems. Therefore,improving its emotional analysis ability and possessing multi-dimensional service capabilities is of great positive significance for improving overall customer satisfaction. Intelligent customer service,The relationship between manual customer service and users can be briefly summarized as shown in the following figure
The intelligent customer service processing process is shown in the following figure
We will use deep learning technology to build a chat robot and train it on a dataset containing chat intention categories,user input,and customer service responses. Based on the Recurrent Neural Network(LSTM)model to classify the category of user input messages,and then provide response outputs from the response list using arandomalgorithm. This instance ran successfully in the execution environments Tensorflow(two.6.0)and Python(3.6.5),with other required libraries being NLTK and Keras.
Introduction to Datasets and Models:
The required data and model description are as follows:
Chatbot.json: Predefined data files for message classification,input messages,and customer service responses.
Wordtoken.pkl: Pickle file that stores Python objects containing vocabulary lists.
Category.pkl: Pickle file,containing a list of message categories.
Model. h5: A trained model that includes information about the model and neuron weights.
This instance data is based on JSON(JavaScript Object Notation),which is a lightweight data exchange format that is completely language independent and easy for machines to parse and generate. JSON is built on two structures:
one)Name: A collection of values. In computer language,it is called object,record,structure,dictionary,hash table,keyed list or associative array.
twodata structure
The corpus is as follows
The training process is as follows
The customer service robot will provide corresponding answers when users input questions on the graphical interface
When the user raises a question outside of the corpus,customer service will display the following answer
The project structure is as follows
Some of the codes are as follows. All codes are required. Please click like and follow the comments section after bookmarking. Leave a private message in the comments section~~~
Test file
#Import Libraryimportnltkimportpickleaspkimportnumpyasnpimportjsonasjsimportrandomfromtensorflowimportkerasfromtensorflow.python.keras.modelsimportload_ modelfromnltk.stem importWordNetLemmatizerwordlem=WordNetLemmatizer()fromtkinterimport*fromtkinterimportTextfromtkinterimportButtonimport tkinternltk.download('punkt')nltk.download('wordnet')#Load training modelload =load_ model('data/model.h5')#Load data and intermediate resultschatbot =js.loads(open('data/chatbot.json').read())wordlist =pk.load(open('data/wordlist.pkl','rb'))category =pk.load(open('data/category.pkl','rb'))def tokenization(text): #Participle word_ tokens=nltk.word_tokenize(text) #Word Form Reduction #foriinsw: word_ tokens= [wordlem.lemmatize(i.lower())foriinword_ tokens]returnword_ tokens#Bag-of-words modeldef bow(text,wordlist): #Participle tokens = tokenization(text) bow = [0]*len(wordlist)fortokenintokens:fori,flaginenumerate(wordlist):ifflag==token:#If the search matches successfully,it is marked as onebow[i]=one print("Matching result of bag-of-words model model:% s" % flag) return(np.array(bow))#Prediction resultsdef predict(text,load): #Set a threshold to filter the content below the thresholderr_ level=zero point two zero outlist= []bow_outcome= bow(text,wordlist) result = load.predict(np.array([bow_outcome]))[0]#Sort based on probability resultsoutcome=[[i,j]fori,jin enumerate(result)ifj> err_ level]outcome.sort(key=lambdax:x[one],reverse=True) forjinoutcome:outlist.append({"k":category[j[0]],"probability":str(j[one])}) returnoutlist#Set response information def getResponse(pred,intents_json):ptype=pred[0]['k']print(User question type:,ptype) ctype = intents_json['chatbot']fortypeinctype:if(type['category']==ptype):result=random.choice(type['output']) print(Response information provided to users:,result) break returnresult#Predictive Message Responsedef chatbot_ Response(query): pred = predict(query,load) outcome = getResponse(pred,chatbot) returnoutcome#Set up message interaction between users and intelligent customer servicedef chatbotInteract():query=txt.get("one.0",'end-onec').strip() txt.delete("zero",END)chatwnd.tag_config('question',background="white",foreground="black") chatwnd.tag_config('answer',background="white",foreground="blue") chatwnd.config(state=NORMAL) chatwnd.insert(END,User question: n+query+'nn','question')outcome = chatbot_ Response(query) chatwnd.insert(END,Customer service answer: n+outcome+'nn','answer') chatwnd.config(state=NORMAL) chatwnd.yview(END) #Set smart customer service application interface styletk_ window=tkinter.Tk(screenName=None,baseName=None)tk_ window.title(Intelligent customer service)tk_ window.geometry("fifty0x600")tk_ window.resizable(False,False)#Set Text Boxchatwnd = Text(tk_window,borderwidth=two,cursor=None,state=NORMAL,background="white",height="onetwo",width="70",font="Arial",wrap=WORD)#Set scroll barsrb = Scrollbar(tk_window,command=chatwnd.yview,activebackground=None,background="white",borderwidth=two,highlightcolor="purple",cursor="arrow",jump=0,orient=VERTICAL,width=one6,elementborderwidth=one)srb.pack( side = RIGHT,fill = Y )chatwnd['yscrollcommand']=srb.set#Set the style of the information input boxtxt = Text(tk_window,borderwidth=0,cursor=None,background="white",width="two5",height="eight",font="Arial",wrap=WORD)#Set the style of the send message buttonmsgBtn = Button(tk_window,font=("kaiti",one4),text=Consultation,width=onetwo,height=eight,highlightcolor=None,image=None,justify=CENTER,state=ACTIVE, borderwidth=0,background="Blue",activebackground="#5two4e7eight",fg='white',relief=RAISED, command= chatbotInteract ) #Display component contentsrb.place(x=four hundred and four,y=onetwo,height=39eight)chatwnd.place(relx=zero,rely=zero point three five,relwidth=0.eight,relheight=zero point six six,anchor='w')msgBtn.place(bordermode=OUTSIDE,x=one75,y=five hundred and forty,height=fifty)txt.place(x=two,y=4oneone,height=one00,width=four hundred)tk_window.mainloop()
Disclaimer: The content of this article is sourced from the internet. The copyright of the text, images, and other materials belongs to the original author. The platform reprints the materials for the purpose of conveying more information. The content of the article is for reference and learning only, and should not be used for commercial purposes. If it infringes on your legitimate rights and interests, please contact us promptly and we will handle it as soon as possible! We respect copyright and are committed to protecting it. Thank you for sharing.(Email:[email protected])
Mobile advertising space rental |
Tag: Tensorflow+natural language processing+LSTM Practice of building an intelligent chat
Top programmer Chen Hao's sudden death from a heart attack has caused netizens to mourn!
NextHow did the Babylonians discover the periodicity of solar and lunar eclipses?
Guess you like
-
Xiaomi Automobile Unveils Intelligent Chassis Pre-Research Technology, Ushering in a New Era of "Human-Car-Home Full Ecosystem"Detail
2024-11-14 11:24:27 1
-
Douyin E-commerce Double 11 Data Report: Merchants Businesses Grow, Consumer Trends EmergeDetail
2024-11-14 11:23:11 1
-
New Trends in SOE Reform: Focusing on Five Values to Build a "Living Organism"Detail
2024-11-14 11:19:26 1
-
CATL Chairman Zeng Yuqun: Musk Doesn't Understand Batteries, Tesla's Bet on Cylindrical Batteries is Doomed to FailDetail
2024-11-13 18:47:38 1
-
China Eastern Airlines Technology and Thales Renew Cooperation Agreement, Deepening Avionics Maintenance PartnershipDetail
2024-11-13 16:40:50 1
- Detail
- Detail
- Detail
-
Li Jiaqi's Livestream Double 11 Report: Domestic Brands Surge, Winter Warmer Economy BoomsDetail
2024-11-12 11:07:26 11
-
BYD: Plug-in Hybrids "To the Rescue," Behind the Price War Lies a "Davis Double-Click" in ProfitabilityDetail
2024-11-12 10:49:05 1
-
The Rise of Online Livestreamers: A Mass Career with 15 Million Dream Chasers in Live RoomsDetail
2024-11-11 15:27:33 11
-
Microsoft "Mail and Calendar" app will be officially discontinued at the end of next year, users need to migrate to the new OutlookDetail
2024-11-10 14:53:36 11
- Detail
-
Alibaba Pictures' Phoenix Cloud Intelligence International Edition iCIRENA Expands to Hong Kong and Macau, Bringing Technological Upgrades to CinemasDetail
2024-11-09 11:22:49 11
-
From Daughter of Heaven to Ordinary Mom: Liu Yang's Space Dream and the Diversification of LifeDetail
2024-11-09 10:36:56 1
- Detail
-
Global Focus: CIIE Signs Deals Worth Over 10 Billion, 6G Technology Takes the Lead, Avian Flu Outbreak Ravages, Typhoon "Ginkgo" ApproachesDetail
2024-11-08 14:39:05 1
-
The Battle for the Smartphone Throne: Apple, Samsung, and Huawei Vie for DominanceDetail
2024-11-07 21:01:50 1
-
Why Chinese Astronauts Lie Down When Exiting the Capsule? The Truth is Not InferiorityDetail
2024-11-07 00:51:26 11
- Detail