saearth 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- saearth-0.1.0/LICENSE +33 -0
- saearth-0.1.0/PKG-INFO +248 -0
- saearth-0.1.0/README.md +221 -0
- saearth-0.1.0/pyproject.toml +27 -0
- saearth-0.1.0/saearth/__init__.py +71 -0
- saearth-0.1.0/saearth/decompose/__init__.py +16 -0
- saearth-0.1.0/saearth/decompose/embeddings.py +23 -0
- saearth-0.1.0/saearth/decompose/encode.py +52 -0
- saearth-0.1.0/saearth/decompose/kmeans.py +46 -0
- saearth-0.1.0/saearth/decompose/sae.py +209 -0
- saearth-0.1.0/saearth/decompose/train.py +142 -0
- saearth-0.1.0/saearth/interpret/__init__.py +15 -0
- saearth-0.1.0/saearth/interpret/agent.py +272 -0
- saearth-0.1.0/saearth/interpret/assays.py +114 -0
- saearth-0.1.0/saearth/interpret/imagery.py +180 -0
- saearth-0.1.0/saearth/interpret/index.py +72 -0
- saearth-0.1.0/saearth/interpret/interpret.py +85 -0
- saearth-0.1.0/saearth/interpret/judge.py +47 -0
- saearth-0.1.0/saearth/interpret/label.py +65 -0
- saearth-0.1.0/saearth/interpret/llm.py +65 -0
- saearth-0.1.0/saearth/interpret/prompts.py +188 -0
- saearth-0.1.0/saearth/interpretations/alphaearth_dims.csv +65 -0
- saearth-0.1.0/saearth/interpretations/alphaearth_sae.csv +1791 -0
- saearth-0.1.0/saearth/interpretations/tessera_sae.csv +1720 -0
- saearth-0.1.0/saearth/models/alphaearth/kmeans.npz +0 -0
- saearth-0.1.0/saearth/models/alphaearth/sae.npz +0 -0
- saearth-0.1.0/saearth/models/tessera/kmeans.npz +0 -0
- saearth-0.1.0/saearth/models/tessera/sae.npz +0 -0
- saearth-0.1.0/saearth.egg-info/PKG-INFO +248 -0
- saearth-0.1.0/saearth.egg-info/SOURCES.txt +32 -0
- saearth-0.1.0/saearth.egg-info/dependency_links.txt +1 -0
- saearth-0.1.0/saearth.egg-info/requires.txt +17 -0
- saearth-0.1.0/saearth.egg-info/top_level.txt +1 -0
- saearth-0.1.0/setup.cfg +4 -0
saearth-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 The SAEarth authors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
Models and interpretations derived from AlphaEarth (saearth/models/alphaearth/,
|
|
24
|
+
saearth/interpretations/alphaearth_*.csv) are licensed under the Creative Commons
|
|
25
|
+
Attribution 4.0 International License (CC BY 4.0),
|
|
26
|
+
https://creativecommons.org/licenses/by/4.0/. They are derived from the
|
|
27
|
+
AlphaEarth Foundations Satellite Embedding dataset, which is produced by Google
|
|
28
|
+
and Google DeepMind and licensed under CC BY 4.0.
|
|
29
|
+
|
|
30
|
+
Models and interpretations derived from TESSERA (saearth/models/tessera/,
|
|
31
|
+
saearth/interpretations/tessera_*.csv) are licensed under the Creative Commons
|
|
32
|
+
Attribution-ShareAlike 4.0 International License (CC BY-SA 4.0),
|
|
33
|
+
https://creativecommons.org/licenses/by-sa/4.0/.
|
saearth-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: saearth
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Sparse, interpretable Earth embeddings: sparse autoencoders and LLM-agent interpretations
|
|
5
|
+
License-Expression: MIT AND CC-BY-4.0 AND CC-BY-SA-4.0
|
|
6
|
+
Project-URL: Homepage, https://saearth.wenruixu.com
|
|
7
|
+
Project-URL: Source, https://github.com/ruaruaxu/saearth
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: numpy
|
|
12
|
+
Requires-Dist: pandas
|
|
13
|
+
Requires-Dist: pyarrow
|
|
14
|
+
Requires-Dist: torch
|
|
15
|
+
Requires-Dist: scikit-learn
|
|
16
|
+
Provides-Extra: interpret
|
|
17
|
+
Requires-Dist: scipy; extra == "interpret"
|
|
18
|
+
Requires-Dist: earthengine-api; extra == "interpret"
|
|
19
|
+
Requires-Dist: rasterio; extra == "interpret"
|
|
20
|
+
Requires-Dist: pillow; extra == "interpret"
|
|
21
|
+
Requires-Dist: matplotlib; extra == "interpret"
|
|
22
|
+
Requires-Dist: requests; extra == "interpret"
|
|
23
|
+
Provides-Extra: notebooks
|
|
24
|
+
Requires-Dist: jupyter; extra == "notebooks"
|
|
25
|
+
Requires-Dist: earthengine-api; extra == "notebooks"
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# SAEarth: Interpreting Earth Embeddings with Sparse Representations and LLM Agents
|
|
29
|
+
|
|
30
|
+
**[Concept Explorer](https://saearth.wenruixu.com)** | **Paper** (arXiv, link coming soon) | [Released models and interpretations](#what-is-released)
|
|
31
|
+
|
|
32
|
+
SAEarth turns a dense Earth embedding into a sparse representation whose dimensions are
|
|
33
|
+
described in natural language and validated on held-out locations. We release this
|
|
34
|
+
representation for the AlphaEarth and TESSERA embeddings: the trained models, a
|
|
35
|
+
description of every interpreted dimension with its held-out fidelity, and the code to
|
|
36
|
+
apply the method to other embeddings.
|
|
37
|
+
|
|
38
|
+
<p align="center"><img src="https://raw.githubusercontent.com/ruaruaxu/saearth/main/assets/framework.png" width="560" alt="SAEarth in two steps: sparse decomposition and agentic interpretation"></p>
|
|
39
|
+
|
|
40
|
+
## Contents
|
|
41
|
+
|
|
42
|
+
- [What is released](#what-is-released)
|
|
43
|
+
- [Quickstart](#quickstart)
|
|
44
|
+
- [Method](#method)
|
|
45
|
+
- [Apply SAEarth to your own embeddings](#apply-saearth-to-your-own-embeddings)
|
|
46
|
+
- [FAQ](#faq)
|
|
47
|
+
- [Citation](#citation)
|
|
48
|
+
- [License](#license)
|
|
49
|
+
|
|
50
|
+
## What is released
|
|
51
|
+
|
|
52
|
+
| | AlphaEarth | TESSERA |
|
|
53
|
+
|---|---|---|
|
|
54
|
+
| Sparse autoencoder (2,048 dimensions, about 4 active) | `saearth/models/alphaearth/sae.npz` | `saearth/models/tessera/sae.npz` |
|
|
55
|
+
| k-means (2,048 clusters, one active) | `saearth/models/alphaearth/kmeans.npz` | `saearth/models/tessera/kmeans.npz` |
|
|
56
|
+
| Interpreted dimensions | 1,790 (`saearth/interpretations/alphaearth_sae.csv`) | 1,719 (`saearth/interpretations/tessera_sae.csv`) |
|
|
57
|
+
| Median held-out test F1 | 0.839 | 0.817 |
|
|
58
|
+
| Faithful (test F1 ≥ 0.69) | 96.4% | 92.7% |
|
|
59
|
+
|
|
60
|
+
The interpreted dimensions carry 99.9% of the activation mass of each SAE.
|
|
61
|
+
`saearth/interpretations/alphaearth_dims.csv` describes the 64 original AlphaEarth dimensions with
|
|
62
|
+
the same agent and test, for comparison.
|
|
63
|
+
|
|
64
|
+
Each interpretation table has one row per dimension:
|
|
65
|
+
|
|
66
|
+
| Column | Meaning |
|
|
67
|
+
|---|---|
|
|
68
|
+
| `dimension` | SAE dimension (0–2,047) |
|
|
69
|
+
| `level` | Matryoshka level, coarse to fine: L1 = 0–127, L2 = 128–383, L3 = 384–895, L4 = 896–2,047 |
|
|
70
|
+
| `theme` | One of eight themes shared by both embeddings, such as Agricultural fields or Built-up settlements |
|
|
71
|
+
| `label` | Short label |
|
|
72
|
+
| `interpretation` | Full description written by the agent |
|
|
73
|
+
| `test_f1` | Fidelity on 100 held-out locations: F1 of the LLM annotator's image-by-image predictions of whether the dimension is in the top third of its activations or inactive |
|
|
74
|
+
| `faithful` | `test_f1 >= 0.69` |
|
|
75
|
+
| `activation_share` | Share of all activation mass carried by the dimension |
|
|
76
|
+
|
|
77
|
+
## Quickstart
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
pip install git+https://github.com/ruaruaxu/saearth.git
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The package includes the released models and interpretation tables. To change the code,
|
|
84
|
+
clone the repository and run `pip install -e .` instead.
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
import numpy as np
|
|
88
|
+
import saearth
|
|
89
|
+
|
|
90
|
+
sae = saearth.load_sae("alphaearth") # or "tessera"
|
|
91
|
+
concepts = saearth.load_concepts("alphaearth") # the interpretation table, indexed by dimension
|
|
92
|
+
|
|
93
|
+
x = np.load("my_alphaearth_embeddings.npy") # [n, 64] float32
|
|
94
|
+
codes = saearth.encode(sae, x) # [n, 2048], about 4 nonzero per row
|
|
95
|
+
for d in np.flatnonzero(codes[0]):
|
|
96
|
+
if d in concepts.index:
|
|
97
|
+
print(d, round(float(codes[0, d]), 3), concepts.label[d])
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
[`notebooks/quickstart.ipynb`](https://github.com/ruaruaxu/saearth/blob/main/notebooks/quickstart.ipynb) reads the AlphaEarth embedding of
|
|
101
|
+
any place from Earth Engine and lists its concepts.
|
|
102
|
+
|
|
103
|
+
**Inputs.** AlphaEarth embeddings as served by the Earth Engine collection
|
|
104
|
+
`GOOGLE/SATELLITE_EMBEDDING/V1/ANNUAL`, or dequantized from the GeoTIFF release with
|
|
105
|
+
`saearth.dequantize_alphaearth`. TESSERA v1.1 embeddings scaled to unit length with
|
|
106
|
+
`saearth.unit_length`. The code of each row is independent of the other rows, so any batch
|
|
107
|
+
size gives the same result.
|
|
108
|
+
|
|
109
|
+
## Method
|
|
110
|
+
|
|
111
|
+
**Step 1: Sparse decomposition** (`saearth.decompose`). A Matryoshka BatchTopK sparse
|
|
112
|
+
autoencoder maps each embedding to 2,048 dimensions, about 4 of which are active per
|
|
113
|
+
location-year. The Matryoshka prefixes order the dimensions from coarse (L1) to fine (L4).
|
|
114
|
+
We also release k-means models with the same number of units, which assign each embedding
|
|
115
|
+
to one cluster.
|
|
116
|
+
|
|
117
|
+
**Step 2: Agentic interpretation** (`saearth.interpret`). For each dimension, the
|
|
118
|
+
locations are split into three disjoint sets, each location contributing one year: a
|
|
119
|
+
validation set (50 top-third, 50 inactive), a test set of the same size, and the remaining
|
|
120
|
+
locations for exploration. An LLM agent sees only annual Sentinel-2 RGB composites (1.28 km
|
|
121
|
+
across at 10 m), statistics computed from these images, and their years, with no location
|
|
122
|
+
information. It can
|
|
123
|
+
|
|
124
|
+
- **query** samples from an activation quantile range, random inactive samples, or inactive
|
|
125
|
+
samples whose embeddings are closest to strongly active ones,
|
|
126
|
+
- **view** up to 50 images per call,
|
|
127
|
+
- **score** a candidate description: an LLM annotator predicts, image by image, whether the
|
|
128
|
+
description matches each validation location, and the agent receives the F1,
|
|
129
|
+
- **finish** when it is satisfied.
|
|
130
|
+
|
|
131
|
+
The description with the best validation F1 is kept and scored once on the test set,
|
|
132
|
+
which the agent never sees. A short label is then written from the description and a map
|
|
133
|
+
of where the dimension is active. The released interpretations use `gpt-6-luna` as agent,
|
|
134
|
+
LLM annotator and label model.
|
|
135
|
+
|
|
136
|
+
## Apply SAEarth to your own embeddings
|
|
137
|
+
|
|
138
|
+
[`notebooks/apply_to_new_embeddings.ipynb`](https://github.com/ruaruaxu/saearth/blob/main/notebooks/apply_to_new_embeddings.ipynb) runs
|
|
139
|
+
both steps end to end on a sample drawn from Earth Engine, with the method, M and K set in
|
|
140
|
+
one cell. Install the extra dependencies first:
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
pip install -e ".[interpret]"
|
|
144
|
+
earthengine authenticate
|
|
145
|
+
export OPENAI_API_KEY=...
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**Step 1.** Fit a decomposition on float32 `[n, d]` embeddings. The defaults reproduce
|
|
149
|
+
the released models; every choice below can be changed.
|
|
150
|
+
|
|
151
|
+
| Option | Default | Choices |
|
|
152
|
+
|---|---|---|
|
|
153
|
+
| Method | `matryoshka_batchtopk` | `matryoshka_batchtopk`, `batchtopk`, `topk`, `kmeans` |
|
|
154
|
+
| M, dimensions (clusters for k-means) | 2,048 | any; the default Matryoshka prefixes need a multiple of 16 |
|
|
155
|
+
| K, active dimensions per embedding (SAE) | 4 | any; k-means has one active cluster |
|
|
156
|
+
| Matryoshka prefixes | M/16, 3M/16, 7M/16, M | any increasing list ending at M |
|
|
157
|
+
| Training steps and batch size (SAE) | 100,000 steps of 4,096 | any |
|
|
158
|
+
|
|
159
|
+
`batchtopk` keeps the `batch_size * K` largest activations of each training batch and
|
|
160
|
+
encodes with a frozen threshold; `matryoshka_batchtopk` adds the nested prefixes, which
|
|
161
|
+
order the dimensions from coarse to fine; `topk` keeps exactly K activations per row. With
|
|
162
|
+
`kmeans`, each embedding activates its nearest cluster with the cosine to its center.
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
from saearth.decompose import train_sae, train_kmeans, encode_sparse
|
|
166
|
+
|
|
167
|
+
sae, metrics = train_sae(train_embeddings, validation_embeddings,
|
|
168
|
+
dictionary_size=1024, k=8, architecture="topk") # metrics: R^2 and mean L0
|
|
169
|
+
sae.save("my_sae.npz")
|
|
170
|
+
codes = encode_sparse(sae, embeddings) # CSR arrays, the input of step 2
|
|
171
|
+
|
|
172
|
+
centers, metrics = train_kmeans(train_embeddings, validation_embeddings, clusters=512)
|
|
173
|
+
codes = encode_sparse(centers, embeddings) # one active cluster per row
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
or from the command line:
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
python -m saearth.decompose.train --method topk --dictionary-size 1024 --k 8 \
|
|
180
|
+
--train train.npy --validation validation.npy --output runs/my_sae
|
|
181
|
+
python -m saearth.decompose.encode --model runs/my_sae/sae.npz --embeddings x.npy --output codes.npz
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**Step 2.** Describe dimensions from imagery, for any of the methods above.
|
|
185
|
+
`rows.parquet` lists each location-year (`location_id`, `year`, `longitude`, `latitude`) in
|
|
186
|
+
the same order as the embeddings and codes.
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
from saearth.interpret import interpret_dimensions
|
|
190
|
+
results = interpret_dimensions("rows.parquet", "x.npy", "codes.npz", dimensions=[12, 454],
|
|
191
|
+
output="out", ee_project="<your-earth-engine-project>")
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
or `python -m saearth.interpret.interpret` with the same arguments. Each
|
|
195
|
+
`out/<dimension>/` folder holds `result.json` (interpretation, label, validation and test
|
|
196
|
+
F1), the agent's full action log `transcript.jsonl`, and the map given to the label model.
|
|
197
|
+
Images are fetched from Earth Engine once and cached in `out/images/`.
|
|
198
|
+
|
|
199
|
+
**Cost.** Interpreting the 1,719 TESSERA dimensions with `gpt-6-luna` cost US$102, about
|
|
200
|
+
US$0.06 per dimension. Step 1 needs no API calls.
|
|
201
|
+
|
|
202
|
+
## FAQ
|
|
203
|
+
|
|
204
|
+
**Where and when do the released models apply?** Anywhere AlphaEarth or TESSERA
|
|
205
|
+
embeddings exist, for 2017 onward. The SAEs were trained on 6.7 million location-years from
|
|
206
|
+
the AlphaEarth training coordinates (2017–2023), which cover all major ecoregions.
|
|
207
|
+
|
|
208
|
+
**Do I need a GPU?** No for encoding and interpretation. Training an SAE with the default
|
|
209
|
+
100,000 steps takes minutes on a GPU and longer on a CPU.
|
|
210
|
+
|
|
211
|
+
**Why are some dimensions not interpreted?** A dimension is interpreted when the top third
|
|
212
|
+
of its activations covers at least 150 distinct locations, enough to build disjoint
|
|
213
|
+
validation and test sets. The 1,790 and 1,719 interpreted dimensions carry 99.9% of all
|
|
214
|
+
activation mass.
|
|
215
|
+
|
|
216
|
+
**What does a test F1 of 0.69 mean?** Two human annotators rated 100 descriptions against
|
|
217
|
+
the most strongly activating images of each dimension. At a test F1 of 0.69, the
|
|
218
|
+
probability that the two annotators give a mean rating of at least 4 ("agree") reaches 0.5.
|
|
219
|
+
For reference, an annotator answering at random scores an F1 of 0.5.
|
|
220
|
+
|
|
221
|
+
**Should I use the SAE or the k-means model?** The SAE describes each location with
|
|
222
|
+
about 4 concepts at once and reconstructs the embedding more closely. k-means assigns one
|
|
223
|
+
cluster per location, which is simpler when a single label per location is enough.
|
|
224
|
+
|
|
225
|
+
## Citation
|
|
226
|
+
|
|
227
|
+
```bibtex
|
|
228
|
+
@article{xu2026saearth,
|
|
229
|
+
title = {SAEarth: Interpreting Earth Embeddings with Sparse Representations and LLM Agents},
|
|
230
|
+
author = {Xu, Wenrui and Agostini, Gabriel and Blumenstock, Joshua and Liang, Lu and Pierson, Emma},
|
|
231
|
+
year = {2026}
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## License
|
|
236
|
+
|
|
237
|
+
Code: MIT. Models and interpretations: CC BY 4.0 for AlphaEarth and CC BY-SA 4.0 for
|
|
238
|
+
TESSERA (see `LICENSE`).
|
|
239
|
+
|
|
240
|
+
Attribution:
|
|
241
|
+
|
|
242
|
+
- The [AlphaEarth Foundations Satellite Embedding dataset](https://developers.google.com/earth-engine/datasets/catalog/GOOGLE_SATELLITE_EMBEDDING_V1_ANNUAL)
|
|
243
|
+
is produced by Google and Google DeepMind and is licensed under
|
|
244
|
+
[CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). We trained sparse
|
|
245
|
+
autoencoders and k-means models on these embeddings and interpreted their dimensions.
|
|
246
|
+
- The TESSERA models and interpretations are derived from TESSERA embeddings.
|
|
247
|
+
- The example images, including those in `assets/framework.png`, contain modified
|
|
248
|
+
Copernicus Sentinel data 2017–2023.
|
saearth-0.1.0/README.md
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# SAEarth: Interpreting Earth Embeddings with Sparse Representations and LLM Agents
|
|
2
|
+
|
|
3
|
+
**[Concept Explorer](https://saearth.wenruixu.com)** | **Paper** (arXiv, link coming soon) | [Released models and interpretations](#what-is-released)
|
|
4
|
+
|
|
5
|
+
SAEarth turns a dense Earth embedding into a sparse representation whose dimensions are
|
|
6
|
+
described in natural language and validated on held-out locations. We release this
|
|
7
|
+
representation for the AlphaEarth and TESSERA embeddings: the trained models, a
|
|
8
|
+
description of every interpreted dimension with its held-out fidelity, and the code to
|
|
9
|
+
apply the method to other embeddings.
|
|
10
|
+
|
|
11
|
+
<p align="center"><img src="https://raw.githubusercontent.com/ruaruaxu/saearth/main/assets/framework.png" width="560" alt="SAEarth in two steps: sparse decomposition and agentic interpretation"></p>
|
|
12
|
+
|
|
13
|
+
## Contents
|
|
14
|
+
|
|
15
|
+
- [What is released](#what-is-released)
|
|
16
|
+
- [Quickstart](#quickstart)
|
|
17
|
+
- [Method](#method)
|
|
18
|
+
- [Apply SAEarth to your own embeddings](#apply-saearth-to-your-own-embeddings)
|
|
19
|
+
- [FAQ](#faq)
|
|
20
|
+
- [Citation](#citation)
|
|
21
|
+
- [License](#license)
|
|
22
|
+
|
|
23
|
+
## What is released
|
|
24
|
+
|
|
25
|
+
| | AlphaEarth | TESSERA |
|
|
26
|
+
|---|---|---|
|
|
27
|
+
| Sparse autoencoder (2,048 dimensions, about 4 active) | `saearth/models/alphaearth/sae.npz` | `saearth/models/tessera/sae.npz` |
|
|
28
|
+
| k-means (2,048 clusters, one active) | `saearth/models/alphaearth/kmeans.npz` | `saearth/models/tessera/kmeans.npz` |
|
|
29
|
+
| Interpreted dimensions | 1,790 (`saearth/interpretations/alphaearth_sae.csv`) | 1,719 (`saearth/interpretations/tessera_sae.csv`) |
|
|
30
|
+
| Median held-out test F1 | 0.839 | 0.817 |
|
|
31
|
+
| Faithful (test F1 ≥ 0.69) | 96.4% | 92.7% |
|
|
32
|
+
|
|
33
|
+
The interpreted dimensions carry 99.9% of the activation mass of each SAE.
|
|
34
|
+
`saearth/interpretations/alphaearth_dims.csv` describes the 64 original AlphaEarth dimensions with
|
|
35
|
+
the same agent and test, for comparison.
|
|
36
|
+
|
|
37
|
+
Each interpretation table has one row per dimension:
|
|
38
|
+
|
|
39
|
+
| Column | Meaning |
|
|
40
|
+
|---|---|
|
|
41
|
+
| `dimension` | SAE dimension (0–2,047) |
|
|
42
|
+
| `level` | Matryoshka level, coarse to fine: L1 = 0–127, L2 = 128–383, L3 = 384–895, L4 = 896–2,047 |
|
|
43
|
+
| `theme` | One of eight themes shared by both embeddings, such as Agricultural fields or Built-up settlements |
|
|
44
|
+
| `label` | Short label |
|
|
45
|
+
| `interpretation` | Full description written by the agent |
|
|
46
|
+
| `test_f1` | Fidelity on 100 held-out locations: F1 of the LLM annotator's image-by-image predictions of whether the dimension is in the top third of its activations or inactive |
|
|
47
|
+
| `faithful` | `test_f1 >= 0.69` |
|
|
48
|
+
| `activation_share` | Share of all activation mass carried by the dimension |
|
|
49
|
+
|
|
50
|
+
## Quickstart
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install git+https://github.com/ruaruaxu/saearth.git
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The package includes the released models and interpretation tables. To change the code,
|
|
57
|
+
clone the repository and run `pip install -e .` instead.
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
import numpy as np
|
|
61
|
+
import saearth
|
|
62
|
+
|
|
63
|
+
sae = saearth.load_sae("alphaearth") # or "tessera"
|
|
64
|
+
concepts = saearth.load_concepts("alphaearth") # the interpretation table, indexed by dimension
|
|
65
|
+
|
|
66
|
+
x = np.load("my_alphaearth_embeddings.npy") # [n, 64] float32
|
|
67
|
+
codes = saearth.encode(sae, x) # [n, 2048], about 4 nonzero per row
|
|
68
|
+
for d in np.flatnonzero(codes[0]):
|
|
69
|
+
if d in concepts.index:
|
|
70
|
+
print(d, round(float(codes[0, d]), 3), concepts.label[d])
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
[`notebooks/quickstart.ipynb`](https://github.com/ruaruaxu/saearth/blob/main/notebooks/quickstart.ipynb) reads the AlphaEarth embedding of
|
|
74
|
+
any place from Earth Engine and lists its concepts.
|
|
75
|
+
|
|
76
|
+
**Inputs.** AlphaEarth embeddings as served by the Earth Engine collection
|
|
77
|
+
`GOOGLE/SATELLITE_EMBEDDING/V1/ANNUAL`, or dequantized from the GeoTIFF release with
|
|
78
|
+
`saearth.dequantize_alphaearth`. TESSERA v1.1 embeddings scaled to unit length with
|
|
79
|
+
`saearth.unit_length`. The code of each row is independent of the other rows, so any batch
|
|
80
|
+
size gives the same result.
|
|
81
|
+
|
|
82
|
+
## Method
|
|
83
|
+
|
|
84
|
+
**Step 1: Sparse decomposition** (`saearth.decompose`). A Matryoshka BatchTopK sparse
|
|
85
|
+
autoencoder maps each embedding to 2,048 dimensions, about 4 of which are active per
|
|
86
|
+
location-year. The Matryoshka prefixes order the dimensions from coarse (L1) to fine (L4).
|
|
87
|
+
We also release k-means models with the same number of units, which assign each embedding
|
|
88
|
+
to one cluster.
|
|
89
|
+
|
|
90
|
+
**Step 2: Agentic interpretation** (`saearth.interpret`). For each dimension, the
|
|
91
|
+
locations are split into three disjoint sets, each location contributing one year: a
|
|
92
|
+
validation set (50 top-third, 50 inactive), a test set of the same size, and the remaining
|
|
93
|
+
locations for exploration. An LLM agent sees only annual Sentinel-2 RGB composites (1.28 km
|
|
94
|
+
across at 10 m), statistics computed from these images, and their years, with no location
|
|
95
|
+
information. It can
|
|
96
|
+
|
|
97
|
+
- **query** samples from an activation quantile range, random inactive samples, or inactive
|
|
98
|
+
samples whose embeddings are closest to strongly active ones,
|
|
99
|
+
- **view** up to 50 images per call,
|
|
100
|
+
- **score** a candidate description: an LLM annotator predicts, image by image, whether the
|
|
101
|
+
description matches each validation location, and the agent receives the F1,
|
|
102
|
+
- **finish** when it is satisfied.
|
|
103
|
+
|
|
104
|
+
The description with the best validation F1 is kept and scored once on the test set,
|
|
105
|
+
which the agent never sees. A short label is then written from the description and a map
|
|
106
|
+
of where the dimension is active. The released interpretations use `gpt-6-luna` as agent,
|
|
107
|
+
LLM annotator and label model.
|
|
108
|
+
|
|
109
|
+
## Apply SAEarth to your own embeddings
|
|
110
|
+
|
|
111
|
+
[`notebooks/apply_to_new_embeddings.ipynb`](https://github.com/ruaruaxu/saearth/blob/main/notebooks/apply_to_new_embeddings.ipynb) runs
|
|
112
|
+
both steps end to end on a sample drawn from Earth Engine, with the method, M and K set in
|
|
113
|
+
one cell. Install the extra dependencies first:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
pip install -e ".[interpret]"
|
|
117
|
+
earthengine authenticate
|
|
118
|
+
export OPENAI_API_KEY=...
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**Step 1.** Fit a decomposition on float32 `[n, d]` embeddings. The defaults reproduce
|
|
122
|
+
the released models; every choice below can be changed.
|
|
123
|
+
|
|
124
|
+
| Option | Default | Choices |
|
|
125
|
+
|---|---|---|
|
|
126
|
+
| Method | `matryoshka_batchtopk` | `matryoshka_batchtopk`, `batchtopk`, `topk`, `kmeans` |
|
|
127
|
+
| M, dimensions (clusters for k-means) | 2,048 | any; the default Matryoshka prefixes need a multiple of 16 |
|
|
128
|
+
| K, active dimensions per embedding (SAE) | 4 | any; k-means has one active cluster |
|
|
129
|
+
| Matryoshka prefixes | M/16, 3M/16, 7M/16, M | any increasing list ending at M |
|
|
130
|
+
| Training steps and batch size (SAE) | 100,000 steps of 4,096 | any |
|
|
131
|
+
|
|
132
|
+
`batchtopk` keeps the `batch_size * K` largest activations of each training batch and
|
|
133
|
+
encodes with a frozen threshold; `matryoshka_batchtopk` adds the nested prefixes, which
|
|
134
|
+
order the dimensions from coarse to fine; `topk` keeps exactly K activations per row. With
|
|
135
|
+
`kmeans`, each embedding activates its nearest cluster with the cosine to its center.
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
from saearth.decompose import train_sae, train_kmeans, encode_sparse
|
|
139
|
+
|
|
140
|
+
sae, metrics = train_sae(train_embeddings, validation_embeddings,
|
|
141
|
+
dictionary_size=1024, k=8, architecture="topk") # metrics: R^2 and mean L0
|
|
142
|
+
sae.save("my_sae.npz")
|
|
143
|
+
codes = encode_sparse(sae, embeddings) # CSR arrays, the input of step 2
|
|
144
|
+
|
|
145
|
+
centers, metrics = train_kmeans(train_embeddings, validation_embeddings, clusters=512)
|
|
146
|
+
codes = encode_sparse(centers, embeddings) # one active cluster per row
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
or from the command line:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
python -m saearth.decompose.train --method topk --dictionary-size 1024 --k 8 \
|
|
153
|
+
--train train.npy --validation validation.npy --output runs/my_sae
|
|
154
|
+
python -m saearth.decompose.encode --model runs/my_sae/sae.npz --embeddings x.npy --output codes.npz
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**Step 2.** Describe dimensions from imagery, for any of the methods above.
|
|
158
|
+
`rows.parquet` lists each location-year (`location_id`, `year`, `longitude`, `latitude`) in
|
|
159
|
+
the same order as the embeddings and codes.
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
from saearth.interpret import interpret_dimensions
|
|
163
|
+
results = interpret_dimensions("rows.parquet", "x.npy", "codes.npz", dimensions=[12, 454],
|
|
164
|
+
output="out", ee_project="<your-earth-engine-project>")
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
or `python -m saearth.interpret.interpret` with the same arguments. Each
|
|
168
|
+
`out/<dimension>/` folder holds `result.json` (interpretation, label, validation and test
|
|
169
|
+
F1), the agent's full action log `transcript.jsonl`, and the map given to the label model.
|
|
170
|
+
Images are fetched from Earth Engine once and cached in `out/images/`.
|
|
171
|
+
|
|
172
|
+
**Cost.** Interpreting the 1,719 TESSERA dimensions with `gpt-6-luna` cost US$102, about
|
|
173
|
+
US$0.06 per dimension. Step 1 needs no API calls.
|
|
174
|
+
|
|
175
|
+
## FAQ
|
|
176
|
+
|
|
177
|
+
**Where and when do the released models apply?** Anywhere AlphaEarth or TESSERA
|
|
178
|
+
embeddings exist, for 2017 onward. The SAEs were trained on 6.7 million location-years from
|
|
179
|
+
the AlphaEarth training coordinates (2017–2023), which cover all major ecoregions.
|
|
180
|
+
|
|
181
|
+
**Do I need a GPU?** No for encoding and interpretation. Training an SAE with the default
|
|
182
|
+
100,000 steps takes minutes on a GPU and longer on a CPU.
|
|
183
|
+
|
|
184
|
+
**Why are some dimensions not interpreted?** A dimension is interpreted when the top third
|
|
185
|
+
of its activations covers at least 150 distinct locations, enough to build disjoint
|
|
186
|
+
validation and test sets. The 1,790 and 1,719 interpreted dimensions carry 99.9% of all
|
|
187
|
+
activation mass.
|
|
188
|
+
|
|
189
|
+
**What does a test F1 of 0.69 mean?** Two human annotators rated 100 descriptions against
|
|
190
|
+
the most strongly activating images of each dimension. At a test F1 of 0.69, the
|
|
191
|
+
probability that the two annotators give a mean rating of at least 4 ("agree") reaches 0.5.
|
|
192
|
+
For reference, an annotator answering at random scores an F1 of 0.5.
|
|
193
|
+
|
|
194
|
+
**Should I use the SAE or the k-means model?** The SAE describes each location with
|
|
195
|
+
about 4 concepts at once and reconstructs the embedding more closely. k-means assigns one
|
|
196
|
+
cluster per location, which is simpler when a single label per location is enough.
|
|
197
|
+
|
|
198
|
+
## Citation
|
|
199
|
+
|
|
200
|
+
```bibtex
|
|
201
|
+
@article{xu2026saearth,
|
|
202
|
+
title = {SAEarth: Interpreting Earth Embeddings with Sparse Representations and LLM Agents},
|
|
203
|
+
author = {Xu, Wenrui and Agostini, Gabriel and Blumenstock, Joshua and Liang, Lu and Pierson, Emma},
|
|
204
|
+
year = {2026}
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## License
|
|
209
|
+
|
|
210
|
+
Code: MIT. Models and interpretations: CC BY 4.0 for AlphaEarth and CC BY-SA 4.0 for
|
|
211
|
+
TESSERA (see `LICENSE`).
|
|
212
|
+
|
|
213
|
+
Attribution:
|
|
214
|
+
|
|
215
|
+
- The [AlphaEarth Foundations Satellite Embedding dataset](https://developers.google.com/earth-engine/datasets/catalog/GOOGLE_SATELLITE_EMBEDDING_V1_ANNUAL)
|
|
216
|
+
is produced by Google and Google DeepMind and is licensed under
|
|
217
|
+
[CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). We trained sparse
|
|
218
|
+
autoencoders and k-means models on these embeddings and interpreted their dimensions.
|
|
219
|
+
- The TESSERA models and interpretations are derived from TESSERA embeddings.
|
|
220
|
+
- The example images, including those in `assets/framework.png`, contain modified
|
|
221
|
+
Copernicus Sentinel data 2017–2023.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "saearth"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Sparse, interpretable Earth embeddings: sparse autoencoders and LLM-agent interpretations"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT AND CC-BY-4.0 AND CC-BY-SA-4.0" # code MIT; AlphaEarth / TESSERA models and tables, see LICENSE
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
dependencies = ["numpy", "pandas", "pyarrow", "torch", "scikit-learn"]
|
|
14
|
+
|
|
15
|
+
[project.optional-dependencies]
|
|
16
|
+
interpret = ["scipy", "earthengine-api", "rasterio", "pillow", "matplotlib", "requests"]
|
|
17
|
+
notebooks = ["jupyter", "earthengine-api"]
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Homepage = "https://saearth.wenruixu.com"
|
|
21
|
+
Source = "https://github.com/ruaruaxu/saearth"
|
|
22
|
+
|
|
23
|
+
[tool.setuptools.packages.find]
|
|
24
|
+
include = ["saearth*"]
|
|
25
|
+
|
|
26
|
+
[tool.setuptools.package-data]
|
|
27
|
+
saearth = ["models/*/*.npz", "interpretations/*.csv"]
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""SAEarth: sparse, interpretable Earth embeddings.
|
|
2
|
+
|
|
3
|
+
Step 1, ``saearth.decompose``: a sparse autoencoder turns each Earth embedding into a
|
|
4
|
+
sparse code over 2,048 dimensions. Step 2, ``saearth.interpret``: an LLM agent describes
|
|
5
|
+
each dimension from satellite imagery and is scored on held-out locations.
|
|
6
|
+
|
|
7
|
+
The released models and interpretations can be used directly:
|
|
8
|
+
|
|
9
|
+
import saearth
|
|
10
|
+
sae = saearth.load_sae("alphaearth") # or "tessera"; saearth.load_kmeans(...) for k-means
|
|
11
|
+
codes = saearth.encode(sae, embeddings) # [n, 2048], about 4 nonzero per row
|
|
12
|
+
concepts = saearth.load_concepts("alphaearth") # label, interpretation, test F1, ...
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
PACKAGE = Path(__file__).resolve().parent # the released models and tables ship inside the package
|
|
18
|
+
EMBEDDINGS = ("alphaearth", "tessera")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _resource(name_or_path, filename: str) -> Path:
|
|
22
|
+
if str(name_or_path) in EMBEDDINGS:
|
|
23
|
+
return PACKAGE / "models" / str(name_or_path) / filename
|
|
24
|
+
return Path(name_or_path)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def load_sae(name_or_path, device: str = "cpu"):
|
|
28
|
+
"""A released SAE ("alphaearth" or "tessera") or an ``sae.npz`` you trained."""
|
|
29
|
+
from .decompose.sae import load_sae as load
|
|
30
|
+
return load(_resource(name_or_path, "sae.npz"), device)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def encode(model, embeddings, batch_size: int = 65_536):
|
|
34
|
+
"""Dense ``[n, M]`` sparse codes of ``[n, d]`` embeddings (TESSERA rows scaled to unit length first).
|
|
35
|
+
|
|
36
|
+
``model`` is an SAE from ``load_sae`` or k-means centers from ``load_kmeans`` (one active cluster per row,
|
|
37
|
+
activation = cosine to its center).
|
|
38
|
+
"""
|
|
39
|
+
import numpy as np
|
|
40
|
+
if isinstance(model, np.ndarray):
|
|
41
|
+
from .decompose.kmeans import assign
|
|
42
|
+
labels, activation = assign(embeddings, model)
|
|
43
|
+
codes = np.zeros((len(labels), len(model)), dtype=np.float32)
|
|
44
|
+
codes[np.arange(len(labels)), labels] = activation
|
|
45
|
+
return codes
|
|
46
|
+
from .decompose.sae import encode as run
|
|
47
|
+
return run(model, embeddings, batch_size)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def unit_length(embeddings):
|
|
51
|
+
"""Scale each row to unit length (TESSERA inputs)."""
|
|
52
|
+
from .decompose.embeddings import unit_length as scale
|
|
53
|
+
return scale(embeddings)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def dequantize_alphaearth(raw):
|
|
57
|
+
"""Signed int8 AlphaEarth GeoTIFF values to the float embeddings."""
|
|
58
|
+
from .decompose.embeddings import dequantize_alphaearth as dequantize
|
|
59
|
+
return dequantize(raw)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def load_kmeans(name_or_path):
|
|
63
|
+
"""Centers of a released k-means model ("alphaearth" or "tessera") or a ``kmeans.npz`` path."""
|
|
64
|
+
from .decompose.kmeans import load_kmeans as load
|
|
65
|
+
return load(_resource(name_or_path, "kmeans.npz"))
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def load_concepts(embedding: str):
|
|
69
|
+
"""The interpreted SAE dimensions of "alphaearth" or "tessera" as a DataFrame indexed by dimension."""
|
|
70
|
+
import pandas as pd
|
|
71
|
+
return pd.read_csv(PACKAGE / "interpretations" / f"{embedding}_sae.csv").set_index("dimension")
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Step 1 of SAEarth: decompose dense Earth embeddings into sparse representations."""
|
|
2
|
+
|
|
3
|
+
from .embeddings import dequantize_alphaearth, unit_length
|
|
4
|
+
from .kmeans import assign, fit_kmeans, kmeans_codes, load_kmeans
|
|
5
|
+
from .sae import ARCHITECTURES, SparseAutoencoder, encode, load_sae
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def __getattr__(name):
|
|
9
|
+
# Imported on first use, so ``python -m saearth.decompose.train`` and ``.encode`` run without a runpy warning.
|
|
10
|
+
if name in ("train_sae", "train_kmeans"):
|
|
11
|
+
from . import train
|
|
12
|
+
return getattr(train, name)
|
|
13
|
+
if name == "encode_sparse":
|
|
14
|
+
from .encode import encode_sparse
|
|
15
|
+
return encode_sparse
|
|
16
|
+
raise AttributeError(name)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Input conventions for the two Earth embeddings.
|
|
2
|
+
|
|
3
|
+
AlphaEarth: 64-d annual embeddings. The Earth Engine collection
|
|
4
|
+
``GOOGLE/SATELLITE_EMBEDDING/V1/ANNUAL`` serves them as floats, ready to use. The
|
|
5
|
+
cloud-optimized GeoTIFF release stores signed 8-bit values; ``dequantize_alphaearth``
|
|
6
|
+
converts them to the same floats.
|
|
7
|
+
|
|
8
|
+
TESSERA: 128-d annual embeddings, scaled to unit length before encoding.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import numpy as np
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def dequantize_alphaearth(raw: np.ndarray) -> np.ndarray:
|
|
15
|
+
"""Signed int8 AlphaEarth values (GeoTIFF release) to float embeddings."""
|
|
16
|
+
values = raw.astype(np.float64)
|
|
17
|
+
return (np.sign(values) * np.square(np.abs(values) / 127.5)).astype(np.float32)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def unit_length(embeddings: np.ndarray) -> np.ndarray:
|
|
21
|
+
"""Scale each row to unit L2 norm (TESSERA inputs)."""
|
|
22
|
+
embeddings = np.asarray(embeddings, dtype=np.float32)
|
|
23
|
+
return embeddings / np.linalg.norm(embeddings, axis=1, keepdims=True)
|