As the error message explains, you cannot use a variable before it was created.
Usually you would initialize it with a start values and reassign the desired value afterwards.
That being said, it also seems as if you would like to use temp_for_tranpose as a method, since you are calling it:
temp_for_transpose(hidden,0,1).contiguous()

which will raise another error, since you cannot “call” a tensor.
Could you explain, what this line of code should do?