Hi,
I am not able to use constrained beam search with flan-t5 models. I was able to use it with GPT-2 models.
The following code results in error - âValueError: Each list in nested_token_ids
canât be a complete subset of
another list, but is [[3, 7, 11763], [3, 7, 11763, 7], [25471], [3, 7, 11763,
15, 26]].â.
Can you please suggest some solutions to this problem?
`from transformers import AutoTokenizer, AutoModelForCausalLM, AutoModelForSeq2SeqLM
from transformers import GPT2LMHeadModel, GPT2Tokenizer
model = AutoModelForSeq2SeqLM.from_pretrained(âgoogle/flan-t5-baseâ)
tokenizer = AutoTokenizer.from_pretrained(âgoogle/flan-t5-baseâ)
force_word = âscaredâ
force_flexible = [âscreamâ, âscreamsâ, âscreamingâ, âscreamedâ]
force_words_ids = [
tokenizer([force_word], add_special_tokens=False).input_ids,
tokenizer(force_flexible, add_special_tokens=False).input_ids,
]
starting_text = [âThe soldiersâ, âThe childâ]
input_ids = tokenizer(starting_text, return_tensors=âptâ).input_ids
outputs = model.generate(
input_ids,
force_words_ids=force_words_ids,
num_beams=10,
num_return_sequences=1,
no_repeat_ngram_size=1,
remove_invalid_values=True,
)
print(âOutput:\nâ + 100 * â-â)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
print(tokenizer.decode(outputs[1], skip_special_tokens=True))
`