SGRank¤
SGRank
pydantic-model
¤
Bases: TopWords
Extracts keyterms using the SGRank algorithm.
Config:
default:validation_config
Fields:
-
doc(str | Doc) -
normalize(Optional[str | Callable[[Span], str]]) -
ngrams(int | Collection[int]) -
include_pos(Optional[str | Collection[str]]) -
window_size(Optional[int]) -
topn(Optional[int | float]) -
idf(Optional[dict[str, float]]) -
keyterms(list[tuple[str, float]] | None)
Source code in lexos/topwords/keyterms/sgrank.py
doc: str | Doc
pydantic-field
¤
The raw text or spaCy doc to analyze.
idf: Optional[dict[str, float]] = None
pydantic-field
¤
Mapping of normalized term to inverse document frequency.
include_pos: Optional[str | Collection[str]] = ('NOUN', 'PROPN', 'ADJ')
pydantic-field
¤
POS tags to include for candidate selection.
ngrams: int | Collection[int] = (1, 2, 3, 4, 5, 6)
pydantic-field
¤
N-gram sizes to consider for keyterm candidates.
normalize: Optional[str | Callable[[Span], str]] = 'lemma'
pydantic-field
¤
How to normalize candidates for scoring.
topn: Optional[int | float] = 10
pydantic-field
¤
The number of top keyterms to return (int or float ratio of candidates).
window_size: Optional[int] = 1500
pydantic-field
¤
Size of the sliding window for co-occurrence, in tokens.
__init__(**kwargs) -> None
¤
Initialize the SGRank object and extract keyterms.
Source code in lexos/topwords/keyterms/sgrank.py
to_df()
¤
to_dict()
¤
sgrank(doc: Doc | str, *, normalize: Optional[str | Callable[[Span], str]] = 'lemma', ngrams: int | Collection[int] = (1, 2, 3, 4, 5, 6), include_pos: Optional[str | Collection[str]] = ('NOUN', 'PROPN', 'ADJ'), window_size: int = 1500, topn: int | float = 10, idf: Optional[dict[str, float]] = None) -> list[tuple[str, float]]
¤
Extract key terms from a document using the SGRank algorithm.
This comment is just taken straight from textacy, will adjust later
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
Doc | str
|
spaCy |
required |
normalize
|
Optional[str | Callable[[Span], str]]
|
If "lemma", lemmatize terms; if "lower", lowercase terms; if None,
use the form of terms as they appeared in |
'lemma'
|
ngrams
|
int | Collection[int]
|
n of which n-grams to include. For example, |
(1, 2, 3, 4, 5, 6)
|
include_pos
|
Optional[str | Collection[str]]
|
One or more POS tags with which to filter for good candidate keyterms. If None, include tokens of all POS tags (which also allows keyterm extraction from docs without POS-tagging.) |
('NOUN', 'PROPN', 'ADJ')
|
window_size
|
int
|
Size of sliding window in which term co-occurrences are determined to occur. Note: Larger values may dramatically increase runtime, owing to the larger number of co-occurrence combinations that must be counted. |
1500
|
topn
|
int | float
|
Number of top-ranked terms to return as keyterms.
If int, represents the absolute number; if float, must be in the open interval
(0.0, 1.0), and is converted to an integer by |
10
|
idf
|
Optional[dict[str, float]]
|
Mapping of |
None
|
Returns:
| Type | Description |
|---|---|
list[tuple[str, float]]
|
Sorted list of top |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
References
Danesh, Sumner, and Martin. "SGRank: Combining Statistical and Graphical Methods to Improve the State of the Art in Unsupervised Keyphrase Extraction." Lexical and Computational Semantics (* SEM 2015) (2015): 117.
Source code in lexos/topwords/keyterms/sgrank.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |