bertopic_strategy
Topic extraction with BERTopic.
extract_topics_with_bertopic(docs, *, kmeans_n_clusters, umap_n_neighbors)
Extracts topics from a list of documents using BERTopic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docs |
list[str]
|
List of documents. |
required |
kmeans_n_clusters |
int
|
The number of clusters to form as well as the number of centroids to generate. This is equivalent to setting the number of topics. |
required |
umap_n_neighbors |
int
|
Number of neighboring sample points used when making the manifold approximation. Increasing this value typically results in a more global view of the embedding structure whilst smaller values result in a more local view. Increasing this value often results in larger clusters being created. |
required |
Returns:
| Type | Description |
|---|---|
list[list[str]]
|
List of topics, where a topic is a list of words. |
Examples:
>>> extract_topics_with_bertopic(
... docs=["detecting code smells with machine learning", "code smells detection tools", "error detection in Java software with machine learning"],
... )
[["word1 topic1", "word2 topic1"], ["word1 topic2", "word2 topic2"]]
Source code in src/sesg/topic_extraction/bertopic_strategy.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |