第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

我如何檢查我的聊天機(jī)器人中的 2 個(gè)句子是否相似

我如何檢查我的聊天機(jī)器人中的 2 個(gè)句子是否相似

慕妹3242003 2023-03-22 16:14:58
我使最簡(jiǎn)單的聊天機(jī)器人成為可能。它會(huì)根據(jù)您之前希望它回答同一問題的內(nèi)容來(lái)回答您的問題。代碼有點(diǎn)像這樣:question = []answer = []qcount = 0stop = 0b = 0while stop == 0:    b = 0    q = input("Ask me anything: ")    if q == "stop":        exit()    for i in range(qcount):        if q == question[i]:            b = 1            print(answer[i])    if b == 0:        question.append(q)        qcount = qcount + 1        a = input("How should i answer that? ")        answer.append(a)有沒有辦法轉(zhuǎn)if q == question[i]到if q is similar to question[i]?
查看完整描述

2 回答

?
慕碼人2483693

TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超9個(gè)贊

我有類似的答案給你。你也可以試試這個(gè)。您不需要計(jì)數(shù)器和退出語(yǔ)句。您可以將 while 語(yǔ)句本身定義為看門人。


我做了一些更多的改進(jìn)。雖然這不會(huì)給你一個(gè)完美的聊天機(jī)器人,但它更接近了。


question = []

answer = []


q = input("Ask me anything: ")

while q.lower() != 'stop':

? ? i = -1

? ? z = q.lower().split()

? ? z.sort()


? ? for x in question:

? ? ? ? y = x.split()

? ? ? ? y.sort()

? ? ? ? if all(elem in y for elem in z):

? ? ? ? ? ? i = question.index(x)

? ? if i >= 0:

? ? ? ? print(answer[i])

? ? else:

? ? ? ? question.append(q.lower())

? ? ? ? a = input("How should i answer that? ")

? ? ? ? answer.append(a)

? ? q = input("Ask me anything: ")

輸出:


Ask me anything: What is your Name

How should i answer that? Joe

Ask me anything: What your name

Joe

Ask me anything: name

Joe

Ask me anything: your name

Joe

Ask me anything: what name

Joe

Ask me anything: what is name

Joe

如您所見,當(dāng)您詢問“姓名是什么”時(shí),它仍然假定您是在詢問您的姓名。您需要使用它來(lái)獲得更復(fù)雜的機(jī)器人。希望這可以幫助您朝著正確的方向前進(jìn)。


我之前的回答也貼在這里。由于我們將字符串與列表進(jìn)行比較,因此它必須完全匹配。檢查有問題的 q 并不能真正給你帶來(lái)優(yōu)勢(shì)。您將需要拆分單詞并進(jìn)行比較。這就是我在新回復(fù)中所做的(見上文)


question = []

answer = []


q = input("Ask me anything: ")

while q.lower() != 'stop':

? ? if q.lower() in question:

? ? ? ? i = question.index(q.lower())

? ? ? ? print (answer[i])

? ? else:

? ? ? ? question.append(q.lower())

? ? ? ? a = input("How should i answer that? ")

? ? ? ? answer.append(a)

? ? q = input("Ask me anything: ")


查看完整回答
反對(duì) 回復(fù) 2023-03-22
?
慕標(biāo)琳琳

TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超9個(gè)贊

使模糊查找器通過替換為此if q == question[i]不if q in question[i]查找特定單詞但查找關(guān)鍵字來(lái)執(zhí)行此操作


question = []

answer = []

qcount = 0

stop = 0


b = 0


while stop == 0:

    b = 0

    q = input("Ask me anything: ")

    if q == "stop":

        exit()

    for i in range(qcount):

         if q in question[i]:  # HERE IS THE ANSWER

            b = 1

            print(answer[i])



    if b == 0:

        question.append(q)

        qcount = qcount + 1


        a = input("How should i answer that? ")

        answer.append(a)


查看完整回答
反對(duì) 回復(fù) 2023-03-22
  • 2 回答
  • 0 關(guān)注
  • 160 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)