Dataset set_format error - ValueError: PyTorch needs to be installed

Hi all, I am new to using HuggingFace. I try to play with one of Hugging Face Dataset and get familiar with it. But I run into a strange error when trying to convert its columns to torch format using the following line:

emotions_encoded.set_format("torch", columns=["input_ids", "attention_mask", "label"])

However, it returns an error saying that I need to have PyTorch installed in order to return PyTorch tensors (see picture attached


). But I have installed it in my virtual environment and it works fine with other things. I really dont understand where this pytorch needs to be installed to get this working. Can you please help me out on this issue.

Apologise for this silly question! Many thanks in advance!

1 Like

Try to install PyTorch with pip/conda/source and restart the kernel of your jupyter notebook. Make sure you are using the correct environment for installation - the same that your notebook uses.