# Should \_input\_hash be required on the input to EntityRecognizer?

**URL:** <https://support.prodi.gy/t/should--input-hash-be-required-on-the-input-to-entityrecognizer/202>\
**Category:** Uncategorized\
**Tags:** ner\
**Created:** [January 9, 2018, 11:48pm UTC](https://support.prodi.gy/t/should--input-hash-be-required-on-the-input-to-entityrecognizer/202 "2018-01-09T23:48:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wpm](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/wpm/32/103_2.png) [@wpm](https://support.prodi.gy/u/wpm)\
**Post date:** [January 9, 2018, 11:48pm UTC](https://support.prodi.gy/t/should--input-hash-be-required-on-the-input-to-entityrecognizer/202/1 "2018-01-09T23:48:05Z")

</div>

After some experimentation I think I figured out how to use `EntityRecognizer`.

```python
>>> import spacy
>>> nlp = spacy.load("en_core_web_lg")
>>> from prodigy.models.ner import EntityRecognizer
>>> r = EntityRecognizer(nlp, label=["PERSON", "GPE"])
>>> text = "Henry ford was born in Michigan."
>>> list(r([{"text":text, "_input_hash":hash(text)}]))
[(0.7973351944856613,
  {'_input_hash': 1567318883,
   '_task_hash': 2143133895,
   'meta': {'score': 0.7973351944856613},
   'spans': [{'end': 31,
     'input_hash': -6212844767141395898,
     'label': 'GPE',
     'rank': 0,
     'score': 0.7973351944856613,
     'source': 'core_web_lg',
     'start': 23,
     'text': 'Michigan'}],
   'text': 'Henry ford was born in Michigan.'}),
 (0.7223527741995048,
  {'_input_hash': 1567318883,
   '_task_hash': -1467116620,
   'meta': {'score': 0.7223527741995048},
   'spans': [{'end': 5,
     'input_hash': -6212844767141395898,
     'label': 'PERSON',
     'rank': 0,
     'score': 0.7223527741995048,
     'source': 'core_web_lg',
     'start': 0,
     'text': 'Henry'}],
   'text': 'Henry ford was born in Michigan.'}),
 (0.005112707458942434,
  {'_input_hash': 1567318883,
   '_task_hash': -2128614395,
   'meta': {'score': 0.005112707458942434},
   'spans': [{'end': 5,
     'input_hash': -6212844767141395898,
     'label': 'GPE',
     'rank': 4,
     'score': 0.005112707458942434,
     'source': 'core_web_lg',
     'start': 0,
     'text': 'Henry'}],
   'text': 'Henry ford was born in Michigan.'}),
 (0.2479421936178019,
  {'_input_hash': 1567318883,
   '_task_hash': -304378400,
   'meta': {'score': 0.2479421936178019},
   'spans': [{'end': 10,
     'input_hash': -6212844767141395898,
     'label': 'PERSON',
     'rank': 1,
     'score': 0.2479421936178019,
     'source': 'core_web_lg',
     'start': 0,
     'text': 'Henry ford'}],
   'text': 'Henry ford was born in Michigan.'})]

```

The call to `EntityRecognizer`'s default function fails if `_input_hash` is not in the input. I assume `_input_hash` is a way for Prodigy to avoid doing redundant work on identical text. Is this correct? If so, wouldn’t it be better to have `hash(text)` be the default value?

Also, the reason I’m using `EntityRecognizer` is so that I can get entity predictions along with confidence scores. (I’m using these to draw a [ROC curve of f-scores](https://support.prodi.gy/t/evaluating-precision-and-recall-of-ner/193/3).) If I can help it, I’d prefer the package I’m writing to only have dependencies on `spacy` and not `prodigy`. Is there a way to get named entity confidence scores directly from the `spacy` API?

---

<div class="post-metadata">

**Author:** ![ines](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/ines/32/3_2.png) [@ines](https://support.prodi.gy/u/ines)\
**Post date:** [January 9, 2018, 11:54pm UTC](https://support.prodi.gy/t/should--input-hash-be-required-on-the-input-to-entityrecognizer/202/2 "2018-01-09T23:54:06Z")

</div>

> [@wpm](#):
>
> I assume \_input\_hash is a way for Prodigy to avoid doing redundant work on identical text. Is this correct? If so, wouldn’t it be better to have hash(text) be the default value?

Prodigy's `EntiyRecognizer` model was developed specifically for Prodigy, so it's also a little more specific in terms of the input it expects.

The input hash is generated from the input data, e.g. the text or the image and lets Prodigy distinguish between tasks with the same input (but potentially different labels or spans). Additionally, Prodigy also generates a task hash based on the input hash and the features you're annotating, e.g. the spans, labels etc. This lets you distinguish between exact questions. You can also use the `set_hashes` helper to take care of the hashing for you:

```python
from prodigy import set_hashes

examples = [set_hashes(eg) for eg in examples]

```

You can also set the additional keyword arguments `input_keys` and `task_keys`, both lists of the keys you want to take into account when hashing. For example, `input_keys=('text', 'custom_text')`. The full docs are available in the `PRODIGY_README.html`.

> [@wpm](#):
>
> Is there a way to get named entity confidence scores directly from the spacy API?

Yes, but this is a little more complex. @honnibal wrote a more detailed reply on this here:

> [@Accessing probabilities in NER](https://support.prodi.gy/t/accessing-probabilities-in-ner/94/2):
>
> Hi, The answer to this question is a little bit involved. The short answer is this: # Number of alternate analyses to consider. More is slower, and not necessarily better -- you need to experiment on your problem. beam\_width = 16 # This clips solutions at each step. We multiply the score of the top-ranked action by this value, and use the result as a threshold. This prevents the parser from exploring options that look very unlikely, saving a bit of efficiency. Accuracy may also improve, becau…
