# Which algorithm should I use to map an input sentence to an output sentence?

I am new to NLP realm. If you have an input text "The price of orange has increased" and output text "Increase the production of orange". Can we make our RNN model to predict the output text? Or what algorithm should I use?

• 2 ways really, both involve converting the input to a 1-hot input. Either convert each character to a 1 hot input (eg, of size 27, 26 in the alphabet, 1 for spaces), or convert each word to a 1 hot vector of the RNN's vocabulary, Sep 9, 2019 at 7:07
• @Recessive Old comment, I know, but: No, those are not the only ways. Another method that is extremely common is to segment text into subwords. Also, you are implying that this tasks needs to be solved with an RNN - which is not the case. May 6, 2020 at 7:28
• @MathiasMüller I fail to see where I implied only an RNN could be used, I only responded to the question on how to input the text to an RNN. When you say segment the text into subwords, would those subwords not be encoded in a 1-hot vector? How do you propose inputting ascii characters into a network that deosn't involve 1-hot encoding? May 6, 2020 at 17:28
• @Recessive "I fail to see where I implied only an RNN could be used" - you are right, I'm sorry about this! "How do you propose inputting ascii characters into a network that deosn't involve 1-hot encoding?" - my view is as follows: all you have to do is map characters/words/subwords to vocabulary indexes. Then those indexes can be replaced with their word embeddings, without constructing one-hot vectors. May 6, 2020 at 18:04
• @MathiasMüller From what I understand, you're saying that the input and output should be an individual number representing the index in the vocabulary? In that case the network would have to use regression to learn, which in my experience has always performed poorly compared to an equivalent solution using classification May 7, 2020 at 3:00

In your case you can use either RNN (especially BiLSTM with ELMo and attention mechanism for better accuracy) or Transformer based architectures (the best of them today is BERT). But for both cases you need data to train the model (i.e sequences of input/output like in your question).

I believe the best choice in your case is BERT as it's achieving state of the art performance in most NLP tasks and is already pretrained so you don't need a massive data to retrain the model. Also, BERT is pretrained on "Next Sentence Prediction" and allows "2 separate sentences" as input which helps a lot in your case. The only drawback, compared to other methods, is that you need fine-tuning the model so it's not a completly "ready to use" model.