Untitled

 avatar
user_3839718
python
a month ago
1.0 kB
2
Indexable
Never
    def tokenize_function(recipes):
        prompt = "generate recipe instructions: "
        input_text = [prompt + ingredients.lower() for ingredients in recipes['ingredients']]
        labels = [directions.lower() for directions in recipes['directions']]
        # Tokenize inputs and labels
        model_inputs = tokenizer(input_text,
                                 max_length=args.token_max_length,
                                 pad_to_max_length=True,
                                 truncation=True,
                                 padding="max_length",
                                 return_tensors="pt",
                                 )
        labels = tokenizer(labels,
                           max_length=args.token_max_length,
                           pad_to_max_length=True,
                           truncation=True,
                           padding="max_length",
                           return_tensors="pt", )
        model_inputs["labels"] = labels["input_ids"]
        return model_inputs
Leave a Comment