Skip to content

Commit

Permalink
resolved bug and removed unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
GameSetAndMatch committed Jul 13, 2023
1 parent 37acb0c commit 7ec8c82
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 27 deletions.
21 changes: 0 additions & 21 deletions deepparse/cli/download_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,6 @@ def main(args=None) -> None:
download_models(saving_cache_path=saving_cache_path)


def download_models_test(saving_cache_path=None):
if saving_cache_path is None:
saving_cache_path = CACHE_PATH

download_fasttext_embeddings(cache_dir=saving_cache_path)
download_fasttext_magnitude_embeddings(cache_dir=saving_cache_path)
BPEmb(
lang="multi", vs=100000, dim=300, cache_dir=saving_cache_path
) # The class manage the download of the pretrained words embedding

for model_type in MODEL_CHOICES:
model_type = model_type.replace("-", "_")
model_path = os.path.join(saving_cache_path, f"{model_type}.ckpt")
version_path = os.path.join(saving_cache_path, f"{model_type}.version")
if not os.path.isfile(model_path) or not os.path.isfile(version_path):
download_weights(model_type, saving_dir=saving_cache_path)
elif not latest_version(model_type, cache_path=saving_cache_path, verbose=True):
print("A new version of the pretrained model is available. The newest model will be downloaded.")
download_weights(model_type, saving_dir=saving_cache_path)


def get_parser() -> argparse.ArgumentParser:
"""Return ArgumentParser for the cli."""
parser = argparse.ArgumentParser()
Expand Down
2 changes: 1 addition & 1 deletion deepparse/embeddings_models/magnitude_embeddings_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MagnitudeEmbeddingsModel(EmbeddingsModel):

def __init__(self, embeddings_path: str, verbose: bool = True) -> None:
super().__init__(verbose=verbose)
self.model = Magnitude(embeddings_path, lazy_loading=-1, blocking=True)
self.model = Magnitude(path=embeddings_path, lazy_loading=-1, blocking=True)

def __call__(self, words: str) -> ndarray:
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/app/test_app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, List
from typing import Dict, List, Union

from unittest.mock import MagicMock
import pytest
Expand Down Expand Up @@ -63,7 +63,7 @@ def test_parse(client: TestClient):
"version": model_version,
}

def mock_format_parsed_addresses() -> Dict[str, str | List[Dict]]:
def mock_format_parsed_addresses() -> Dict[str, Union[str, List[Dict]]]:
return mocked_response

app.dependency_overrides[format_parsed_addresses] = mock_format_parsed_addresses
Expand Down
6 changes: 3 additions & 3 deletions tests/embeddings_models/test_magnitude_embeddings_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ def setUp(self):
self.model = MagicMock()
self.model.dim = self.dim

def test_whenInstanciatedWithPath_thenShouldLoadFasttextModel(self):
def test_whenInstantiatedWithPath_thenShouldLoadFasttextModel(self):
with patch(
"deepparse.embeddings_models.magnitude_embeddings_model.Magnitude",
return_value=self.model,
) as loader:
_ = MagnitudeEmbeddingsModel(self.a_path, verbose=self.verbose)
_ = MagnitudeEmbeddingsModel(embeddings_path=self.a_path, verbose=self.verbose)

loader.assert_called_with(self.a_path)
loader.assert_called_with(blocking=True, lazy_loading=-1, path=self.a_path)

def test_whenCalledToEmbed_thenShouldCallLoadedModel(self):
with patch(
Expand Down

0 comments on commit 7ec8c82

Please sign in to comment.