国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

使用 Python 創(chuàng)建端到端聊天機器人

這篇具有很好參考價值的文章主要介紹了使用 Python 創(chuàng)建端到端聊天機器人。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

聊天機器人是一種計算機程序,它了解您的查詢意圖以使用解決方案進行回答。聊天機器人是業(yè)內(nèi)最受歡迎的自然語言處理應用。因此,如果您想構建端到端聊天機器人,本文適合您。在本文中,我將帶您了解如何使用 Python 創(chuàng)建端到端聊天機器人。

1. 效果圖

訓練的意圖及回復越多,機器人將越靈活準確。
用例少不準確或者基本是提供的內(nèi)容的回答。

使用 Python 創(chuàng)建端到端聊天機器人
使用 Python 創(chuàng)建端到端聊天機器人

2. 原理

2.1 什么是端到端聊天機器人?

端到端聊天機器人是指可以在不需要人工幫助的情況下從頭到尾處理完整對話的聊天機器人。

要創(chuàng)建端到端聊天機器人,需要編寫一個計算機程序,該程序可以理解用戶請求,生成適當?shù)捻憫?,并在必要時采取行動。這包括收集數(shù)據(jù),選擇編程語言和NLP工具,訓練聊天機器人,以及在將其提供給用戶之前對其進行測試和完善。 部署后,用戶可以通過向聊天機器人發(fā)送多個請求來與聊天機器人進行交互,聊天機器人可以自行處理整個對話。

2.2 創(chuàng)建端到端聊天機器人步驟

  1. 定義意向
  2. 創(chuàng)建訓練數(shù)據(jù)
  3. 訓練聊天機器人
  4. 構建聊天機器人
  5. 測試聊天機器人
  6. 部署聊天機器人

3. 源碼

3.1 streamlit安裝

python3.7.6+ streamlit 0.68.0,1.20.0,1.21.0 都不行,只有1.9版本ok

pip install streamlit==1.9

使用 Python 創(chuàng)建端到端聊天機器人文章來源地址http://www.zghlxwxcb.cn/news/detail-429862.html

3.2 源碼

# 端到端聊天機器人
# streamlit run ete_chatbot.py

import os
import nltk
import ssl
import streamlit as st
import random
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import LogisticRegression

ssl._create_default_https_context = ssl._create_unverified_context
nltk.data.path.append(os.path.abspath("nltk_data"))
nltk.download('punkt')

# 定義聊天機器人的一些意圖。可以添加更多意圖,使聊天機器人更有用且功能更強大
intents = [
    {
        "tag": "greeting",
        "patterns": ["Hi", "Hello", "Hey", "How are you", "What's up"],
        "responses": ["Hi there", "Hello", "Hey", "I'm fine, thank you", "Nothing much"]
    },
    {
        "tag": "goodbye",
        "patterns": ["Bye", "See you later", "Goodbye", "Take care"],
        "responses": ["Goodbye", "See you later", "Take care"]
    },
    {
        "tag": "thanks",
        "patterns": ["Thank you", "Thanks", "Thanks a lot", "I appreciate it"],
        "responses": ["You're welcome", "No problem", "Glad I could help"]
    },
    {
        "tag": "about",
        "patterns": ["What can you do", "Who are you", "What are you", "What is your purpose"],
        "responses": ["I am a chatbot", "My purpose is to assist you", "I can answer questions and provide assistance"]
    },
    {
        "tag": "help",
        "patterns": ["Help", "I need help", "Can you help me", "What should I do"],
        "responses": ["Sure, what do you need help with?", "I'm here to help. What's the problem?", "How can I assist you?"]
    },
    {
        "tag": "age",
        "patterns": ["How old are you", "What's your age"],
        "responses": ["I don't have an age. I'm a chatbot.", "I was just born in the digital world.", "Age is just a number for me."]
    },
    {
        "tag": "weather",
        "patterns": ["What's the weather like", "How's the weather today"],
        "responses": ["I'm sorry, I cannot provide real-time weather information.", "You can check the weather on a weather app or website."]
    },
    {
        "tag": "budget",
        "patterns": ["How can I make a budget", "What's a good budgeting strategy", "How do I create a budget"],
        "responses": ["To make a budget, start by tracking your income and expenses. Then, allocate your income towards essential expenses like rent, food, and bills. Next, allocate some of your income towards savings and debt repayment. Finally, allocate the remainder of your income towards discretionary expenses like entertainment and hobbies.", "A good budgeting strategy is to use the 50/30/20 rule. This means allocating 50% of your income towards essential expenses, 30% towards discretionary expenses, and 20% towards savings and debt repayment.", "To create a budget, start by setting financial goals for yourself. Then, track your income and expenses for a few months to get a sense of where your money is going. Next, create a budget by allocating your income towards essential expenses, savings and debt repayment, and discretionary expenses."]
    },
    {
        "tag": "credit_score",
        "patterns": ["What is a credit score", "How do I check my credit score", "How can I improve my credit score"],
        "responses": ["A credit score is a number that represents your creditworthiness. It is based on your credit history and is used by lenders to determine whether or not to lend you money. The higher your credit score, the more likely you are to be approved for credit.", "You can check your credit score for free on several websites such as Credit Karma and Credit Sesame."]
    }
]

# Create the vectorizer and classifier 創(chuàng)建矢量化器和分類器
vectorizer = TfidfVectorizer()
clf = LogisticRegression(random_state=0, max_iter=10000)

# 準備意圖數(shù)據(jù)并訓練模型
tags = []
patterns = []
for intent in intents:
    for pattern in intent['patterns']:
        tags.append(intent['tag'])
        patterns.append(pattern)

# 訓練模型
x = vectorizer.fit_transform(patterns)
y = tags
clf.fit(x, y)

def chatbot(input_text):
    input_text = vectorizer.transform([input_text])
    tag = clf.predict(input_text)[0]
    for intent in intents:
        if intent['tag'] == tag:
            response = random.choice(intent['responses'])
            return response


# 為了部署聊天機器人,將使用 Python 中的 streamlit 庫,它提供了驚人的功能,只需幾行代碼即可為機器學習應用程序創(chuàng)建用戶界面
counter = 0

def main():
    global counter
    st.title("Chatbot")
    st.write("Welcome to the chatbot. Please type a message and press Enter to start the conversation.")

    counter += 1
    user_input = st.text_input("You:", key=f"user_input_{counter}")

    if user_input:
        response = chatbot(user_input)
        st.text_area("Chatbot:", value=response, height=100, max_chars=None, key=f"chatbot_response_{counter}")

        if response.lower() in ['goodbye', 'bye']:
            st.write("Thank you for chatting with me. Have a great day!")
            st.stop()

if __name__ == '__main__':
    main()

參考

  • https://thecleverprogrammer.com/2023/03/27/end-to-end-chatbot-using-python/

到了這里,關于使用 Python 創(chuàng)建端到端聊天機器人的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • 使用Java和ChatGPT Api來創(chuàng)建自己的大模型聊天機器人

    什么是大模型? 大型語言模型(LLM)是一種深度學習模型,它使用大量數(shù)據(jù)進行預訓練,并能夠通過提示工程解決各種下游任務。LLM 的出發(fā)點是建立一個適用于自然語言處理的基礎模型,通過預訓練和提示工程的方式實現(xiàn)模型在新的數(shù)據(jù)分布和任務上的強大泛化能力。LLM 旨

    2024年02月12日
    瀏覽(22)
  • 如何使用OpenAI API和Python SDK構建自己的聊天機器人

    如何使用OpenAI API和Python SDK構建自己的聊天機器人

    近日,OpenAI公司的ChatGPT模型走紅網(wǎng)絡。同時,OpenAI也推出了Chat API和gpt-3.5-turbo模型,讓開發(fā)者能夠更輕松地使用與ChatGPT類似的自然語言處理模型。 通過OpenAI API,我們可以使用gpt-3.5-turbo模型,實現(xiàn)多種任務,包括:撰寫電子郵件或其他文本內(nèi)容,編寫Python代碼,創(chuàng)建對話代

    2024年02月01日
    瀏覽(49)
  • 簡介:在這篇教程中,我們將使用React.js框架創(chuàng)建一個簡單的聊天機器人的前端界面,并利用Dialogflo

    作者:禪與計算機程序設計藝術 介紹及動機 聊天機器人(Chatbot)一直是互聯(lián)網(wǎng)領域中的熱門話題。而很多聊天機器人的功能都依賴于人工智能(AI)技術。越來越多的企業(yè)希望擁有自己的聊天機器人系統(tǒng),從而提升自己的競爭力。為此,業(yè)界也出現(xiàn)了很多基于開源技術或云

    2024年02月06日
    瀏覽(26)
  • 制作一個Python聊天機器人

    我們學習一下如何使用 ChatterBot 庫在 Python 中創(chuàng)建聊天機器人,該庫實現(xiàn)了各種機器學習算法來生成響應對話,還是挺不錯的 聊天機器人也稱為聊天機器人、機器人、人工代理等,基本上是由人工智能驅(qū)動的軟件程序,其目的是通過文本或語音與用戶進行對話。 我們?nèi)粘=佑|

    2024年01月19日
    瀏覽(22)
  • 【NLP開發(fā)】Python實現(xiàn)聊天機器人(微軟Azure機器人服務)

    【NLP開發(fā)】Python實現(xiàn)聊天機器人(微軟Azure機器人服務)

    ??NLP開發(fā)系列相關文章編寫如下??: 1 ??【小沐學NLP】Python實現(xiàn)詞云圖?? 2 ??【小沐學NLP】Python實現(xiàn)圖片文字識別?? 3 ??【小沐學NLP】Python實現(xiàn)中文、英文分詞?? 4 ??【小沐學NLP】Python實現(xiàn)聊天機器人(ELIZA))?? 5 ??【小沐學NLP】Python實現(xiàn)聊天機器人(ALICE)?? 6

    2024年02月04日
    瀏覽(29)
  • [LLM]Streamlit+LLM(大型語言模型)創(chuàng)建實用且強大的Web聊天機器人

    [LLM]Streamlit+LLM(大型語言模型)創(chuàng)建實用且強大的Web聊天機器人

    Streamlit 是一個開源框架,使開發(fā)人員能夠快速構建和共享用于機器學習和數(shù)據(jù)科學項目的交互式 Web 應用程序。它還提供了一系列小部件,只需要一行 Python 代碼即可創(chuàng)建,例如 st.table(…) 。對于我們創(chuàng)建一個簡單的用于私人使用的聊天機器人網(wǎng)站來說,Streamlit 是一個非常合

    2024年01月16日
    瀏覽(20)
  • 【小沐學NLP】Python實現(xiàn)聊天機器人(微軟Azure機器人服務)

    【小沐學NLP】Python實現(xiàn)聊天機器人(微軟Azure機器人服務)

    ??NLP開發(fā)系列相關文章編寫如下??: 1 ??【小沐學NLP】Python實現(xiàn)詞云圖?? 2 ??【小沐學NLP】Python實現(xiàn)圖片文字識別?? 3 ??【小沐學NLP】Python實現(xiàn)中文、英文分詞?? 4 ??【小沐學NLP】Python實現(xiàn)聊天機器人(ELIZA))?? 5 ??【小沐學NLP】Python實現(xiàn)聊天機器人(ALICE)?? 6

    2024年02月12日
    瀏覽(98)
  • 【python+wechaty+docker+nodejs】24年從0開始搭建使用python-wechaty接入微信聊天機器人全過程記錄

    全網(wǎng)搜索了所有相關文章,由于個人原是java老程序員,對python有點興趣,正好這個機器人的python資料比較多,因此就著手嘗試。 在網(wǎng)上基本沒有找到python-wechaty的完整說明的使用手冊因此自己寫一個記錄一下全過程。 真正的從0開始。只有系統(tǒng)。沒有其他的情況下,都是全新

    2024年01月24日
    瀏覽(20)
  • NoneBot2,基于Python的聊天機器人

    NoneBot2,基于Python的聊天機器人

    NoneBot2 是一個現(xiàn)代、跨平臺、可擴展的 Python 聊天機器人框架,它基于 Python 的類型注解和異步特性,能夠為你的需求實現(xiàn)提供便捷靈活的支持。 NoneBot2 具有豐富的插件生態(tài)系統(tǒng),可以實現(xiàn)多種功能,例如自動回復、天氣查詢、消息推送等等。此外,它還提供了完善的文檔和

    2023年04月16日
    瀏覽(30)
  • 我用python/C++自制了一個聊天機器人

    我用python/C++自制了一個聊天機器人

    2015年, OpenAI 由馬斯克、美國創(chuàng)業(yè)孵化器Y Combinator總裁阿爾特曼、全球在線支付平臺PayPal聯(lián)合創(chuàng)始人彼得·蒂爾等硅谷科技大亨創(chuàng)立,公司核心宗旨在于 實現(xiàn)安全的通用人工智能(AGI) ,使其有益于人類。 ChatGPT 則是近期 OpenAI 推出的一個基于對話的原型 AI 聊天機器人,2022年

    2023年04月17日
    瀏覽(25)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包