import torch


def get_token_embedding_by_names(token, token_names):
    """
    Adapted flair.data.Token get_embedding()
    :param token:
    :param token_names:
    :return:
    """
    token_embeddings = [
        token._embeddings[embed] for embed in sorted(token_names)
    ]
    if token_embeddings:
        return torch.cat(token_embeddings, dim=0)
    else:
        return torch.Tensor()