MCPcopy Create free account
hub / github.com/tensorflow/models / process

Method process

official/projects/triviaqa/preprocess.py:428–453  ·  view source on GitHub ↗
(
      self,
      element: Tuple[Text, List[Features]],
      answer_sets: Dict[Text, Set[Text]],
  )

Source from the content-addressed store, hash-verified

426 self._sentencepiece_model_path)
427
428 def process(
429 self,
430 element: Tuple[Text, List[Features]],
431 answer_sets: Dict[Text, Set[Text]],
432 ) -> Generator[Tuple[Features, List[AnswerSpan]], None, None]:
433 question_id, features = element
434 answer_set = answer_sets[question_id]
435 has_answer = False
436 for feature in features:
437 answer_spans = []
438 for answer_span in find_answer_spans(feature.context, answer_set):
439 realigned_answer_span = realign_answer_span(
440 feature, answer_set, self._sentencepiece_processor, answer_span)
441 if realigned_answer_span:
442 answer_spans.append(realigned_answer_span)
443 if not answer_spans:
444 answer_spans = _handle_exceptional_examples(
445 feature, self._sentencepiece_processor)
446 if answer_spans:
447 has_answer = True
448 else:
449 metrics.Metrics.counter('_', 'answerless_examples').inc()
450 yield feature, answer_spans
451 if not has_answer:
452 metrics.Metrics.counter('_', 'answerless_questions').inc()
453 logging.error('Question %s has no answer.', question_id)
454
455
456def make_example(

Callers

nothing calls this directly

Calls 3

find_answer_spansFunction · 0.85
realign_answer_spanFunction · 0.85

Tested by

no test coverage detected