# How do you correct labels when you already have a prodigy.db full of labelled data?

**URL:** <https://support.prodi.gy/t/how-do-you-correct-labels-when-you-already-have-a-prodigy-db-full-of-labelled-data/6154>\
**Category:** Uncategorized\
**Tags:** usage, textcat, spacy\
**Created:** [November 29, 2022, 11:13am UTC](https://support.prodi.gy/t/how-do-you-correct-labels-when-you-already-have-a-prodigy-db-full-of-labelled-data/6154 "2022-11-29T11:13:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bev.manz](https://avatars.discourse-cdn.com/v4/letter/b/4bbf92/32.png) [@bev.manz](https://support.prodi.gy/u/bev.manz)\
**Post date:** [November 29, 2022, 11:13am UTC](https://support.prodi.gy/t/how-do-you-correct-labels-when-you-already-have-a-prodigy-db-full-of-labelled-data/6154/1 "2022-11-29T11:13:10Z")

</div>

I read about textcat.correct but I'm not sure it is what I'm after. Essentially I want a process that runs a quick version of the model with the live database, and then allows me to relabel/correct items in the database that someone may have labelled incorrectly. I have created a bit of a long workaround to extract data from database, run a bert model, then take the incorrect test predictions and push them back into prodigy after removing them from the database. This is quite longwinded and I was hoping there's a way to just launch prodigy to relabel items in current database that it is finding maybe incorrect predictions by the model?

---

<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 29, 2022, 6:56pm UTC](https://support.prodi.gy/t/how-do-you-correct-labels-when-you-already-have-a-prodigy-db-full-of-labelled-data/6154/2 "2022-11-29T18:56:08Z")

</div>

hi @bev.manz!

You can create a [custom recipe](https://prodi.gy/docs/custom-recipes) that slightly tweaks the `textcat.correct` so it'll only serve incorrect predictions (if you have the known predictions you can compare your model's predictions to).

You can start with the recipe's script by finding your Prodigy path location. Run `python -m prodigy stats` and find `Location:` folder. Then look for the `recipes/textcat.py` where you'll find the `textcat.correct` recipe.

Key would be this part that add the model's suggestions (predictions) and only yield those that are incorrect:

```python
# Add classifier predictions to each task in stream under 'options' key with the score per category
# and 'selected' key with the categories above the threshold.
def add_suggestions(stream):
    texts = ((eg["text"], eg) for eg in stream)
    # Process the stream using spaCy's nlp.pipe, which yields doc objects.
    # If as_tuples=True is set, you can pass in (text, context) tuples.
    for doc, eg in nlp.pipe(texts, as_tuples=True, batch_size=10):
        task = copy.deepcopy(eg)
        options = []
        selected = []
        for cat, score in doc.cats.items():
            if cat in labels:
                options.append({"id": cat, "text": cat, "meta": f"{score:.2f}"})

                # change to logic for correct prediction (i.e., selected = corrected)
                if score >= threshold:
                    selected.append(cat)
        task["options"] = options
        task["accept"] = selected
        yield task

```

The key is to change the logic of the `selected` (aka, those that are auto-accepted/skipped for annotation). You could instead provide some logic that are incorrect predictions.

To load as your recipe's source (i.e., current dataset, which we can call `my_labeled_dataset`) you can add `dataset:` as a prefix, so `dataset:my_labeled_dataset`. See [the docs for more details](https://prodi.gy/docs/api-loaders#datasets).

You may also appreciate the docs on [how to load/customize recipes](https://prodi.gy/docs/custom-recipes#writing) (e.g., `-F my_recipe.py`) and [customize their arguments](https://prodi.gy/docs/custom-recipes#recipe-args).

Hope this helps and let us know if you have further questions!
