需要源碼和數(shù)據(jù)集請點贊關(guān)注收藏后評論區(qū)留言私信~~~
一、問答智能客服簡介
QA問答是Question-and-Answer的縮寫,根據(jù)用戶提出的問題檢索答案,并用用戶可以理解的自然語言回答用戶,問答型客服注重一問一答處理,側(cè)重知識的推理。
從應(yīng)用領(lǐng)域視角,可將問答系統(tǒng)分為限定域問答系統(tǒng)和開放域問答系統(tǒng)。
根據(jù)支持問答系統(tǒng)產(chǎn)生答案的文檔庫、知識庫,以及實現(xiàn)的技術(shù)分類,可分為自然語言的數(shù)據(jù)庫問答系統(tǒng)、對話式問答系統(tǒng)、閱讀理解系統(tǒng)、基于常用問題集的問答系統(tǒng)、基于知識庫的問答系統(tǒng)等。
智能問答客服功能架構(gòu)
典型的問答系統(tǒng)包含問題輸入 問題理解 信息檢索 信息抽取 答案排序 答案生成和結(jié)果輸出等,首先由用戶提出問題,檢索操作通過在知識庫中查詢得到相關(guān)信息,并依據(jù)特定規(guī)則從提取到的信息中抽取相應(yīng)的候選答案特征向量,最后篩選候選答案結(jié)果輸出給用戶?
?智能問答客服框架
1: 問題處理 問題處理流程識別問題中包含的信息,判斷問題的主題信息和主題范疇歸屬,比如是屬于一般類問題還是屬于特定主題類問題,然后提取與主題相關(guān)的關(guān)鍵信息,比如人物信息、地點信息和時間信息等。
2 :問題映射 根據(jù)用戶咨詢的問題,進行問題映射消除歧義。通過字符串相似度匹配和同義詞表等解決映射問題,根據(jù)需要執(zhí)行拆分和合并操作。
3 :查詢構(gòu)建 通過對輸入問題進行處理,將問題轉(zhuǎn)化為計算機可以理解的查詢語言,然后查詢知識圖譜或者數(shù)據(jù)庫,通過檢索獲得相應(yīng)備選答案。
4 :知識推理 根據(jù)問題屬性進行推理,問題基本屬性如果屬于知識圖譜或者數(shù)據(jù)庫中的已知定義信息,則可以從知識圖譜或者數(shù)據(jù)庫中查找,直接返回答案。如果問題屬性是未定義類問題,則需要通過機器算法推理生成答案。
5: 消岐排序 根據(jù)知識圖譜中查詢返回的一個或者多個備選答案,結(jié)合問題屬性進行消歧處理和優(yōu)先級排序,輸出最佳答案。
二、智能醫(yī)療客服問答實戰(zhàn)
定制性智能客服程序一般需要實現(xiàn)選擇語料庫,去除噪聲信息后 根據(jù)算法對預料進行訓練,最后提供人機接口問答對話,基于互聯(lián)網(wǎng)獲得的醫(yī)學語料庫,并通過余弦相似度基本原理,設(shè)計并開發(fā)以下問答型智能醫(yī)療客服應(yīng)用程序
項目結(jié)構(gòu)如下?
效果展示?
下面是csv文件中定義的一些病例
預先定義好的歡迎語句?
?
?
運行chatrobot文件? 彈出以下窗口 輸出問題后點擊提交咨詢即可??
?
對于語料庫中沒有的問題會自動推斷給出答案(通常不太準確)?
?
?
?三、代碼
部分代碼如下 全部代碼和數(shù)據(jù)集請點贊關(guān)注收藏后評論區(qū)留言私信文章來源:http://www.zghlxwxcb.cn/news/detail-411184.html
# -*- coding:utf-8 -*-
from fuzzywuzzy import fuzz
import sys
import jieba
import csv
import pickle
print(sys.getdefaultencoding())
import logging
from fuzzywuzzy import fuzz
import math
from scipy import sparse
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.feature_extraction.text import TfidfTransformer
from scipy.sparse import lil_matrix
from sklearn.naive_bayes import MultinomialNB
import warnings
from tkinter import *
import time
import difflib
from collections import Counter
import numpy as np
filename = 'label.csv'
def tokenization(filename):
corpus = []
label = []
question = []
answer = []
with open(filename, 'r', encoding="utf-8") as f:
data_corpus = csv.reader(f)
next(data_corpus)
for words in data_corpus:
word = jieba.cut(words[1])
tmp = ''
for x in word:
tmp += x
corpus.append(tmp)
question.append(words[1])
label.append(words[0])
answer.append(words[2])
with open('corpus.h5','wb') as f:
pickle.dump(corpus,f)
with open('label.h5','wb') as f:
pickle.dump(label,f)
with open('question.h5', 'wb') as f:
pickle.dump(question, f)
with open('answer.h5', 'wb') as f:
pickle.dump(answer, f)
return corpus,label,question,answer
def train_model():
with open('corpus.h5','rb') as f_corpus:
corpus = pickle.load(f_corpus)
with open('label.h5','rb') as f_label:
label = pickle.load(f_label,encoding='bytes')
vectorizer = CountVectorizer(min_df=1)
transformer = TfidfTransformer()
tfidf = transformer.fit_transform(vectorizer.fit_transform(corpus))
words_frequency = vectorizer.fit_transform(corpus)
word = vectorizer.get_feature_names()
saved = tfidf_calculate(vectorizer.vocabulary_,sparse.csc_matrix(words_frequency),len(corpus))
model = MultinomialNB()
model.fit(tfidf,label)
with open('model.h5','wb') as f_model:
pickle.dump(model,f_model)
with open('idf.h5','wb') as f_idf:
pickle.dump(saved,f_idf)
return model,tfidf,label
class tfidf_calculate(object):
def __init__(self,feature_index,frequency,docs):
self.feature_index = feature_index
self.frequency = frequency
self.docs = docs
self.len = len(feature_index)
def key_count(self,input_words):
keys = jieba.cut(input_words)
count = {}
for key in keys:
num = count.get(key, 0)
count[key] = num + 1
return count
def getTfidf(self,input_words):
count = self.key_count(input_words)
result = lil_matrix((1, self.len))
frequency = sparse.csc_matrix(self.frequency)
for x in count:
word = self.feature_index.get(x)
if word != None and word>=0:
word_frequency = frequency.getcol(word)
feature_docs = word_frequency.sum()
tfidf = count.get(x) * (math.log((self.docs+1) / (feature_docs+1))+1)
result[0, word] = tfidf
return result
if __name__=="__main__":
tokenization(filename)
train_model()
創(chuàng)作不易 覺得有幫助請點贊關(guān)注收藏~~~文章來源地址http://www.zghlxwxcb.cn/news/detail-411184.html
到了這里,關(guān)于【Python自然語言處理+tkinter圖形化界面】實現(xiàn)智能醫(yī)療客服問答機器人實戰(zhàn)(附源碼、數(shù)據(jù)集、演示 超詳細)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!