Daryl Lim Claude Opus 4.6 commited on
Commit
f50ef54
Β·
1 Parent(s): 177f899

Update CLAUDE.md for lazy loading and langmap rename

Browse files

- Document CPU fallback with warning instead of hard GPU requirement
- Update package name from LangMap/ to langmap/
- Note lazy loading behavior and fast import-safety test

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. CLAUDE.md +45 -0
CLAUDE.md ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ A Hugging Face Spaces app that translates English text to ~400 languages using Google's [MADLAD-400](https://arxiv.org/pdf/2309.04662) 3B Seq2Seq model. Built with Gradio and deployed on HF Spaces. Falls back to CPU with a warning when no GPU is available.
8
+
9
+ ## Commands
10
+
11
+ ```bash
12
+ # Setup
13
+ python -m venv .venv
14
+ source .venv/bin/activate
15
+ pip install -r requirements.txt
16
+
17
+ # Run (launches on http://localhost:7860)
18
+ python app.py
19
+
20
+ # Lint and format
21
+ ruff check .
22
+ ruff format .
23
+
24
+ # Type check
25
+ ty check
26
+
27
+ # Test
28
+ pytest # all tests (slow tests require GPU + model download)
29
+ pytest -m "not slow" # fast tests only
30
+ pytest -m slow # model tests only
31
+ ```
32
+
33
+ ## Architecture
34
+
35
+ **`app.py`** β€” Single-file application. Uses `@lru_cache` for lazy loading of the `google/madlad400-3b-mt` tokenizer and model with `float16` precision (no download on import). Translation prepends a language token to the input text (e.g., `<2fr>Hello`) before tokenization and generation. The `@spaces.GPU` decorator allocates GPU on HF Spaces infrastructure.
36
+
37
+ **`langmap/`** β€” Package with `langid_mapping.py`, a hand-maintained dictionary mapping ~400 language tokens to human-readable language names (sourced from pages 16–21 of the MADLAD-400 paper). Available languages at runtime are the intersection of this mapping and the model's vocabulary.
38
+
39
+ **`tests/`** β€” Pytest suite split into fast (`test_langmap.py`) and slow (`test_app.py`). Slow tests require GPU and model download; they are auto-skipped without MPS/CUDA. Fast tests in `test_app.py` verify the module imports without triggering model download.
40
+
41
+ ## Tooling
42
+
43
+ - **Ruff** β€” linter and formatter (`ruff.toml`). Rules: `E`, `F`, `I`, `W`. Line length: 120.
44
+ - **ty** β€” type checker (`ty.toml`). Python 3.12 target.
45
+ - **pytest** β€” test runner (`pytest.ini`). Custom `slow` marker for GPU-dependent tests.