Attach a lot of summaries to a Tensor (for TensorBoard visualization).
183669
def variable_summaries(var):
  """"""
  with tf.name_scope('summaries'):
    mean = tf.reduce_mean(var)
    tf.summary.scalar('mean', mean)
    with tf.name_scope('stddev'):
      stddev = tf.sqrt(tf.reduce_mean(tf.square(var - mean)))
    tf.summary.scalar('stddev', stddev)
    tf.summary.scalar('max', tf.reduce_max(var))
    tf.summary.scalar('min', tf.reduce_min(var))
    tf.summary.histogram('histogram', var)
487190
def get_summaries(ordered=True):
    """"""

    if ordered:
        cmditems = _sort_commands(commands_dict, commands_order)
    else:
        cmditems = commands_dict.items()

    for name, command_class in cmditems:
        yield (name, command_class.summary)
718514
def make_summaries(self):
        """"""
        self.summary_df = save_summaries(self.frames, self.keys,
                                         self.selected_summaries,
                                         self.batch_dir, self.name)
        logger.debug("made and saved summaries")
30448
def data_loader(self, sentences, shuffle=False):
        """"""
        dataset = BertEmbeddingDataset(sentences, self.transform)
        return DataLoader(dataset=dataset, batch_size=self.batch_size, shuffle=shuffle)
871911
def _merge_multi_context(outputs, major_axis):
    
    rets = []
    for tensors, axis in zip(outputs, major_axis):
        if axis >= 0:
            # pylint: disable=no-member,protected-access
            if len(tensors) == 1:
                rets.append(tensors[0])
            else:
                # Concatenate if necessary
                rets.append(nd.concat(*[tensor.as_in_context(tensors[0].context)
                                        for tensor in tensors],
                                      dim=axis))
            # pylint: enable=no-member,protected-access
        else:
            # negative axis means the there is no batch_size axis, and all the
            # results should be the same on each device. We simply take the
            # first one, without checking they are actually the same
            rets.append(tensors[0])
    return rets
114995
protected static void summarizeAndEnhanceModel(ModelSummary summary, Model model, boolean find_compatible_frames, Map<String, Frame> all_frames, Map<String, Set<String>> all_frames_cols) {
    if (model instanceof GLMModel) {
      summarizeGLMModel(summary, (GLMModel) model);
    } else if (model instanceof DRF.DRFModel) {
      summarizeDRFModel(summary, (DRF.DRFModel) model);
    } else if (model instanceof hex.deeplearning.DeepLearningModel) {
      summarizeDeepLearningModel(summary, (hex.deeplearning.DeepLearningModel) model);
    } else if (model instanceof hex.gbm.GBM.GBMModel) {
      summarizeGBMModel(summary, (hex.gbm.GBM.GBMModel) model);
    } else if (model instanceof hex.singlenoderf.SpeeDRFModel) {
      summarizeSpeeDRFModel(summary, (hex.singlenoderf.SpeeDRFModel) model);
    } else if (model instanceof NBModel) {
      summarizeNBModel(summary, (NBModel) model);
    } else {
      // catch-all
      summarizeModelCommonFields(summary, model);
    }

    if (find_compatible_frames) {
      Map<String, Frame> compatible_frames = findCompatibleFrames(model, all_frames, all_frames_cols);
      summary.compatible_frames = compatible_frames.keySet();
    }
  }
312880
def stream_tfevents(path, file_api, step=0):
    """"""
    last_step = 0
    row = {}
    buffer = []
    last_row = {}
    for summary in tf.train.summary_iterator(path):
        parsed = tf_summary_to_dict(summary)
        if last_step != parsed["tensorflow_step"]:
            step += 1
            last_step = parsed["tensorflow_step"]
            # TODO: handle time
            if len(row) > 0:
                last_row = to_json(row)
                buffer.append(Chunk("wandb-history.jsonl",
                                    util.json_dumps_safer_history(to_json(row))))
        row.update(parsed)
    file_api._send(buffer)
    return last_row
48148
def cli_info(data, title='Info'):
    '''
    
    '''

    wrapper = textwrap.TextWrapper()
    wrapper.initial_indent = ' ' * 4
    wrapper.subsequent_indent = wrapper.initial_indent

    return '{title}:\n\n{text}'.format(title=title, text=wrapper.fill(data))
1137562
def summarize_topics(f='lsi_topics.json', num_topics=1000, num_tokens=10, column_width=10, do_print=True, justify=True, data_path=DATA_PATH):
    """"""
    if isinstance(f, basestring):
        if os.path.sep not in f:
            f = os.path.expanduser(os.path.join(data_path, f))
        f = open(f, 'rUb')
    if isinstance(f, pd.DataFrame):
        f = list(np.array(f[f.columns[-1]]))
    elif isinstance(f, file):
        f = json.load(f)
    if isinstance(f, Mapping):
        f = [v for k, v in sorted(f.items())]
    topics = list(f)
    s = ''
    digits = num_digits(min(len(topics), num_topics) - 1)
    for i, t in enumerate(topics):
        if i > num_topics:
            break
        t_sorted = sorted(t.items(), key=lambda x: -abs(x[1]))[:num_tokens]
        line = '{:{}d}: {}'.format(i, digits, ' '.join(('-+'[int(v > 0)] + '{:{}s}'.format(k[:column_width], column_width) for (k, v) in t_sorted)))
        if not justify:
            line = ' '.join([col for col in line.split(' \t') if col])
        s += line + '\n'
    if do_print:
        print(s)
    return s.split('\n')[:-1]
349373
def _activation_summary(x):
  
  # Remove 'tower_[0-9]/' from the name in case this is a multi-GPU training
  # session. This helps the clarity of presentation on tensorboard.
  tensor_name = re.sub('%s_[0-9]*/' % TOWER_NAME, '', x.op.name)
  tf.summary.histogram(tensor_name + '/activations', x)
  tf.summary.scalar(tensor_name + '/sparsity',
                                       tf.nn.zero_fraction(x))
1039284
def _activation_summary(x):
  
  # Remove 'tower_[0-9]/' from the name in case this is a multi-GPU training
  # session. This helps the clarity of presentation on tensorboard.
  tf.histogram_summary(x.name + '/activations', x)
  tf.scalar_summary(x.name + '/sparsity', tf.nn.zero_fraction(x))
786019
def summarize_metrics(eval_metrics_writer, metrics, epoch):
  """"""
  for (name, value) in six.iteritems(metrics):
    summary = tf.Summary()
    summary.value.add(tag=name, simple_value=value)
    eval_metrics_writer.add_summary(summary, epoch)
  eval_metrics_writer.flush()
171106
def pick_summary_data(key, summary_df, selected_summaries):
    """"""

    selected_summaries_dict = create_selected_summaries_dict(selected_summaries)
    value = selected_summaries_dict[key]
    return summary_df.iloc[:, summary_df.columns.get_level_values(1) == value]
691115
def _eval_summary(self, context: MonitorContext, feed_dict: Optional[Dict]=None) -> None:
        

        if self._summary is None:
            raise RuntimeError('TensorBoard monitor task should set the Tensorflow.Summary object')

        if context.session is None:
            raise RuntimeError('To run a TensorBoard monitor task the TF session object'
                               ' must be provided when creating an instance of the Monitor')

        summary = context.session.run(self._summary, feed_dict=feed_dict)
        self._file_writer.add_summary(summary, context.global_step)
        if self._flush_immediately:
            self.flush()
310322
def _write_summary_cnts(self, cnts):
        """"""
        # Count level(shortest path to root) and depth(longest path to root)
        # values for all unique GO Terms.
        max_val = max(max(dep for dep in cnts['depth']),
                      max(lev for lev in cnts['level']))
        self.log.write('Dep <-Depth Counts->  <-Level Counts->\n')
        self.log.write('Lev   BP    MF    CC    BP    MF    CC\n')
        self.log.write('--- ----  ----  ----  ----  ----  ----\n')
        for i in range(max_val+1):
            vals = ['{:>5}'.format(cnts[desc][i][ns]) for desc in sorted(cnts) for ns in self.nss]
            self.log.write('{:>02} {}\n'.format(i, ' '.join(vals)))
246152
def summarize_attr(key, value, col_width=None):
    """"""
    # Indent key and add ':', then right-pad if col_width is not None
    k_str = '    {}:'.format(key)
    if col_width is not None:
        k_str = pretty_print(k_str, col_width)
    # Replace tabs and newlines, so we print on one line in known width
    v_str = str(value).replace('\t', '\\t').replace('\n', '\\n')
    # Finally, truncate to the desired display width
    return maybe_truncate('{} {}'.format(k_str, v_str),
                          OPTIONS['display_width'])
492020
def plot_summaries(self, show=False, save=True, figure_type=None):
        

        if not figure_type:
            figure_type = self.default_figure_type

        if not figure_type in self.default_figure_types:
            logger.debug("unknown figure type selected")
            figure_type = self.default_figure_type

        color_list, symbol_list = self._create_colors_markers_list()
        summary_df = self.summary_df
        selected_summaries = self.selected_summaries
        batch_dir = self.batch_dir
        batch_name = self.name
        fig, ax = plot_summary_figure(self.info_df, summary_df, color_list,
                                      symbol_list, selected_summaries,
                                      batch_dir, batch_name, show=show,
                                      save=save, figure_type=figure_type)
        self.figure[figure_type] = fig
        self.axes[figure_type] = ax