Skip to content

Commit

Permalink
Merge pull request #632 from PrimozGodec/scorer-widget
Browse files Browse the repository at this point in the history
[ENH] Score documents widget
  • Loading branch information
VesnaT authored Apr 30, 2021
2 parents 0513a8b + 757d0b1 commit f78144f
Show file tree
Hide file tree
Showing 7 changed files with 990 additions and 12 deletions.
Binary file added doc/widgets/images/Score-Documents.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions doc/widgets/score-documents.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Score Documents
===============

Scores documents based on word appearance.

**Inputs**

- Corpus: A collection of documents
- Words: A table with at least one column with words

**Outputs**

- Corpus: A collection of documents with scores

**Score Document** assigns scores to each document based on words at the input. The score with the selected scoring method is calculated for each word and aggregated together with the selected aggregation function on the document level.

![](images/Score-Documents.png)

1. Select one or more scoring methods for words:
- **Word frequency**: The count of the frequency of a word in the text.
- **Word ratio**: Indicate the appearance of the word in the document.
- **Similarity**: The cosine similarity between document embedding and word embedding.
2. Select aggregation function to aggregate word scores in document scores.
3. Filter documents based on the document title in the first column
4. The table with the document titles in the first column and scores for in other columns.
17 changes: 10 additions & 7 deletions orangecontrib/text/vectorization/document_embedder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import json
import sys
import warnings
from typing import Tuple, Any, Optional
from typing import Tuple, Any, Optional, Union, List
import numpy as np

from Orange.misc.server_embedder import ServerEmbedderCommunicator
Expand Down Expand Up @@ -93,13 +93,13 @@ def __init__(self, language: str = 'en',
embedder_type='text')

def __call__(
self, corpus: Corpus, processed_callback=None
) -> Tuple[Corpus, Corpus]:
self, corpus: Union[Corpus, List[List[str]]], processed_callback=None
) -> Union[Tuple[Corpus, Corpus], List[Optional[List[float]]]]:
"""Adds matrix of document embeddings to a corpus.
Parameters
----------
corpus : Corpus
corpus : Corpus or list of lists
Corpus on which transform is performed.
Returns
Expand All @@ -114,12 +114,15 @@ def __call__(
ValueError
If corpus is not instance of Corpus.
"""
if not isinstance(corpus, Corpus):
raise ValueError("Input should be instance of Corpus.")
if not isinstance(corpus, (Corpus, list)):
raise ValueError("Input should be instance of Corpus or list.")
embs = self._embedder.embedd_data(
list(corpus.ngrams),
list(corpus.ngrams) if isinstance(corpus, Corpus) else corpus,
processed_callback=processed_callback)

if isinstance(corpus, list):
return embs

dim = None
for emb in embs: # find embedding dimension
if emb is not None:
Expand Down
80 changes: 80 additions & 0 deletions orangecontrib/text/widgets/icons/ScoreDocuments.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit f78144f

Please sign in to comment.