Text choice save error - Request Entity Too Large

Hi, I am using the choice interface to annotate text with multiple categories. It has always worked but now it won't let me save after a few annotations (just threw an error when saving 13 examples).

I checked the console and found the error Failed to load resource: the server responded with a status of 413 (Request Entity Too Large) , which I've encountered before when annotating images.

I believe this error is due to the large number of options I am setting for this particular task. Is that possible? Is there a way to prevent the options to be saved with the examples? I don't really need them...


That's definitely strange. What's in your task, and how many options do you have in there?

It's possible that this error happens when you annotate images, because by default, the image gets converted to a base64 string and if the image is large, that string can get very large, too. So you end up with this huge JSON blob. But in order to create an object this big with only plain text, you'd really need to have a lot of text.

Well, I am now using about 500 options :roll_eyes::sweat_smile: I know it is not the ideal annotation workflow, but it is a requirement for what I am testing at the moment. The documents have the same size as I've always used.

Is there a way to go around this and prevent the options to be saved with each example? Again: it is text and using the choice interface.

Okay, this explains a lot :sweat_smile:

I'm not sure what the best solution would be, because you'd have to remove the options on the client and before they're sent back to the server, right? I guess you could write a hacky script that listens on prodigyupdate and if content.accept has an entry (an option was selected, assuming it's single choice) it calls update({ options: [] }). Seems pretty unsatisfying, though.

To be honest, if this is really the workflow you want, you're probably better off writing a custom interface that uses a dropdown and then updates the task's accept on change. This means you'd only have to send over your options once with the HTML template (and not with every task) and you'd probably get a better user experience as well.

Thanks Ines. It is indeed a difficult use case.

Do you have any instructions or examples on how to create my own custom interface?

Check out the section on custom Javascript in the PRODIGY_README.html. This thread also has some examples: Custom view templates with scripts - #6 by ines

Essentially, you want your recipe config to return a html_template that looks something like this ({{text}} will get replaced with the "text" value of the current annotation task):

{{text}}<br /><br />

<select class="dropdown">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<!-- and so on... ->

In your javascript, you can then add an event listener to it and update the current task with the selected value. Something like this – untested, but should work:

document.addEventListener('prodigymount', event => {
    const dropdown = document.querySelector('.dropdown')
    dropdown.addEventListener('change', event => {
        // dropdown.value is the selected answer
        console.log('Selected:', dropdown.value)
        window.prodigy.update({ accept: [ dropdown.value ]})

This is all assuming you only want to allow single selections. If you want multiple selections, you could make it a <select multiple> and then add some logic to read out the selected options.

Thanks Ines, I'll follow up on the custom view. Is there an option to auto-save after each single annotation? This could be the easiest patch for the current problem.

Oh yeah, I guess you could also set the batch_size lower, to like 1 or 2. Or set "instant_submit": True to send each annotation back immediately. (It does mean that you won't get to undo, though.)

Thanks. I can't find instant_submit in the README, where should I use that?

Like this? :

return {
    'dataset': dataset,   # save annotations in this dataset
    'view_id': 'choice',  # use the choice interface
    'stream': stream,
    'config': {'choice_style': 'multiple', 'show_stats': True, 'instant_submit': True},

I am running prodigy version 1.6.1

Ah, okay – the instant_submit is a newer feature and was added in Prodigy v1.7. See here: https://prodi.gy/docs/changelog#1.7.0 Setting "batch_size": 1 should be pretty similar, though, for your use case.

Thanks. So setting batch_size: 1 will make Prodigy save at each 1 annotation? Is there a way to update the config file so that I don't have to add this setting to each recipe?

Well, it will technically save after 2 annotations and then one annotation per batch (because it always keeps one annotation on the client so you can undo). But in your case, you're mostly concerned about the size of the batches sent back and forth, so this should solve the problem.

Yes, you can also put those global settings in your prodigy.json.

1 Like