grabbou commited on
Commit
9381784
·
verified ·
1 Parent(s): 6490f58

Add model card

Browse files
Files changed (1) hide show
  1. README.md +47 -0
README.md ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ base_model: openai/clip-vit-base-patch32
4
+ pipeline_tag: feature-extraction
5
+ library_name: coreai
6
+ tags:
7
+ - core-ai
8
+ - ios
9
+ - clip
10
+ - embeddings
11
+ ---
12
+
13
+ # CLIP ViT-B/32 encoders for Core AI
14
+
15
+ [`openai/clip-vit-base-patch32`](https://huggingface.co/openai/clip-vit-base-patch32) exported to Apple Core AI as one `.aimodel` with separate text and image encoders, so text and images embed on their own into the same space.
16
+
17
+ Apple's [`models/clip`](https://github.com/apple/coreai-models/tree/main/models/clip) recipe traces one function that needs an image and a fixed batch of three prompts on every call, so this export uses [`export.py`](./export.py), based on it (coreai-torch 0.4.3, torch 2.13):
18
+
19
+ ```sh
20
+ uv run --script export.py --output-dir exports --dtype float16
21
+ ```
22
+
23
+ | Folder | Contents | Size | Platforms |
24
+ | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ---------- |
25
+ | `clip-vit-base-patch32/` | `clip-vit-base-patch32.aimodel` with `encode_text(input_ids, attention_mask) -> text_embeds` (`[batch, 77]` int32) and `encode_image(pixel_values) -> image_embeds` (`[batch, 3, 224, 224]` float16, CLIP mean and std), batch 1–64, 512-dim L2-normalized embeddings. `tokenizer/`: the CLIP tokenizer | 290 MB | iOS, macOS |
26
+
27
+ ## Use
28
+
29
+ With [`@react-native-ai/core-ai`](https://github.com/callstackincubator/ai/tree/main/packages/core-ai), download `clip-vit-base-patch32/` into app storage, then embed text with the AI SDK and images with the native API:
30
+
31
+ ```ts
32
+ import { coreAI, CoreAI } from '@react-native-ai/core-ai'
33
+ import { cosineSimilarity, embedMany } from 'ai'
34
+
35
+ const model = coreAI.embeddingModel({
36
+ id: 'clip-vit-base-patch32',
37
+ source: { type: 'file', uri: pathToFolder },
38
+ })
39
+ const { embeddings } = await embedMany({ model, values: ['a photo of a cat', 'a photo of a car'] })
40
+ const { embeddings: [image] } = await model.embedImages([imageUri])
41
+
42
+ cosineSimilarity(embeddings[0], image) // higher for the matching caption
43
+ ```
44
+
45
+ ## License
46
+
47
+ CLIP is MIT licensed. This repository only converts it to Core AI format.