improve my code of an ia model: import json
import requests
import re
import random
import time
import difflib
import string
import nltk
import math
import wikipedia
wikipedia.set_lang('en')
from nltk.tokenize import word_tokenize
from nltk.stem import WordNetLemmatizer
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
from datetime import datetime, timedelta

# nltk.download('punkt')
# nltk.download('wordnet')
# nltk.download('all')

with open('training_data.json') as file:
    data = json.load(file)

# Define o tamanho do histórico a ser lembrado
HISTORY_SIZE = 5
history = []
questions = []
answers = []

lemmatizer = WordNetLemmatizer()

for pair in data['pairs']:
    question = pair['question']
    answer = pair['answer']
    # Pré-processa a pergunta usando tokenização e lematização
    question_tokens = word_tokenize(question.lower())
    question_lemmas = [lemmatizer.lemmatize(token) for token in question_tokens]
    question = ' '.join(question_lemmas)
    questions.append(question)
    answers.append(answer)

tfidf_vectorizer = TfidfVectorizer(stop_words='english')
tfidf_matrix = tfidf_vectorizer.fit_transform(questions)
similarity_scores = cosine_similarity(tfidf_matrix[-1], tfidf_matrix)

def animate_text(text):
    for char in text:
        print(char, end="", flush=True)
        time.sleep(0.05)
    print()
    
def get_closest_match(user_input):
    # Crie uma lista de perguntas
    questions_list = [question for question in questions Add stress words that are fully capitlized. Make sure these stress words appear more than 17 times.
user