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

[ENH] Score documents widget #632

Merged
merged 8 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
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
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