Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch suggest in SVC backend #670

Merged
merged 1 commit into from
Feb 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions annif/backend/svc.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ def _scores_to_suggestions(self, scores, params):
)
return ListSuggestionResult(results)

def _suggest(self, text, params):
self.debug(
'Suggesting subjects for text "{}..." (len={})'.format(text[:20], len(text))
)
vector = self.vectorizer.transform([text])
if vector.nnz == 0: # All zero vector, empty result
return ListSuggestionResult([])
confidences = self._model.decision_function(vector)[0]
def _suggest_batch(self, texts, params):
vector = self.vectorizer.transform(texts)
confidences = self._model.decision_function(vector)
# convert to 0..1 score range using logistic function
scores = scipy.special.expit(confidences)
return self._scores_to_suggestions(scores, params)
scores_list = scipy.special.expit(confidences)
return [
ListSuggestionResult([])
if row.nnz == 0
else self._scores_to_suggestions(scores, params)
for scores, row in zip(scores_list, vector)
]