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

Function test_set_labels

tests/test_representation/test_labels.py:40–72  ·  view source on GitHub ↗
(model, request)

Source from the content-addressed store, hash-verified

38 ],
39)
40def test_set_labels(model, request):
41 topic_model = copy.deepcopy(request.getfixturevalue(model))
42
43 labels = topic_model.generate_topic_labels()
44 topic_model.set_topic_labels(labels)
45 assert topic_model.custom_labels_ == labels
46
47 if model != "online_topic_model":
48 labels = {1: "My label", 2: "Another label"}
49 topic_model.set_topic_labels(labels)
50 assert topic_model.custom_labels_[1 + topic_model._outliers] == "My label"
51 assert topic_model.custom_labels_[2 + topic_model._outliers] == "Another label"
52
53 labels = {1: "Change label", 3: "New label"}
54 topic_model.set_topic_labels(labels)
55 assert topic_model.custom_labels_[1 + topic_model._outliers] == "Change label"
56 assert topic_model.custom_labels_[3 + topic_model._outliers] == "New label"
57 else:
58 labels = {
59 sorted(set(topic_model.topics_))[0]: "My label",
60 sorted(set(topic_model.topics_))[1]: "Another label",
61 }
62 topic_model.set_topic_labels(labels)
63 assert topic_model.custom_labels_[0] == "My label"
64 assert topic_model.custom_labels_[1] == "Another label"
65
66 labels = {
67 sorted(set(topic_model.topics_))[0]: "Change label",
68 sorted(set(topic_model.topics_))[2]: "New label",
69 }
70 topic_model.set_topic_labels(labels)
71 assert topic_model.custom_labels_[0 + topic_model._outliers] == "Change label"
72 assert topic_model.custom_labels_[2 + topic_model._outliers] == "New label"

Callers

nothing calls this directly

Calls 2

generate_topic_labelsMethod · 0.80
set_topic_labelsMethod · 0.80

Tested by

no test coverage detected