Open win10ogod opened 1 year ago
我觉得这个想法很有意思。
但 ChatterBot 本是简单的数据库检索、通过相似语句匹配、得到输出答句,这是个完全的浅层学习过程(甚至好像没有用到向量和矩阵)。在这样的系统中引入深度的注意力机制是否值得。
在你编辑前给的第一版代码里,似乎是完全用 PyTorch 重写了 ChatterBot 推理的整个过程。只是把原来的一些通过编程实现的匹配、检索工作换成了基于神经网络的向量、概率实现,我觉得二者也许大概是等价的。
而后面改过的这版代码似乎更没有意义了,手写了一种 attention,然后似乎就没有然后了,没看懂 🙈
你好,此项目的ChatterBot如何实现,还有如何使用呢?
然后原代碼取自XzaiCloud/AI-Vtuber項目,这是新版的代码 `from chatterbot import ChatBot from chatterbot.trainers import ListTrainer from chatterbot.conversation import Statement import numpy as np
def dot_product_attention(query, values):
scores = np.dot(query, values.T)
# Apply softmax to the scores to get the attention weights
attention_weights = np.softmax(scores)
# Calculate the weighted average of the values using the attention weights
weighted_values = np.dot(attention_weights, values)
return weighted_values
with open('db.txt', 'r', encoding='utf-8') as f: corpus = f.readlines()
my_bot = ChatBot(input('请输入ChatBot名称:')) trainer = ListTrainer(my_bot)
print('开始训练!')
for conversation in corpus:
statements = conversation.strip().split('\t')
if len(statements) == 2:
# Create a Statement object for each statement
statement_1 = Statement(text=statements[0])
statement_2 = Statement(text=statements[1])
# Convert the text of the statements to numpy arrays
query = np.array(statement_1.text.split())
values = np.array(statement_2.text.split())
# Calculate the attention weighted input vector using dot_product_attention
input_vector = dot_product_attention(query, values)
# Train the ChatBot with the attention weighted input vector
trainer.train([Statement(text=input_vector)])
else:
# If the conversation is not in the expected format, skip it
continue
print('训练完毕!')` 這個程式碼示例將每對對話語句作為輸入向量傳遞給 dot_product_attention 函數,該函數計算注意力加權的輸入向量。然後,注意力加權的輸入向量被轉換成 Statement 物件,並傳遞給 train() 方法,以便用於訓練聊天機器人。
你好,此项目的ChatterBot如何实现,还有如何使用呢?
这个项目目前主要使用 OpenAI 的 ChatGPT API,ChatterBot 只是作为备用机制。使用 ChatterBot 的实现在: https://github.com/cdfmlr/musharing_chatbot/ ,只是对 ChatterBot 项目( https://github.com/RaSan147/ChatterBot_update )的 API 封装。
然后原代碼取自XzaiCloud/AI-Vtuber項目,这是新版的代码
@XzaiCloud 你在 ChatterBot 加了注意力机制?😱
加了可能忘了 我最近忙死了,啥都记不到
啊这
然后原代碼取自XzaiCloud/AI-Vtuber項目,这是新版的代码
@win10ogod XzaiCloud/AI-Vtuber 似乎没有这个源码?😭
我也记得没加
我更推荐使用blenderbot
chatterbot有点过时了
blenderbot 有中文的项目吗? 一直想要找中文的blenderbot
我不太了解编程不过试着问了chatgpt。 这是chatgpt的代碼纪录: