YAKE¤
Yake
pydantic-model
¤
Bases: TopWords
Extracts keyterms using the YAKE algorithm.
Config:
default:validation_config
Fields:
-
doc(DocLike) -
normalize(Optional[Literal['orth', 'lower', 'lemma', 'norm'] | None]) -
include_pos(Optional[str | Collection[str]]) -
stopwords(Optional[str | Collection[str]]) -
ngrams(Optional[int | Iterable[int] | None]) -
window_size(Optional[int]) -
topn(Optional[int | float]) -
keyterms(list[tuple[str, float]] | None)
Source code in lexos/topwords/keyterms/yake.py
doc: DocLike
pydantic-field
¤
Input as a spaCy doc, raw string, or sequence of terms.
include_pos: Optional[str | Collection[str]] = ('NOUN', 'PROPN', 'ADJ')
pydantic-field
¤
POS tags to include for candidates; ignored when unavailable.
ngrams: Optional[int | Iterable[int] | None] = (1, 2, 3)
pydantic-field
¤
N-gram sizes to consider for keyterm candidates.
normalize: Optional[Literal['orth', 'lower', 'lemma', 'norm'] | None] = 'lemma'
pydantic-field
¤
How to normalize terms for scoring.
stopwords: Optional[str | Collection[str]] = None
pydantic-field
¤
Custom stopwords to exclude from candidates and scoring.
topn: Optional[int | float] = 10
pydantic-field
¤
Number of top keyterms (or ratio if float in (0, 1]).
window_size: Optional[int] = 2
pydantic-field
¤
Context window size on each side of each term.
__init__(**kwargs)
¤
Initialize the Yake object and extract keyterms.
Source code in lexos/topwords/keyterms/yake.py
to_df() -> pd.DataFrame
¤
Return the extracted keyterms as a pandas DataFrame.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: A DataFrame with columns 'term' and 'score' containing the extracted keyterms. |
Source code in lexos/topwords/keyterms/yake.py
to_dict() -> dict[str, Any]
¤
Return the extracted keyterms as a dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: A dictionary containing the extracted keyterms. |
Source code in lexos/topwords/keyterms/yake.py
yake(doc: DocLike, *, normalize: Literal['orth', 'lower', 'lemma', 'norm'] | None = 'lemma', include_pos: Optional[str | Collection[str]] = ('NOUN', 'PROPN', 'ADJ'), stopwords: Optional[str | Collection[str]] = None, ngrams: int | Iterable[int] | None = (1, 2, 3), window_size: int = 2, topn: int | float = 10) -> list[tuple[str, float]]
¤
Extract key terms from a document using the YAKE algorithm.
This implementation is inspired by Textacy's YAKE extractor but adds compatibility for raw strings and sequences of strings/token-like objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
DocLike
|
Input document as a spaCy Doc, raw string, or sequence of terms. |
required |
normalize
|
Literal['orth', 'lower', 'lemma', 'norm'] | None
|
How to normalize terms for scoring. |
'lemma'
|
include_pos
|
Optional[str | Collection[str]]
|
POS tags to include for candidates; ignored when unavailable. |
('NOUN', 'PROPN', 'ADJ')
|
stopwords
|
Optional[str | Collection[str]]
|
Custom stopwords to exclude from candidates and scoring. |
None
|
ngrams
|
int | Iterable[int] | None
|
N-gram sizes to consider for keyterm candidates. |
(1, 2, 3)
|
window_size
|
int
|
Context window size on each side of each term. |
2
|
topn
|
int | float
|
Number of top keyterms to return (or ratio if float in (0, 1]). |
10
|
Returns:
| Type | Description |
|---|---|
list[tuple[str, float]]
|
list[tuple[str, float]]: Extracted keyterms as (term, score) tuples. |
Source code in lexos/topwords/keyterms/yake.py
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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |