2017-03-26 47 views
0

我用Chatterbot做了一個簡單的反饋循環程序。下面的代碼需要一到兩分鐘才能響應自己,並且需要類似的加載時間。我的問題是關於效率 - 爲了獲得對chatterbot的正常響應需要一到兩分鐘?如果不是,我如何提高效率?Python Chatterbot效率問題

其他詳細信息 - 如果我的chatterbot創建中沒有將靜音性能警告參數設置爲true,則會出現以下錯誤。

不合適的生產警告:JsonFileStorageAdapter不是 推薦用於生產環境。
self.UnsuitableForProductionWarning

這是我的代碼。

from chatterbot import ChatBot 
from chatterbot.trainers import ChatterBotCorpusTrainer 

chatterbot = ChatBot("Training Example",silence_performance_warning=True,storage_adapter='chatterbot.storage.JsonFileStorageAdapter') 
chatterbot.set_trainer(ChatterBotCorpusTrainer) 

chatterbot.train(
    "chatterbot.corpus.english.greetings", 
    "chatterbot.corpus.english.conversations" 
) 

print("Ready") 
print("1 : How are you?") 
response = "How are you?" 
first = False 

while True: 
    response = chatterbot.get_response(str(response)) 
    if first: 
     print("1 : "+str(response)) 
     first = False 
    else: 
     print("2 : "+str(response)) 
     first = True 

據我所知,由於bot自身的反應本質,它最終只能重複輸出一條消息。這我並不擔心。

更新 - 問題駐留在visual studio 2015中。我發現使用標準IDLE運行我的代碼會立即返回我預期的輸出。

+2

你確定實際上有兩個分鐘之間的響應(有很大的CPU活動),還是有可能是有故意的等待指令(設置得太高)? – lenz

+0

在恆定的高水平下,CPU有很大的活動。我發現我的問題的根源是使用Python工具與Visual Studio 2015混淆,因爲使用IDLE結果編譯和運行我的代碼時沒有這樣的效率問題。 – RoughlyCuboid

回答

1

對您處理的每一個請求進行模型訓練都非常困難。使用單獨的腳本來訓練和醃製您的訓練好的模型,然後在您的交互式腳本(您向我們展示的那個,減去訓練)中加載醃製的模型,並使用它來處理響應。

+1

如果我正確理解OP,while循環的每次迭代都有一到兩分鐘的等待時間,因此'chatterbot.get_response'方法花費的時間太長。 – lenz