There are many ways to do this, but here is a simple and straightforward version:
input_dy = torch.empty(dy.size(0), 2)
input_dy[:,0] = dy
input_dy[:,1] = 1-dy

y_true = torch.round(input_dy)

I don’t understand the second part of the question; is the “one-hot” encoding supposed to have a shape of [4] as well? If it was truly “one-hot” I would expect the shape to be [4, 2] as well. The posted code snippet implements a true-false encoding rather than a one-hot.