PyTorch telegram chatbot

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(, response, parse_mode='HTML')


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\”, line 3, in
from elmoformanylangs import Embedder
File “C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\”, line 2, in
from .elmo import Embedder
File “C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\elmoformanylangs\”, line 12, in
from .frontend import create_one_batch
File “C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\elmoformanylangs\”, line 10, in
from .modules.token_embedder import ConvTokenEmbedder, LstmTokenEmbedder
File “C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\elmoformanylangs\modules\”, line 8, in
from .highway import Highway
File “C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\elmoformanylangs\modules\”, line 12, in
class Highway(torch.nn.Module):
File “C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\elmoformanylangs\modules\”, line 46, in Highway
File “C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\overrides\”, 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\”, line 172, in _overrides
_validate_method(method, super_class, check_signature)
File “C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\overrides\”, 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\”, 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\”, line 303, in ensure_return_type_compatibility
raise TypeError(
TypeError: Highway.forward: return type <class 'torch.Tensor'> is not a <class 'NoneType'>.

1 Like

I assume it is the single backslashes that is seen as an escape sequence.

  • Might work if you escape them \\

  • Use forward slashes /.

  • Use an r prefixed string

  • Use os.path.join

1 Like

Thanks a lot! We fixed the first bug! But there’s still a little bit left, hehe :slight_smile:

Well, we are not just here to debug all your code for you. I just saw something that seemed obvious and mentioned it.

I would suggest you search for the errors, for example the error on the last line. When I do that, this is one of the hits I get.

Might be relevant, might not.

Also, I don’t really use Python nor do I know anything about the libraries you are using.

BTW, are you sure you want your telegram bot token exposed. Again, I have no knowledge about it, but most tokens are not meant to be posted to the public.

I’m sorry! I didn’t mean to seem selfish ^^

Thanks for your help sir, anyway! I will look into this further. <3
Oh, and about the token, thanks for noticing, I’ll hide it now

ps. well, well, for some reason I can’t change the token in the article, so I’ll find another way to make it inaccessible

I removed the toke for you. But you should probably generate a new one.