Sentence embeddings from a pretrained BERT-family encoder exported to ONNX: the text is tokenized with WordPieceTokenizer, run through API.Onnx, and pooled into one vector per text.
A library of its own because it needs both System.NLP and API.Onnx, and the compiler resolves every class a linked library names: an embedder inside onnx.obl would make every ONNX program link nlp too, and one inside nlp.obl would make every NLP program need ONNX Runtime (docs/ML_BERT_DESIGN.md). Compile with -lib models,opencv,cipher,json,onnx,nlp,nlp_onnx.
Prediction
One text's classification: the top label, its score, and every label's score in label order.
Operations
GetLabel #
The top label, from the model's id2label.
method : public : GetLabel() ~ StringReturn
| Type | Description |
|---|---|
| String | label |
GetScore #
The top label's score: a probability under SOFTMAX or SIGMOID, the raw logit under NONE.
method : public : GetScore() ~ FloatReturn
| Type | Description |
|---|---|
| Float | score |
GetScores #
Every label's score, in label order.
method : public : GetScores() ~ Float[]Return
| Type | Description |
|---|---|
| Float | scores |
IsTruncated #
Whether the text was longer than the model's maximum length and was cut to fit.
method : public : IsTruncated() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true when truncated |
New # constructor
Constructor, for a classifier of the program's own.
New(top_label:String, index:Int, score:Float, scores:Float[], truncated:Bool)Parameters
| Name | Type | Description |
|---|---|---|
| top_label | String | the top label |
| index | Int | the top label's index |
| score | Float | the top label's score |
| scores | Float | every label's score, in label order |
| truncated | Bool | whether text was dropped to fit the model |