lit icon indicating copy to clipboard operation
lit copied to clipboard

GlueModel from example returns map object instead of list

Open aaarrti opened this issue 3 years ago • 2 comments

Hi, as you can see on the 1st screenshot, GlueModel from lit_nlp.examples.models.glue_models returns map object, instead of intended list. After executing map_result = nn.predict_minibatch([{'sentence1': 'Hello there'}]) list_result = list(map_result), the result looks more like it should (see 2nd screenshot). Is it the intended behaviour? image image

aaarrti avatar Aug 17 '22 16:08 aaarrti

I'm not familiar with this debugger, but it looks like list_result in the second image is a single-element list, which should be correct.

iftenney avatar Aug 17 '22 17:08 iftenney

Thanks for reaching out.

Looks like the glue models predict_minibatch code uses the python build-in function map to create the output dicts for each input. This function returns a map iterable which as you saw can be converted to an actual list by wrapping it in the list constructor.

So technically the glue models code doesn't conform to the API from api/models.py in that it returns an iterable instead of a list. But, given how LIT uses the results, the returned value is used as a list to send the results back to the front-end.

So I suppose I would say that the code in glue models would technically be more correct if it converted the map iterable result to a list before returning, but it doesn't cause any issues in how LIT functions.

jameswex avatar Aug 17 '22 17:08 jameswex

Update to this before closing: The LIT v1.0 release updated the Model.predict type annotations to be an Iterable instead of a list.

RyanMullins avatar Jan 16 '24 15:01 RyanMullins

Closing this issue due to inactivity.

RyanMullins avatar Jan 16 '24 15:01 RyanMullins