sat-3l-sm, Core ML, 8-bit weights

A Core ML conversion of segment-any-text/sat-3l-sm, the 3-layer model of Segment any Text (wtpsplit): the chance that a sentence ends after each token, in 85 languages, read off text with or without punctuation and capitals.

Converted from the original PyTorch weights at commit 137da054051ad9f1eac42025f758db4ac9f22535 (PyTorch trace โ†’ Core ML with coremltools 8.3, then the weights quantised to eight bits) by conversion/convert.py, with the versions in conversion/requirements.txt. Running the script again gives the same weights and vocabulary, byte for byte.

Eight bits cost almost nothing: of 502 sentence ends the full-precision model finds in TED talks at a threshold of 0.25, ten come out differently, and the build weighs 206 MB instead of 816 MB. Half precision did not work: our conversion found no sentence ends at all. The script checks that the chances it gives stay within 0.1 of the PyTorch model's.

Files

  • Sat3lSm-int8.mlpackage: the model, macOS 15 or later. Inputs, both int32 [1, 128]: input_ids โ€” <s> (0), the text's token ids, </s> (2), padded with <pad> (1); attention_mask โ€” 1 for every token of the text and the two around it, 0 for padding. Output end_chances, float [1, 128]: the chance, 0 to 1, that a sentence ends after the token at that position.
  • vocab.json: the SentencePiece unigram vocabulary of XLM-RoBERTa (sentencepiece.bpe.model of FacebookAI/xlm-roberta-base at commit e73636d4f797dec63c3081bb6ed5c7b0bb3f2089): pieces as [piece, score, type] in the order of the model's ids (SentencePiece's own, moved up by one, behind <s>, <pad>, </s>, <unk>), and unk_id. Text is NFKC-normalised before it is cut into pieces.
  • ORIGINAL_README.md: the original model card.
  • LICENSE: the MIT License of the original model.
  • conversion/convert.py, conversion/requirements.txt: the conversion.

Usage

import coremltools as ct
import numpy as np
import sentencepiece as spm

model = ct.models.MLModel("Sat3lSm-int8.mlpackage")
sp = spm.SentencePieceProcessor(model_file="sentencepiece.bpe.model")  # from FacebookAI/xlm-roberta-base

ids = [0] + [3 if i == 0 else i + 1 for i in sp.encode("so where are you from i am living in poland")] + [2]
input_ids = np.array([ids + [1] * (128 - len(ids))], dtype=np.int32)
attention_mask = np.array([[1] * len(ids) + [0] * (128 - len(ids))], dtype=np.int32)
chances = model.predict({"input_ids": input_ids, "attention_mask": attention_mask})["end_chances"][0]

A word ends a sentence when the chance at its last token passes a threshold; 0.25 suits text with no punctuation, higher values cut less often.

License

MIT, as the original model, which was initialised from XLM-RoBERTa (MIT). All credit for the model goes to its authors: Markus Frohmann, Igor Sterner, Ivan Vuliฤ‡, Benjamin Minixhofer and Markus Schedl.

Downloads last month
10
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for aidsoid/sat-3l-sm-CoreML-int8

Quantized
(3)
this model

Paper for aidsoid/sat-3l-sm-CoreML-int8