In [1]:
import numpy as np
import re
from IPython.display import display, Math, Latex, Image
In [8]:
import numpy as np
imgs = np.load('pred_imgs.npy')
preds = np.load('pred_latex.npy')
properties = np.load('properties.npy').tolist()
displayPreds = lambda Y: display(Math(Y.split('#END')[0]))
idx_to_chars = lambda Y: ' '.join(map(lambda x: properties['idx_to_char'][x],Y))
#displayIdxs = lambda Y: display(Math(''.join(map(lambda x: properties['idx_to_char'][x],Y))))
In [9]:
import PIL.Image
from cStringIO import StringIO
import IPython.display
import numpy as np
def showarray(a, fmt='png'):
    a = np.uint8(a)
    f = StringIO()
    PIL.Image.fromarray(a).save(f, fmt)
    IPython.display.display(IPython.display.Image(data=f.getvalue()))
In [10]:
batch_size=16
from PIL import Image as Img
for i in xrange(batch_size):
    preds_chars = idx_to_chars(preds[i,1:]).replace('$','')
    print "Original (Input) Image: %d"%(i+1)
    showarray(imgs[i][0])
    print "Predicted Latex"
    print preds_chars.split('#END')[0]
    print "\nRendering the predicted latex"
    displayPreds(preds_chars)
    print "\n"
Original (Input) Image: 1
Predicted Latex
S _ { \mathrm { B R F } } ( { \cal M } , t ) = S _ { \mathrm { C a r a n } } + S _ { \mathrm { o f f - d i a g } } ~ , ~ ~ 

Rendering the predicted latex
$$S _ { \mathrm { B R F } } ( { \cal M } , t ) = S _ { \mathrm { C a r a n } } + S _ { \mathrm { o f f - d i a g } } ~ , ~ ~ $$

Original (Input) Image: 2
Predicted Latex
Z ( \Delta \beta ) = \int d { \bf r } \cdot \rho ( { \bf r } , \beta ; { \bf r } _ { 0 } , \beta _ { 0 } ) \mid _ { { \bf r } ( \beta ) = r ( { \beta } _ { 0 } ) } 

Rendering the predicted latex
$$Z ( \Delta \beta ) = \int d { \bf r } \cdot \rho ( { \bf r } , \beta ; { \bf r } _ { 0 } , \beta _ { 0 } ) \mid _ { { \bf r } ( \beta ) = r ( { \beta } _ { 0 } ) } $$

Original (Input) Image: 3
Predicted Latex
B _ { i } ^ { 2 } = ( d e t D ) ^ { - 1 } D _ { i j } [ v ^ { - 1 } e ^ { - \phi } E _ { j } ^ { 1 } + \psi B _ { j } ^ { 1 } ] . 

Rendering the predicted latex
$$B _ { i } ^ { 2 } = ( d e t D ) ^ { - 1 } D _ { i j } [ v ^ { - 1 } e ^ { - \phi } E _ { j } ^ { 1 } + \psi B _ { j } ^ { 1 } ] . $$

Original (Input) Image: 4
Predicted Latex
\beta _ { p p ^ { \prime } } ^ { 2 } - \beta _ { p p } \beta _ { p p ^ { \prime } } = 0 \qquad ( \mathrm { f o r ~ e v e r y } p , \, p ^ { \prime } ) , 

Rendering the predicted latex
$$\beta _ { p p ^ { \prime } } ^ { 2 } - \beta _ { p p } \beta _ { p p ^ { \prime } } = 0 \qquad ( \mathrm { f o r ~ e v e r y } p , \, p ^ { \prime } ) , $$

Original (Input) Image: 5
Predicted Latex
{ \cal Z } = { \cal W } [ \phi ( z = \infty ) ] - { \cal W } [ \phi ( z = - \infty ) ] \, . 

Rendering the predicted latex
$${ \cal Z } = { \cal W } [ \phi ( z = \infty ) ] - { \cal W } [ \phi ( z = - \infty ) ] \, . $$

Original (Input) Image: 6
Predicted Latex
( \delta _ { c a } \delta _ { b d } - \delta _ { c d } \delta _ { b a } ) = C _ { e c } C _ { a d } ^ { e } - C _ { e [ c b } C _ { a d } ^ { e } . 

Rendering the predicted latex
$$( \delta _ { c a } \delta _ { b d } - \delta _ { c d } \delta _ { b a } ) = C _ { e c } C _ { a d } ^ { e } - C _ { e [ c b } C _ { a d } ^ { e } . $$

Original (Input) Image: 7
Predicted Latex
V _ { - b / 2 } V _ { \alpha } = C _ { + } \left[ V _ { \alpha - b / 2 } \right] + C _ { - } \left[ V _ { \alpha + b / 2 } \right] 

Rendering the predicted latex
$$V _ { - b / 2 } V _ { \alpha } = C _ { + } \left[ V _ { \alpha - b / 2 } \right] + C _ { - } \left[ V _ { \alpha + b / 2 } \right] $$

Original (Input) Image: 8
Predicted Latex
( \delta _ { c a } \delta _ { b d } - \delta _ { c d } \delta _ { b a } ) = C _ { e c } C _ { a d } ^ { e } - C _ { e [ c b } C _ { a d } ^ { e } . 

Rendering the predicted latex
$$( \delta _ { c a } \delta _ { b d } - \delta _ { c d } \delta _ { b a } ) = C _ { e c } C _ { a d } ^ { e } - C _ { e [ c b } C _ { a d } ^ { e } . $$

Original (Input) Image: 9
Predicted Latex
I [ g , \Gamma ] = G ^ { 2 } \int ( R ^ { 2 } + G ^ { 2 } \Lambda ^ { 2 } ) ^ { 2 } \sqrt { g } d ^ { 4 } x 

Rendering the predicted latex
$$I [ g , \Gamma ] = G ^ { 2 } \int ( R ^ { 2 } + G ^ { 2 } \Lambda ^ { 2 } ) ^ { 2 } \sqrt { g } d ^ { 4 } x $$

Original (Input) Image: 10
Predicted Latex
S _ { f } ^ { f r e e } ( m ; \psi , \overline { { \psi } } ) = - [ \overline { { \psi } } \gamma ^ { \mu } \partial _ { \mu } \psi + m \overline { { \psi } } \psi ] . 

Rendering the predicted latex
$$S _ { f } ^ { f r e e } ( m ; \psi , \overline { { \psi } } ) = - [ \overline { { \psi } } \gamma ^ { \mu } \partial _ { \mu } \psi + m \overline { { \psi } } \psi ] . $$

Original (Input) Image: 11
Predicted Latex
e ^ { - T V ( R ) } \; = \int [ D \mathbf { u } ] \, e ^ { - { \cal A } _ { E [ \mathbf { u } ] } } , \; \; \; T \to \infty \, , 

Rendering the predicted latex
$$e ^ { - T V ( R ) } \; = \int [ D \mathbf { u } ] \, e ^ { - { \cal A } _ { E [ \mathbf { u } ] } } , \; \; \; T \to \infty \, , $$

Original (Input) Image: 12
Predicted Latex
{ \omega } _ { \mu ^ { \prime } } ^ { \; \; \; \; \; \; \; \; \; = - L _ { b } { } ^ { d } \left( \partial _ { \mu } L ^ { a } { } _ { d } ) + { L ^ { a } } _ { c } \, \omega _ { \mu } { } ^ { c } { _ { d } } \, L _ { b } { } ^ { d } \; . 

Rendering the predicted latex
$${ \omega } _ { \mu ^ { \prime } } ^ { \; \; \; \; \; \; \; \; \; = - L _ { b } { } ^ { d } \left( \partial _ { \mu } L ^ { a } { } _ { d } ) + { L ^ { a } } _ { c } \, \omega _ { \mu } { } ^ { c } { _ { d } } \, L _ { b } { } ^ { d } \; . $$

Original (Input) Image: 13
Predicted Latex
\psi _ { i } ( \sigma ) \psi _ { k } ( \rho ) = S _ { i } ^ { r s } \psi _ { r } ( \rho ) \psi _ { s } ( \sigma ) \quad , \dots 

Rendering the predicted latex
$$\psi _ { i } ( \sigma ) \psi _ { k } ( \rho ) = S _ { i } ^ { r s } \psi _ { r } ( \rho ) \psi _ { s } ( \sigma ) \quad , \dots $$

Original (Input) Image: 14
Predicted Latex
K _ { s t } \, \tilde { \beta } _ { s u } + K _ { s u } \, \tilde { \beta } _ { s t } = K _ { u t } \, \tilde { \beta } _ { u s } + K _ { u s } \, \tilde { \beta } _ { u t } , 

Rendering the predicted latex
$$K _ { s t } \, \tilde { \beta } _ { s u } + K _ { s u } \, \tilde { \beta } _ { s t } = K _ { u t } \, \tilde { \beta } _ { u s } + K _ { u s } \, \tilde { \beta } _ { u t } , $$

Original (Input) Image: 15
Predicted Latex
R _ { r e g } = \oplus _ { a = 1 } ^ { r } N _ { a } R ^ { a } , \quad N _ { a } = \mathrm { d i m } R ^ { a } 

Rendering the predicted latex
$$R _ { r e g } = \oplus _ { a = 1 } ^ { r } N _ { a } R ^ { a } , \quad N _ { a } = \mathrm { d i m } R ^ { a } $$

Original (Input) Image: 16
Predicted Latex
\delta \bar { Q } _ { \beta } = [ Q _ { \beta } , \bar { K } _ { \epsilon } ] = \bar { c } _ { i } \epsilon ^ { i j } ( i q _ { j } + \beta \partial _ { j } H ) , 

Rendering the predicted latex
$$\delta \bar { Q } _ { \beta } = [ Q _ { \beta } , \bar { K } _ { \epsilon } ] = \bar { c } _ { i } \epsilon ^ { i j } ( i q _ { j } + \beta \partial _ { j } H ) , $$

In [ ]: