Example #1
0
    def show(self):

        self._update_phrases_counts()
        # print progress-bar off known_words
        progressBar(self._counters[Level.HIGH], self.all_count, magenta, 80)

        # count high
        View.print_title('Seen: ' + str(self.seen) + ' High: ' +
                         str(self._counters[Level.HIGH]) + ' Mid: ' +
                         str(self._counters[Level.MID]) + ' Low: ' +
                         str(self._counters[Level.LOW]) + ' Unknown: ' +
                         str(self._counters[Level.UNKNOWN]))
                                                 batch_elmo_inp,
                                                 targets=batch_labels)
                model.train()
                batch_labels = batch_labels.cpu().detach().numpy()
                batch_lengths = batch_lengths.cpu().detach().numpy()
                ncorr, ntotal = batch_accuracy_func(batch_predictions,
                                                    batch_labels,
                                                    batch_lengths)
                batch_acc = ncorr / ntotal
                train_acc += batch_acc
                # update progress
                progressBar(
                    batch_id + 1,
                    int(np.ceil(len(train_data) / TRAIN_BATCH_SIZE)), [
                        "batch_time", "batch_loss", "avg_batch_loss",
                        "batch_acc", "avg_batch_acc"
                    ], [
                        time.time() - st_time, batch_loss, train_loss /
                        (batch_id + 1), batch_acc, train_acc / (batch_id + 1)
                    ])
            print(f"\nEpoch {epoch_id} train_loss: {train_loss/(batch_id+1)}")

            # valid loss
            valid_loss = 0.
            valid_acc = 0.
            print("valid_data size: {}".format(len(valid_data)))
            valid_data_iter = batch_iter(valid_data,
                                         batch_size=VALID_BATCH_SIZE,
                                         shuffle=False)
            for batch_id, (batch_labels,
                           batch_sentences) in enumerate(valid_data_iter):