Views
No views yet
vocab.txt - WordPiece vocabulary (119,547 tokens)bert_mlm.mlmodelc/ - Compiled CoreML model for iOS1import CoreML
2
3// Load model
4let config = MLModelConfiguration()
5config.computeUnits = .cpuOnly
6let model = try MLModel(contentsOf: modelURL, configuration: config)
7
8// Prepare inputs
9let inputIds: MLMultiArray = // tokenized input with [MASK] tokens
10let attentionMask: MLMultiArray = // attention mask
11let tokenTypeIds: MLMultiArray = // token type ids (all zeros for single sentence)
12
13// Run inference
14let input = try MLDictionaryFeatureProvider(dictionary: [
15 "input_ids": MLFeatureValue(multiArray: inputIds),
16 "attention_mask": MLFeatureValue(multiArray: attentionMask),
17 "token_type_ids": MLFeatureValue(multiArray: tokenTypeIds)
18])
19let output = try model.prediction(from: input)
20let logits = output.featureValue(for: "logits")?.multiArrayValue1@article{devlin2018bert,
2 title={BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding},
3 author={Devlin, Jacob and Chang, Ming-Wei and Lee, Kenton and Toutanova, Kristina},
4 journal={arXiv preprint arXiv:1810.04805},
5 year={2018}
6}