Hi
Can you elaborate please? I have the same problem.
I’m trying to give my model a sentence and then append the model predicted word to end of the sentence, then slide the window and feed back the sentence (from second word to the previously predicted word) to the model and so on… but all i got is a repeated word.
Here is how I prepare data batches:
# get words
words = data.split()
# remove repeated words to get vocab:
vocab = set(words)
print(f'\nvocab size: {len(vocab)}')
# make word dict
word2idx = {w:idx for idx, w in enumerate(vocab)}
idx2word = {idx:w for w, idx in word2idx.items()}

# get data bacthes
sequence_len = 30
batch_size = 50
word_size = 20
num_epochs = 2

data_batches = []
for i in range(len(words) - sequence_len - 1):  # 1 for target word
	data = [word2idx[x] for x in words[i: i + sequence_len]]
	target = word2idx[words[i + sequence_len]]

	data_batches.append([data, target])

num_batchs = np.ceil(len(data_batches) / batch_size).astype(np.int)
random.shuffle(data_batches)
print(f'\nnumber of batches: {num_batchs}')

This is my model:
class MyNet(nn.Module):
	def __init__(self, vocab_size, word_size, sequence_len, batch_size, hidden_dim):
		super().__init__()

		self.seq_len = sequence_len
		self.batch_size = batch_size
		self.hidden_dim = hidden_dim
		self.num_layers = 2
		self.h_0 = None
		self.c_0 = None

		self.encoder = nn.Embedding(vocab_size, word_size)
		self.lstm = nn.LSTM(input_size=word_size, hidden_size=hidden_dim,
							num_layers=self.num_layers, batch_first=True, dropout=0)
		self.linear = nn.Linear(hidden_dim, vocab_size)

	def reset_hidden(self):
		# For initialising/resetting hidden state.
		self.h_0 = torch.zeros(self.num_layers, self.batch_size, self.hidden_dim)
		self.c_0 = torch.zeros(self.num_layers, self.batch_size, self.hidden_dim)

	def forward(self, x):
		encoded = self.encoder(x)
		# print(f'encoded: {encoded.shape}')
		lstm_out, (self.h_0, self.c_0) = self.lstm(encoded)
		# print(f'{lstm_out.shape}, {lstm_out[:, -1, :].shape}')
		# Only take the output from the final timestep
		y_pred = self.linear(lstm_out[:, -1, :])
		
		return y_pred

And this is training process:
# begin training
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = MyNet(len(vocab), word_size, sequence_len, batch_size, 50).to(device)
criterion = torch.nn.CrossEntropyLoss()
optimizer = torch.optim.SGD(model.parameters(), lr=0.01, momentum=0.5)


for e in range(num_epochs):
	print(f'\n\nepoch #{e}:\n')
	model.reset_hidden()
	
	for i in range(num_batchs):
		batch = data_batches[i * batch_size: (i+1) * batch_size]
		x = torch.tensor([b[0] for b in batch], device=device)
		y = torch.tensor([b[1] for b in batch], device=device)
		# print(x.shape, y.shape)

		y_pred = model(x)

		loss = criterion(y_pred, y)

		optimizer.zero_grad()
		loss.backward()
		optimizer.step()

		if i % 50 == 0:
			print(f'\tbatch #{i}:\tloss={loss.item():.10f}')

torch.save(model.state_dict(), './model.pth')

Finally this is how I test my model:
# testing model
# choosing a random seqence
sentence = data_batches[np.random.randint(1, 500)][0]
print('\n', [idx2word[idx] for idx in sentence])
model.eval()

# trying to predict next 10 words
for i in range(10):
	# model.reset_hidden()
	x = torch.tensor(sentence[i : sequence_len +  i], device=device)
	out = model(x.view(1, *x.size()))
	out = torch.argmax(out)

	word = idx2word[out.detach().item()]
	print(word)

	sentence.append(out.detach().item())