# function set\_hashes

**URL:** <https://support.prodi.gy/t/function-set-hashes/6006>\
**Category:** Uncategorized\
**Tags:** solved\
**Created:** [October 4, 2022, 9:12pm UTC](https://support.prodi.gy/t/function-set-hashes/6006 "2022-10-04T21:12:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vincent](https://avatars.discourse-cdn.com/v4/letter/v/e9bcb4/32.png) [@Vincent](https://support.prodi.gy/u/Vincent)\
**Post date:** [October 4, 2022, 9:12pm UTC](https://support.prodi.gy/t/function-set-hashes/6006/1 "2022-10-04T21:12:33Z")

</div>

Hello,

I am facing compatibility issues with prodigy package and another processing project. I use prodigy for NER tagging and would like to only use _set\_hashes_ function on the other processing project. Could you describe how you hash text in this function so I can find recalculate text hashes in the other project without building prodigy package?

Thank you,

Vincent

---

<div class="post-metadata">

**Author:** ![ryanwesslen](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/ryanwesslen/32/2969_2.png) [@ryanwesslen](https://support.prodi.gy/u/ryanwesslen)\
**Post date:** [October 5, 2022, 4:54pm UTC](https://support.prodi.gy/t/function-set-hashes/6006/2 "2022-10-05T16:54:09Z")

</div>

Hi @Vincent!

`set_hashes` calls `get_hash` (`from prodigy.util import get_hash`), which will set `input_hash` based on any values for keys `"text", "image", "html", "input"` using [`murmurhash`](https://github.com/explosion/murmurhash).

`task_hash` is similar but will prefix the task with the `input_hash` and a new `murmurhash` hash for values with keys `"spans", "label", "options", "arcs"`.

Also, it's important to be aware of a small quirk if you have any keys named in the ignore list. See this post for more details:

> [@How does "set\_hashes" work ?](https://support.prodi.gy/t/how-does-set-hashes-work/5686/2):
>
> Hi Jim. You have stumbled apon a keyname that's in the default ignore list and I can totally imagine the confusion. Let's go over it step-by-step. If the key is just text, nothing unexpected is happening. from prodigy import set\_hashes paths = ["a", "b", "c"] [set\_hashes({"text": p}) for p in paths] # [{'text': 'a', '\_input\_hash': -1808989213, '\_task\_hash': -1053809049}, # {'text': 'b', '\_input\_hash': 748838038, '\_task\_hash': -150095526}, # {'text': 'c', '\_input\_hash': -600324218, '\_task\_…

Hopefully this helps!

---

<div class="post-metadata">

**Author:** ![Vincent](https://avatars.discourse-cdn.com/v4/letter/v/e9bcb4/32.png) [@Vincent](https://support.prodi.gy/u/Vincent)\
**Post date:** [October 26, 2022, 4:15pm UTC](https://support.prodi.gy/t/function-set-hashes/6006/3 "2022-10-26T16:15:46Z")

</div>

Thanks for your answer. I tried to install _murmurhash_ but still could not get the same results.

> version prodigy==1.10.7  
> version murmurhash==1.0.9

```python
import murmurhash
murmurhash.hash("foo")
>> -156908512
#VERSUS
from prodigy.util import set_hashes
set_hashes({"text":"foo"})
>> {'text': 'foo', '_input_hash': 1503402072, '_task_hash': -1940932841}

```

Would you mind sharing your murmurhash hashing?

Thank you in advance for your help.

Vincent

---

<div class="post-metadata">

**Author:** ![koaning](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/koaning/32/230_2.png) [@koaning](https://support.prodi.gy/u/koaning)\
**Post date:** [October 27, 2022, 1:47pm UTC](https://support.prodi.gy/t/function-set-hashes/6006/4 "2022-10-27T13:47:17Z")

</div>

There's some extra stuff happening in the `set_hashes` function. In particular, it uses the `get_hash` function which internally also encodes an optional prefix as well as the key of the dictionary.

```python
import srsly 
import murmurhash 
from prodigy.util import get_hash 

task = {"text": "hello"}
keys = ("text", )
prefix = ""

prodigy_hash = get_hash(task, keys=keys, prefix="", ignore=tuple())
# 1832607575

```

But here's what we send into murmurhash inside of the that function:

```python
murmurhash.hash('text="hello"')
# 1832607575

```

In general though, its much safer to use the `get_hash` function directly instead of building your own thing. There may be hashing edge-cases in the future that we might abstract away in the `get_hash` function. The function is public, but the implementation could theoretically change in the future.

---

<div class="post-metadata">

**Author:** ![Vincent](https://avatars.discourse-cdn.com/v4/letter/v/e9bcb4/32.png) [@Vincent](https://support.prodi.gy/u/Vincent)\
**Post date:** [October 28, 2022, 8:07am UTC](https://support.prodi.gy/t/function-set-hashes/6006/5 "2022-10-28T08:07:53Z")

</div>

Thank you very much for your answer. This is very helpful. Can I ask you the same for \_task\_hash calculation using murmuhash library and I will be ready to move forward!

Have a good day.

Vincent

---

<div class="post-metadata">

**Author:** ![koaning](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/koaning/32/230_2.png) [@koaning](https://support.prodi.gy/u/koaning)\
**Post date:** [October 31, 2022, 3:12pm UTC](https://support.prodi.gy/t/function-set-hashes/6006/6 "2022-10-31T15:12:45Z")

</div>

The task hashes are also set with the `get_hash` function internally. The string is sorted by key beforehand.

Is there a reason why you can't use the `get_hash` function and must use `murmurhash` directly?

---

<div class="post-metadata">

**Author:** ![Vincent](https://avatars.discourse-cdn.com/v4/letter/v/e9bcb4/32.png) [@Vincent](https://support.prodi.gy/u/Vincent)\
**Post date:** [November 3, 2022, 9:12am UTC](https://support.prodi.gy/t/function-set-hashes/6006/7 "2022-11-03T09:12:49Z")

</div>

Hi Koaning,

I have a side project for statistics in the database using dependencies that are not compatible with prodigy lib. The only function from prodigy lib that I need in the project is `get_hash` or `set_hashes`. That's why I am asking what's behind these functions 🙂

---

<div class="post-metadata">

**Author:** ![koaning](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/koaning/32/230_2.png) [@koaning](https://support.prodi.gy/u/koaning)\
**Post date:** [November 4, 2022, 12:53pm UTC](https://support.prodi.gy/t/function-set-hashes/6006/8 "2022-11-04T12:53:42Z")

</div>

Here's the implementation that we currently use. Note! This implementation might change in the future, but it is what's used right now.

```python
import srsly
from prodigy.util import IGNORE_HASH_KEYS 

def get_hash(
    task,
    keys,
    prefix= "",
    *,
    ignore=IGNORE_HASH_KEYS,
):
    """Get hash for a task based on task keys.
    task (dict): The task to hash.
    keys (tuple): The keys to include.
    prefix (str): Optional prefix to add. For task hashes, they input hash
        is used as the prefix.
    ignore (list): Optional list of keys to ignore. The hash will be insensitive
        to the presence and values of the ignored keys, anywhere in the object.
        Defaults to ('score', 'rank', 'model').
    RETURNS (str): The hash.
    """
    task = _filter_keys(task, set(ignore))
    values = [
        f"{key}={srsly.json_dumps(task[key], sort_keys=True)}"
        for key in keys
        if key in task
    ]
    values = "".join(values)
    if not values:
        values = srsly.json_dumps(task, sort_keys=True)
    values = str(prefix) + values
    hash_ = murmurhash.hash(values)
    return hash_

```
