Esempio n. 1
0
 def get_html(self, generated, image_format='bmp', image_dir=''):
     id2word = self.vocabulary(value_type='language')
     questions = generated['question']
     question_lengths = generated['question_length']
     answers = generated['answer']
     answer_lengths = generated['answer_length']
     data_html = list()
     for n, (question, question_length, answer, answer_length) in enumerate(
             zip(questions, question_lengths, answers, answer_lengths)):
         data_html.append(
             '<div class="instance"><div class="world"><img src="{image_dir}world-{world}.{format}" alt="world-{world}.{format}"></div><div class="num"><p><b>({num})</b></p></div><div class="questions">'
             .format(image_dir=image_dir,
                     world=n,
                     format=image_format,
                     num=(n + 1)))
         for question, question_length, answer, answer_length in zip(
                 question, question_length, answer, answer_length):
             data_html.append(
                 '<p>{question}&ensp;&ndash;&ensp;{answer}</p>'.format(
                     question=util.tokens2string(
                         id2word[word]
                         for word in question[:question_length]),
                     answer=util.tokens2string(
                         id2word[word] for word in answer[:answer_length])))
         data_html.append('</div></div>')
     html = '<!DOCTYPE html><html><head><title>{dtype} {name}</title><style>.data{{width: 100%; height: 100%;}} .instance{{width: 100%; margin-top: 1px; margin-bottom: 1px; background-color: #DDEEFF;}} .world{{height: {world_height}px; display: inline-block; vertical-align: middle;}} .num{{display: inline-block; vertical-align: middle; margin-left: 10px;}} .questions{{display: inline-block; vertical-align: middle; margin-left: 10px;}}</style></head><body><div class="data">{data}</div></body></html>'.format(
         dtype=self.type,
         name=self.name,
         world_height=self.world_shape[0],
         data=''.join(data_html))
     return html
Esempio n. 2
0
 def get_html(self, generated):
     id2word = self.vocabulary(value_type='language')
     descriptions = generated['description']
     description_lengths = generated['description_length']
     agreements = generated['agreement']
     data_html = list()
     for n, (description, description_length, agreement) in enumerate(
             zip(descriptions, description_lengths, agreements)):
         if agreement == 1.0:
             agreement = 'correct'
         elif agreement == 0.0:
             agreement = 'incorrect'
         else:
             assert False
         data_html.append(
             '<div class="{agreement}"><div class="world"><img src="world1-{world}.bmp" alt="world1-{world}.bmp"></div><div class="vertical"></div><div class="world"><img src="world2-{world}.bmp" alt="world2-{world}.bmp"></div><div class="vertical"></div><div class="world"><img src="world3-{world}.bmp" alt="world3-{world}.bmp"></div><div class="num"><p><b>({num})</b></p></div><div class="description"><p>{description}</p></div></div>'
             .format(agreement=agreement,
                     world=n,
                     num=(n + 1),
                     description=util.tokens2string(
                         id2word[word]
                         for word in description[:description_length])))
     html = '<!DOCTYPE html><html><head><title>{dtype} {name}</title><style>.data{{width: 100%; height: 100%;}} .correct{{width: 100%; margin-top: 1px; margin-bottom: 1px; background-color: #BBFFBB;}} .incorrect{{width: 100%; margin-top: 1px; margin-bottom: 1px; background-color: #FFBBBB;}} .world{{height: {world_height}px; display: inline-block; vertical-align: middle;}} .vertical{{display: inline-block; width: 1px; height: {world_height}px; background-color: #777777; vertical-align: middle;}} .num{{display: inline-block; vertical-align: middle; margin-left: 10px;}} .description{{display: inline-block; vertical-align: middle; margin-left: 10px;}}</style></head><body><div class="data">{data}</div></body></html>'.format(
         dtype=self.type,
         name=self.name,
         world_height=self.world_shape[0],
         data=''.join(data_html))
     return html
Esempio n. 3
0
 def get_html(self, generated, id2word):
     captions = generated['caption']
     caption_lengths = generated['caption_length']
     agreements = generated['agreement']
     data_html = list()
     for n, (caption, caption_length, agreement) in enumerate(
             zip(captions, caption_lengths, agreements)):
         if agreement == 1.0:
             agreement = 'correct'
         elif agreement == 0.0:
             agreement = 'incorrect'
         else:
             agreement = 'ambiguous'
         data_html.append(
             '<div class="{agreement}"><div class="world"><img src="world-{world}.bmp" alt="world-{world}.bmp"></div><div class="caption"><p>{caption}</p></div></div>'
             .format(agreement=agreement,
                     world=n,
                     caption=util.tokens2string(
                         id2word[word]
                         for word in caption[:caption_length])))
     html = '<!DOCTYPE html><html><head><title>{dtype} {name}</title><style>.data{{width: 100%; height: 100%;}} .correct{{width: 100%; margin-top: 1px; margin-bottom: 1px; background-color: #BBFFBB;}} .incorrect{{width: 100%; margin-top: 1px; margin-bottom: 1px; background-color: #FFBBBB;}} .ambiguous{{width: 100%; margin-top: 1px; margin-bottom: 1px; background-color: #FFFFBB;}} .world{{height: {world_height}px; display: inline-block; vertical-align: middle;}} .caption{{display: inline-block; vertical-align: middle; margin-left: 10px;}}</style></head><body><div class="data">{data}</div></body></html>'.format(
         dtype=self.type,
         name=self.name,
         world_height=self.world_shape[0],
         data=''.join(data_html))
     return html
Esempio n. 4
0
 def get_html(self, generated, id2word):
     questions = generated['question']
     question_lengths = generated['question_length']
     answers = generated['answer']
     data_html = list()
     for n, (question, question_length, answer) in enumerate(zip(questions, question_lengths, answers)):
         data_html.append('<div class="instance"><div class="world"><img src="world-{world}.bmp" alt="world-{world}.bmp"></div><div class="questions">'.format(world=n))
         for question, question_length, answer in zip(question, question_length, answer):
             data_html.append('<p>{question}&ensp;&ndash;&ensp;{answer}</p>'.format(
                 question=util.tokens2string(id2word[word] for word in question[:question_length]),
                 answer=self.answers[answer]
             ))
         data_html.append('</div></div>')
     html = '<!DOCTYPE html><html><head><title>{dtype} {name}</title><style>.data{{width: 100%; height: 100%;}} .instance{{width: 100%; margin-top: 1px; margin-bottom: 1px; background-color: #CCCCCC;}} .world{{height: {world_height}px; display: inline-block; vertical-align: middle;}} .questions{{display: inline-block; vertical-align: middle; margin-left: 10px;}}</style></head><body><div class="data">{data}</div></body></html>'.format(
         dtype=self.type,
         name=self.name,
         world_height=self.world_shape[0],
         data=''.join(data_html)
     )
     return html