[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
-
WeChat's Official Account Launches "Author Read Aloud Voice" Feature for Personalized Article ListeningDetail
2024-12-18 17:19:57 1
-
The 12th China University Students' Polymer Materials Innovation and Entrepreneurship Competition Finals Grand Opening in Guangrao CountyDetail
2024-12-18 16:04:28 1
-
Tracing the Ancient Shu Road, Winds of the Three Kingdoms: Global Influencer Shu Road Journey LaunchesDetail
2024-12-18 15:23:35 1
-
Seres: A Pioneer in ESG Practices, Driving Sustainable Development of China's New Energy Vehicle IndustryDetail
2024-12-17 16:20:26 1
- Detail
-
My Health, My Guard: Huawei WATCH D2 Aids Precise Blood Pressure Management in the Winter Health BattleDetail
2024-12-17 09:36:15 1
-
Investigation into the Chaos of Airline Seat Selection: Paid Seat Selection, Seat Locking Mechanisms, and Consumer Rights ProtectionDetail
2024-12-15 16:45:48 1
-
Japanese Scientists Grow Human Organs in Pigs: A Balancing Act of Breakthrough and EthicsDetail
2024-12-14 19:48:50 1
-
Pang Donglai and Sam's Club: Two Paths to Transformation in China's Retail IndustryDetail
2024-12-14 17:57:03 1
-
In-Depth Analysis of China's Precision Reducer Industry: Technological Innovation and Market CompetitionDetail
2024-12-14 16:04:26 1
-
Alibaba's "TAO" App Launches in Japan, Targeting High-Quality Service and Convenient LogisticsDetail
2024-12-13 13:22:23 1
-
In-depth Analysis of China's Cross-border E-commerce Industry Chain: Opportunities and Challenges CoexistDetail
2024-12-13 11:37:17 1
-
Sweet Potato Robotics: How a Unified Software and Hardware Computing Platform Accelerates Robotics Industry DevelopmentDetail
2024-12-13 06:36:34 1
- Detail
-
Yang Liwei: From China's First Taikonaut to a Cornerstone of the Space ProgramDetail
2024-12-12 03:27:26 1
- Detail
- Detail
-
12306 Official Debunks 90-Day Advance Booking for Spring Festival Travel Rush: Beware of ScamsDetail
2024-12-12 02:01:05 1
-
Avoiding TV Buying Traps: A Deep Dive into 4K, HDR, 120Hz, and Other Key SpecificationsDetail
2024-12-11 22:45:54 1
-
NVIDIA's Q3 FY25 Earnings Report: Revenue Surges Past $35 Billion, Setting a New RecordDetail
2024-12-11 21:48:21 1