Which I wanted was a software that return ‘2’ when I give float list’1,2,3,4’as input.
However, it made error message

import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import datetime
import torch.optim as optim
torch.manual_seed(1)
input_size=1
hidden_size=1
learning_rate=0.1
x_data=[[1,2,3,4]]
x_one_hot=[[[1],[2],[3],[4]]]
y_data=[[2]]
x=torch.FloatTensor(x_one_hot)
y=torch.LongTensor(y_data)
#declare RNN
rnn=torch.nn.RNN(input_size,hidden_size,batch_first=True)
#loss&optimizer setting
criterion=torch.nn.CrossEntropyLoss()
optimizer=optim.Adam(rnn.parameters(),learning_rate)
#start training
for i in range(100):
optimizer.zero_grad()
outputs,_status=rnn(x)
#print(outputs.shape)
#print(outputs.view(-1,input_size).shape)
#print(y.view(-1).shape)
print(outputs[0].shape)
print(y[0].shape)
loss=criterion(outputs[0],y[0])
loss.backward()
optimizer.step()
result=outputs.data.numpy().argmax(axis=2)
print(“prediction:”,result)

and this is an error message
RuntimeError: Assertion `cur_target >= 0 && cur_target < n_classes’ failed.
I need some help.Thank you.