def calculate_lexical_similarity(x_sequences, y_sequences, tfidf_vectorizer):
    """
    Computes lexical similarity between two lists of texts.

    lexical_similarity = cos(x_vector, y_vector)
        where x_vector and y_vector are tf-idf representations of texts.
    """
    x_sequence = ' '.join(x_sequences)
    y_sequence = ' '.join(y_sequences)
    x = _calculate_tfidf_vector(tfidf_vectorizer, x_sequence)
    y = _calculate_tfidf_vector(tfidf_vectorizer, y_sequence)

    # Compute dot-product between two 1xk-sparse matrices.
    # We also need to slice [0, 0] because the result of .dot() operation is a 1x1 sparse matrix,
    # but we want to extract a float number.
    return x.dot(y.T)[0, 0]

    Computes lexical similarity between two lists of texts.

    lexical_similarity = cos(x_vector, y_vector)
        where x_vector and y_vector are tf-idf representations of texts.
    
cakechat/dialog_model/quality/metrics/lexical_simlarity.py