notebooks icon indicating copy to clipboard operation
notebooks copied to clipboard

NameError: name 'tokenizer' is not defined

Open zaibian opened this issue 3 years ago • 3 comments
trafficstars

image why?

zaibian avatar Feb 25 '22 08:02 zaibian

Hi @zaibian please make sure you've imported from transformers import AutoTokenizer and selected model_checkpoint = "distilgpt2" also uncomment the requirement cells.

ghost avatar Feb 28 '22 10:02 ghost

I had the same problem, did you solve it please?

ZhouGe001 avatar May 13 '24 12:05 ZhouGe001

Currying worked for me to get rid of the external variable reference.

def tokenize_function_maker(tokenizer):
    def inner(examples):
        tokenizer(examples["text"])
    return inner

tokenized_datasets = datasets.map(tokenize_function_maker(tokenizer), batched=True, num_proc=4, remove_columns=["text"])

philipbohannon avatar Nov 08 '24 22:11 philipbohannon