topic_extraction
Topic extraction strategies.
DocStudy
Bases: TypedDict
Data container for a study that will be used to generate a doc.
Attributes:
| Name | Type | Description |
|---|---|---|
title |
str
|
Title of the study. |
abstract |
str
|
Abstract of the study. |
keywords |
str
|
Keywords of the study. |
Examples:
>>> study: DocStudy = {
... "title": "machine learning",
... "abstract": "machine learning is often used in the industry with the goal of...",
... "keywords": "machine learning, code smells, defect detection"
... }
>>> study
{'title': 'machine learning', 'abstract': 'machine learning is often used in the industry with the goal of...', 'keywords': 'machine learning, code smells, defect detection'}
Source code in src/sesg/topic_extraction/create_docs.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
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 | |
extract_topics_with_lda(docs, *, min_document_frequency, n_topics)
Extracts topics from a list of documents using LDA method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docs |
list[str]
|
List of documents. |
required |
min_document_frequency |
float
|
CountVectorizer parameter - Minimum document frequency for the word to appear on the bag of words. |
required |
n_topics |
int
|
LDA parameter - Number of topics to generate. |
required |
Returns:
| Type | Description |
|---|---|
list[list[str]]
|
list of topics, where a topic is a list of words. |
Examples:
>>> extract_topics_with_lda(
... docs=["detecting code smells with machine learning", "code smells detection tools", "error detection in Java software with machine learning"],
... min_document_frequency=0.1,
... n_topics=2,
... )
[["word1 topic1", "word2 topic1"], ["word1 topic2", "word2 topic2"]]
Source code in src/sesg/topic_extraction/lda_strategy.py
7 8 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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |