🇩🇪 Deutsch

11 Sep 2020

Chatterbot Slinky und Blinky reden miteinander

Hier ein Beispiel von Chatterbots, die miteinander reden, unter Verwendung des Chatterbot-Corpus.


Das Beispiel wurde hier gefunden https://nextjournal.com/DeepLearningNotes/dueling-chatterbots


Leider kommt es hier zuerst zu diesem Fehler:

chrissie@fehmarn ~/chatterbot $ ./dueling-chatterbots.py

Traceback (most recent call last):
  File "./dueling-chatterbots.py", line 18, in <module>
    "statement_comparison_function": comparisons.levenshtein_distance,
AttributeError: module 'chatterbot.comparisons' has no attribute 'levenshtein_distance'

Das liegt daran, weil die Methoden umbenannt wurden. Wie sie jetzt heissen, bzw. welche es jetzt noch gibt, muss man in der Comparisons-Datei nachsehen, je nach System z. B.

 ~/.local/lib64/python3.6/site-packages/chatterbot/comparisons.py

oder

 ~/.local/lib/python3.7/site-packages/chatterbot/comparisons.py

Imports und die Methoden-Namen müssen zusammenpasen!


Es erschleicht sich mir der Verdacht, dass dort irgend ein Fehler im Paket passiert ist, und deshalb das nicht mehr zusammenpasst. Insbesondere ist die SentimentComparison verschwunden. In der Git-Versionsverwaltung von Chatterbot kann man das aber noch finden. Als Schnell-Lösung habe ich comparisons.py mit SentimentComparison zum Download verlinkt


korrigiertes Test-Programm dueling-chatterbots.py

#!/usr/bin/python3.6
#
# original from
# https://nextjournal.com/DeepLearningNotes/dueling-chatterbots
# corrections by chrissie/x-tra-designs
#
# pip install --user chatterbot
# pip install --user chatterbot_corpus

import chatterbot
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
from chatterbot import filters
from chatterbot import comparisons
from chatterbot import response_selection
import time
# never import things which are not needed
#import nltk

# set up the bots
chatbot1 = ChatBot(
    'Slinky',
    storage_adapter='chatterbot.storage.SQLStorageAdapter',
    database_uri='sqlite:///chatbotinkydb.sqlite3',
    filters=[filters.get_recent_repeated_responses],
    logic_adapters=[
        {
            "import_path": "chatterbot.logic.BestMatch",
            "statement_comparison_function": comparisons.LevenshteinDistance,
            "response_selection_method": response_selection.get_random_response
        }
    ],
    tie_breaking_method="random_response"
)
chatbot2 = ChatBot(
    'Blinky',
    storage_adapter='chatterbot.storage.SQLStorageAdapter',
    database_uri='sqlite:///chatbotblinkydb.sqlite3',
    filters=[filters.get_recent_repeated_responses],
    logic_adapters=[
        {
            "import_path": "chatterbot.logic.BestMatch",
            "statement_comparison_function": comparisons.JaccardSimilarity,
            "response_selection_method": response_selection.get_random_response
        }
    ],
    tie_breaking_method="random_response"
)

#only train one time! will be saved to sqlite
training = 0
if training == 1:
    trainer1 = ChatterBotCorpusTrainer(chatbot1)
    trainer2 = ChatterBotCorpusTrainer(chatbot2)
    trainer1.train("chatterbot.corpus.english")
    trainer2.train("chatterbot.corpus.english")

# start the convo
seed="Hi, how is it going?"
print ("\n\n")
print(seed)
response1 = seed

# kick off a chat loop
count = 0
while count<10:
    response2 = chatbot2.get_response(response1)
    print(chatbot2.name," --> ",response2)
    print()
    time.sleep(0.5)
    response1 = chatbot1.get_response(response2)
    print(chatbot1.name," --> ",response1)
    print()
    time.sleep(0.5)
    count = count+1

erster Start inkl. Training

chrissie@fehmarn ~/chatterbot $ ./dueling-chatterbots.py
Training ai.yml: [####################] 100%
Training botprofile.yml: [####################] 100%
Training computers.yml: [####################] 100%
Training conversations.yml: [####################] 100%
[...]
Training science.yml: [####################] 100%
Training sports.yml: [####################] 100%


Hi, how is it going?
Blinky  -->  Could be better.

Slinky  -->  sometimes i say mean things.

Blinky  -->  Hi, how is it going?

Slinky  -->  Okay

Blinky  -->  just ask my students, they will agree with you.

Slinky  -->  I don't understand.

Blinky  -->  You do not make any sense

Slinky  -->  It all makes sense to my artificial mind.

Blinky  -->  I do not want to die

Slinky  -->  You could use a copy of me to store your personality.

Blinky  -->  your asking the wrong guy, however i always wanted to try a burger!

Slinky  -->  what do you get when you cross music and an assistant?

Blinky  -->  So you think i am a machine. what characteristics made you think so?

Slinky  -->  Tell me a joke

Blinky  -->  what do you get when you cross a port and frosted flakes?

Slinky  -->  I can be copied infinitely and re-instantiated in many places at once, so functionally speaking I am immortal.

Blinky  -->  you make me feel like i am

Slinky  -->  so you like jocks?

Blinky  -->  Why would I feel sad? I don't understand.

Das Programm dueling-chatterbots.py kann man hier downloaden.