Python data.Ids2Words() Examples
The following are 25
code examples of data.Ids2Words().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
data
, or try the search function
.
Example #1
Source File: seq2seq_attention_decode.py From HumanRecognition with MIT License | 6 votes |
def _DecodeBatch(self, article, abstract, output_ids): """Convert id to words and writing results. Args: article: The original article string. abstract: The human (correct) abstract string. output_ids: The abstract word ids output by machine. """ decoded_output = ' '.join(data.Ids2Words(output_ids, self._vocab)) end_p = decoded_output.find(data.SENTENCE_END, 0) if end_p != -1: decoded_output = decoded_output[:end_p] tf.logging.info('article: %s', article) tf.logging.info('abstract: %s', abstract) tf.logging.info('decoded: %s', decoded_output) self._decode_io.Write(abstract, decoded_output.strip())
Example #2
Source File: seq2seq_attention_decode.py From yolo_v2 with Apache License 2.0 | 6 votes |
def _DecodeBatch(self, article, abstract, output_ids): """Convert id to words and writing results. Args: article: The original article string. abstract: The human (correct) abstract string. output_ids: The abstract word ids output by machine. """ decoded_output = ' '.join(data.Ids2Words(output_ids, self._vocab)) end_p = decoded_output.find(data.SENTENCE_END, 0) if end_p != -1: decoded_output = decoded_output[:end_p] tf.logging.info('article: %s', article) tf.logging.info('abstract: %s', abstract) tf.logging.info('decoded: %s', decoded_output) self._decode_io.Write(abstract, decoded_output.strip())
Example #3
Source File: seq2seq_attention_decode.py From multilabel-image-classification-tensorflow with MIT License | 6 votes |
def _DecodeBatch(self, article, abstract, output_ids): """Convert id to words and writing results. Args: article: The original article string. abstract: The human (correct) abstract string. output_ids: The abstract word ids output by machine. """ decoded_output = ' '.join(data.Ids2Words(output_ids, self._vocab)) end_p = decoded_output.find(data.SENTENCE_END, 0) if end_p != -1: decoded_output = decoded_output[:end_p] tf.logging.info('article: %s', article) tf.logging.info('abstract: %s', abstract) tf.logging.info('decoded: %s', decoded_output) self._decode_io.Write(abstract, decoded_output.strip())
Example #4
Source File: seq2seq_attention_decode.py From Gun-Detector with Apache License 2.0 | 6 votes |
def _DecodeBatch(self, article, abstract, output_ids): """Convert id to words and writing results. Args: article: The original article string. abstract: The human (correct) abstract string. output_ids: The abstract word ids output by machine. """ decoded_output = ' '.join(data.Ids2Words(output_ids, self._vocab)) end_p = decoded_output.find(data.SENTENCE_END, 0) if end_p != -1: decoded_output = decoded_output[:end_p] tf.logging.info('article: %s', article) tf.logging.info('abstract: %s', abstract) tf.logging.info('decoded: %s', decoded_output) self._decode_io.Write(abstract, decoded_output.strip())
Example #5
Source File: seq2seq_attention_decode.py From object_detection_with_tensorflow with MIT License | 6 votes |
def _DecodeBatch(self, article, abstract, output_ids): """Convert id to words and writing results. Args: article: The original article string. abstract: The human (correct) abstract string. output_ids: The abstract word ids output by machine. """ decoded_output = ' '.join(data.Ids2Words(output_ids, self._vocab)) end_p = decoded_output.find(data.SENTENCE_END, 0) if end_p != -1: decoded_output = decoded_output[:end_p] tf.logging.info('article: %s', article) tf.logging.info('abstract: %s', abstract) tf.logging.info('decoded: %s', decoded_output) self._decode_io.Write(abstract, decoded_output.strip())
Example #6
Source File: seq2seq_attention_decode.py From models with Apache License 2.0 | 6 votes |
def _DecodeBatch(self, article, abstract, output_ids): """Convert id to words and writing results. Args: article: The original article string. abstract: The human (correct) abstract string. output_ids: The abstract word ids output by machine. """ decoded_output = ' '.join(data.Ids2Words(output_ids, self._vocab)) end_p = decoded_output.find(data.SENTENCE_END, 0) if end_p != -1: decoded_output = decoded_output[:end_p] tf.logging.info('article: %s', article) tf.logging.info('abstract: %s', abstract) tf.logging.info('decoded: %s', decoded_output) self._decode_io.Write(abstract, decoded_output.strip())
Example #7
Source File: seq2seq_attention_decode.py From Action_Recognition_Zoo with MIT License | 6 votes |
def _DecodeBatch(self, article, abstract, output_ids): """Convert id to words and writing results. Args: article: The original article string. abstract: The human (correct) abstract string. output_ids: The abstract word ids output by machine. """ decoded_output = ' '.join(data.Ids2Words(output_ids, self._vocab)) end_p = decoded_output.find(data.SENTENCE_END, 0) if end_p != -1: decoded_output = decoded_output[:end_p] tf.logging.info('article: %s', article) tf.logging.info('abstract: %s', abstract) tf.logging.info('decoded: %s', decoded_output) self._decode_io.Write(abstract, decoded_output.strip())
Example #8
Source File: seq2seq_attention_decode.py From ECO-pytorch with BSD 2-Clause "Simplified" License | 6 votes |
def _DecodeBatch(self, article, abstract, output_ids): """Convert id to words and writing results. Args: article: The original article string. abstract: The human (correct) abstract string. output_ids: The abstract word ids output by machine. """ decoded_output = ' '.join(data.Ids2Words(output_ids, self._vocab)) end_p = decoded_output.find(data.SENTENCE_END, 0) if end_p != -1: decoded_output = decoded_output[:end_p] tf.logging.info('article: %s', article) tf.logging.info('abstract: %s', abstract) tf.logging.info('decoded: %s', decoded_output) self._decode_io.Write(abstract, decoded_output.strip())
Example #9
Source File: seq2seq_attention_decode.py From g-tensorflow-models with Apache License 2.0 | 6 votes |
def _DecodeBatch(self, article, abstract, output_ids): """Convert id to words and writing results. Args: article: The original article string. abstract: The human (correct) abstract string. output_ids: The abstract word ids output by machine. """ decoded_output = ' '.join(data.Ids2Words(output_ids, self._vocab)) end_p = decoded_output.find(data.SENTENCE_END, 0) if end_p != -1: decoded_output = decoded_output[:end_p] tf.logging.info('article: %s', article) tf.logging.info('abstract: %s', abstract) tf.logging.info('decoded: %s', decoded_output) self._decode_io.Write(abstract, decoded_output.strip())
Example #10
Source File: seq2seq_attention_decode.py From hands-detection with MIT License | 6 votes |
def _DecodeBatch(self, article, abstract, output_ids): """Convert id to words and writing results. Args: article: The original article string. abstract: The human (correct) abstract string. output_ids: The abstract word ids output by machine. """ decoded_output = ' '.join(data.Ids2Words(output_ids, self._vocab)) end_p = decoded_output.find(data.SENTENCE_END, 0) if end_p != -1: decoded_output = decoded_output[:end_p] tf.logging.info('article: %s', article) tf.logging.info('abstract: %s', abstract) tf.logging.info('decoded: %s', decoded_output) self._decode_io.Write(abstract, decoded_output.strip())
Example #11
Source File: seq2seq_attention_decode.py From DOTA_models with Apache License 2.0 | 6 votes |
def _DecodeBatch(self, article, abstract, output_ids): """Convert id to words and writing results. Args: article: The original article string. abstract: The human (correct) abstract string. output_ids: The abstract word ids output by machine. """ decoded_output = ' '.join(data.Ids2Words(output_ids, self._vocab)) end_p = decoded_output.find(data.SENTENCE_END, 0) if end_p != -1: decoded_output = decoded_output[:end_p] tf.logging.info('article: %s', article) tf.logging.info('abstract: %s', abstract) tf.logging.info('decoded: %s', decoded_output) self._decode_io.Write(abstract, decoded_output.strip())
Example #12
Source File: seq2seq_attention_decode.py From object_detection_kitti with Apache License 2.0 | 6 votes |
def _DecodeBatch(self, article, abstract, output_ids): """Convert id to words and writing results. Args: article: The original article string. abstract: The human (correct) abstract string. output_ids: The abstract word ids output by machine. """ decoded_output = ' '.join(data.Ids2Words(output_ids, self._vocab)) end_p = decoded_output.find(data.SENTENCE_END, 0) if end_p != -1: decoded_output = decoded_output[:end_p] tf.logging.info('article: %s', article) tf.logging.info('abstract: %s', abstract) tf.logging.info('decoded: %s', decoded_output) self._decode_io.Write(abstract, decoded_output.strip())
Example #13
Source File: seq2seq_attention.py From g-tensorflow-models with Apache License 2.0 | 5 votes |
def _Eval(model, data_batcher, vocab=None): """Runs model eval.""" model.build_graph() saver = tf.train.Saver() summary_writer = tf.summary.FileWriter(FLAGS.eval_dir) sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) running_avg_loss = 0 step = 0 while True: time.sleep(FLAGS.eval_interval_secs) try: ckpt_state = tf.train.get_checkpoint_state(FLAGS.log_root) except tf.errors.OutOfRangeError as e: tf.logging.error('Cannot restore checkpoint: %s', e) continue if not (ckpt_state and ckpt_state.model_checkpoint_path): tf.logging.info('No model to eval yet at %s', FLAGS.train_dir) continue tf.logging.info('Loading checkpoint %s', ckpt_state.model_checkpoint_path) saver.restore(sess, ckpt_state.model_checkpoint_path) (article_batch, abstract_batch, targets, article_lens, abstract_lens, loss_weights, _, _) = data_batcher.NextBatch() (summaries, loss, train_step) = model.run_eval_step( sess, article_batch, abstract_batch, targets, article_lens, abstract_lens, loss_weights) tf.logging.info( 'article: %s', ' '.join(data.Ids2Words(article_batch[0][:].tolist(), vocab))) tf.logging.info( 'abstract: %s', ' '.join(data.Ids2Words(abstract_batch[0][:].tolist(), vocab))) summary_writer.add_summary(summaries, train_step) running_avg_loss = _RunningAvgLoss( running_avg_loss, loss, summary_writer, train_step) if step % 100 == 0: summary_writer.flush()
Example #14
Source File: seq2seq_attention.py From HumanRecognition with MIT License | 5 votes |
def _Eval(model, data_batcher, vocab=None): """Runs model eval.""" model.build_graph() saver = tf.train.Saver() summary_writer = tf.summary.FileWriter(FLAGS.eval_dir) sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) running_avg_loss = 0 step = 0 while True: time.sleep(FLAGS.eval_interval_secs) try: ckpt_state = tf.train.get_checkpoint_state(FLAGS.log_root) except tf.errors.OutOfRangeError as e: tf.logging.error('Cannot restore checkpoint: %s', e) continue if not (ckpt_state and ckpt_state.model_checkpoint_path): tf.logging.info('No model to eval yet at %s', FLAGS.train_dir) continue tf.logging.info('Loading checkpoint %s', ckpt_state.model_checkpoint_path) saver.restore(sess, ckpt_state.model_checkpoint_path) (article_batch, abstract_batch, targets, article_lens, abstract_lens, loss_weights, _, _) = data_batcher.NextBatch() (summaries, loss, train_step) = model.run_eval_step( sess, article_batch, abstract_batch, targets, article_lens, abstract_lens, loss_weights) tf.logging.info( 'article: %s', ' '.join(data.Ids2Words(article_batch[0][:].tolist(), vocab))) tf.logging.info( 'abstract: %s', ' '.join(data.Ids2Words(abstract_batch[0][:].tolist(), vocab))) summary_writer.add_summary(summaries, train_step) running_avg_loss = _RunningAvgLoss( running_avg_loss, loss, summary_writer, train_step) if step % 100 == 0: summary_writer.flush()
Example #15
Source File: seq2seq_attention.py From hands-detection with MIT License | 5 votes |
def _Eval(model, data_batcher, vocab=None): """Runs model eval.""" model.build_graph() saver = tf.train.Saver() summary_writer = tf.summary.FileWriter(FLAGS.eval_dir) sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) running_avg_loss = 0 step = 0 while True: time.sleep(FLAGS.eval_interval_secs) try: ckpt_state = tf.train.get_checkpoint_state(FLAGS.log_root) except tf.errors.OutOfRangeError as e: tf.logging.error('Cannot restore checkpoint: %s', e) continue if not (ckpt_state and ckpt_state.model_checkpoint_path): tf.logging.info('No model to eval yet at %s', FLAGS.train_dir) continue tf.logging.info('Loading checkpoint %s', ckpt_state.model_checkpoint_path) saver.restore(sess, ckpt_state.model_checkpoint_path) (article_batch, abstract_batch, targets, article_lens, abstract_lens, loss_weights, _, _) = data_batcher.NextBatch() (summaries, loss, train_step) = model.run_eval_step( sess, article_batch, abstract_batch, targets, article_lens, abstract_lens, loss_weights) tf.logging.info( 'article: %s', ' '.join(data.Ids2Words(article_batch[0][:].tolist(), vocab))) tf.logging.info( 'abstract: %s', ' '.join(data.Ids2Words(abstract_batch[0][:].tolist(), vocab))) summary_writer.add_summary(summaries, train_step) running_avg_loss = _RunningAvgLoss( running_avg_loss, loss, summary_writer, train_step) if step % 100 == 0: summary_writer.flush()
Example #16
Source File: seq2seq_attention.py From models with Apache License 2.0 | 5 votes |
def _Eval(model, data_batcher, vocab=None): """Runs model eval.""" model.build_graph() saver = tf.train.Saver() summary_writer = tf.summary.FileWriter(FLAGS.eval_dir) sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) running_avg_loss = 0 step = 0 while True: time.sleep(FLAGS.eval_interval_secs) try: ckpt_state = tf.train.get_checkpoint_state(FLAGS.log_root) except tf.errors.OutOfRangeError as e: tf.logging.error('Cannot restore checkpoint: %s', e) continue if not (ckpt_state and ckpt_state.model_checkpoint_path): tf.logging.info('No model to eval yet at %s', FLAGS.train_dir) continue tf.logging.info('Loading checkpoint %s', ckpt_state.model_checkpoint_path) saver.restore(sess, ckpt_state.model_checkpoint_path) (article_batch, abstract_batch, targets, article_lens, abstract_lens, loss_weights, _, _) = data_batcher.NextBatch() (summaries, loss, train_step) = model.run_eval_step( sess, article_batch, abstract_batch, targets, article_lens, abstract_lens, loss_weights) tf.logging.info( 'article: %s', ' '.join(data.Ids2Words(article_batch[0][:].tolist(), vocab))) tf.logging.info( 'abstract: %s', ' '.join(data.Ids2Words(abstract_batch[0][:].tolist(), vocab))) summary_writer.add_summary(summaries, train_step) running_avg_loss = _RunningAvgLoss( running_avg_loss, loss, summary_writer, train_step) if step % 100 == 0: summary_writer.flush()
Example #17
Source File: seq2seq_attention.py From multilabel-image-classification-tensorflow with MIT License | 5 votes |
def _Eval(model, data_batcher, vocab=None): """Runs model eval.""" model.build_graph() saver = tf.train.Saver() summary_writer = tf.summary.FileWriter(FLAGS.eval_dir) sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) running_avg_loss = 0 step = 0 while True: time.sleep(FLAGS.eval_interval_secs) try: ckpt_state = tf.train.get_checkpoint_state(FLAGS.log_root) except tf.errors.OutOfRangeError as e: tf.logging.error('Cannot restore checkpoint: %s', e) continue if not (ckpt_state and ckpt_state.model_checkpoint_path): tf.logging.info('No model to eval yet at %s', FLAGS.train_dir) continue tf.logging.info('Loading checkpoint %s', ckpt_state.model_checkpoint_path) saver.restore(sess, ckpt_state.model_checkpoint_path) (article_batch, abstract_batch, targets, article_lens, abstract_lens, loss_weights, _, _) = data_batcher.NextBatch() (summaries, loss, train_step) = model.run_eval_step( sess, article_batch, abstract_batch, targets, article_lens, abstract_lens, loss_weights) tf.logging.info( 'article: %s', ' '.join(data.Ids2Words(article_batch[0][:].tolist(), vocab))) tf.logging.info( 'abstract: %s', ' '.join(data.Ids2Words(abstract_batch[0][:].tolist(), vocab))) summary_writer.add_summary(summaries, train_step) running_avg_loss = _RunningAvgLoss( running_avg_loss, loss, summary_writer, train_step) if step % 100 == 0: summary_writer.flush()
Example #18
Source File: seq2seq_attention.py From object_detection_with_tensorflow with MIT License | 5 votes |
def _Eval(model, data_batcher, vocab=None): """Runs model eval.""" model.build_graph() saver = tf.train.Saver() summary_writer = tf.summary.FileWriter(FLAGS.eval_dir) sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) running_avg_loss = 0 step = 0 while True: time.sleep(FLAGS.eval_interval_secs) try: ckpt_state = tf.train.get_checkpoint_state(FLAGS.log_root) except tf.errors.OutOfRangeError as e: tf.logging.error('Cannot restore checkpoint: %s', e) continue if not (ckpt_state and ckpt_state.model_checkpoint_path): tf.logging.info('No model to eval yet at %s', FLAGS.train_dir) continue tf.logging.info('Loading checkpoint %s', ckpt_state.model_checkpoint_path) saver.restore(sess, ckpt_state.model_checkpoint_path) (article_batch, abstract_batch, targets, article_lens, abstract_lens, loss_weights, _, _) = data_batcher.NextBatch() (summaries, loss, train_step) = model.run_eval_step( sess, article_batch, abstract_batch, targets, article_lens, abstract_lens, loss_weights) tf.logging.info( 'article: %s', ' '.join(data.Ids2Words(article_batch[0][:].tolist(), vocab))) tf.logging.info( 'abstract: %s', ' '.join(data.Ids2Words(abstract_batch[0][:].tolist(), vocab))) summary_writer.add_summary(summaries, train_step) running_avg_loss = _RunningAvgLoss( running_avg_loss, loss, summary_writer, train_step) if step % 100 == 0: summary_writer.flush()
Example #19
Source File: seq2seq_attention.py From object_detection_kitti with Apache License 2.0 | 5 votes |
def _Eval(model, data_batcher, vocab=None): """Runs model eval.""" model.build_graph() saver = tf.train.Saver() summary_writer = tf.summary.FileWriter(FLAGS.eval_dir) sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) running_avg_loss = 0 step = 0 while True: time.sleep(FLAGS.eval_interval_secs) try: ckpt_state = tf.train.get_checkpoint_state(FLAGS.log_root) except tf.errors.OutOfRangeError as e: tf.logging.error('Cannot restore checkpoint: %s', e) continue if not (ckpt_state and ckpt_state.model_checkpoint_path): tf.logging.info('No model to eval yet at %s', FLAGS.train_dir) continue tf.logging.info('Loading checkpoint %s', ckpt_state.model_checkpoint_path) saver.restore(sess, ckpt_state.model_checkpoint_path) (article_batch, abstract_batch, targets, article_lens, abstract_lens, loss_weights, _, _) = data_batcher.NextBatch() (summaries, loss, train_step) = model.run_eval_step( sess, article_batch, abstract_batch, targets, article_lens, abstract_lens, loss_weights) tf.logging.info( 'article: %s', ' '.join(data.Ids2Words(article_batch[0][:].tolist(), vocab))) tf.logging.info( 'abstract: %s', ' '.join(data.Ids2Words(abstract_batch[0][:].tolist(), vocab))) summary_writer.add_summary(summaries, train_step) running_avg_loss = _RunningAvgLoss( running_avg_loss, loss, summary_writer, train_step) if step % 100 == 0: summary_writer.flush()
Example #20
Source File: seq2seq_attention.py From ECO-pytorch with BSD 2-Clause "Simplified" License | 5 votes |
def _Eval(model, data_batcher, vocab=None): """Runs model eval.""" model.build_graph() saver = tf.train.Saver() summary_writer = tf.train.SummaryWriter(FLAGS.eval_dir) sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) running_avg_loss = 0 step = 0 while True: time.sleep(FLAGS.eval_interval_secs) try: ckpt_state = tf.train.get_checkpoint_state(FLAGS.log_root) except tf.errors.OutOfRangeError as e: tf.logging.error('Cannot restore checkpoint: %s', e) continue if not (ckpt_state and ckpt_state.model_checkpoint_path): tf.logging.info('No model to eval yet at %s', FLAGS.train_dir) continue tf.logging.info('Loading checkpoint %s', ckpt_state.model_checkpoint_path) saver.restore(sess, ckpt_state.model_checkpoint_path) (article_batch, abstract_batch, targets, article_lens, abstract_lens, loss_weights, _, _) = data_batcher.NextBatch() (summaries, loss, train_step) = model.run_eval_step( sess, article_batch, abstract_batch, targets, article_lens, abstract_lens, loss_weights) tf.logging.info( 'article: %s', ' '.join(data.Ids2Words(article_batch[0][:].tolist(), vocab))) tf.logging.info( 'abstract: %s', ' '.join(data.Ids2Words(abstract_batch[0][:].tolist(), vocab))) summary_writer.add_summary(summaries, train_step) running_avg_loss = _RunningAvgLoss( running_avg_loss, loss, summary_writer, train_step) if step % 100 == 0: summary_writer.flush()
Example #21
Source File: seq2seq_attention.py From Action_Recognition_Zoo with MIT License | 5 votes |
def _Eval(model, data_batcher, vocab=None): """Runs model eval.""" model.build_graph() saver = tf.train.Saver() summary_writer = tf.train.SummaryWriter(FLAGS.eval_dir) sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) running_avg_loss = 0 step = 0 while True: time.sleep(FLAGS.eval_interval_secs) try: ckpt_state = tf.train.get_checkpoint_state(FLAGS.log_root) except tf.errors.OutOfRangeError as e: tf.logging.error('Cannot restore checkpoint: %s', e) continue if not (ckpt_state and ckpt_state.model_checkpoint_path): tf.logging.info('No model to eval yet at %s', FLAGS.train_dir) continue tf.logging.info('Loading checkpoint %s', ckpt_state.model_checkpoint_path) saver.restore(sess, ckpt_state.model_checkpoint_path) (article_batch, abstract_batch, targets, article_lens, abstract_lens, loss_weights, _, _) = data_batcher.NextBatch() (summaries, loss, train_step) = model.run_eval_step( sess, article_batch, abstract_batch, targets, article_lens, abstract_lens, loss_weights) tf.logging.info( 'article: %s', ' '.join(data.Ids2Words(article_batch[0][:].tolist(), vocab))) tf.logging.info( 'abstract: %s', ' '.join(data.Ids2Words(abstract_batch[0][:].tolist(), vocab))) summary_writer.add_summary(summaries, train_step) running_avg_loss = _RunningAvgLoss( running_avg_loss, loss, summary_writer, train_step) if step % 100 == 0: summary_writer.flush()
Example #22
Source File: seq2seq_attention.py From Gun-Detector with Apache License 2.0 | 5 votes |
def _Eval(model, data_batcher, vocab=None): """Runs model eval.""" model.build_graph() saver = tf.train.Saver() summary_writer = tf.summary.FileWriter(FLAGS.eval_dir) sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) running_avg_loss = 0 step = 0 while True: time.sleep(FLAGS.eval_interval_secs) try: ckpt_state = tf.train.get_checkpoint_state(FLAGS.log_root) except tf.errors.OutOfRangeError as e: tf.logging.error('Cannot restore checkpoint: %s', e) continue if not (ckpt_state and ckpt_state.model_checkpoint_path): tf.logging.info('No model to eval yet at %s', FLAGS.train_dir) continue tf.logging.info('Loading checkpoint %s', ckpt_state.model_checkpoint_path) saver.restore(sess, ckpt_state.model_checkpoint_path) (article_batch, abstract_batch, targets, article_lens, abstract_lens, loss_weights, _, _) = data_batcher.NextBatch() (summaries, loss, train_step) = model.run_eval_step( sess, article_batch, abstract_batch, targets, article_lens, abstract_lens, loss_weights) tf.logging.info( 'article: %s', ' '.join(data.Ids2Words(article_batch[0][:].tolist(), vocab))) tf.logging.info( 'abstract: %s', ' '.join(data.Ids2Words(abstract_batch[0][:].tolist(), vocab))) summary_writer.add_summary(summaries, train_step) running_avg_loss = _RunningAvgLoss( running_avg_loss, loss, summary_writer, train_step) if step % 100 == 0: summary_writer.flush()
Example #23
Source File: seq2seq_attention.py From yolo_v2 with Apache License 2.0 | 5 votes |
def _Eval(model, data_batcher, vocab=None): """Runs model eval.""" model.build_graph() saver = tf.train.Saver() summary_writer = tf.summary.FileWriter(FLAGS.eval_dir) sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) running_avg_loss = 0 step = 0 while True: time.sleep(FLAGS.eval_interval_secs) try: ckpt_state = tf.train.get_checkpoint_state(FLAGS.log_root) except tf.errors.OutOfRangeError as e: tf.logging.error('Cannot restore checkpoint: %s', e) continue if not (ckpt_state and ckpt_state.model_checkpoint_path): tf.logging.info('No model to eval yet at %s', FLAGS.train_dir) continue tf.logging.info('Loading checkpoint %s', ckpt_state.model_checkpoint_path) saver.restore(sess, ckpt_state.model_checkpoint_path) (article_batch, abstract_batch, targets, article_lens, abstract_lens, loss_weights, _, _) = data_batcher.NextBatch() (summaries, loss, train_step) = model.run_eval_step( sess, article_batch, abstract_batch, targets, article_lens, abstract_lens, loss_weights) tf.logging.info( 'article: %s', ' '.join(data.Ids2Words(article_batch[0][:].tolist(), vocab))) tf.logging.info( 'abstract: %s', ' '.join(data.Ids2Words(abstract_batch[0][:].tolist(), vocab))) summary_writer.add_summary(summaries, train_step) running_avg_loss = _RunningAvgLoss( running_avg_loss, loss, summary_writer, train_step) if step % 100 == 0: summary_writer.flush()
Example #24
Source File: seq2seq_attention.py From DOTA_models with Apache License 2.0 | 5 votes |
def _Eval(model, data_batcher, vocab=None): """Runs model eval.""" model.build_graph() saver = tf.train.Saver() summary_writer = tf.summary.FileWriter(FLAGS.eval_dir) sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) running_avg_loss = 0 step = 0 while True: time.sleep(FLAGS.eval_interval_secs) try: ckpt_state = tf.train.get_checkpoint_state(FLAGS.log_root) except tf.errors.OutOfRangeError as e: tf.logging.error('Cannot restore checkpoint: %s', e) continue if not (ckpt_state and ckpt_state.model_checkpoint_path): tf.logging.info('No model to eval yet at %s', FLAGS.train_dir) continue tf.logging.info('Loading checkpoint %s', ckpt_state.model_checkpoint_path) saver.restore(sess, ckpt_state.model_checkpoint_path) (article_batch, abstract_batch, targets, article_lens, abstract_lens, loss_weights, _, _) = data_batcher.NextBatch() (summaries, loss, train_step) = model.run_eval_step( sess, article_batch, abstract_batch, targets, article_lens, abstract_lens, loss_weights) tf.logging.info( 'article: %s', ' '.join(data.Ids2Words(article_batch[0][:].tolist(), vocab))) tf.logging.info( 'abstract: %s', ' '.join(data.Ids2Words(abstract_batch[0][:].tolist(), vocab))) summary_writer.add_summary(summaries, train_step) running_avg_loss = _RunningAvgLoss( running_avg_loss, loss, summary_writer, train_step) if step % 100 == 0: summary_writer.flush()
Example #25
Source File: decode.py From text2text with Apache License 2.0 | 4 votes |
def _DecodeBatch(self, source, targets, dec_outputs): """Converts id to words and writes results. Args: source: The original source string. targets: The human (correct) target string. dec_outputs: The target word ids output by machine. Returns: List of metric scores for this batch. """ output = ['None'] * len(dec_outputs) source_words = source.split() for i in range(len(dec_outputs)): if dec_outputs[i] < 0: # it's from copier position = -1 - dec_outputs[i] if position < len(source_words): output[i] = source_words[position] else: output[i] = '<out_of_bound>' elif dec_outputs[i] >= 0: # it's from generator or unk (if 0) output[i] = data.Ids2Words([dec_outputs[i]], self._output_vocab)[0] source = source.replace(data.SENTENCE_START + ' ', '').replace( ' ' + data.SENTENCE_END, '') targets = [ x.replace(data.SENTENCE_START + ' ', '').replace( ' ' + data.SENTENCE_END, '') for x in targets ] decoded = ' '.join(output) end_p = decoded.find(data.SENTENCE_END, 0) if end_p != -1: decoded = decoded[:end_p].strip() bleu_score = metrics.get_bleu(decoded, targets) f1_score = metrics.get_f1(decoded, targets) exact_score = metrics.get_exact(decoded, targets) self._decode_io.Write(source, targets, decoded, bleu_score, f1_score, exact_score) return bleu_score, f1_score, exact_score