# Ner teach not working

**URL:** <https://support.prodi.gy/t/ner-teach-not-working/6120>\
**Category:** Uncategorized\
**Tags:** ner\
**Created:** [November 15, 2022, 10:55am UTC](https://support.prodi.gy/t/ner-teach-not-working/6120 "2022-11-15T10:55:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JulieSarah](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/juliesarah/32/3417_2.png) [@JulieSarah](https://support.prodi.gy/u/JulieSarah)\
**Post date:** [November 15, 2022, 10:55am UTC](https://support.prodi.gy/t/ner-teach-not-working/6120/1 "2022-11-15T10:55:07Z")

</div>

Hi all

I faced this issue:

```python
✘ Error while validating stream: no first example
This likely means that your stream is empty.This can also mean all the examples
in your stream have been annotated in datasets included in your --exclude recipe
parameter.

```

While running :

> prodigy ner.teach sample $MODEL\_FILE $DATA\_FILE --label PersonName,Organisation,TeamId,Email,TelNumber,UserId --patterns $PATTERN\_FILE

I added pattern file because the model didn't learn some entities of the taxonomy.

Could you help with it please,

Thank you

Best regards  
Julie

---

<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:** [November 15, 2022, 1:37pm UTC](https://support.prodi.gy/t/ner-teach-not-working/6120/2 "2022-11-15T13:37:06Z")

</div>

hi @JulieSarah,

Typically, this means there's nothing to load from the file. Can you provide an example of your data? You can remove any sensitive data. It's common like the answers below to have a small mistake in your input data.

> [@can't run textcat.teach getting Error while validating stream: no first example](https://support.prodi.gy/t/cant-run-textcat-teach-getting-error-while-validating-stream-no-first-example/1227/2):
>
> That error usually means that there’s nothing to load from the file – either because there’s nothing in there, or because no example of the correct format was found (for instance, if none of the records have a text). In your example, you’re loading in a file reviews.txt with the CSV loader – are you sure that’s correct? And did you have a look at the README and checked whether your data has the correct format? For CSV, the text should be available in a column “text” or “Text”. For TXT, each tex…

> [@Having problems with file during ner.manual (Error while validating stream: no first example)](https://support.prodi.gy/t/having-problems-with-file-during-ner-manual-error-while-validating-stream-no-first-example/4951/3):
>
> Hi! If you look really closely at the format of the input data, you can see that it somehow ended up with some strange markup in the keys – I wonder if something went wrong when you saved/converted the data? For example, the key ends up being "[{\"text": ... and the whole JSON was saved out as a string key, instead of as JSON. So the error happens because the format isn't a dictionary with the key "text" and Prodigy doesn't know what to load.

Unfortunately there are [44 issues](https://support.prodi.gy/search?q=Error%20while%20validating%20stream%3A%20no%20first%20example) that mention a similar error so there could a variety of issues.

Let me know if you can provide an example and then we can go from there. Also, let us know if you can do [logging](https://prodi.gy/docs/install#debugging-logging) and provide back any details.

---

<div class="post-metadata">

**Author:** ![JulieSarah](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/juliesarah/32/3417_2.png) [@JulieSarah](https://support.prodi.gy/u/JulieSarah)\
**Post date:** [November 15, 2022, 1:59pm UTC](https://support.prodi.gy/t/ner-teach-not-working/6120/3 "2022-11-15T13:59:56Z")

</div>

Here is a sample of my jsonl. For csv I got the same issue.

```python
> {'text': 'blabla "A" FAULT', 'Meta': 'id1'}
> {'text': 'bla', 'Meta': 'id2'}
> {'text': 'blablabla', 'Meta': 'id6'}

```

From the logging, i had at the end:

````python
> 14:55:03: DB: Initializing database SQLite
> 14:55:03: DB: Connecting to database SQLite
> 14:55:03: DB: Creating dataset '2022-11-15_14-55-03'
> {'created': datetime.datetime(2022, 11, 15, 10, 53, 53)}
> 
> 14:55:03: FEED: Initializing from controller
> {'auto_count_stream': False, 'batch_size': 5, 'dataset': 'sample_part_installations_oso_compatible_manufacturer_part_description_filtered_teach', 'db': <prodigy.components.db.Database object at 0x7fc75a9121f0>, 'exclude': ['sample_part_installations_oso_compatible_manufacturer_part_description_filtered_teach'], 'exclude_by': 'task', 'max_sessions': 10, 'overlap': False, 'self': <prodigy.components.feeds.Feed object at 0x7fc75ae00a60>, 'stream': <generator object teach.<locals>.<genexpr> at 0x7fc75afea890>, 'target_total_annotated': 0, 'timeout_seconds': 3600, 'total_annotated': 0, 'total_annotated_by_session': Counter(), 'validator': <prodigy.components.validate.Validator object at 0x7fc75a912310>, 'view_id': 'ner'}
> 
> 14:55:03: PREPROCESS: Splitting sentences
> {'batch_size': 32, 'min_length': None, 'nlp': <spacy.lang.en.English object at 0x7fc75ae00dc0>, 'no_sents_warned': False, 'stream': <generator object at 0x7fc75afe75e0>, 'text_key': 'text'}
> 
> 14:55:03: CONFIG: Using config from global prodigy.json
> /local/home/ta-2f93-titan-jma/.prodigy/prodigy.json
> 
> 14:55:03: CONFIG: Using config from working dir
> /data/neras/neras_annotator/.prodigy.json
> 
> 14:55:03: FILTER: Filtering duplicates from stream
> {'by_input': True, 'by_task': True, 'stream': <generator object at 0x7fc75afe74a0>, 'warn_fn': <bound method Printer.warn of <wasabi.printer.Printer object at 0x7fc7740fc4c0>>, 'warn_threshold': 0.4}
> 
> 14:55:03: FILTER: Filtering out empty examples for key 'text'
> ```

````

---

<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:** [November 15, 2022, 3:48pm UTC](https://support.prodi.gy/t/ner-teach-not-working/6120/4 "2022-11-15T15:48:22Z")

</div>

Okay - yes, I had to modify your `.jsonl` a bit for formatting, but yes, when I used this data:

```python
{"text": "blabla \"A\" FAULT", "meta": {"id": "id1"}}
{"text": "bla", "meta": {"id": "id2"}}
{"text": "blablabla", "meta": {"id": "id6"}}

```

and I ran this command (since I didn't have your model used in the recipe, I used `en_core_web_sm` as an alternative):

```python
python -m prodigy ner.teach sample en_core_web_sm data/sample.jsonl --label PERSON 

```

I got this error:

```python
✘ Error while validating stream: no first example
This likely means that your stream is empty.This can also mean all the examples
in your stream have been annotated in datasets included in your --exclude recipe
parameter.

```

However, like the error says, I think the problem is that you're not getting any predicted entities or pattern matches, hence the stream is empty.

For example, if I modify the data to:

```python
{"text": "blabla \"A\" FAULT", "meta": {"id": "id1"}}
{"text": "Joe Biden is president of the United States.", "meta": {"id": "id2"}}
{"text": "blablabla", "meta": {"id": "id6"}}

```

It does load up one example.

 ![localhost_8080_](https://us1.discourse-cdn.com/flex020/uploads/prodigy/original/2X/b/b80ff29f4de39a2173300711b35a79dd4488293e.png)

I suspect your problem is not enough of the predictions on your data is hitting the active learning criteria. `ner.teach` is really just running this (if we ignore patterns):

```python
from prodigy.components.sorters import prefer_uncertain

def score_stream(stream):
    for example in stream:
        score = model.predict(example["text"])
        yield (score, example)

stream = prefer_uncertain(score_stream(stream))

```

When you run this, `prefer_uncertain` isn't returning any of your predictions from your stream as the default algorithm `ema`. It tracks the exponential moving average of the uncertainties, and also tracks a moving variance. It then asks questions which are one standard deviation or more above the current average uncertainty.

What you may want to do is modify the algorithm (or bias sorter) in the function `prefer_uncertain`.

Here's more of a background:

> [@prefer\_uncertain: how does it use the stream to pick examples to score?](https://support.prodi.gy/t/prefer-uncertain-how-does-it-use-the-stream-to-pick-examples-to-score/131/2):
>
> You can choose between two algorithms for prefer\_uncertain: prefer\_uncertain(stream, algorithm='probability'): This randomly drops examples with probability proportional to distance from 0.5. So if an example is given a score 0.5 by the model, it will be dropped with probability close to 0.0 (so you’ll probably see it for annotation). If an example is given a score 0.99 or 0.01 by the model, it will probably be dropped. Probabilities are clipped so that even if all of the scores are 0.0 or 1.…

FYI to find your local recipe, run `python -m prodigy stats`, find your `Location:` path, then find the file `recipes/ner.py` where you'll find where `ner.teach` is defined. You can then either modify it directly or copy it to create your modified `ner.teach` recipe where you can try out a modified version.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![JulieSarah](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/juliesarah/32/3417_2.png) [@JulieSarah](https://support.prodi.gy/u/JulieSarah)\
**Post date:** [November 16, 2022, 9:40am UTC](https://support.prodi.gy/t/ner-teach-not-working/6120/5 "2022-11-16T09:40:34Z")

</div>

Thank you @ryanwesslen , so you stated that if I modify the prefer\_uncertain function, I won't have this error even if I have no entity on my jsonl?

I don't understand if the error I got is here because none of my jsonl lines have a sole entity or just because the first line one has no entity.

Maybe a workaround would be to filter the sample ensuring I have entities, what would you recommend for that in term of prodigy workflow?

Thank you

Julie

---

<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:** [November 16, 2022, 9:27pm UTC](https://support.prodi.gy/t/ner-teach-not-working/6120/6 "2022-11-16T21:27:06Z")

</div>

> [@JulieSarah](#):
>
> prefer\_uncertain function, I won't have this error even if I have no entity on my jsonl?

So I can't guarantee you won't -- but as I mentioned, the current default algorithm is `ema`:

> - `prefer_uncertain(stream, algorithm='ema')`: This is the default sorter. It tracks the exponential moving average of the uncertainties, and also tracks a moving variance. It then asks questions which are one standard deviation or more above the current average uncertainty.

Therefore, it will only "ask questions" for spans that are one or more standard deviation above the current average uncertainty. I think you're not seeing any examples b/c none of your spans meet this criteria. Hence, why I recommended modifying.

> [@JulieSarah](#):
>
> Maybe a workaround would be to filter the sample ensuring I have entities, what would you recommend for that in term of prodigy workflow?

Yes, you could but I would just use the `ner.correct` which will allow you to correct good and bad examples. Remember, the `ner.teach` is for modifying the order of what examples you see (active learning). If you don't want to use it, that's completely fine. You're welcome to filter out entities, but remember you do need negative examples (e.g., examples without any entities). So if you label only those with predicted entities, you may not build as robust of a model.
