[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
-
The 2025 Chinese New Year (Spring Festival) film box office has exploded, exceeding 3 billion RMB and setting a new record for presales!Detail
2025-01-29 11:55:06 1
-
Seres and Beihang University Join Hands to Build an Innovative Ecosystem, Deepening Industry-Academia-Research Collaboration and Promoting Technological TransformationDetail
2025-01-28 14:46:18 1
-
Douyin 2024 Platform Governance Report: Safeguarding Security, Building a Better CommunityDetail
2025-01-28 14:25:55 1
-
Chinese Scientists Develop a Lightweight Bionic Dexterous Hand with 19 Degrees of Freedom, Promising to Revolutionize Prosthetic and Robotics TechnologyDetail
2025-01-28 14:16:39 1
-
DeepSeek: A Chinese AI Startup's Meteoric Rise Shakes Up Global Tech and Sends US Stocks PlungingDetail
2025-01-28 14:13:23 1
-
WeChat's New Year's Red Envelope Feature Gets a Voice Message Upgrade for Warmer Wishes!Detail
2025-01-26 11:37:36 1
-
360 Digital Security Group and Zhibangyang Education Technology Join Forces to Build a New Ecosystem for Cybersecurity and AI Talent CultivationDetail
2025-01-24 15:09:51 1
-
Visionox Achieves Mass Production of AMOLED with Solid-State Laser Annealing (SLA) Technology, Ushering in a New Era for the Display IndustryDetail
2025-01-24 14:34:23 1
-
Seres at the Davos Forum: The Path to Globalizing New Energy Vehicles Through Cooperation in the Intelligent EraDetail
2025-01-23 13:28:12 1
-
Amazon to Close All French-Speaking Quebec Warehouses, Laying Off Nearly 2,000 EmployeesDetail
2025-01-23 10:51:23 1
-
The official launch of the 2025 Electric Bicycle Trade-in Policy: Upgraded Subsidy Standards, Procedures, and PromotionDetail
2025-01-23 10:48:52 1
-
Xbox Series X|S Officially Supports External Hard Drives Larger Than 16TB: Saying Goodbye to Storage WorriesDetail
2025-01-23 10:39:19 1
-
Leaders from the Beijing Chaoyang District CPPCC Visited Quantum Leap Group, Affirming its Contributions and Future Prospects in the Silver Hair EconomyDetail
2025-01-22 17:06:56 1
-
China's Car Imports Remain Sluggish in 2024: 12% Decline, Sharp Drop in New Energy VehiclesDetail
2025-01-22 11:37:25 1
-
China Railway Group Limited (CRGL) officially debunks "speed-up" ticket booking software: Not a shortcut, but a pathway to riskDetail
2025-01-22 11:36:09 1
-
Dago Bio Completes Over $20 Million A+ Round Funding to Accelerate Novel Molecular Glue Drug DevelopmentDetail
2025-01-22 11:34:05 11
-
Rapid Degradation of Global Lake Submerged Vegetation: Satellite Observations Reveal a Critical Period of Ecosystem ShiftDetail
2025-01-22 11:29:03 1
-
Star Ace Capital Group and Abu Dhabi Investment Office Partner to Build a Global Esports Industry BenchmarkDetail
2025-01-22 11:27:50 1
-
Hisense Television Leads the 100-Inch Large-Screen Market in 2024, Achieving an Unparalleled Industry LegacyDetail
2025-01-22 11:12:49 1
-
WeChat Launches "Gifts" Feature: Streamlining Gift-Giving and Powering Social Commerce GrowthDetail
2025-01-21 16:05:45 1