Unable to convert output to PyTorch tensors format, PyTorch is not installed.
Package:
transformers
50617

Exception Class:
ImportError
Raise code
)
import tensorflow as tf
as_tensor = tf.constant
is_tensor = tf.is_tensor
elif tensor_type == TensorType.PYTORCH:
if not is_torch_available():
raise ImportError("Unable to convert output to PyTorch tensors format, PyTorch is not installed.")
import torch
as_tensor = torch.tensor
is_tensor = torch.is_tensor
elif tensor_type == TensorType.JAX:
if not is_flax_available():
raise ImportError("Unable to convert output to JAX tensors format, JAX is not installed.")
Links to the raise (2)
https://github.com/huggingface/transformers/blob/bd9871657bb9500a9f4437a873db6df5f1ae6dbb/src/transformers/feature_extraction_utils.py#L138 https://github.com/huggingface/transformers/blob/bd9871657bb9500a9f4437a873db6df5f1ae6dbb/src/transformers/tokenization_utils_base.py#L671Ways to fix
Error code:
from transformers import BatchEncoding
data = {"inputs": [[1, 2, 3], [4, 5, 6]], "labels": [0, 1]}
encod = BatchEncoding(data)
ec = encod.convert_to_tensors('pt')
print(ec)
Fix version:
Make sure you have installed Torch
pip install torch
Add a possible fix
Please authorize to post fix