MCPcopy
hub / github.com/MaartenGr/BERTopic / test_linkage

Function test_linkage

tests/test_variations/test_hierarchy.py:36–46  ·  view source on GitHub ↗
(model, documents, request)

Source from the content-addressed store, hash-verified

34 ],
35)
36def test_linkage(model, documents, request):
37 topic_model = copy.deepcopy(request.getfixturevalue(model))
38 linkage_function = lambda x: sch.linkage(x, "single", optimal_ordering=True)
39 hierarchical_topics = topic_model.hierarchical_topics(documents, linkage_function=linkage_function)
40 merged_topics = set([v for vals in hierarchical_topics.Topics.values for v in vals])
41 tree = topic_model.get_topic_tree(hierarchical_topics)
42
43 assert len(hierarchical_topics) > 0
44 assert len(tree) > 50
45 assert len(tree.split("\n")) <= 2 * len(set(topic_model.topics_))
46 assert merged_topics == set(topic_model.topics_).difference({-1})
47
48
49@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 2

hierarchical_topicsMethod · 0.80
get_topic_treeMethod · 0.80

Tested by

no test coverage detected