inception-project / inception-external-recommender

Get annotation suggestions for the INCEpTION text annotation platform from spaCy, Sentence BERT, scikit-learn and more. Runs as a web-service compatible with the external recommender API of INCEpTION.
Apache License 2.0
40 stars 17 forks source link

Allow recommenders to return probability scores #37

Closed pseudomonas closed 8 months ago

pseudomonas commented 1 year ago

I've adapted the Sklearn script for POS-tagging, and it'd be really useful for it to return a set of label-score tuples for each token. The create_prediction api doesn't seem to support that though?

reckart commented 1 year ago

What does the tuple represent?

pseudomonas commented 1 year ago

each potential label, and the probability that the classifier assigns to it in that space. (could be a dictionary rather than a tuple; sklearn-crfsuite uses dictionaries)

inception's internal classifiers have scores attached which allows functionality like "ignore recommendations below N probability" and "show potential labels in order of likelihood"; I'd like to get that working for external recommenders too.

reckart commented 1 year ago

Ah, sorry. What you do is, that you create a prediction for each of the label/score tuples.

prediction = create_prediction(cas, layer, feature, begin, end, predicted_label)
prediction.set(f'{feature}_score', score)
prediction.set(f'{feature}_score_explanation', 'Some reason for the score (optional)')
cas.add_annotation(prediction)
pseudomonas commented 1 year ago

Thank you!

(also, is there documentation to this effect somewhere, so I can avoid asking unnecessary questions in future? I couldn't really find anything with the googling that I did.)

reckart commented 1 year ago

Eh... not yet :) ... and to be honest, it should probably simply be something that the create_prediction method offers as optional arguments. If it had these arguments, you probably wouldn't have had to ask.

pseudomonas commented 1 year ago

In that case I'll ask my other question in another Issue thread, and hopefully if someone else has the same question they can find that. BTW, would you like my POS-tagging code once I've made the changes above?

reckart commented 1 year ago

Contributions are always welcome :)

reckart commented 1 year ago

If you like to submit a PR to add the optional parameters to create_prediction, that's also welcome ;)

reckart commented 8 months ago

There are optional parameters to create_span_prediction() and create_relation_prediction() now.