Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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 top keywords, 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

keymeaning
centralthe central span of the group
sizethe number of members
membersthe spans of the group
keywordsup to top (word, score) pairs, best first
namethe 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')