Error when running `ner.batch_train` inside Python

I’m running into an error when I try to call ner.batch_train inside a Python script:

File "/Users/ahalterman/anaconda3/lib/python3.6/site-packages/prodigy/recipes/", line 372, in batch_train
    msg = export_model_data(output_model, model.nlp, examples, evals)
  File "cython_src/prodigy/util.pyx", line 173, in prodigy.util.export_model_data
AttributeError: 'str' object has no attribute 'resolve'

I don’t get the error when I run it from the command line with the same info.

I tried:

  • specifying the full path to the output model
  • switching to positional arguments like here

but neither one helped.

Ah, I think I know what’s happening: When the output path is specified on the command line, Prodigy defines it as a pathlib.Path in the argument annotations. This means any input here is automatically converted to a Path, and the recipe then only assumes Paths and freely calls their methods. (Ironically, what fails here is resolving the path to the full location to provide more useful output after training.)

So can you try passing in a Path, e.g.

from pathlib import Path
output_path = Path('/path/to/output')

That did it! Thanks.

Glad to hear it’s working! We’re definitely going to improve the usability of prodigy.serve, considering this issue and the other one you posted. When we added it, we weren’t even sure if people would want or need it, so we only set it up as a pretty basic helper that just forwarded the arguments. But it shouldn’t be hard to make it more robust - for example, by using Plac to handle the argument validation and conversion, just like it does on the command line.