TypeError: [E017] Can only add unicode or bytes. Got type: <class 'NoneType'>

Hi Everyone,

I was stuck with a problem for a while.When I use

prodigy ner.teach currency_ner en_core_web_lg nytimes_news_articles.txt --label CURRENCY --patterns currency_patterns.jsonl

I get this error

Using 1 labels: CURRENCY
Traceback (most recent call last):
File “/usr/lib64/python3.7/runpy.py”, line 193, in _run_module_as_main
main”, mod_spec)
File “/usr/lib64/python3.7/runpy.py”, line 85, in _run_code
exec(code, run_globals)
File “/usr/local/lib64/python3.7/site-packages/prodigy/main.py”, line 259, in
controller = recipe(args, use_plac=True)
File “cython_src/prodigy/core.pyx”, line 253, in prodigy.core.recipe.recipe_decorator.recipe_proxy
File “/home/ec2-user/.local/lib/python3.7/site-packages/plac_core.py”, line 328, in call
cmd, result = parser.consume(arglist)
File “/home/ec2-user/.local/lib/python3.7/site-packages/plac_core.py”, line 207, in consume
return cmd, self.func(
(args + varargs + extraopts), **kwargs)
File “/usr/local/lib64/python3.7/site-packages/prodigy/recipes/ner.py”, line 111, in teach
matcher = PatternMatcher(model.nlp).from_disk(patterns)
File “cython_src/prodigy/models/matcher.pyx”, line 192, in prodigy.models.matcher.PatternMatcher.from_disk
File “cython_src/prodigy/models/matcher.pyx”, line 133, in prodigy.models.matcher.PatternMatcher.add_patterns
File “nn_parser.pyx”, line 815, in spacy.syntax.nn_parser.Parser.add_label
File “ner.pyx”, line 218, in spacy.syntax.ner.BiluoPushDown.add_action
File “strings.pyx”, line 138, in spacy.strings.StringStore.add

TypeError: [E017] Can only add unicode or bytes. Got type: <class ‘NoneType’>

Can someone help me to work it out?Thanks!!!

It looks like the error happens when the patterns are loaded into the pattern matcher. So I suspect there's some invalid property in your data, likely null (which translates to Python's none)?

Have a look at your currency_patterns.jsonl and see if anything looks suspicious here!

Thanks for your reply!
I checked my currency_ptterns.jsonl by using

less currency_patterns.jsonl

I got this
{“label”:null,“pattern”:[{“lower”:“yuan”}]}
{“label”:null,“pattern”:[{“lower”:“usd”}]}
{“label”:null,“pattern”:[{“lower”:“yens”}]}
{“label”:null,“pattern”:[{“lower”:“euro”}]}
{“label”:null,“pattern”:[{“lower”:“yen”}]}
{“label”:null,“pattern”:[{“lower”:“euros”}]}
{“label”:null,“pattern”:[{“lower”:“eur”}]}
{“label”:null,“pattern”:[{“lower”:“baht”}]}
{“label”:null,“pattern”:[{“lower”:“rubles”}]}
{“label”:null,“pattern”:[{“lower”:“pesos”}]}
{“label”:null,“pattern”:[{“lower”:“dollar”}]}
{“label”:null,“pattern”:[{“lower”:“gbp”}]}
{“label”:null,“pattern”:[{“lower”:“francs”}]}
{“label”:null,“pattern”:[{“lower”:“peso”}]}
{“label”:null,“pattern”:[{“lower”:“rupees”}]}
{“label”:null,“pattern”:[{“lower”:“currency”}]}
{“label”:null,“pattern”:[{“lower”:“rupiah”}]}
{“label”:null,“pattern”:[{“lower”:“ringgit”}]}
{“label”:null,“pattern”:[{“lower”:“zloty”}]}
{“label”:null,“pattern”:[{“lower”:“renminbi”}]}
{“label”:null,“pattern”:[{“lower”:“roubles”}]}
{“label”:null,“pattern”:[{“lower”:“currencies”}]}
{“label”:null,“pattern”:[{“lower”:“rupee”}]}
{“label”:null,“pattern”:[{“lower”:“euro”}]}
{“label”:null,“pattern”:[{“lower”:“yens”}]}
{“label”:null,“pattern”:[{“lower”:“yuan”}]}
{“label”:null,“pattern”:[{“lower”:“USD”}]}
{“label”:null,“pattern”:[{“lower”:“kroner”}]}
{“label”:null,“pattern”:[{“lower”:“dollars”}]}
{“label”:null,“pattern”:[{“lower”:“lira”}]}
{“label”:null,“pattern”:[{“lower”:“ruble”}]}
{“label”:null,“pattern”:[{“lower”:“franc”}]}
{“label”:null,“pattern”:[{“lower”:“dirhams”}]}
{“label”:null,“pattern”:[{“lower”:“greenback”}]}
{“label”:null,“pattern”:[{“lower”:“krona”}]}
{“label”:null,“pattern”:[{“lower”:“kronor”}]}
{“label”:null,“pattern”:[{“lower”:“dollers”}]}
{“label”:null,“pattern”:[{“lower”:“naira”}]}
{“label”:null,“pattern”:[{“lower”:“dolars”}]}
{“label”:null,“pattern”:[{“lower”:“jpy”}]}
{“label”:null,“pattern”:[{“lower”:“pesetas”}]}
{“label”:null,“pattern”:[{“lower”:“rmb”}]}
{“label”:null,“pattern”:[{“lower”:“dollors”}]}
{“label”:null,“pattern”:[{“lower”:“hkd”}]}
{“label”:null,“pattern”:[{“lower”:“guilders”}]}
{“label”:null,“pattern”:[{“lower”:“hryvnia”}]}
{“label”:null,“pattern”:[{“lower”:“yuans”}]}
{“label”:null,“pattern”:[{“lower”:“cents”}]}
{“label”:null,“pattern”:[{“lower”:“drachmas”}]}
{“label”:null,“pattern”:[{“lower”:“zlotys”}]}
{“label”:null,“pattern”:[{“lower”:“rials”}]}
{“label”:null,“pattern”:[{“lower”:“tenge”}]}
{“label”:null,“pattern”:[{“lower”:“birr”}]}
{“label”:null,“pattern”:[{“lower”:“forint”}]}
{“label”:null,“pattern”:[{“lower”:“greenbacks”}]}
{“label”:null,“pattern”:[{“lower”:“sek”}]}
{“label”:null,“pattern”:[{“lower”:“riyal”}]}
{“label”:null,“pattern”:[{“lower”:“bolivars”}]}
{“label”:null,“pattern”:[{“lower”:“pound”}]}
{“label”:null,“pattern”:[{“lower”:“rial”}]}

Thanks for checking – and see, the error makes sense then:

In order to use the patterns as suggestions for a label, they need to be assigned to a label – for example "label": "CURRENCY". (If you've created the patterns with terms.to-patterns, you likely forgot to pass in a label.)

Ah yes! I am sorry that I am too careless.
many thanks!

1 Like

No worries, glad you got it working! :slightly_smiling_face: