import torch


def predict_rating(review, classifier, vectorizer,
                   decision_threshold=0.5):
    """
    Predict the rating of a given review

    :param review (str):   the text to review
    :param classifier (ReviewClassifier): the trained model
    :param vectorizer (ReviewVectorizer): The corresponding verctorizer
    :param decision_threshold (float): the numerical boundry which seperates negative and positive classes
    :return: return the rating (positive or negative)
    """

    vectorizer_review = torch.tensor(vectorizer.vectorize(review))
    result = classifier(vectorizer_review.view(1, - 1).float(), apply_sigmoid=True)

    index = 1
    if result < decision_threshold:
        index = 0

    return vectorizer.rating_vocab.lookup_index(index)