# using prodigy.serve for textcat.batch-train

**URL:** <https://support.prodi.gy/t/using-prodigy-serve-for-textcat-batch-train/1405>\
**Category:** Uncategorized\
**Tags:** api, solved\
**Created:** [April 16, 2019, 5:48pm UTC](https://support.prodi.gy/t/using-prodigy-serve-for-textcat-batch-train/1405 "2019-04-16T17:48:37Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ati](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@Ati](https://support.prodi.gy/u/Ati)\
**Post date:** [April 16, 2019, 5:48pm UTC](https://support.prodi.gy/t/using-prodigy-serve-for-textcat-batch-train/1405/1 "2019-04-16T17:48:37Z")

</div>

I get the following error when using prodigy.serve to call textcat.batch-train recipe:

File “/usr/local/lib/python3.6/site-packages/prodigy/ **init**.py”, line 23, in serve  
controller.config.update(config)  
AttributeError: ‘float’ object has no attribute ‘config’

Should I change what the recipe is returning and include a config?

Thanks,  
Ati

---

<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:** [April 16, 2019, 6:16pm UTC](https://support.prodi.gy/t/using-prodigy-serve-for-textcat-batch-train/1405/2 "2019-04-16T18:16:41Z")

</div>

Hi! This is a strange error – could you share the code you’re running? It looks like that for some reason, the `controller` actually ends up being a float 🤔

---

<div class="post-metadata">

**Author:** ![Ati](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@Ati](https://support.prodi.gy/u/Ati)\
**Post date:** [April 16, 2019, 6:40pm UTC](https://support.prodi.gy/t/using-prodigy-serve-for-textcat-batch-train/1405/3 "2019-04-16T18:40:15Z")

</div>

Hi Ines,

Thanks for quick reply.  
Here is how I use prodigy.serve():

prodigy.serve(‘textcat.batch-train’, ‘my\_dataset’, ‘en\_core\_web\_sm’, ‘/tmp’)

---

<div class="post-metadata">

**Author:** ![Ati](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@Ati](https://support.prodi.gy/u/Ati)\
**Post date:** [April 16, 2019, 6:45pm UTC](https://support.prodi.gy/t/using-prodigy-serve-for-textcat-batch-train/1405/4 "2019-04-16T18:45:16Z")

</div>

I should say the recipe works: the batch-train is done, and the model is saved in the right directory. But after saving the model the run is exited with this error.

---

<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:** [April 17, 2019, 9:45am UTC](https://support.prodi.gy/t/using-prodigy-serve-for-textcat-batch-train/1405/5 "2019-04-17T09:45:53Z")

</div>

Ahhh, thanks for the clarification. That makes more sense now. For some reason (not sure why), running the recipes via `prodigy.serve` doesn’t seem to handle “non-annotation recipes” properly that don’t return a dictionary of components. The `textcat.batch-train` recipe function only returns a float (the accuracy number) – this allows it to be called from within other recipes like `textcat.train-curve` and report the training results.

I’ll look into this! In the meantime, you could probably add a `try`/`except` around your function call and check for the attribute error to suppress it.

---

<div class="post-metadata">

**Author:** ![Ati](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@Ati](https://support.prodi.gy/u/Ati)\
**Post date:** [April 17, 2019, 3:03pm UTC](https://support.prodi.gy/t/using-prodigy-serve-for-textcat-batch-train/1405/6 "2019-04-17T15:03:01Z")

</div>

Thanks Ines. I did the try/except.

---

<div class="post-metadata">

**Author:** ![iero](https://avatars.discourse-cdn.com/v4/letter/i/41988e/32.png) [@iero](https://support.prodi.gy/u/iero)\
**Post date:** [May 6, 2019, 6:28pm UTC](https://support.prodi.gy/t/using-prodigy-serve-for-textcat-batch-train/1405/7 "2019-05-06T18:28:09Z")

</div>

hello Ines

Any news on this error ?

I use this function:

```python
import logging
from pathlib import Path

import prodigy
from prodigy.recipes.ner import batch_train

@prodigy.recipe('sentinel.ner.batch.train',
                dataset=prodigy.recipe_args['dataset'],
                spacy_model=prodigy.recipe_args['spacy_model'],
                label=prodigy.recipe_args['label']
                )
def batch_train_custom(dataset, spacy_model, label):
    print("Train {} to {}".format(dataset, label))
    output_path = Path('models/'+dataset)

    return batch_train(dataset=dataset,
                       input_model=spacy_model,
                       output_model=output_path,
                       label=label,
                       factor=1,
                       dropout=0.2,
                       n_iter=10,
                       batch_size=-1,
                       beam_width=16,
                       eval_id=None,
                       eval_split=0.2,
                       unsegmented=False,
                       no_missing=False,
                       silent=False)

```

It works and the model is created. But I have this error:

```python
Model: /tmp/models/temporary_model
Training data: /tmp/models/temporary_model/training.jsonl
Evaluation data: /tmp/models/temporary_model/evaluation.jsonl
Traceback (most recent call last):
  File "/Users/iero/miniconda/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    " __main__", mod_spec)
  File "/Users/iero/miniconda/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/iero/code/sentinel/sorcerer.py", line 300, in <module>
    prodigy.serve('sentinel.ner.batch.train', training_name, nlp_models[option.lang], training_labels)
  File "/Users/iero/miniconda/lib/python3.6/site-packages/prodigy/ __init__.py", line 23, in serve
    controller.config.update(config)
AttributeError: 'dict' object has no attribute 'config'

```

Any idea ?

---

<div class="post-metadata">

**Author:** ![iero](https://avatars.discourse-cdn.com/v4/letter/i/41988e/32.png) [@iero](https://support.prodi.gy/u/iero)\
**Post date:** [May 6, 2019, 6:59pm UTC](https://support.prodi.gy/t/using-prodigy-serve-for-textcat-batch-train/1405/8 "2019-05-06T18:59:26Z")

</div>

Maybe I do need to replace my return call by something as:

```python
    return {
        'view_id': 'ner',  
        'dataset': dataset,
        'output_model': output_path,
        'config': {
            'label': label
        }

```

???

---

<div class="post-metadata">

**Author:** ![Ati](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@Ati](https://support.prodi.gy/u/Ati)\
**Post date:** [May 6, 2019, 7:04pm UTC](https://support.prodi.gy/t/using-prodigy-serve-for-textcat-batch-train/1405/9 "2019-05-06T19:04:21Z")

</div>

This is how I solved it and Ines suggested the same as a quick fix:

```python
    try:
        prodigy.serve('recipe', arg1, arg2)
    except AttributeError: 
        pass

```

---

<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:** [May 6, 2019, 7:05pm UTC](https://support.prodi.gy/t/using-prodigy-serve-for-textcat-batch-train/1405/10 "2019-05-06T19:05:07Z")

</div>

This is the same problem described earlier in the thread – it’ll be fixed in the next release! The thing here is that the batch training recipes don’t return a dictionary of components and other objects instead – like, the accuracy numbers. (The error raised is an `AttributeError` when it’s trying to access the controller’s config – not a `KeyError`, so your initial idea of adding a config to the recipe components won’t make a difference.)

And yes, in the meantime, wrapping it in a `try`/`except` should make the error go away 🙂

---

<div class="post-metadata">

**Author:** ![iero](https://avatars.discourse-cdn.com/v4/letter/i/41988e/32.png) [@iero](https://support.prodi.gy/u/iero)\
**Post date:** [May 6, 2019, 7:07pm UTC](https://support.prodi.gy/t/using-prodigy-serve-for-textcat-batch-train/1405/11 "2019-05-06T19:07:41Z")

</div>

Thanks @Ati and @ines , i’ll do that !

---

<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:** [May 6, 2019, 8:25pm UTC](https://support.prodi.gy/t/using-prodigy-serve-for-textcat-batch-train/1405/12 "2019-05-06T20:25:17Z")

</div>

Btw, no idea why I didn’t think of this earlier but… `prodigy.serve` is really mostly intended for _serving_ the Prodigy application. The `batch_train` recipe is just a regular function, so the easiest way to use it is to import it and call it as a function.

```python
from prodigy.recipes.textcat import batch_train

batch_train(...) # etc.

```

---

<div class="post-metadata">

**Author:** ![iero](https://avatars.discourse-cdn.com/v4/letter/i/41988e/32.png) [@iero](https://support.prodi.gy/u/iero)\
**Post date:** [May 6, 2019, 9:32pm UTC](https://support.prodi.gy/t/using-prodigy-serve-for-textcat-batch-train/1405/13 "2019-05-06T21:32:19Z")

</div>

Thanks again, it’s working now !

---

<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:** [May 6, 2019, 9:35pm UTC](https://support.prodi.gy/t/using-prodigy-serve-for-textcat-batch-train/1405/14 "2019-05-06T21:35:47Z")

</div>

Okay, great! I think I’ll actually remove the “bug” label from this – the recommended way of calling a recipe from Python that _doesn’t_ need to serve the app should be to just import the function and call it. Much more straightforward and also more logical.

`prodigy.serve` is the helper function for executing recipes that need to serve something – like the annotation server and web app.
