
See below for technical details about the model.

# Description

This model is a named entity recognition model that was trained to run on text that discusses Torah topics (e.g. dvar torahs, Torah blogs, translations of classic Torah texts etc.).

It detects the following types of entities:

| Label | Description
|---|---|
| מקור | Citations to Torah texts. See notes below. |

## Notes on normalization

All text the model was trained on was initially put through the following normalizer: [link](https://github.com/Sefaria/Machine-Learning/blob/main/util/helper.py#L43).
Results will be signicantly worse if this normalizer is not used.

## Notes on citation matches

- Final parentheses is not included in the match. E.g. if the citation is `בראשית (א:א)` then the final parentheses will not be included. We found that the model would get confused if the final parentheses was part of the entity. It is fairly simple to add it back in via a deterministic check.
- Only the first word of a dibur hamatchil is included in the match. E.g. `תוספות ד״ה אמר רבי עקיבא` only until the word `אמר` will be tagged. We found the model had trouble determining the end of the dibur hamatchil.
- See Ref part model for a model that can break down citations into chunks so it is simpler to parse them.

## Using with Sefaria-Project

The [Sefaria-Project](https://github.com/Sefaria/Sefaria-Project) repo can use this model to return objects linked to objects in the Sefaria database. Non-citation entities are linked to `Topic` objects and citation entities are linked to `Ref` objects.

Note, this model is designed to be used in conjunction with the corresponding [subref model](https://huggingface.co/Sefaria/he_subref_ner). That model takes citations as input and tags the parts of the citation. The below instructions explain how to integrate both of these models into Sefaria-Project.

### Configuring Sefaria-Project to use this model

The assumption is that Sefaria-Project is set up on your environment following the instructions in our [README](https://github.com/Sefaria/Sefaria-Project/blob/master/README.mkd).

Download this repo and the [subref repo](https://huggingface.co/Sefaria/he_subref_ner).

In `local_settings.py`, modify the following lines:

```python
ENABLE_LINKER = True

RAW_REF_MODEL_BY_LANG_FILEPATH = {
   "he": "/path/to/he-ref-ner model"
}

RAW_REF_PART_MODEL_BY_LANG_FILEPATH = {
	"he": "/path/to/he-subref-ner model",
}
```

Make sure spaCy is installed.

```bash
pip install spacy==3.4.1
```

### Running the model with Sefaria-Project

The following code shows an example of instantiating the `Linker` object which uses the ML models and running the `Linker` with input.

```python
import django
django.setup()
from sefaria.model.text import library

text = "משה קבל תורה מסיני (אבות פרק א משנה א)"
linker = library.get_linker("he")
doc = linker.link(text)

print("Named entities")
for resolved_named_entity in doc.resolved_named_entities:
    print("---")
    print("Text:", resolved_named_entity.raw_entity.text)
    print("Topic Slug:", resolved_named_entity.topic.slug)

print("Citations")
for resolved_ref in doc.resolved_refs:
    print("---")
    print("Text:", resolved_ref.raw_entity.text)
    print("Ref:", resolved_ref.ref.normal())
```

# Technical Details

| Feature | Description |
| --- | --- |
| **Name** | `he_ref_ner` |
| **Version** | `1.0.0` |
| **spaCy** | `>=3.4.1,<3.5.0` |
| **Default Pipeline** | `tok2vec`, `ner` |
| **Components** | `tok2vec`, `ner` |
| **Vectors** | 391957 keys, 391957 unique vectors (50 dimensions) |
| **Sources** | n/a |
| **License** | n/a |
| **Author** | [n/a]() |

### Label Scheme

<details>

<summary>View label scheme (1 labels for 1 components)</summary>

| Component | Labels |
| --- | --- |
| **`ner`** | `מקור` |

</details>

### Accuracy

| Type | Score |
| --- | --- |
| `ENTS_F` | 82.96 |
| `ENTS_P` | 86.42 |
| `ENTS_R` | 79.77 |
| `TOK2VEC_LOSS` | 44775.36 |
| `NER_LOSS` | 4561.19 |
{"language": ["he"], "tags": ["spacy", "token-classification"], "widget": [{"text": "\u05de\u05e9\u05d4 \u05e7\u05d1\u05dc \u05ea\u05d5\u05e8\u05d4 \u05de\u05e1\u05d9\u05e0\u05d9 (\u05d0\u05d1\u05d5\u05ea \u05e4\u05e8\u05e7 \u05d0 \u05de\u05e9\u05e0\u05d4 \u05d0)"}, {"text": "\u05d9\u05e8\u05d5\u05e9\u05dc\u05de\u05d9 \u05e4\u05d0\u05d4 \u05db\u05d2 \u05e2\"\u05d3"}, {"text": "\u05e8\u05d0\u05d4 \u05e8\u05e9\"\u05d9 \u05d1\u05e8\u05db\u05d5\u05ea \u05d3\u05e3 \u05d9\u05d1 \u05d3\"\u05d4 \u05d5\u05d0\u05de\u05e8 \u05e9\u05d4\u05d5\u05d0 \u05d7\u05d5\u05dc\u05e7"}]}
spacy token-classification he model-index region:us