netzhang commited on
Commit
57b8204
·
verified ·
1 Parent(s): 0b2edaf

WIP: Add dataset card with DuckDB query examples (demo only)

Browse files
Files changed (1) hide show
  1. README.md +204 -0
README.md ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ dataset_info:
3
+ - config_name: bioclip-2_float16
4
+ features:
5
+ - name: uuid
6
+ dtype: string
7
+ - name: kingdom
8
+ dtype: string
9
+ - name: phylum
10
+ dtype: string
11
+ - name: class
12
+ dtype: string
13
+ - name: order
14
+ dtype: string
15
+ - name: family
16
+ dtype: string
17
+ - name: genus
18
+ dtype: string
19
+ - name: species
20
+ dtype: string
21
+ - name: img_type
22
+ dtype: string
23
+ - name: basisOfRecord
24
+ dtype: string
25
+ - name: publisher
26
+ dtype: string
27
+ - name: identifier
28
+ dtype: string
29
+ - name: emb
30
+ sequence: float16
31
+ length: 768
32
+ splits:
33
+ - name: train
34
+ num_examples: 239580103
35
+ configs:
36
+ - config_name: bioclip-2_float16
37
+ data_files:
38
+ - split: train
39
+ path: bioclip-2_float16/*.parquet
40
+ license: mit
41
+ ---
42
+
43
+ # TreeOfLife-200M Embeddings
44
+
45
+ > **Work in progress** — this dataset card is under active development.
46
+
47
+ 239 million BioCLIP 2 embeddings (768-dim, float16) for [TreeOfLife-200M](https://huggingface.co/datasets/imageomics/TreeOfLife-200M) images, sorted by taxonomic hierarchy. We recommend using [DuckDB](https://duckdb.org/) to access this dataset.
48
+
49
+ ## Query Remotely
50
+
51
+ Query directly from HuggingFace without downloading anything. DuckDB uses Parquet page indexes to skip irrelevant files, making filtered queries fast over the network.
52
+
53
+ > `order` and `class` are SQL reserved words — always quote them as `"order"` and `"class"`.
54
+
55
+ ### Python
56
+
57
+ ```python
58
+ import duckdb
59
+
60
+ con = duckdb.connect()
61
+ # Authenticate for higher rate limits (recommended)
62
+ con.execute("CREATE SECRET (TYPE HUGGINGFACE, TOKEN 'hf_...')")
63
+
64
+ glob = "hf://datasets/imageomics/TreeOfLife-200M-Embeddings/bioclip-2_float16/*.parquet"
65
+
66
+ # Get all embeddings for a species
67
+ df = con.sql(f"""
68
+ SELECT uuid, emb
69
+ FROM read_parquet('{glob}')
70
+ WHERE species = 'Danaus plexippus'
71
+ """).df()
72
+
73
+ # Count by taxonomic order
74
+ con.sql(f"""
75
+ SELECT "order", COUNT(*) as n
76
+ FROM read_parquet('{glob}')
77
+ WHERE "order" IS NOT NULL
78
+ GROUP BY "order"
79
+ ORDER BY n DESC
80
+ LIMIT 10
81
+ """).show()
82
+
83
+ # Filter by family
84
+ con.sql(f"""
85
+ SELECT genus, species, COUNT(*) as n
86
+ FROM read_parquet('{glob}')
87
+ WHERE family = 'Felidae'
88
+ GROUP BY genus, species
89
+ ORDER BY n DESC
90
+ LIMIT 10
91
+ """).show()
92
+ ```
93
+
94
+ ### CLI
95
+
96
+ ```bash
97
+ # Install DuckDB: https://duckdb.org/docs/installation
98
+ # Then query directly from the command line:
99
+
100
+ duckdb -c "
101
+ SELECT species, COUNT(*) as n
102
+ FROM read_parquet('hf://datasets/imageomics/TreeOfLife-200M-Embeddings/bioclip-2_float16/*.parquet')
103
+ WHERE family = 'Nymphalidae'
104
+ GROUP BY species
105
+ ORDER BY n DESC
106
+ LIMIT 10;
107
+ "
108
+ ```
109
+
110
+ ## Download a Taxonomic Slice
111
+
112
+ Instead of downloading the full 331 GB dataset, extract only the taxa you need. The sorted data and page indexes ensure only the relevant row groups are fetched over the network.
113
+
114
+ ### Python
115
+
116
+ ```python
117
+ import duckdb
118
+
119
+ con = duckdb.connect()
120
+ con.execute("CREATE SECRET (TYPE HUGGINGFACE, TOKEN 'hf_...')")
121
+
122
+ glob = "hf://datasets/imageomics/TreeOfLife-200M-Embeddings/bioclip-2_float16/*.parquet"
123
+
124
+ # Save a single family to a local file
125
+ con.sql(f"""
126
+ COPY (
127
+ SELECT * FROM read_parquet('{glob}')
128
+ WHERE family = 'Felidae'
129
+ ) TO 'felidae.parquet'
130
+ """)
131
+
132
+ # Now query locally — instant
133
+ con.sql("SELECT species, COUNT(*) as n FROM 'felidae.parquet' GROUP BY species ORDER BY n DESC").show()
134
+ ```
135
+
136
+ ### CLI
137
+
138
+ ```bash
139
+ duckdb -c "
140
+ COPY (
141
+ SELECT * FROM read_parquet('hf://datasets/imageomics/TreeOfLife-200M-Embeddings/bioclip-2_float16/*.parquet')
142
+ WHERE \"order\" = 'Primates'
143
+ ) TO 'primates.parquet';
144
+ "
145
+ ```
146
+
147
+ | Slice Example | Rows | Size | Time |
148
+ |---------------|------|------|------|
149
+ | Species: *Danaus plexippus* | 299,874 | 913 MB | ~1 min* |
150
+ | Family: Felidae | 149,890 | 457 MB | ~1 min* |
151
+ | Order: Primates | 160,307 | 489 MB | ~1 min* |
152
+
153
+ *\*First query in a session includes a one-time ~3 min glob resolution overhead: DuckDB expands the `*.parquet` wildcard by making HTTP requests to HuggingFace to discover all 685 filenames. Subsequent queries in the same session reuse the cached file list.*
154
+
155
+ ## Download Everything
156
+
157
+ For full-dataset analytics, download all files first.
158
+
159
+ ```bash
160
+ huggingface-cli download imageomics/TreeOfLife-200M-Embeddings \
161
+ --repo-type dataset --include "bioclip-2_float16/*" --local-dir ./data
162
+ ```
163
+
164
+ ```bash
165
+ duckdb -c "
166
+ SELECT \"order\", COUNT(*) as n
167
+ FROM read_parquet('./data/bioclip-2_float16/*.parquet')
168
+ WHERE \"order\" IS NOT NULL
169
+ GROUP BY \"order\"
170
+ ORDER BY n DESC
171
+ LIMIT 10;
172
+ "
173
+ ```
174
+
175
+ ## Schema
176
+
177
+ | Column | Type | Description |
178
+ |--------|------|-------------|
179
+ | `uuid` | `string` | Unique image identifier |
180
+ | `kingdom` | `string` | Taxonomic kingdom |
181
+ | `phylum` | `string` | Taxonomic phylum |
182
+ | `class` | `string` | Taxonomic class |
183
+ | `order` | `string` | Taxonomic order |
184
+ | `family` | `string` | Taxonomic family |
185
+ | `genus` | `string` | Taxonomic genus |
186
+ | `species` | `string` | Taxonomic species |
187
+ | `img_type` | `string` | Image source type |
188
+ | `basisOfRecord` | `string` | Basis of record |
189
+ | `publisher` | `string` | Data publisher |
190
+ | `identifier` | `string` | Source URI |
191
+ | `emb` | `fixed_size_list<float16>[768]` | BioCLIP 2 embedding |
192
+
193
+ ## Data Organization
194
+
195
+ - **Sort order:** `kingdom > phylum > class > order > family > genus > species`
196
+ - **Row groups:** 50,000 rows each with column statistics and page indexes
197
+ - **Compression:** ZSTD level 3
198
+ - **Precision:** float16 (lossless cosine similarity vs float32 source)
199
+
200
+ ## Configs
201
+
202
+ | Config | Model | Precision | Files | Size | Rows |
203
+ |--------|-------|-----------|-------|------|------|
204
+ | `bioclip-2_float16` | BioCLIP 2 | float16 | 685 | 331 GB | 239,580,103 |