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

Function _handle_exceptional_examples

official/projects/triviaqa/preprocess.py:363–415  ·  view source on GitHub ↗

Special cases in data.

(
    features: Features,
    processor: spm.SentencePieceProcessor)

Source from the content-addressed store, hash-verified

361
362
363def _handle_exceptional_examples(
364 features: Features,
365 processor: spm.SentencePieceProcessor) -> List[AnswerSpan]:
366 """Special cases in data."""
367 if features.id == 'qw_6687--Viola.txt':
368 pattern = 'three strings in common—G, D, and A'.encode('utf-8')
369 i = features.context.find(pattern)
370 if i != -1:
371 span = AnswerSpan(i + len(pattern) - 1, i + len(pattern), 'A')
372 span = realign_answer_span(features, None, processor, span)
373 assert span is not None, 'Span should exist.'
374 return [span]
375 if features.id == 'sfq_26183--Vitamin_A.txt':
376 pattern = ('Vitamin A is a group of unsaturated nutritional organic '
377 'compounds that includes retinol').encode('utf-8')
378 i = features.context.find(pattern)
379 if i != -1:
380 span = AnswerSpan(i + pattern.find(b'A'), i + pattern.find(b'A') + 1, 'A')
381 span = realign_answer_span(features, None, processor, span)
382 assert span is not None, 'Span should exist.'
383 spans = [span]
384 span = AnswerSpan(i, i + pattern.find(b'A') + 1, 'Vitamin A')
385 span = realign_answer_span(features, None, processor, span)
386 return spans + [span]
387 if features.id == 'odql_292--Colombia.txt':
388 pattern = b'Colombia is the third-most populous country in Latin America'
389 i = features.context.find(pattern)
390 if i != -1:
391 span = AnswerSpan(i, i + len(b'Colombia'), 'Colombia')
392 span = realign_answer_span(features, None, processor, span)
393 assert span is not None, 'Span should exist.'
394 return [span]
395 if features.id == 'tc_1648--Vietnam.txt':
396 pattern = 'Bảo Đại'.encode('utf-8')
397 i = features.context.find(pattern)
398 if i != -1:
399 span = AnswerSpan(i, i + len(pattern), 'Bảo Đại')
400 span = realign_answer_span(features, None, processor, span)
401 assert span is not None, 'Span should exist.'
402 return [span]
403 if features.id == 'sfq_22225--Irish_mythology.txt':
404 pattern = 'Tír na nÓg'.encode('utf-8')
405 spans = []
406 i = 0
407 while features.context.find(pattern, i) != -1:
408 i = features.context.find(pattern)
409 span = AnswerSpan(i, i + len(pattern), 'Tír na nÓg')
410 span = realign_answer_span(features, None, processor, span)
411 assert span is not None, 'Span should exist.'
412 spans.append(span)
413 i += len(pattern)
414 return spans
415 return []
416
417
418class FindAnswerSpans(beam.DoFn):

Callers 1

processMethod · 0.85

Calls 4

AnswerSpanClass · 0.85
realign_answer_spanFunction · 0.85
findMethod · 0.80
encodeMethod · 0.45

Tested by

no test coverage detected