def get_embeddings(data, embedding_cache, flattened):
    """
    Get cached embeddings or compute for the dataset

    # Parameters
        data: `probe.load_data.WordInspectionDataset`
            dataset from which we get embeddings
        embedding_cache: `str`
            path to file where embeddings are cached (could be None)
        flattened: `bool`
            sentence embeddings needed to be flatted

    # Returns
        `Tuple(`torch.Tensor`, `torch.Tensor`, `range`, `torch.Tensor`)`
    """

    if embedding_cache is None:
        if flattened:
            encoded_data = data.get_flattened_encoded()
        else:
            encoded_data = data.get_encoded()
        return data.bert_word_embeddings(encoded_data)
    return data.load_saved_embeddings(embedding_cache)