RuntimeError: bool value of Tensor with more than one value is ambiguous
## ❓ Questions & Help

<!-- Using tokenizer to decode tensor is throwing this error: RuntimeError: bool value of Tensor with more than one value is ambiguous -->

Here's the code I'm trying to run, the tensor itself gets returned, but when I try to decode it I get the error above.  

Any ideas?  Thanks! 

`if __name__ == '__main__':
	# main()
	model_class, tokenizer_class = MODEL_CLASSES['gpt2']
	tokenizer = tokenizer_class.from_pretrained('gpt2')
	context_tokens = tokenizer.encode("My favorite first date idea is")

	model = model_class.from_pretrained('gpt2')
	model.to('cpu')
	model.eval()

	out = sample_sequence(
		model=model,
		context=context_tokens,
		length=140,
		temperature=0.9,
		top_k=1,
		top_p=0.9
	)

	text = tokenizer.decode(out)
	print(text)`


Could you please provide more information, especially regarding the `sample_sequence` function and where it is coming from?<|||||>Thanks for the response!

My goal is to wrap the GPT2 model interface in a function so I can input a prompt and output generated text.  I'm trying to adapt one of the examples, and I'm getting there, but I wasn't able to find anything on the error specific to Pytorch-Transformers.

Here's the `sample_sequence` function:

    def sample_sequence(model, length, context, num_samples=1, temperature=1, top_k=0, top_p=0.0, device='cpu'):

	context = torch.tensor(context, dtype=torch.long, device=device)
	context = context.unsqueeze(0).repeat(num_samples, 1)
	generated = context
	with torch.no_grad():
		for _ in trange(length):
			inputs = {'input_ids': generated}
			outputs = model(**inputs)
			next_token_logits = outputs[0][0, -1, :] / temperature
			filtered_logits = top_k_top_p_filtering(next_token_logits, top_k=top_k, top_p=top_p)
			next_token = torch.multinomial(F.softmax(filtered_logits, dim=-1), num_samples=1)
			generated = torch.cat((generated, next_token.unsqueeze(0)), dim=1)
		return generated<|||||>Your sample sequence function returns a `torch.tensor([[int64]])`, of shape `[batch_size, sequence_length]`. In your specific case it is of size `[1, 146]`.

You cannot feed such an object to the tokenizer for decoding, as it only accepts a list of integers.

You can fetch the list of integers by calling the `tolist()` method on your output, and then feed it to the tokenizer for decoding:

```
out = sample_sequence(
	model=model,
	context=context_tokens,
	length=140,
	temperature=0.9,
	top_k=1,
	top_p=0.9
)

generated_list = out[0].tolist()
text = tokenizer.decode(generated_list)

print(text)
```<|||||>It worked!

This was very helpful, thank you!  Just getting familiar with this package, it's awesome!