Exemple #1
0
def test_postprocess_output():
    output = _make_output([["a", "b", "c"]], score=[2], attention=[None])
    example = _make_example([["x", "y"]], metadata=[None])

    def func(src, tgt, config=None):
        assert src == ["x", "y"]
        assert tgt == ["a", "b", "c"]
        return " ".join(src + tgt)

    result = serving.postprocess_output(output, example, func)
    assert result["text"] == "x y a b c"
    assert result["score"] == 2
def test_postprocess_output_multiparts():
    example = _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 target == [["a", "b", "c"], ["d", "e"]]
            assert metadata == [3, 2]
            return ""

    output = _make_output([["a", "b", "c"], ["d", "e"]], score=[2, 6], attention=[None, None])
    result = serving.postprocess_output(output, example, Processor())
    assert result["score"] == 8
def test_postprocess_output_with_metadata():
    output = _make_output([["a", "b", "c"]], score=[2], attention=[None])
    example = _make_example([["x", "y"]], metadata=[3])

    class Processor:
        def process_input(self, source, target=None, metadata=None, **kwargs):
            assert source == [["x", "y"]]
            assert target == [["a", "b", "c"]]
            assert metadata == [3]
            return ""

    result = serving.postprocess_output(output, example, Processor())
    assert result["score"] == 2
Exemple #4
0
def test_postprocess_output_with_metadata():
    output = _make_output([["a", "b", "c"]], score=[2], attention=[None])
    example = _make_example([["x", "y"]], metadata=[3])

    def func(src, tgt, config=None):
        assert isinstance(src, tuple)
        assert src[0] == ["x", "y"]
        assert src[1] == 3
        assert tgt == ["a", "b", "c"]
        return ""

    result = serving.postprocess_output(output, example, func)
    assert result["score"] == 2
Exemple #5
0
def test_postprocess_output_multiparts():
    example = _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"]]
        return ""

    output = _make_output([["a", "b", "c"], ["d", "e"]],
                          score=[2, 6],
                          attention=[None, None])
    result = serving.postprocess_output(output, example, func)
    assert result["score"] == 8