gpu-icons-search 0.0.0-stage → 0.0.0
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.
- package/LICENSE.md +21 -0
- package/README.md +136 -2
- package/dist/aliases.json +1 -0
- package/dist/fallback.d.mts +13 -0
- package/dist/fallback.mjs +30 -0
- package/dist/features-BljwdDt0.mjs +49 -0
- package/dist/index.d.mts +45 -0
- package/dist/index.mjs +571 -0
- package/dist/model.bin +0 -0
- package/dist/types-gON7Y_i0.d.mts +18 -0
- package/package.json +80 -4
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-PRESENT Anthony Fu <https://github.com/antfu>
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,137 @@
|
|
|
1
|
-
#
|
|
1
|
+
# gpu-icons-search
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
4
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
5
|
+
[![bundle][bundle-src]][bundle-href]
|
|
6
|
+
[![JSDocs][jsdocs-src]][jsdocs-href]
|
|
7
|
+
[![License][license-src]][license-href]
|
|
8
|
+
|
|
9
|
+
A small model that runs on WebGPU and predicts related icon words for a search query. For example, `hom` gives `home` and `house`. It handles English keywords, short descriptions, half-typed words and typos.
|
|
10
|
+
|
|
11
|
+
The model only predicts words. Your own text matcher, for example fzf, still finds the icons. [Icones](https://github.com/antfu-collective/icones) is the first intended user: the predictions replace its manual alias list.
|
|
12
|
+
|
|
13
|
+
> [!WARNING]
|
|
14
|
+
> This project is experimental and not published to npm yet. See [MODEL_CARD.md](./MODEL_CARD.md) for the scores and the limits of the current model.
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { predict } from 'gpu-icons-search'
|
|
20
|
+
|
|
21
|
+
const predictions = await predict('hom')
|
|
22
|
+
// [
|
|
23
|
+
// { word: 'home', score: 0.43, from: 'hom', kind: 'completion' },
|
|
24
|
+
// { word: 'house', score: 0.42, from: 'hom', kind: 'related' },
|
|
25
|
+
// ]
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`predict` loads the model on the first call. It rejects if WebGPU is not available. Every predicted word comes from a built-in list of words that occur in Iconify icon names.
|
|
29
|
+
|
|
30
|
+
Create your own predictor to control the weight file, the GPU device and the lifetime:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { createPredictor, isSupported } from 'gpu-icons-search'
|
|
34
|
+
|
|
35
|
+
if (isSupported()) {
|
|
36
|
+
const predictor = await createPredictor({ weights: '/assets/model.bin' })
|
|
37
|
+
const controller = new AbortController()
|
|
38
|
+
console.log(await predictor.predict('shoping cart', { limit: 8, signal: controller.signal }))
|
|
39
|
+
predictor.dispose()
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Abort a call when the user presses the next key. The call then rejects and its result is dropped.
|
|
44
|
+
|
|
45
|
+
## Use the predictions with fzf
|
|
46
|
+
|
|
47
|
+
Run your matcher on the typed text first. Then run it on each predicted word as an exact match, in score order. This keeps the matches of the typed text on top.
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { extendedMatch, Fzf } from 'fzf'
|
|
51
|
+
import { predict } from 'gpu-icons-search'
|
|
52
|
+
|
|
53
|
+
const fzf = new Fzf(iconNames, { casing: 'case-insensitive', match: extendedMatch })
|
|
54
|
+
|
|
55
|
+
async function search(query: string): Promise<string[]> {
|
|
56
|
+
const results = new Set(fzf.find(query).map(entry => entry.item))
|
|
57
|
+
for (const prediction of await predict(query)) {
|
|
58
|
+
// The quote makes fzf match the word exactly
|
|
59
|
+
for (const entry of fzf.find(`'${prediction.word}`))
|
|
60
|
+
results.add(entry.item)
|
|
61
|
+
}
|
|
62
|
+
return [...results]
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`training/src/search.ts` holds the full reference integration, which also replaces a single word of a longer query.
|
|
67
|
+
|
|
68
|
+
## Without WebGPU
|
|
69
|
+
|
|
70
|
+
The package has no CPU version of the model. For browsers without WebGPU, it ships a static table with the predictions of the model for common words. The table knows whole words only: no typos, no half-typed words, no descriptions.
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { isSupported, predict } from 'gpu-icons-search'
|
|
74
|
+
import { loadAliasTable, predictFromTable } from 'gpu-icons-search/fallback'
|
|
75
|
+
|
|
76
|
+
async function predictAnywhere(query: string) {
|
|
77
|
+
if (isSupported())
|
|
78
|
+
return predict(query)
|
|
79
|
+
return predictFromTable(await loadAliasTable(), query)
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## How it works
|
|
84
|
+
|
|
85
|
+
1. The CPU splits the query into words and hashes each word to rows of a feature table.
|
|
86
|
+
2. A WGSL shader turns the rows into one vector per word and one for the whole query.
|
|
87
|
+
3. A second shader compares each vector with the vector of every word in the word list.
|
|
88
|
+
4. A third shader keeps the best words, and the CPU reads them back.
|
|
89
|
+
|
|
90
|
+
The weights use 6 bits each. The weight file with the word list is below 1 MB.
|
|
91
|
+
|
|
92
|
+
## Development
|
|
93
|
+
|
|
94
|
+
The repository has three parts:
|
|
95
|
+
|
|
96
|
+
- The root is the published package: the WebGPU runtime in `src/`.
|
|
97
|
+
- `training/` holds the data pipeline, the benchmark and the PyTorch training loop.
|
|
98
|
+
- `playground/` compares the model with the current Icones search.
|
|
99
|
+
|
|
100
|
+
Install Node.js 22 or later, pnpm, and [uv](https://docs.astral.sh/uv/) for the Python part. On Linux without a GPU, also install Playwright Chromium: the scripts use its software Vulkan driver for WebGPU.
|
|
101
|
+
|
|
102
|
+
```sh
|
|
103
|
+
pnpm install
|
|
104
|
+
pnpm data # read Iconify and the tag sources, build the training targets
|
|
105
|
+
pnpm bench # print the benchmark table of the baselines
|
|
106
|
+
pnpm train # fit a candidate with PyTorch (uses the Apple GPU on a Mac)
|
|
107
|
+
pnpm evaluate # run the candidate on real WebGPU and score it
|
|
108
|
+
pnpm promote # copy the candidate into weights/ if it passes the ship gate
|
|
109
|
+
pnpm play # start the playground
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
[PLAN.md](./PLAN.md) records the design decisions. [THIRD_PARTY_NOTICES.md](./THIRD_PARTY_NOTICES.md) lists the training data and its licenses.
|
|
113
|
+
|
|
114
|
+
## Sponsors
|
|
115
|
+
|
|
116
|
+
<p align="center">
|
|
117
|
+
<a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
|
|
118
|
+
<img src="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg" alt="Sponsors"/>
|
|
119
|
+
</a>
|
|
120
|
+
</p>
|
|
121
|
+
|
|
122
|
+
## License
|
|
123
|
+
|
|
124
|
+
[MIT](./LICENSE) License © [Anthony Fu](https://github.com/antfu)
|
|
125
|
+
|
|
126
|
+
<!-- Badges -->
|
|
127
|
+
|
|
128
|
+
[npm-version-src]: https://img.shields.io/npm/v/gpu-icons-search?style=flat&colorA=080f12&colorB=1fa669
|
|
129
|
+
[npm-version-href]: https://npmx.dev/package/gpu-icons-search
|
|
130
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/gpu-icons-search?style=flat&colorA=080f12&colorB=1fa669
|
|
131
|
+
[npm-downloads-href]: https://npmx.dev/package/gpu-icons-search
|
|
132
|
+
[bundle-src]: https://img.shields.io/bundlephobia/minzip/gpu-icons-search?style=flat&colorA=080f12&colorB=1fa669&label=minzip
|
|
133
|
+
[bundle-href]: https://bundlephobia.com/result?p=gpu-icons-search
|
|
134
|
+
[license-src]: https://img.shields.io/github/license/antfu/gpu-icons-search.svg?style=flat&colorA=080f12&colorB=1fa669
|
|
135
|
+
[license-href]: https://github.com/antfu/gpu-icons-search/blob/main/LICENSE
|
|
136
|
+
[jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
|
|
137
|
+
[jsdocs-href]: https://www.jsdocs.io/package/gpu-icons-search
|