def dump_line(self, outputs): output = io.StringIO() writer = csv.writer(output) row = [ outputs[u"span_start_probs"][0], outputs[u"span_end_probs"][0], *outputs[u"best_span"], outputs[u"best_span_str"] ] writer.writerow(row) return output.getvalue() BidafCsvPredictor = Predictor.register(u'bidaf-csv') # pylint: disable=unused-variable(BidafCsvPredictor)
from typing import Dict, Any, List, Optional import logging import pandas as pd from allennlp.predictors import Predictor from allennlp.common.util import JsonDict from allennlp.data import TokenIndexer, Tokenizer, Instance, Vocabulary from qb.model import Guesser from qb.data import QantaReader from qb.util import stqdm log = logging.getLogger(__name__) Predictor.register("qb_predictor") class QbPredictor(Predictor): def __init__(self, model: Guesser, dataset_reader: QantaReader, top_k: int = 10): super().__init__(model, dataset_reader) self._top_k = top_k model.top_k = top_k def _json_to_instance(self, json_dict: JsonDict): return self._dataset_reader.text_to_instance(text=json_dict["text"])
def predict_json(self, inputs): result = super(Bidaf3Predictor, self).predict_json(inputs) result[u"explicit"] = True return result Bidaf3Predictor = Predictor.register(u'bidaf-explicit') # pylint: disable=unused-variable(Bidaf3Predictor)