def test_postprocess_outputs_multiparts(): # 2 parts and 2 hypothesis. outputs = [[ _make_output([["a", "b", "c"], ["d", "e"]], score=[1, 3], attention=[None, None]), _make_output([["a", "c", "b"], ["e", "e"]], score=[2, 4], attention=[None, None]) ]] examples = [_make_example([["x", "y"], ["z"]], metadata=[3, 2])] def func(src, tgt, config=None): assert isinstance(src, tuple) assert src[0] == [["x", "y"], ["z"]] assert src[1] == [3, 2] assert tgt == [["a", "b", "c"], ["d", "e"]] or tgt == [["a", "c", "b"], ["e", "e"]] return " ".join(tgt[0] + tgt[1]) results = serving.postprocess_outputs(outputs, examples, func) assert len(results) == 1 assert len(results[0]) == 2 assert results[0][0] == {"text": "a b c d e", "score": 1 + 3} assert results[0][1] == {"text": "a c b e e", "score": 2 + 4}
def test_postprocess_outputs_multiparts(): # 2 parts and 2 hypothesis. outputs = [[ _make_output([["a", "b", "c"], ["d", "e"]], score=[1, 3], attention=[None, None]), _make_output([["a", "c", "b"], ["e", "e"]], score=[2, 4], attention=[None, None]) ]] examples = [_make_example([["x", "y"], ["z"]], metadata=[3, 2])] class Processor: def process_input(self, source, target=None, metadata=None, **kwargs): assert source == [["x", "y"], ["z"]] assert metadata == [3, 2] assert (target == [["a", "b", "c"], ["d", "e"]] or target == [["a", "c", "b"], ["e", "e"]]) return " ".join(target[0] + target[1]) results = serving.postprocess_outputs(outputs, examples, Processor()) assert len(results) == 1 assert len(results[0]) == 2 assert results[0][0] == {"text": "a b c d e", "score": 1 + 3} assert results[0][1] == {"text": "a c b e e", "score": 2 + 4}
def test_postprocess_outputs(): outputs = [[ _make_output([["a", "b", "c"]], score=[1], attention=[None]), _make_output([["a", "c", "b"]], score=[2], attention=[None]) ], [ _make_output([["d", "e"]], score=[3], attention=[None]), _make_output([["e", "e"]], score=[4], attention=[None]) ]] examples = [ _make_example([["x", "y"]]), _make_example([["s", "t"]]), ] def func(src, tgt, config=None): return " ".join(tgt) results = serving.postprocess_outputs(outputs, examples, func) assert len(results) == 2 assert len(results[0]) == 2 assert results[0][0] == {"text": "a b c", "score": 1} assert results[0][1] == {"text": "a c b", "score": 2} assert len(results[1]) == 2 assert results[1][0] == {"text": "d e", "score": 3} assert results[1][1] == {"text": "e e", "score": 4}
def test_postprocess_outputs(): outputs = [[ _make_output([["a", "b", "c"]], score=[1], attention=[None]), _make_output([["a", "c", "b"]], score=[2], attention=[None]) ], [ _make_output([["d", "e"]], score=[3], attention=[None]), _make_output([["e", "e"]], score=[4], attention=[None]) ]] examples = [ _make_example([["x", "y"]]), _make_example([["s", "t"]]), ] class Processor: def process_input(self, source, target=None, **kwargs): return " ".join(target[0]) results = serving.postprocess_outputs(outputs, examples, Processor()) assert len(results) == 2 assert len(results[0]) == 2 assert results[0][0] == {"text": "a b c", "score": 1} assert results[0][1] == {"text": "a c b", "score": 2} assert len(results[1]) == 2 assert results[1][0] == {"text": "d e", "score": 3} assert results[1][1] == {"text": "e e", "score": 4}