def main(args=None) -> None: """ CLI function to manually download all the dependencies for a pre-trained model. Example of usage: .. code-block:: sh download_model fasttext """ if args is None: args = sys.argv[1:] parsed_args = get_args(args) model_type = parsed_args.model_type if "fasttext" in model_type and "fasttext-light" not in model_type: download_fasttext_embeddings(saving_dir=CACHE_PATH) elif model_type == "fasttext-light": download_fasttext_magnitude_embeddings(saving_dir=CACHE_PATH) elif "bpemb" in model_type: BPEmb( lang="multi", vs=100000, dim=300 ) # The class manage the download of the pre-trained words embedding model_path = os.path.join(CACHE_PATH, f"{model_type}.ckpt") version_path = os.path.join(CACHE_PATH, f"{model_type}.version") if not os.path.isfile(model_path) or not os.path.isfile(version_path): download_weights(model_type, CACHE_PATH) elif not latest_version(model_type, cache_path=CACHE_PATH): print( "A new version of the pre-trained model is available. The newest model will be downloaded." ) download_weights(model_type, CACHE_PATH)
def test_givenModelBPEmbWeightsToDownloadVerbose_whenDownloadOk_thenVerbose( self): self._capture_output() with patch("deepparse.tools.download_from_url"): download_weights(model="bpemb", saving_dir="./", verbose=True) actual = self.test_out.getvalue().strip() expected = "Downloading the weights for the network bpemb." self.assertEqual(actual, expected)
def test_givenModelWeightsToDownload_whenDownloadOk_thenWeightsAreDownloaded(self): with patch("deepparse.tools.download_from_url") as downloader: download_weights(model="fasttext", saving_dir="./", verbose=self.verbose) downloader.assert_any_call("fasttext", "./", "ckpt") downloader.assert_any_call("fasttext", "./", "version") with patch("deepparse.tools.download_from_url") as downloader: download_weights(model="bpemb", saving_dir="./", verbose=self.verbose) downloader.assert_any_call("bpemb", "./", "ckpt") downloader.assert_any_call("bpemb", "./", "version")
def main(args: argparse.Namespace) -> None: """ Script to manually download all the dependancies for a pre-trained model. """ model = args.model root_path = os.path.join(os.path.expanduser('~'), ".cache", "deepparse") os.makedirs(root_path, exist_ok=True) if model == 'fasttext': download_fasttext_embeddings("fr", saving_dir=root_path) if model == 'bpemb': BPEmb( lang="multi", vs=100000, dim=300 ) # The class manage the download of the pre-trained words embedding model_path = os.path.join(root_path, f"{model}.ckpt") version_path = os.path.join(root_path, f"{model}.version") if not os.path.isfile(model_path) or not os.path.isfile(version_path): download_weights(model, root_path) elif verify_latest_version(model, root_path): warnings.warn( "A new version of the pre-trained model is available. The newest model will be downloaded." ) download_weights(model, root_path)