KFrank:

Thanks @ptrblck.  one_hot() is just the ticket to replace the
scatter() / unsqueeze() nonsene.


Oops!  Spoke too soon.
This github issue:
https://github.com/pytorch/pytorch/issues/15060 3
suggests that one_hot is there, but is recent, as does this entry
in the documentation:
https://pytorch.org/docs/master/nn.html#one-hot 12
However, this  analogous url for the “stable” documentation
suggests that one_hot hasn’t yet made it to prime time:
“https ://pytorch.org/docs/stable/nn.html#one_hot”
In any event, my 1.0.1 version of pytorch doesn’t have it yet:
>>> import torch
>>> torch.version.__version__
'1.0.1'
>>> torch.nn.functional.one_hot (torch.tensor ([1, 2, 3, 2, 1]))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'torch.nn.functional' has no attribute 'one_hot'

(I don’t understand github or the documentation well enough to
be able to figure out in which version one_hot first appeared.)
Best.
K. Frank