finnvoorhees commited on
Commit
dbae32f
0 Parent(s):

initial commit

Browse files
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
ModernBERT-base.mlpackage/Data/com.apple.CoreML/FeatureDescriptions.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "Inputs" : {
3
+ "attention_mask" : {
4
+ "MLFeatureShortDescription" : "--"
5
+ },
6
+ "input_ids" : {
7
+ "MLFeatureShortDescription" : "--"
8
+ }
9
+ },
10
+ "Outputs" : {
11
+ "logits" : {
12
+ "MLFeatureShortDescription" : "--"
13
+ }
14
+ },
15
+ "TrainingInputs" : {
16
+
17
+ },
18
+ "States" : {
19
+
20
+ }
21
+ }
ModernBERT-base.mlpackage/Data/com.apple.CoreML/Metadata.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "MLModelVersionStringKey" : "--",
3
+ "MLModelDescriptionKey" : "ModernBERT is a modernized bidirectional encoder-only Transformer model (BERT-style) pre-trained on 2 trillion tokens of English and code data with a native context length of up to 8,192 tokens.\n\nhttps:\/\/huggingface.co\/answerdotai\/ModernBERT-base",
4
+ "MLModelCreatorDefinedKey" : {
5
+ "com.github.apple.coremltools.source_dialect" : "TorchScript",
6
+ "com.github.apple.coremltools.source" : "torch==2.5.1",
7
+ "com.github.apple.coremltools.version" : "8.1"
8
+ },
9
+ "MLModelAuthorKey" : "Answer.AI",
10
+ "MLModelLicenseKey" : "Apache license 2.0"
11
+ }
ModernBERT-base.mlpackage/Data/com.apple.CoreML/model.mlmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ebcc912b77e91056515709e659752d132ad97e78e2e4a6032bee1aec80fedf90
3
+ size 266649
ModernBERT-base.mlpackage/Data/com.apple.CoreML/weights/weight.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b4e6706d003041ba9244f96433429f7bf9c9de12ad17df917b947dc691b581e3
3
+ size 299325824
ModernBERT-base.mlpackage/Manifest.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "fileFormatVersion": "1.0.0",
3
+ "itemInfoEntries": {
4
+ "06E6264F-CB31-4D71-A23C-A3D3689A565C": {
5
+ "author": "com.apple.CoreML",
6
+ "description": "CoreML Model Weights",
7
+ "name": "weights",
8
+ "path": "com.apple.CoreML/weights"
9
+ },
10
+ "5510B1F0-2CBA-49A0-B455-0C475F598606": {
11
+ "author": "com.apple.CoreML",
12
+ "description": "External FeatureDescription Overlay",
13
+ "name": "FeatureDescriptions.json",
14
+ "path": "com.apple.CoreML/FeatureDescriptions.json"
15
+ },
16
+ "90F77D61-5B31-4442-BA5D-CFF0227A04B1": {
17
+ "author": "com.apple.CoreML",
18
+ "description": "CoreML Model Specification",
19
+ "name": "model.mlmodel",
20
+ "path": "com.apple.CoreML/model.mlmodel"
21
+ },
22
+ "F4E8C7BD-D5AA-4A9E-B724-C70CE42D4C48": {
23
+ "author": "com.apple.CoreML",
24
+ "description": "External Metadata Overlay",
25
+ "name": "Metadata.json",
26
+ "path": "com.apple.CoreML/Metadata.json"
27
+ }
28
+ },
29
+ "rootModelIdentifier": "90F77D61-5B31-4442-BA5D-CFF0227A04B1"
30
+ }
ModernBERT-large.mlpackage/Data/com.apple.CoreML/FeatureDescriptions.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "Inputs" : {
3
+ "attention_mask" : {
4
+ "MLFeatureShortDescription" : ""
5
+ },
6
+ "input_ids" : {
7
+ "MLFeatureShortDescription" : ""
8
+ }
9
+ },
10
+ "Outputs" : {
11
+ "logits" : {
12
+ "MLFeatureShortDescription" : ""
13
+ }
14
+ },
15
+ "TrainingInputs" : {
16
+
17
+ },
18
+ "States" : {
19
+
20
+ }
21
+ }
ModernBERT-large.mlpackage/Data/com.apple.CoreML/Metadata.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "MLModelDescriptionKey" : "ModernBERT is a modernized bidirectional encoder-only Transformer model (BERT-style) pre-trained on 2 trillion tokens of English and code data with a native context length of up to 8,192 tokens.\n\nhttps:\/\/huggingface.co\/answerdotai\/ModernBERT-large",
3
+ "MLModelCreatorDefinedKey" : {
4
+ "com.github.apple.coremltools.source_dialect" : "TorchScript",
5
+ "com.github.apple.coremltools.version" : "8.1",
6
+ "com.github.apple.coremltools.source" : "torch==2.5.1"
7
+ },
8
+ "MLModelAuthorKey" : "Answer.AI",
9
+ "MLModelLicenseKey" : "Apache license 2.0"
10
+ }
ModernBERT-large.mlpackage/Data/com.apple.CoreML/model.mlmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9cf60aa2e976e2c594e83db8f8ba42ecf9cc9f14348b4221347b7df6f612a8bd
3
+ size 335419
ModernBERT-large.mlpackage/Data/com.apple.CoreML/weights/weight.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:90b125e16fb2050ae1c29c076c2733d167e556bdd853e9e917c120eeb87a7c25
3
+ size 791793600
ModernBERT-large.mlpackage/Manifest.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "fileFormatVersion": "1.0.0",
3
+ "itemInfoEntries": {
4
+ "0B8AE6F6-1317-4127-8BD5-2AB46EC557CE": {
5
+ "author": "com.apple.CoreML",
6
+ "description": "External Metadata Overlay",
7
+ "name": "Metadata.json",
8
+ "path": "com.apple.CoreML/Metadata.json"
9
+ },
10
+ "3D71FBFB-60F3-48A0-8F1B-8550A02403E1": {
11
+ "author": "com.apple.CoreML",
12
+ "description": "CoreML Model Specification",
13
+ "name": "model.mlmodel",
14
+ "path": "com.apple.CoreML/model.mlmodel"
15
+ },
16
+ "56305CCC-0DD8-43A2-8834-124ACA88424A": {
17
+ "author": "com.apple.CoreML",
18
+ "description": "External FeatureDescription Overlay",
19
+ "name": "FeatureDescriptions.json",
20
+ "path": "com.apple.CoreML/FeatureDescriptions.json"
21
+ },
22
+ "75F45B20-DDAB-400A-8F8E-87D2E0A4DFB6": {
23
+ "author": "com.apple.CoreML",
24
+ "description": "CoreML Model Weights",
25
+ "name": "weights",
26
+ "path": "com.apple.CoreML/weights"
27
+ }
28
+ },
29
+ "rootModelIdentifier": "3D71FBFB-60F3-48A0-8F1B-8550A02403E1"
30
+ }
README.md ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ tags:
6
+ - fill-mask
7
+ - masked-lm
8
+ - long-context
9
+ - modernbert
10
+ ---
11
+
12
+ # ModernBERT-CoreML
13
+
14
+ This repo contains [ModernBERT-base](https://huggingface.co/answerdotai/ModernBERT-base) and [ModernBERT-large](https://huggingface.co/answerdotai/ModernBERT-large) converted to CoreML.
15
+
16
+ ### Example Usage
17
+
18
+ ```swift
19
+ import CoreML
20
+ import Tokenizers
21
+
22
+ let text = "The capital of Ireland is [MASK]."
23
+
24
+ print("Loading…")
25
+ let model = try await ModernBERT_base.load()
26
+ let tokenizer = try await AutoTokenizer.from(pretrained: "answerdotai/ModernBERT-base")
27
+
28
+ let tokens = tokenizer(text)
29
+ let inputIDs = MLShapedArray(scalars: tokens.map(Int32.init), shape: [1, tokens.count])
30
+ let attentionMask = MLShapedArray<Int32>(scalars: tokens.map { _ in 1 }, shape: [1, tokens.count])
31
+ let input = ModernBERT_baseInput(
32
+ input_ids: inputIDs,
33
+ attention_mask: attentionMask
34
+ )
35
+
36
+ print("Predicting…")
37
+ let output = try await model.prediction(input: input)
38
+ let logits = output.logitsShapedArray
39
+ let maskPosition = tokens.firstIndex(
40
+ of: tokenizer.encode(text: "[MASK]", addSpecialTokens: false)[0]
41
+ )!
42
+ let maskLogits = logits[0, maskPosition]
43
+ let maskToken = Int(await MLTensor(maskLogits).argmax().shapedArray(of: Int32.self).scalar!)
44
+ let maskText = tokenizer.decode(tokens: [maskToken])
45
+
46
+ // The capital of Ireland is Dublin.
47
+ print(text.replacingOccurrences(of: "[MASK]", with: maskText.trimmingCharacters(in: .whitespaces)))
48
+ ```