label_groups()
Give each group of spans a name. No thesaurus, no model.
label_groups(
groups: dict,
by: str = 'keywords',
top: int = 3,
) -> dict
Source: theoryminer/harmonizer/labels.py
The keywords of a group are the words that its members repeat and that the other groups do not use (class-based TF-IDF):
score(word) = (count in the group / words in the group)
* log(1 + groups / groups that hold the word)
Function words (“the”, “of”, …) never enter a name. A group with one member takes the member as its name. The spans are not changed. The function reads no file.
Arguments
groups
The groups to name.
- Values: the result of pairwise_grouping() or clusterer(): {span: {“group”: id, “central”: span}}.
- Default: none. Give the groups.
by
How the name is made.
- Values: “keywords”: the
topkeywords, joined by a space. “medoid”: the central span. “both”: the central span, “ | “, then the keywords. - Default “keywords” (since 0.2.0).
top
The number of keywords for each group.
- Values: a whole number, 1 or more.
- Default 3.
Returns
{key: group}: one dict per group. The key is the group id, or the span text for a noise span. Each group has the keys
| key | meaning |
|---|---|
central | the central span of the group |
size | the number of members |
members | the spans of the group |
keywords | up to top (word, score) pairs, best first |
name | the name, made by by |
Raises
ValueError: An unknown by.
Example
>>> labelled = label_groups(clusterer(cards))
>>> labelled[1]["size"], labelled[1]["name"]
(5, 'loneliness reducing alleviate')