社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

arsho

arsho 最近创建的主题
arsho 最近回复了
6 年前
回复了 arsho 创建的主题 » 如何在chatbot python flask中返回空响应?
  • LowConfidenceAdapter 如果无法以高置信度确定响应,则可用于返回默认响应。
  • 设置一个 threshold 值作为响应的最小置信分数。如果信心低于这个 门槛 值时,它将返回默认响应。

使用更新的代码 LowConfidenceAdapter :

from chatterbot import ChatBot

from chatterbot.trainers import ListTrainer
chatbot = ChatBot("Training Example",
                  logic_adapters=[
                    {
                        'import_path': 'chatterbot.logic.BestMatch'
                    },
                    {
                        'import_path': 'chatterbot.logic.LowConfidenceAdapter',
                        'threshold': 0.65,
                        'default_response': 'I am sorry, but I do not understand.'
                    }
                ])

chatbot.set_trainer(ListTrainer)

chatbot.train([
    "Hi there!",
    "Hello"])

chatbot.train([
    "Hello",
    "Hey!"])

chatbot.train([
    "How are you?",
    "I am good."])
chatbot.train([    
    "That is good to hear.",
    "Thank you",
    "You are welcome."])
chatbot.train([
    "Sure, I'd like to book a flight to Iceland.",
    "Your flight has been booked."])

while True:
    try:
        a = input("Question please..? ")
        response = chatbot.get_response(a)
        print(response)
    except (KeyboardInterrupt,SystemExit):
        print("\nYour loop has been closed.")
        break

输出:

chatterbot example

6 年前
回复了 arsho 创建的主题 » python测试程序-读取csv并解析问题/答案
  • 重新排列列表并首先选择 n 线
  • 使用 strip 删除答案末尾的新行

更新代码:

import random
def quiz():
    score=0
    questionsRight=0
    fileName = input("Please enter the name of the quiz file: ")
    quizFile = open(fileName,"r")
    quizData = quizFile.readlines()
    random.shuffle(quizData)
    questionno=1
    for i in range(5):
        x = quizData[i].strip()
        data = x.split(",")        
        question = data[0]
        CorrectAnswer = data[1]

        print("Question #",questionno)
        print(question)
        answer = input("What is your answer? ")
        if answer == CorrectAnswer:
            print("Correct!")
            score=score+1
            questionsRight=questionsRight+1
            questionno = questionno+1

        else:
            print("Incorrect.")
            print("Correc answer should be: "+CorrectAnswer)
            questionno = questionno+1
        print()

    totalScore = (score / 10) * 100
    print("You got ",score," questions right, and a score of ",totalScore,"%.")
quiz()

输出:

output

data.csv :

Demo question 1,Answer 1
Demo question 2,Answer 2
Demo question 3,Answer 3
Demo question 4,Answer 4
Demo question 5,Answer 5
Demo question 6,Answer 6
Demo question 7,Answer 7
Demo question 8,Answer 8
Demo question 9,Answer 9
Demo question 10,Answer 10
Demo question 11,Answer 11
Demo question 12,Answer 12
Demo question 13,Answer 13
Demo question 14,Answer 14
Demo question 15,Answer 15
Demo question 16,Answer 16
Demo question 17,Answer 17
Demo question 18,Answer 18
Demo question 19,Answer 19
Demo question 20,Answer 20
Demo question 21,Answer 21

改进:

参考文献: