The application provides a translation method and device, wherein the translation method comprises: obtaining a
sentence to be translated; inputting the
sentence to be translated into a translation model to obtain a translated
sentence corresponding to the sentence to be translated, wherein the translation model comprises an encoding layer and a weight layer, the encoding layer comprises at least one first stack layer, the first stack layer comprises a multi-head attention mechanism sublayer and a feedforward
network layer, and the weight layer is used to generate a weight vector according to at least one encoding vector output by the encoding layer and a
weight coefficient corresponding to each encoding vector, and the weight vector is used to generate the translated sentence. Since the translation model comprises the multi-head attention mechanism sublayer, richer information can be obtained by introducing the attention mechanism, so that the weight corresponding to each first stack layer is adjusted, the architecture of the translation model is optimized, and the translation effect of the sentence to be translated is further improved in the use process of the translation model.