# Combining NER with text classification

**URL:** <https://support.prodi.gy/t/combining-ner-with-text-classification/305>\
**Category:** Uncategorized\
**Tags:** usage, ner, textcat\
**Created:** [February 11, 2018, 1:33pm UTC](https://support.prodi.gy/t/combining-ner-with-text-classification/305 "2018-02-11T13:33:55Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [February 11, 2018, 2:54pm UTC](https://support.prodi.gy/t/combining-ner-with-text-classification/305/2 "2018-02-11T14:54:54Z")

</div>

> [@cmtru](#):
>
> but can I combine the two into a single model which I can load into spacy? Does that make sense?

Yes, absolutely! Both `ner.batch-train` and `textcat.batch-train` export loadable spaCy models, so you could start off with a blank or default spaCy model, train a model on your NER annotations and then use it as the input model for `textcat.teach`. For example:

```bash
prodigy textcat.batch-train my_textcat_dataset /path/to/ner-model ...

```

Ideally, you would create **two separate datasets** – one for your NER annotations and one for your text classifier annotations. You can use the same input data for both sets.

> [@cmtru](#):
>
> Used ner.manual to identify entities in a set of input data (which is basically a bunch of email transcripts)

To achieve better NER accuracy, you might also want to try training your model with `ner.teach` – especially if you're training new entity types from scratch. `ner.manual` is great to create gold-standard data and evaluation sets, but in order to properly train a new type, you need _a lot_ of manual annotations – ideally thousands or more. Using `ner.teach` and a patterns file with examples of the entities you're looking for can speed up the process, because the model in the loop can help you collect more relevant annotations.

In case you haven't seen it yet, here's our [video tutorial on training a new entity type](https://www.youtube.com/watch?v=l4scwf8KeIA). I also wrote more detailed comments about training NER from scratch [here](https://support.prodi.gy/t/trying-to-train-module-with-ner-manual-after-ner-batch-train-results-are-not-perfect/277/4) and [here](https://support.prodi.gy/t/how-do-i-add-technical-terms-and-abbreviations/303/2).

> [@cmtru](#):
>
> I then tried to export a model for use in spacy, and I get the error below.

`textcat.batch-train` expects all annotations in the dataset to have a `"label"` field containing the category label. Maybe your set contains examples without a label set? As I mentioned above, annotations you collect for different tasks (NER, textcat) should ideally have their own datasets. So a possible explanation for the error could be that your set contains both text classification and NER annotations (which don't have a label set).

You can use the `db-out` command to preview or export your dataset and check:

```bash
prodigy db-out mytest_systems_2 | less # preview dataset
prodigy db-out mytest_systems_2 /tmp # export dataset to a file

```

If it turns out that your set contains examples you want to exclude, you can edit the JSONL file manually and use `db-in` to import it to a new dataset. Each annotation session is also available in the database as a session dataset (named after the timestamp) – so you can also view and export individual sessions. To see a list of all datasets and session sets, you can use the `prodigy stats -ls` command.

---

_[View the full topic](https://support.prodi.gy/t/combining-ner-with-text-classification/305)._
