def __init__(self, pipeline: "nlpaug_flow.Pipeline", num_transformed: int = 1, identifiers: List[Identifier] = None, *args, **kwargs): assert isinstance(pipeline, nlpaug_flow.Pipeline), ( "`pipeline` must be an nlpaug Pipeline object. Please use \n" "from nlpaug.flow import Sequential\n" "rg.NlpAugTransformation(pipeline=Sequential(flow=[...])).") super(NlpAugTransformation, self).__init__(num_transformed=num_transformed, identifiers=Identifier.range( n=num_transformed, _name=self.__class__.__name__, pipeline=[ Identifier( _name=augmenter.name, src=augmenter.aug_src if hasattr( augmenter, "aug_src") else None, action=augmenter.action, method=augmenter.method, ) for augmenter in pipeline ], ) if not identifiers else identifiers, *args, **kwargs) # Set the pipeline self.pipeline = pipeline
def __init__(self, num_transformed=1, alpha_sr=0.1, alpha_ri=0.1, alpha_rs=0.1, p_rd=0.1): super(EasyDataAugmentation, self).__init__(identifiers=Identifier.range( n=num_transformed, _name=self.__class__.__name__, alpha_sr=alpha_sr, alpha_ri=alpha_ri, alpha_rs=alpha_rs, p_rd=p_rd, )) # Set the parameters self.alpha_sr = alpha_sr self.alpha_ri = alpha_ri self.alpha_rs = alpha_rs self.p_rd = p_rd # Download wordnet self._download_wordnet()
def __init__(self, metric: Sequence[str], threshold: float): super(RougeMatrixSentenceTransformation, self).__init__( num_transformed=1, identifiers=Identifier.range(n=1, _name=self.__class__.__name__), ) self.metric = metric self.threshold = threshold
def __init__( self, n_src2tgt: int = 1, n_tgt2src: int = 1, langs: str = "en2de", torchhub_dir: str = None, device: str = "cuda", src2tgt_topk: int = 1000, src2tgt_temp: float = 1.0, tgt2src_topk: int = 1000, tgt2src_temp: float = 1.0, ): if not _fastbpe_available: raise ImportError( "fastBPE not available for import. Please install fastBPE with pip " "install fastBPE." ) super(FairseqBacktranslation, self).__init__( identifiers=Identifier.range( n=n_src2tgt * n_tgt2src, _name=self.__class__.__name__, langs=langs, src2tgt_topk=src2tgt_topk, src2tgt_temp=src2tgt_temp, tgt2src_topk=tgt2src_topk, tgt2src_temp=tgt2src_temp, ) ) # Set the parameters self.n_src2tgt = n_src2tgt self.n_tgt2src = n_tgt2src self.src2tgt_topk = src2tgt_topk self.src2tgt_temp = src2tgt_temp self.tgt2src_topk = tgt2src_topk self.tgt2src_temp = tgt2src_temp # Setup the backtranslation models self.src2tgt, self.tgt2src = self.load_models( langs=langs, torchhub_dir=torchhub_dir, # self.logdir if not torchhub_dir else torchhub_dir, device=device, )
def __init__(self, apply_fn: Callable = None, identifiers: List[Identifier] = None, num_outputs: int = None, *args, **kwargs): if not identifiers: assert ( num_outputs ), "Must pass in num_outputs if no identifiers are specified." # Set the identifiers for the outputs of the Operation self._identifiers = (Identifier.range( n=num_outputs, _name=self.__class__.__name__, **kwargs) if not identifiers else identifiers) # Assign the apply_fn if apply_fn: self.apply = apply_fn
def __init__( self, n_src2tgt: int = 1, n_tgt2src: int = 1, langs: str = "en2de", torchhub_dir: str = None, device: str = "cuda", src2tgt_topk: int = 1000, src2tgt_temp: float = 1.0, tgt2src_topk: int = 1000, tgt2src_temp: float = 1.0, ): super(FairseqBacktranslation, self).__init__(identifiers=Identifier.range( n=n_src2tgt * n_tgt2src, _name=self.__class__.__name__, langs=langs, src2tgt_topk=src2tgt_topk, src2tgt_temp=src2tgt_temp, tgt2src_topk=tgt2src_topk, tgt2src_temp=tgt2src_temp, )) # Set the parameters self.n_src2tgt = n_src2tgt self.n_tgt2src = n_tgt2src self.src2tgt_topk = src2tgt_topk self.src2tgt_temp = src2tgt_temp self.tgt2src_topk = tgt2src_topk self.tgt2src_temp = tgt2src_temp # Setup the backtranslation models self.src2tgt, self.tgt2src = self.load_models( langs=langs, torchhub_dir=torchhub_dir, # self.logdir if not torchhub_dir else torchhub_dir, device=device, )
def test_range(self): # Use the range function to create multiple identifiers identifiers = Identifier.range(3, _name="MyIdentifier", param="a", param_2="b") for i, identifier in enumerate(identifiers): self.assertEqual(identifier, f"MyIdentifier-{i + 1}(param=a, param_2=b)")