'query() of generator `max_length` being succeeded

Goal: set min_length and max_length in Hugging Face Transformers generator query.

I've passed 50, 200 as these parameters. Yet, the length of my outputs are much higher...

There's no runtime failure.

from transformers import pipeline, set_seed
generator = pipeline('text-generation', model='gpt2')
set_seed(42)

def query(payload, multiple, min_char_len, max_char_len):
    print(min_char_len, max_char_len)
    list_dict = generator(payload, min_length=min_char_len, max_length=max_char_len, num_return_sequences=multiple)
    test = [d['generated_text'].split(payload)[1].strip() for d in list_dict]
    for t in test: print(len(t))
    return test

query('example', 1, 50, 200)

Output:

50 200
Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation.
1015


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source