distilbert-NER for Kjarni

This is dslim's distilbert-NER, unchanged, hosted so it runs locally with Kjarni: it finds the names of people, organizations, places and other things in English text, from one native library with no Python runtime, PyTorch, ONNX Runtime or server. The model is about 260 MB and downloads on first use.

Usage

In Kjarni the model is called distilbert-ner. Each example prints the entities in one sentence: PER for people, ORG for organizations, LOC for places and MISC for the rest.

Command line

curl -fsSL https://kjarni.ai/install.sh | sh    # Windows: irm https://kjarni.ai/install.ps1 | iex
kjarni ner -q -m distilbert-ner "Tim Cook announced the new iPhone at Apple's headquarters in Cupertino on Tuesday."
  PER   Tim Cook  99.9%
  MISC  iPhone  79.2%
  ORG   Apple's  77.3%
  LOC   Cupertino  99.6%

Python

# pip install kjarni
from kjarni import EntityRecognizer

ner = EntityRecognizer(model="distilbert-ner", quiet=True)
text = "Tim Cook announced the new iPhone at Apple's headquarters in Cupertino on Tuesday."
for e in ner.recognize(text):
    print(f"{e.label:<5} {e.score:.3f}  {e.text}")
PER   0.999  Tim Cook
MISC  0.792  iPhone
ORG   0.773  Apple's
LOC   0.996  Cupertino

Rust

// cargo add kjarni anyhow tokio --features tokio/full
use kjarni::EntityRecognizer;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let ner = EntityRecognizer::new("distilbert-ner").await?;
    let text = "Tim Cook announced the new iPhone at Apple's headquarters in Cupertino on Tuesday.";
    for e in ner.recognize(text).await? {
        println!("{:<5} {:.3}  {}", e.label, e.score, e.text);
    }
    Ok(())
}

C#

// dotnet add package Kjarni
using Kjarni;

using var ner = new EntityRecognizer("distilbert-ner", quiet: true);
var text = "Tim Cook announced the new iPhone at Apple's headquarters in Cupertino on Tuesday.";
foreach (var e in ner.Recognize(text))
    Console.WriteLine($"{e.Label,-5} {e.Score:F3}  {e.Text}");

C++ (through the C API)

#include <kjarni.h>
#include <cstdio>

int main() {
    KjarniNerConfig config = kjarni_ner_config_default();
    config.model_name = "distilbert-ner";
    config.quiet = 1;

    KjarniNer* ner = nullptr;
    if (kjarni_ner_new(&config, &ner) != KJARNI_ERROR_CODE_OK) return 1;

    KjarniEntities found{};
    if (kjarni_ner_recognize(ner, "Tim Cook announced the new iPhone at Apple's headquarters in Cupertino on Tuesday.", &found) != KJARNI_ERROR_CODE_OK) return 1;
    for (uintptr_t i = 0; i < found.len; ++i)
        std::printf("%-5s %.3f  %s\n", found.entities[i].label, found.entities[i].score, found.entities[i].text);

    kjarni_entities_free(found);
    kjarni_ner_free(ner);
}

Go

// go get github.com/kjarni-ai/kjarni-go
package main

import (
    "fmt"
    "log"

    kjarni "github.com/kjarni-ai/kjarni-go"
)

func main() {
    ner, err := kjarni.NewEntityRecognizer("distilbert-ner", kjarni.AggregationFirst, kjarni.WithQuiet(true))
    if err != nil {
        log.Fatal(err)
    }
    defer ner.Close()

    entities, err := ner.Recognize("Tim Cook announced the new iPhone at Apple's headquarters in Cupertino on Tuesday.")
    if err != nil {
        log.Fatal(err)
    }
    for _, e := range entities {
        fmt.Printf("%-5s %.3f  %s\n", e.Label, e.Score, e.Text)
    }
}

Each prints the entities above. Every entity also has its start and end offsets in the text. Words are grouped into entities as transformers' aggregation_strategy="first" does; the other strategies are options. On this sentence the entities, their offsets and their scores to three decimals are the same as transformers 5.16's ner pipeline with aggregation_strategy="first", which writes the third as Apple ' s. See the Kjarni documentation for installation details.

What changed from the original

Nothing in the model. The safetensors weights, configuration and tokenizer files are byte for byte the same as in dslim/distilbert-NER at revision dfa2838a127384aabb82ed7719e16dab84c42a2a. This README replaces the original model card; the ONNX and other copies of the weights are left out.

About the model

distilbert-NER is DistilBERT, 66 million parameters, fine-tuned by dslim on CoNLL-2003, a set of English Reuters news articles labelled with four kinds of entity: people, organizations, locations and miscellaneous. dslim reports an F1 of 0.92 on CoNLL-2003. It reads up to 512 tokens.

See the original model card for training data, evaluation, limitations and biases.

License

The Apache License 2.0, as the original. Kjarni and this hosting are not affiliated with or endorsed by dslim.

Downloads last month
2
Safetensors
Model size
65.2M params
Tensor type
F32
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for kjarni-ai/distilbert-NER

Finetuned
(29)
this model