
河北铝单板生产厂家一分耕耘一分收获(chatlink immks)
发布时间:2023-04-02 21:03:57 人气:8 来源:铝单板厂家
原标题:Chat客服入门案例|商务智能对话客服(二)

ChatGPT是人工智能研究实验室OpenAI新推出的一种人工智能技术驱动的自然语言处理工具,使用了Transformer神经网络架构,也是GPT-3.5架构,这是一种用于处理序列数据的模型,拥有语言理解和文本生成能力,尤其是它会通过连接大量的语料库来训练模型,这些语料库包含了真实世界中的对话,使得ChatGPT具备上知天文下知地理,还能根据聊天的上下文进行互动的能力,做到与真正人类几乎无异的聊天场景进行交流。
ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

01

■ 图9-13本地模板连接设置


■ 图9-15本地模板选项 接着根据提示信息输入问题,进行问答对话,参见图9-16。

■ 图9-16本地模板连接测试 (1) 测试程序function.py主要代码 # 导入库文件importnumpy asnp defdisplay_response(outcome1,outcome2)。
: ifoutcome1 isnotNone: outcome = outcome1 elifoutcome2 isnotNone: outcome = outcome2 else: outcome =
"非常抱歉,目前暂时没有搜索到与您的问题相匹配的答案,我们会继续关注您的问题,欢迎您下次继续光临"returnoutcome #文本余弦相似度计算defcosine_similarity(text1, text2)。
: cos_text1 = (Counter(text1)) cos_text2 = (Counter(text2)) similarity_text1 = [] similarity_text2 = []
fori inset(text1 + text2): similarity_text1.append(cos_text1[i]) similarity_text2.append(cos_text2[i])
similarity_text1 = np.array(similarity_text1) similarity_text2 = np.array(similarity_text2) returnsimilarity_text1.dot(similarity_text2) / (np.sqrt(similarity_text1.dot(similarity_text1)) * np.sqrt(similarity_text2.dot(similarity_text2)))
#智能客服问候语匹配,相似度的数值可以定制 defgreeting_response(msg,input_greet,output_greet): selection = {} forkey, value
inenumerate(input_greet): comparison = cosine_similarity(msg, value) ifcomparison > 0.6: selection[key] = comparison
sort = sorted(selection.items, key= lambdax: x[ 1], reverse= True) outcome = output_greet[sort[ 0][ 0
]] iflen(selection) != 0elseNonereturnoutcome #问答预测操作 defprediction(message): input_greet = [] output_greet = []
withopen( "label.csv", r,encoding= utf-8) asdf: greets = csv.reader(df) next(greets) forgreet ingreets:
input_greet.append(greet[ 1]) output_greet.append(greet[ 2]) #相似度阈值的设定可以定制 selection = {} forkey, value
inenumerate(input_greet): comparison = cosine_similarity(message, value) ifcomparison > 0.1: selection[key] = comparison
sort = sorted(selection.items, key= lambdax: x[ 1], reverse= True) outcome = output_greet[sort[ 0][ 0
]] iflen(selection) != 0elseNonereturnoutcome #根据用户输入信息输出响应处理defentrance(msg): input_greet = [] output_greet = []
withopen( "greeting.csv", r,encoding= utf-8) asdf: greets = csv.reader(df) next(greets) forgreet ingreets:
input_greet.append(greet[ 0]) output_greet.append(greet[ 1]) outcome1 = greeting_response(msg,input_greet,output_greet)
outcome2 = prediction(msg) outcome = display_response(outcome1,outcome2) returnoutcome (2) 界面显示模块chatrobot.py主要代码。
#导入库文件importtime importtkinter astk fromtkinter import* fromtkinter importTk fromtkinter importText
fromtkinter importButton fromfunction import* #设置智能客服应用界面风格tk = Tk(screenName= None, baseName= None)
tk.title( 智能医疗客服) tk.geometry( 500x600) tk.resizable( True, True) #定义用户提问和客服回答消息处理函数defmsgProcess: #获取用户的输入信息
msg = txt.get( "1.0", end-1c).strip #删除用户的输入信息txt.delete( "0.0",END) #定义用户消息和客服消息的颜色显示区分chatmsg.tag_config(
question, background= "white", foreground= "blue") chatmsg.tag_config( answer, background= "white", foreground=
"black") ifmsg != "": #获取和显示用户消息 tmsg = 【用户问题】 + time.strftime( %Y/%m/%d %H:%M, time.localtime) + chatmsg.insert(END, tmsg,
question) chatmsg.insert(END, msg + , question) #根据用户的输入信息进行匹配操作outcome = entrance(msg) chatmsg.config(state=NORMAL)
#获取和显示客服应答消息 botresponse = 【客服回答】 + time.strftime( %Y/%m/%d %H:%M, time.localtime) + chatmsg.insert(END, botresponse,
answer) chatmsg.insert(END, outcome + , answer) else: tmsg = 用户问题: + time.strftime( %Y/%m/%d %H:%M
, time.localtime) + chatmsg.insert(END, tmsg, question) chatmsg.config(state=NORMAL) chatmsg.insert(END, msg +
, question) botresponse = 客服回答: + time.strftime( %Y/%m/%d %H:%M, time.localtime) + chatmsg.insert(END, botresponse,
answer) chatmsg.insert(END, "对不起,我没有理解您的问题,请输入您要咨询的问题"+ , answer) # 取消发送消息defmsgCancel: txt.delete( 。
0.0, END) chatmsg = Text(tk, borderwidth= 0, cursor= None,state=NORMAL, background= "white", height=
"12", width= "70", font= "kaiti",wrap=WORD) #设置滚动条srb = Scrollbar(tk, command=chatmsg.yview, activebackground=
None,background= "white",borderwidth= 0,highlightcolor= "purple",cursor= "arrow", jump= 0,orient=VERTICAL,width=
16,elementborderwidth= 1) srb.pack( side = RIGHT, fill = Y ) chatmsg[ yscrollcommand] = srb.set chatmsg.see(
"end") #设置信息输入框风格txt = Text(tk, borderwidth= 0, cursor= None,background= "white",width= "25", height=
"8", font= "kaiti",wrap=WORD) #设置发送消息按钮风格msgBtnS = Button(tk, font=( "kaiti", 12, "bold"), text= "提交咨询"
, width= 12, height= 8,highlightcolor= None,image= None,justify=CENTER,state=ACTIVE,borderwidth= 0, background=
"#111fed", activebackground= "#524e78",foreground = white,relief=RAISED, command= msgProcess ) msgBtnC = Button(tk, font=(
"kaiti", 12, "bold"), text= "取消咨询", width= 12,height= 8,highlightcolor= None,image= None,justify=CENTER,state=ACTIVE,borderwidth=
0, background= "#111fed", activebackground= "#524e78",foreground = white,relief=RAISED, command= msgCancel )
#显示组件内容srb.place(relx= 0.8, rely= 0.35, relwidth= 0.03, relheight= 0.66, anchor= e) chatmsg.place(relx=
0.0, rely= 0.35, relwidth= 0.8, relheight= 0.66, anchor= w) txt.place(relx= 0.002, rely= 0.685, relwidth=
0.8,relheight= 0.2) msgBtnS.place(bordermode=OUTSIDE,relx= 0.1, rely= 0.9, relwidth= 0.2,relheight= 0.05
) msgBtnC.place(bordermode=OUTSIDE,relx= 0.4, rely= 0.9, relwidth= 0.2,relheight= 0.05) tk.mainloop 02
参考书籍《Python自然语言处理——算法、技术及项目案例实战(微课视频版)》作者:(日)中本一郎、马冀、张积林、郭彦、庄伟卿、冯丽娟、江明、黄益定价:59.90元扫码优惠购书本书全面介绍了数据挖掘和商务智能的基础知识、主要技术、基于Python语言的商务应用生成技术。
全书共12章,主要内容包括数据挖掘、深度学习、Seq2Seq、商务智能应用创建及部署、Tensorflow、卷积神经网络、循环神经网络和Rasa技术本书注重理论结合实战,实例部分配套操作步骤,重要代码讲解,中间图形和文本输出,将实战内容融合在课程教学过程中,使理论紧密联系实际,帮助学生在潜移默化中获得知识。
返回搜狐,查看更多责任编辑:
相关新闻
- 铝单板厂家联系电话号码高效便捷种类齐全(红米多少个系列) 2023-05-03
- 南昌铝单板厂家电话按照客户要求定制(realme 真我gt neo 5g怎么样) 2023-05-03
- 木纹铝单板厂家直销专业售后品质保证(红米快充多少钱一个) 2023-05-03
- 铝单板厂家排名及价格全国发货及时供应(redmi k60pro) 2023-05-03
- 铝单板厂家哪家好全国发货及时供应(红米note128g多少钱) 2023-05-03
- 铝单板厂家联系电话号码高效便捷种类齐全(红米多少个系列) 2023-05-03
- 承德铝单板厂家佛是金装人是衣装(波兰吞并切欣) 2023-05-02
- 张家口铝单板厂家哪家好塞翁失马焉知非福(英国老师几点上班) 2023-05-02
- 保定铝单板批发厂家养兵千日用兵一时(西安有几家世界500强企业) 2023-05-02
- 石家庄铝单板批发厂家一言既出驷马难追(中国在2030年的五大超级都市圈) 2023-05-02