Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/fast_langdetect/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ def _load_unix(self, model_path: Path) -> Any:
"""Load model on Unix-like systems."""
try:
return fasttext.load_model(str(model_path))
except MemoryError as e:
# Let MemoryError propagate up to be handled by _get_model
raise e
except Exception as e:
raise DetectError(f"fast-langdetect: Failed to load model: {e}")

Expand Down Expand Up @@ -317,7 +320,7 @@ def _get_model(self, low_memory: bool = True) -> Any:
)
self._models[cache_key] = model
return model
except Exception as e:
except MemoryError as e:
if low_memory is not True and self.config.allow_fallback:
logger.info("fast-langdetect: Falling back to low-memory model...")
return self._get_model(low_memory=True)
Expand Down