Views
No views yet
Unofficial community mirror. Not affiliated with, maintained by, or endorsed by the Free Law Project, Nomic AI, or Answer.AI. All credit for the model itself goes to the Free Law Project — if you use these embeddings, please credit them.
freelawproject/modernbert-embed-base_finetune_8192.
The upstream repo hosts safetensors only; this repo exists so the model can be used with
onnxruntime / onnxruntime-node for local and offline inference.model.onnx — a format conversion of the upstream weights to ONNX (fp32). No
retraining, no fine-tuning, no weight changes.model_quantized.onnx — a modified, derived artifact: int8 dynamic weight
quantization of the fp32 export. Quantization changes the weight values; treat it as a
smaller, approximate variant.| Stage | Repo | License |
|---|---|---|
| Base encoder | answerdotai/ModernBERT-base | Apache-2.0 |
| Embedding model | nomic-ai/modernbert-embed-base | Apache-2.0 |
| Legal fine-tune (upstream of this repo) | freelawproject/modernbert-embed-base_finetune_8192 | CC0-1.0 |
| This repo | ONNX conversion + int8 quantization of the above | see License below |
freelawproject/opinions-synthetic-query-8192
dataset). It "maps sentences & paragraphs to a 768 dimensional dense vector space and can be
used for tasks like semantic textual similarity, semantic search, paraphrase mining, text
classification, clustering, and more." See the upstream card for training details and
evaluation — none of that is reproduced or re-measured here, and this repo adds no benchmark
numbers of its own.1_Pooling module — the ONNX graph here is the transformer only, so you must apply
pooling and normalization yourself; see the example below)| File | Precision | Size | Notes |
|---|---|---|---|
model.onnx | fp32 | ~596 MB | Format conversion only. Validated against the PyTorch reference at export time: max abs diff 2.26e-05 on last_hidden_state. |
model_quantized.onnx | int8 (dynamic, QInt8) | ~143 MB | Derived from model.onnx. Smaller download, lower memory, CPU-friendly. No accuracy evaluation has been run on this variant — validate on your own retrieval task before relying on it. |
config.json, tokenizer.json, tokenizer_config.json, special_tokens_map.json | — | — | Copied unchanged from the optimum export of the upstream fine-tune repo. |
LICENSE | — | — | CC0-1.0 legal code (upstream fine-tune license). |
LICENSE-Apache-2.0 | — | — | Apache-2.0 text, for the portions inherited from the Apache-2.0 ancestor models. |
tokenizer.json, run the session with input_ids +
attention_mask, mean-pool last_hidden_state with the attention mask, then L2-normalize.
Output is a 768-dim unit vector per input.1import { AutoTokenizer } from "@huggingface/transformers";
2import * as ort from "onnxruntime-node";
3
4const repo = "ReconOut/modernbert-embed-base_finetune_8192-ONNX";
5const tokenizer = await AutoTokenizer.from_pretrained(repo);
6const session = await ort.InferenceSession.create("./model_quantized.onnx");
7
8const texts = ["The court granted the motion for summary judgment."];
9const { input_ids, attention_mask } = await tokenizer(texts, {
10 padding: true,
11 truncation: true,
12});
13
14const outputs = await session.run({
15 input_ids: new ort.Tensor("int64", input_ids.data, input_ids.dims),
16 attention_mask: new ort.Tensor("int64", attention_mask.data, attention_mask.dims),
17});
18
19// Mean-pool last_hidden_state over non-padding tokens, then L2-normalize.
20const hidden = outputs.last_hidden_state; // dims: [batch, seq, 768]
21const [batch, seq, dim] = hidden.dims;
22const embeddings = [];
23for (let b = 0; b < batch; b++) {
24 const vec = new Float32Array(dim);
25 let count = 0;
26 for (let t = 0; t < seq; t++) {
27 if (attention_mask.data[b * seq + t] === 0n) continue;
28 count++;
29 for (let d = 0; d < dim; d++) {
30 vec[d] += hidden.data[(b * seq + t) * dim + d];
31 }
32 }
33 for (let d = 0; d < dim; d++) vec[d] /= count;
34
35 let norm = 0;
36 for (let d = 0; d < dim; d++) norm += vec[d] * vec[d];
37 norm = Math.sqrt(norm);
38 for (let d = 0; d < dim; d++) vec[d] /= norm;
39
40 embeddings.push(vec); // 768-dim, unit length
41}input_ids and attention_mask only (no token_type_ids).nomic-ai/modernbert-embed-base, which documents task
prefixes (e.g. search_query: / search_document:). Check the upstream and ancestor model
cards to decide whether prefixes apply to your use case — this mirror takes no position.1# 1) fp32 export (task: feature-extraction)
2optimum-cli export onnx --model freelawproject/modernbert-embed-base_finetune_8192 --task feature-extraction <out>
3
4# 2) int8 dynamic quantization of the fp32 export
5python -c "from onnxruntime.quantization import quantize_dynamic, QuantType; quantize_dynamic('model.onnx','model_quantized.onnx',weight_type=QuantType.QInt8)"last_hidden_state for the fp32 export.LICENSE) — a public
domain dedication. Note that CC0 does not grant trademark or patent rights, and no such
rights are granted or implied by this mirror.answerdotai/ModernBERT-base by
Answer.AI and nomic-ai/modernbert-embed-base
by Nomic AI); the Apache-2.0 text is included
as LICENSE-Apache-2.0 with this attribution for the portions inherited from those models.