# NER from user-generated content (spelling mistakes etc.)

**URL:** <https://support.prodi.gy/t/ner-from-user-generated-content-spelling-mistakes-etc/713>\
**Category:** Uncategorized\
**Tags:** usage, ner, solved\
**Created:** [July 25, 2018, 10:52pm UTC](https://support.prodi.gy/t/ner-from-user-generated-content-spelling-mistakes-etc/713 "2018-07-25T22:52:52Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [July 30, 2018, 9:29am UTC](https://support.prodi.gy/t/ner-from-user-generated-content-spelling-mistakes-etc/713/3 "2018-07-30T09:29:34Z")

</div>

Hi, thanks for your detailed questions and sorry for the delay on getting back to you! (I was in Edinburgh for EuroPython and only got back this weekend.) Answers below:

> [@blume](#):
>
> If so, does it make sense to use a seed list containing not only entities that are spelled correctly but also those spelled incorrectly?

In general, yes – if you're dealing with user-generated content, it'll definitely be more efficient to cover as many spelling variations as possible (especially the most common ones). This is also the reason we use word vectors and `terms.teach` to extend our seed lists with other similar terms, including common misspellings. I actually found this part really helpful and interesting, because most of those misspellings were things I would have never thought of myself! Based on the dataset created with `terms.teach`, you can then create your patterns file using `terms.to-patterns`.

For German, spaCy doesn't ship with pre-trained word vectors (yet) – but you can use the FastText vectors and [add them to a spaCy model](https://spacy.io/usage/vectors-similarity#custom), or train your own using [Gensim and Word2Vec](https://radimrehurek.com/gensim/models/word2vec.html). This also leads over to the next question...

> [@blume](#):
>
> What I’m worrying about as well are entities that comprise more than one word, often two or three or even more words (e.g. noun phrase consisting of a head noun plus a prepositional phrase).

By default, word vectors are typically trained for single tokens, so it's difficult to use them to find more similar multi-word phrases out of the box. German is a little nicer here, because you end up more specific nouns ("Baumwollfieber" vs. "brown" + "lung" + "disease" – sorry, I just googled for a random Fieber 😉 This is also the reason why @honnibal usually advocates for a more German-like tokenization scheme in English that merges noun chunks by default).

If it turns out that you need more specific tokens for more specific noun phrases, you can can pre-process your corpus using spaCy and merge all noun phrases, using a similar logic to what you'd expect for your entities. This is also part of the trick we use in [sense2vec](https://github.com/explosion/sense2vec) ([demo here](https://explosion.ai/demos/sense2vec) in case you haven't seen it yet).

Training vectors on merged tokens can be very useful to find more similar expressions that you missed in your patterns. It's also a good sanity check – if the most similar results don't turn up anything useful in the vectors, it's often a good indicator that your intended NER classification scheme won't work very well either. NER works best for clearly defined categories of "things" that occur in similar contexts.

If you find that your entities are too complex, it's often a better approach to focus on a simpler definition and then extend the entity span using rules and/or the dependency parse. For example, instead of trying to teach the model that "hohes Fieber" is an entity, you could focus on predicting "Fieber" and then extend the entities to include all adjectives attached to it. [This thread](https://support.prodi.gy/t/extending-existing-entity-type-with-patterns/651) and [this thread](https://support.prodi.gy/t/ner-or-phrasematcher/686) both have some more details and examples of this approach.

> [@blume](#):
>
> What I forgot to ask: When you want to train a model für two named entity categories, should you then make two separate seed lists or how do you make sure that prodigy understands that some terms are seeds for entity A and the others are seeds for entity B?

In `ner.teach`, you'd normally provide the seed terms of entity patterns via a `patterns.jsonl` file, which lets you specify a label:

```json
{"label": "DISEASE", "pattern": [{"lower": "fieber"}]}
{"label": "MEDICATION", "pattern": [{"lower": "aspirin"}]}

```

This is used by Prodigy to identify which label the pattern refers to. You can use one large patterns file containing all labels if you like, even if you're only training one label at a time. For example, if you set `--label DISEASE` on `ner.teach`, Prodigy should only use the patterns for that label, even if your file contains other patterns as well.

---

_[View the full topic](https://support.prodi.gy/t/ner-from-user-generated-content-spelling-mistakes-etc/713)._
