Abstract: A system and method for training a neural network model includes obtaining, by a processing device, a document image containing raw text, tokenizing the raw text in the document image to obtain tokens located in a plurality of rows, identifying a first token in one of the plurality of rows, calculating a horizontal language feature of the first token based on the first token and one or more tokens in the row, and encoding, using a first encoder, the horizontal language feature into a horizontal language embedding, calculating a vertical language feature of the first token based on the token and one or more tokens in rows above or below the row, and encoding, using a second encoder, the vertical language feature into a vertical language embedding, and training a neural network model using the horizontal language embeddings and the vertical language embeddings.