

import io
import json
import unittest

from parameterized import parameterized

from transformers import FSMTForConditionalGeneration, FSMTTokenizer
from transformers.testing_utils import get_tests_dir, require_torch, slow, torch_device
from utils import calculate_bleu


__UpperCAmelCase    				=     get_tests_dir() + '/test_data/fsmt/fsmt_val_data.json'
with io.open(filename, 'r', encoding='utf-8') as f:
  __UpperCAmelCase    				=     json.load(f)





@require_torch
class A__    ( unittest.TestCase ):



 """simple docstring"""







 def    __magic_name__       (		self :	Optional[Any]     ,						A_ :	Tuple       ):






      '''simple docstring'''




      return FSMTTokenizer.from_pretrained(A_       )

 def    __magic_name__       (		self :	int     ,						A_ :	Optional[Any]       ):






      '''simple docstring'''




      _lowerCAmelCase   :					Tuple        =    FSMTForConditionalGeneration.from_pretrained(A_       ).to(A_       )
      if torch_device == "cuda":
           model.half()
      return model


 @parameterized.expand(
     [
         ["en-ru", 26.0],
         ["ru-en", 22.0],
         ["en-de", 22.0],
         ["de-en", 29.0],
     ]       )
 @slow
 def    __magic_name__       (		self :	List[str]     ,						A_ :	Optional[Any]     ,						A_ :	Optional[Any]       ):






      '''simple docstring'''




      _lowerCAmelCase   :					Union[str, Any]        =    F'''facebook/wmt19-{pair}'''
      _lowerCAmelCase   :					str        =    self.get_tokenizer(A_       )
      _lowerCAmelCase   :					List[Any]        =    self.get_model(A_       )

      _lowerCAmelCase   :					Tuple        =    bleu_data[pair]["src"]
      _lowerCAmelCase   :					Dict        =    bleu_data[pair]["tgt"]

      _lowerCAmelCase   :					Tuple        =    tokenizer(A_     ,						return_tensors="pt"     ,						truncation=A_     ,						padding="longest"       ).to(A_       )
      _lowerCAmelCase   :					Optional[Any]        =    model.generate(
          input_ids=batch.input_ids     ,						num_beams=8     ,						)
      _lowerCAmelCase   :					Dict        =    tokenizer.batch_decode(
          A_     ,						skip_special_tokens=A_     ,						clean_up_tokenization_spaces=A_       )
      _lowerCAmelCase   :					Union[str, Any]        =    calculate_bleu(A_     ,						A_       )
      print(A_       )
      self.assertGreaterEqual(scores["bleu"]     ,						A_       )









import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


__UpperCAmelCase    				=     '\nHugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf originally as a company that developed a chatbot app targeted at teenagers.[2] After open-sourcing the model behind the chatbot, the company pivoted to focus on being a platform for machine learning.\n\nIn March 2021, Hugging Face raised $40 million in a Series B funding round.[3]\n\nOn April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model.[4] In 2022, the workshop concluded with the announcement of BLOOM, a multilingual large language model with 176 billion parameters.[5]\n'





class A__    ( unittest.TestCase  ,		A ):



 """simple docstring"""







 def    __magic_name__       (		self :	Tuple       ):






      '''simple docstring'''




      _lowerCAmelCase   :					Dict        =    load_tool("text-question-answering"       )
      self.tool.setup()
      _lowerCAmelCase   :					int        =    load_tool("text-question-answering"     ,						remote=A_       )

 def    __magic_name__       (		self :	List[str]       ):






      '''simple docstring'''




      _lowerCAmelCase   :					Dict        =    self.tool(A_     ,						"What did Hugging Face do in April 2021?"       )
      self.assertEqual(A_     ,						"launched the BigScience Research Workshop"       )

 def    __magic_name__       (		self :	Tuple       ):






      '''simple docstring'''




      _lowerCAmelCase   :					int        =    self.remote_tool(A_     ,						"What did Hugging Face do in April 2021?"       )
      self.assertEqual(A_     ,						"launched the BigScience Research Workshop"       )

 def    __magic_name__       (		self :	Dict       ):






      '''simple docstring'''




      _lowerCAmelCase   :					Union[str, Any]        =    self.tool(text=A_     ,						question="What did Hugging Face do in April 2021?"       )
      self.assertEqual(A_     ,						"launched the BigScience Research Workshop"       )


 def    __magic_name__       (		self :	Optional[Any]       ):






      '''simple docstring'''




      _lowerCAmelCase   :					Optional[int]        =    self.remote_tool(text=A_     ,						question="What did Hugging Face do in April 2021?"       )
      self.assertEqual(A_     ,						"launched the BigScience Research Workshop"       )






