Closed natkramarz closed 1 year ago
@natkramarz Can you try the following:
public NDList processInput(TranslatorContext ctx, Float input) {
NDManager manager = ctx.getNDManager();
NDArray categoryArray = manager.zeros(new Shape(18));
NDArray inputArray = manager.zeros(new Shape(59));
NDArray hiddenArray = manager.zeros(new Shape(128));
return new NDList(categoryArray, inputArray, hiddenArray);
}
DJL will automatically create batch dimension for you. If you want to manual batch the input, you can extend from NoBatchifyTranslator
:
public class InputTranslator implements NoBatchifyTranslator<Float, Float> {
...
}
Thank you, both ways work :)
Description
TorchScript cannot concatenate tensors of different sizes.
Expected Behavior
for
torch.cat([category, input, hidden], 1)
should produce tensor of shape (1, 18 + 59 + 128)Error Message
How to Reproduce?
Steps to reproduce
class RNN(nn.Module): def init(self, input_size, hidden_size, output_size): super(RNN, self).init()
model = RNN(n_letters, 128, n_letters) model.eval() def sample(category, start_letter='A'): with torch.no_grad(): category = category_tensor(category) input = input_tensor(start_letter) hidden = rnn.initHidden()
sample('german', 'R')
Translator and RandomNameFromRNN classes:
What have you tried to solve it?
Environment Info
Please run the command
./gradlew debugEnv
from the root directory of DJL (if necessary, clone DJL first). It will output information about your system, environment, and installation that can help us debug your issue. Paste the output of the command below: