Here’s a working example that uses teacher forcing half of the time, and trains on its own outputs the other half: https://gist.github.com/spro/ef26915065225df65c1187562eca7ec4 63
You often see unsqueeze because Linear layers expect B x N tensors while RNNs expect S x B x N (sequence, batch, size). In the referenced tutorial the inputs are in a different shape from the outputs (inputs are character indexes in a LongTensor, outputs are probabilities in a FloatTensor) so you have to do some manual work to convert it.