# How to easily convert some patterns into terms for classification

**URL:** <https://support.prodi.gy/t/how-to-easily-convert-some-patterns-into-terms-for-classification/2315>\
**Category:** Uncategorized\
**Tags:** textcat, done, terms, solved\
**Created:** [December 13, 2019, 8:40pm UTC](https://support.prodi.gy/t/how-to-easily-convert-some-patterns-into-terms-for-classification/2315 "2019-12-13T20:40:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anz2](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/anz2/32/1105_2.png) [@Anz2](https://support.prodi.gy/u/Anz2)\
**Post date:** [December 13, 2019, 8:40pm UTC](https://support.prodi.gy/t/how-to-easily-convert-some-patterns-into-terms-for-classification/2315/1 "2019-12-13T20:40:52Z")

</div>

Hi, I am trying to teach some complex terms for classification. I prepared some phrases that can be appearing in given class (not just one word!). For example: "I can't download" and then I converted that into terms which gave me the resulting spacy style pattern "{"label":"SOME\_CLASS","pattern":[{"lower":"I can't download"}]}". I have used pattern matching many times in spacy and from that experience I am assuming that such pattern will never find anything unless I create custom tokenizer which tokenizes text in such a way that that whole phrase will be one token.  
I need at least something like that: {"label":"SOME\_CLASS","pattern":[{"lower":"I"}, {"lower": "can't"}, {"lower":"download"}]}. Is it supported and I didn't found?

---

<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:** [December 16, 2019, 11:37am UTC](https://support.prodi.gy/t/how-to-easily-convert-some-patterns-into-terms-for-classification/2315/2 "2019-12-16T11:37:32Z")

</div>

> [@Anz2](#):
>
> I need at least something like that: {"label":"SOME\_CLASS","pattern":[{"lower":"I"}, {"lower": "can't"}, {"lower":"download"}]}. Is it supported and I didn't found?

At the moment, the `terms.to-patterns` recipe doesn't tokenize (although it will in the next version). But creating those patterns shouldn't be very difficult – all you have to do is tokenize the text:

```python
phrases = ["I can't download"]
nlp = spacy.blank("en")
patterns = []
for doc in nlp.pipe(phrases):
    pattern = [{"lower": token.lower_} for token in doc]
    patterns.append({"label": "SOME_CLASS", "pattern": pattern})

```

**Edit:** Now also shipped in v1.9: you can set a `--spacy-model` argument on `terms.to-patterns` that's either the name of a model or `blank:en` etc. (to just use a blank language tokenizer).
