[Python] Can't see color in Visual Studio Code

Discussão em 'Python' iniciado por Stack, Maio 1, 2025.

  1. Stack

    Stack Membro Participativo

    I'm following "Hands on Large Language Models" by Alammar.

    One of the examples is:

    from transformers import AutoModelForCausalLM, AutoTokenizer

    colors_list = [
    '102;194;165', '252;141;98', '141;160;203',
    '231;138;195', '166;216;84', '255;217;47'
    ]

    def show_tokens(sentence, tokenizer_name):
    tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)
    token_ids = tokenizer(sentence).input_ids
    for idx, t in enumerate(token_ids):
    print(
    f'\x1b[0;30;48;2;{colors_list[idx % len(colors_list)]}m' +
    tokenizer.decode(t) +
    '\x1b[0m',
    end=' '
    )

    text = """
    English and CAPITALIZATION
    鸟
    show_tokens False None elif == >= else: two tabs:" " Three tabs: " "
    12.0*50=600
    """

    show_tokens(text, "bert-base-uncased")


    Which is supposed to show up as:

    [​IMG]

    However, in Visual Studio Code I see it as:

    [​IMG]

    Continue reading...

Compartilhe esta Página