[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
-
China Leads in Developing IEC 63206 International Standard, Driving Global Innovation in Industrial Process Control System RecordersDetail
2025-01-18 11:06:14 1
-
The 2024 Micro-Short Series Industry Ecological Insight Report: 647,000 Job Opportunities, Rise of Diversified Business Models, and High-Quality Content as the Future TrendDetail
2025-01-17 17:33:01 1
-
Global PC Market Shows Moderate Recovery in 2024: High AIPC Prices a Bottleneck, Huge Growth Potential in 2025Detail
2025-01-17 11:02:09 1
-
Bosch's Smart Cockpit Platform Surpasses 2 Million Units Shipped, Showcasing Strength in Intelligent Driving TechnologyDetail
2025-01-17 10:55:29 1
-
YY Guangzhou Awarded "2024 Network Information Security Support Unit" for Outstanding ContributionsDetail
2025-01-17 10:43:28 1
-
TikTok CEO Invited to Trump's Inauguration, Biden Administration May Delay BanDetail
2025-01-16 20:06:11 1
-
Douyin Denies Opening International Registration: Overseas IPs Don't Equate to Overseas Registration; Platform Actively Combats Account ImpersonationDetail
2025-01-16 14:26:12 1
-
Lei Jun, Xiaomi's founder, chairman, and CEO, has set a new goal: learning to drive a forklift!Detail
2025-01-15 10:22:30 11
-
ByteDance Scholarship 2024: Fifteen Outstanding Doctoral Students Awarded RMB 100,000 Each to Advance Frontier Technology ExplorationDetail
2025-01-14 15:56:39 1
-
Fliggy Launches "Peace of Mind for the New Year" Service Initiative to Ensure Smooth Travel During the Year of the Snake Spring Festival RushDetail
2025-01-14 15:24:53 1
-
Arm's Massive Fee Hike and Potential In-House Chip Development: A Precursor to a Seismic Shift in the Chip Industry?Detail
2025-01-14 11:02:36 1
-
Adobe Firefly Launches: Generative AI Suite Revolutionizes Image and Video Processing EfficiencyDetail
2025-01-14 10:46:39 1
-
Chinese New Year Elements Sell Like Hotcakes Overseas: Cross-border E-commerce "Spring Festival Economy" Booms, Cainiao Overseas Warehouses Help Merchants Capture Market ShareDetail
2025-01-13 14:17:50 1
-
China Railway's 12306 System Successfully Navigates Spring Festival Travel RushDetail
2025-01-13 12:56:54 1
-
Handan, Hebei Province Successfully Tests First Low-Altitude Drone Delivery Route, Ushering in a New Era of Smart LogisticsDetail
2025-01-13 12:50:13 1
-
Kuaishou Leads in Developing Anti-Fraud Industry Standards, Contributing to a Secure and Reliable Short-Video CommunityDetail
2025-01-13 09:47:32 11
-
Microsoft Offers Top Salaries to Retain AI Talent: AI Software Engineers Earn Over $400,000 AnnuallyDetail
2025-01-12 17:28:34 11
- Detail
-
Chang'e-5 Mission Unveils Secrets: New Discoveries Regarding Lunar Magnetic Field Strength and Deep Dynamics 2 Billion Years AgoDetail
2025-01-10 11:42:44 11
-
SenseTime's "Day Day New" Multimodal Large Model: Native Fusion Enables Diverse ApplicationsDetail
2025-01-10 11:40:40 21