mirror of
https://github.com/huggingface/transformers.git
synced 2025-07-19 04:28:26 +06:00

* add translation example * make style * adapt docstring * add gpu device as input for example * small renaming * better README
29 lines
864 B
Python
29 lines
864 B
Python
import logging
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
from .evaluate_wmt import run_generate
|
|
|
|
|
|
text = [" New York (CNN)When Liana Barrientos was 23 years old, she got married in Westchester County."]
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
logger = logging.getLogger()
|
|
|
|
|
|
class TestT5Examples(unittest.TestCase):
|
|
def test_t5_cli(self):
|
|
stream_handler = logging.StreamHandler(sys.stdout)
|
|
logger.addHandler(stream_handler)
|
|
tmp = Path(tempfile.gettempdir()) / "utest_generations.hypo"
|
|
with tmp.open("w") as f:
|
|
f.write("\n".join(text))
|
|
testargs = ["evaluate_cnn.py", str(tmp), "output.txt", str(tmp), "score.txt"]
|
|
with patch.object(sys, "argv", testargs):
|
|
run_generate()
|
|
self.assertTrue(Path("output.txt").exists())
|