I’ve been wanting to write something similar for a long time: a chat bot that will come up with answers on its own and maybe even self-learn from the user’s answers… I understand that this is a lost cause, so I don’t really worry if I see errors, but I still wonder what I’m doing wrong .
Here is my silly code:
import torch
from elmoformanylangs import Embedder
import telebot
class NeuralChatBot:
def __init__(self, model_path):
self.embedder = Embedder(model_path)
def respond(self, user_input):
with torch.no_grad():
input_ids = self.embedder.sents2elmo([user_input.split()])
response = self.generate_response(input_ids)
return response
def generate_response(self, input_ids):
return str(input_ids[0][0])
model_path = 'C:\Desktop\gjvjubnt\ELMoForManyLangs-master'
bot = NeuralChatBot(model_path)
telegram_bot_token = someToken'
telegram_bot = telebot.TeleBot(telegram_bot_token)
@telegram_bot.message_handler(func=lambda message: True)
def echo_all(message):
user_input = message.text
response = bot.respond(user_input)
telegram_bot.send_message(message.chat.id, response, parse_mode='HTML')
telegram_bot.polling(none_stop=True)
I wrote it together with neural networks and other forums (I don’t remember which ones), now it seems to me that this code is a fabric full of patches and holes. I ask you to find errors and help me correct them in as much detail as possible. he
if required: here are the errors I received
SyntaxWarning: invalid escape sequence ‘\D’
model_path = ‘C:\Desktop\gjvjubnt\ELMoForManyLangs-master’
Traceback (most recent call last):
File “C:\Users\user\Desktop\gjvjubnt\gjvjubnt.py”, line 3, in
from elmoformanylangs import Embedder
File “C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\elmoformanylangs_init_.py”, line 2, in
from .elmo import Embedder
File “C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\elmoformanylangs\elmo.py”, line 12, in
from .frontend import create_one_batch
File “C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\elmoformanylangs\frontend.py”, line 10, in
from .modules.token_embedder import ConvTokenEmbedder, LstmTokenEmbedder
File “C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\elmoformanylangs\modules\token_embedder.py”, line 8, in
from .highway import Highway
File “C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\elmoformanylangs\modules\highway.py”, line 12, in
class Highway(torch.nn.Module):
File “C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\elmoformanylangs\modules\highway.py”, line 46, in Highway
@overrides
^^^^^^^^^
File “C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\overrides\overrides.py”, line 83, in overrides
return _overrides(method, check_signature, check_at_runtime)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\overrides\overrides.py”, line 172, in _overrides
_validate_method(method, super_class, check_signature)
File “C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\overrides\overrides.py”, line 191, in _validate_method
ensure_signature_is_compatible(super_method, method, is_static)
File “C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\overrides\signature.py”, line 103, in ensure_signature_is_compatible
ensure_return_type_compatibility(super_type_hints, sub_type_hints, method_name)
File “C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\overrides\signature.py”, line 303, in ensure_return_type_compatibility
raise TypeError(
TypeError: Highway.forward: return type <class 'torch.Tensor'>
is not a <class 'NoneType'>
.