ZeroShotClassification
¶
Bases: BaseRepresentation
Zero-shot Classification on topic keywords with candidate labels
Parameters:
Name | Type | Description | Default |
---|---|---|---|
candidate_topics |
List[str]
|
A list of labels to assign to the topics if they
exceed |
required |
model |
str
|
A transformers pipeline that should be initialized as
"zero-shot-classification". For example,
|
'facebook/bart-large-mnli'
|
pipeline_kwargs |
Mapping[str, Any]
|
Kwargs that you can pass to the transformers.pipeline
when it is called. NOTE: Use |
{}
|
min_prob |
float
|
The minimum probability to assign a candidate label to a topic |
0.8
|
Usage:
from bertopic.representation import ZeroShotClassification
from bertopic import BERTopic
# Create your representation model
candidate_topics = ["space and nasa", "bicycles", "sports"]
representation_model = ZeroShotClassification(candidate_topics, model="facebook/bart-large-mnli")
# Use the representation model in BERTopic on top of the default pipeline
topic_model = BERTopic(representation_model=representation_model)
Source code in bertopic\representation\_zeroshot.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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
extract_topics(topic_model, documents, c_tf_idf, topics)
¶
Extract topics
Parameters:
Name | Type | Description | Default |
---|---|---|---|
topic_model |
Not used |
required | |
documents |
DataFrame
|
Not used |
required |
c_tf_idf |
csr_matrix
|
Not used |
required |
topics |
Mapping[str, List[Tuple[str, float]]]
|
The candidate topics as calculated with c-TF-IDF |
required |
Returns:
Name | Type | Description |
---|---|---|
updated_topics |
Mapping[str, List[Tuple[str, float]]]
|
Updated topic representations |
Source code in bertopic\representation\_zeroshot.py
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|