How can I convert a list of strings to tensor in pytorch?
I am working on a classification problem in which I have a list of strings as class labels and I want to convert them to tensor. So far, I have tried to convert a list of strings to numpy array
using a function np.array
provided by the numpy module.
truth = torch.from_numpy(np.array(truths))
but I am getting the following error.
RuntimeError: can't convert a given np.ndarray to a tensor - it has an invalid type. The only supported types are: double, float, int64, int32, and uint8.
Can you suggest an alternative approach? Thanks to
+5
source to share