# UnicodeDecodeError:

**URL:** <https://support.prodi.gy/t/unicodedecodeerror/6037>\
**Category:** Uncategorized\
**Created:** [October 21, 2022, 6:31pm UTC](https://support.prodi.gy/t/unicodedecodeerror/6037 "2022-10-21T18:31:05Z")\
**Posts on this page:** 1\
**Showing post:** 6

<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 26, 2022, 8:59am UTC](https://support.prodi.gy/t/unicodedecodeerror/6037/6 "2022-10-26T08:59:12Z")

</div>

I'm trying to repeat your steps. I started by creating a folder called `issue-6037` and moving your files in there with the names `news_headlines.jsonl` and `news_headlines_small.jsonl`. From there I started annotating via this recipe:

```python
python -m prodigy ner.manual ner_news_headlines blank:en news_headlines.jsonl --label PERSON,ORG,PRODUCT,LOCATION

```

This is what that interface looks like:

 ![CleanShot 2022-10-26 at 10.38.11](https://us1.discourse-cdn.com/flex020/uploads/prodigy/original/2X/e/ecf45acb0f700b97d7a3f27966efe0961e431e83.png)

I annotated six examples and I hit the save button. Next, I ran your `terms` recipe.

```python
python -m prodigy terms.to-patterns ner_news_headlines --label PERSON,ORG,PRODUCT,LOCATION --spacy-model blank:en > news_pattern.jsonl

```

This is what my `news_pattern.sjonl` file looks like:

```python
{"label":"PERSON,ORG,PRODUCT,LOCATION","pattern":[{"lower":"uber"},{"lower":"\u2019s"},{"lower":"lesson"},{"lower":":"},{"lower":"silicon"},{"lower":"valley"},{"lower":"\u2019s"},{"lower":"start"},{"lower":"-"},{"lower":"up"},{"lower":"machine"},{"lower":"needs"},{"lower":"fixing"}]}
{"label":"PERSON,ORG,PRODUCT,LOCATION","pattern":[{"lower":"pearl"},{"lower":"automation"},{"lower":","},{"lower":"founded"},{"lower":"by"},{"lower":"apple"},{"lower":"veterans"},{"lower":","},{"lower":"shuts"},{"lower":"down"}]}
{"label":"PERSON,ORG,PRODUCT,LOCATION","pattern":[{"lower":"how"},{"lower":"silicon"},{"lower":"valley"},{"lower":"pushed"},{"lower":"coding"},{"lower":"into"},{"lower":"american"},{"lower":"classrooms"}]}
{"label":"PERSON,ORG,PRODUCT,LOCATION","pattern":[{"lower":"women"},{"lower":"in"},{"lower":"tech"},{"lower":"speak"},{"lower":"frankly"},{"lower":"on"},{"lower":"culture"},{"lower":"of"},{"lower":"harassment"}]}
{"label":"PERSON,ORG,PRODUCT,LOCATION","pattern":[{"lower":"silicon"},{"lower":"valley"},{"lower":"investors"},{"lower":"flexed"},{"lower":"their"},{"lower":"muscles"},{"lower":"in"},{"lower":"uber"},{"lower":"fight"}]}
{"label":"PERSON,ORG,PRODUCT,LOCATION","pattern":[{"lower":"uber"},{"lower":"is"},{"lower":"a"},{"lower":"creature"},{"lower":"of"},{"lower":"an"},{"lower":"industry"},{"lower":"struggling"},{"lower":"to"},{"lower":"grow"},{"lower":"up"}]}

```

And I think, looking at this file, that the recipe isn't doing what you had hoped it did. Notice how each row has `"PERSON,ORG,PRODUCT,LOCATION"` as a label? While this isn't the error message that you're experiencing, I'm assuming that it's related. The `terms.to-patterns` recipe is designed to be used together with the `terms.teach` recipe, not the `ner.manual` one.

This Youtube video helps explain how it's meant to be used.

[![](https://img.youtube.com/vi/5pvU9yvdzAg/maxresdefault.jpg "Terms and Seeds - Prodigy Shorts") ](https://www.youtube.com/watch?v=5pvU9yvdzAg)

## Custom Recipe

That said, nothing is stopping you from writing a custom script that can turn your previous annotations as terms. Here's a small script that does that.

```python
import srsly 
import prodigy 
from prodigy.components.db import connect

@prodigy.recipe(
    "terms.from-ner",
    ner_dataset=("Dataset loader NER annotations from", "positional", None, str),
    file_out=("File to write patterns into", "positional", None, str)
)
def custom_recipe(ner_dataset: str, file_out: str):
    # Connect to Prodigy database
    db = connect()
    # Load in annotated examples 
    annotated = db.get_dataset(ner_dataset)
    # Loop over examples
    pattern_set = set()
    for example in annotated:
        for span in example.get("spans", []):
            pattern_str = example['text'][span['start']: span['end']]
            # Store into tuple, because sets like that
            tup = (pattern_str, span['label'])
            pattern_set.add(tup)
    patterns = [{"pattern": p, "label": l} for p, l in pattern_set]
    srsly.write_jsonl(file_out, patterns)

```

If you're curious how to work with patterns and custom code, you may appreciate the guide in the docs [here](https://prodi.gy/docs/text-classification#patterns). When I run this locally via:

```python
python -m prodigy terms.from-ner ner_news_headlines patterns.jsonl -F recipe.py

```

Then the file `patterns.jsonl` contains this:

```python
{"pattern":"Apple","label":"ORG"}
{"pattern":"Silicon Valley","label":"LOCATION"}
{"pattern":"Uber","label":"ORG"}
{"pattern":"Pearl Automation","label":"ORG"}

```

I can now use these patterns to do `ner.manual`.

```python
python -m prodigy ner.manual news_data blank:en news_headlines.jsonl --label PERSON,ORG,PRODUCT,LOCATION --patterns patterns.jsonl

```

Here's what it looks like:

 ![CleanShot 2022-10-26 at 10.58.22](https://us1.discourse-cdn.com/flex020/uploads/prodigy/original/2X/2/2bdbbd19288f36ad8e8b9bdce621bd27bf43fc10.png)

Note how some entities are pre-labelled but also note that there's now PATTERN metadata in there. This tells you which patterns got activated. I hope this helps!

---

_[View the full topic](https://support.prodi.gy/t/unicodedecodeerror/6037)._
