How to convert a list of lists to a Pytorch tensor?


I have a list of lists like this.

[[[1690.0, ['R04', 'crashed', 'nose']]],
 [[1690.0, ['No', 'nose']], [1710.0, ['R04', 'crashed', 'nose']]],
 [[1690.0, ['R03', 'crashed', 'nose']],
  [1710.0, ['Part','missing]]]

If I try to convert it using torch.tensor(p_x) it gives error TypeError: new(): invalid data type 'str'

How do I convert this to a Pytorch tensor?


pytorch tensors can’t hold strings. you’ll have to first figure out what to do with those strings before converting them to a pytorch tensor.

Use some kind of encoding or embedding to convert the string into a vector and then it can be converted into a tensor.