I am trying to use transformers in repl.it and it returns a bus error as soon as I run it

82 Views Asked by At

For a school project, I am creating an AI chatbot in python through repl.it, but the code had multiple errors that had to be fixed. I got to the point where the only error I get is "bus error (core dumped)".

I tried using the replit AI to help solve the issues, and it said that I should try using a different environment, so I decided to try using Visual Studio Code, but that came with a whole bunch of other errors on its own.

This is our code:

from transformers import AutoModelForCausalLM, AutoTokenizer

def generate_response(input_text, model, tokenizer, max_length=5000):
  input_ids = tokenizer.encode(input_text, return_tensors="pt")

  return tokenizer.decode(input_ids, skip_special_tokens=True)

  response_ids = model.generate(input_ids, max_length=max_length.item(), num_return_sequences=1, no_repeat_ngram_size=2)

  response = tokenizer.decode(response_ids[0], skip_special_tokens=True)

  return response

def main():
  model_name = "gpt2"
  tokenizer = AutoTokenizer.from_pretrained(model_name)
  model = AutoModelForCausalLM.from_pretrained(model_name)

  print("Chatbot: Hi! I'm your chatbot. Type 'exit' to end the conversation.")
  while True:
    user_input = input("You: ")
    if user_input.lower() == "exit":
      print("Chatbot: Goodbye!")

      break

    else:
      response = generate_response(user_input, model, tokenizer, max_length=5000)
      print("Chatbot:", response)
if __name__ == "__main__":
  main()
0

There are 0 best solutions below