|
| 1 | +[](https://pypi.org/project/leet-topic/) |
| 2 | + |
1 | 3 |  |
2 | 4 |
|
3 | | -LeetTopic builds upon Top2Vec, BerTopic and other transformer-based topic modeling Python libraries. Unlike BerTopic and Top2Vec, LeetTopic allows users to control the degree to which outliers are resolved into neighboring topics. |
| 5 | +LeetTopic builds upon [Top2Vec](https://github.com/ddangelov/Top2Vec), [BerTopic](https://github.com/MaartenGr/BERTopic) and other transformer-based topic modeling Python libraries. Unlike BerTopic and Top2Vec, LeetTopic allows users to control the degree to which outliers are resolved into neighboring topics. |
4 | 6 |
|
5 | | -It also lets you turn any DataFrame into a Bokeh application for exploring your documents and topics. |
| 7 | +It also lets you turn any DataFrame into a [Bokeh](https://bokeh.org/) application for exploring your documents and topics. As of 0.0.10, LeetTopic also allows users to generate an [Annoy](https://github.com/spotify/annoy) Index as part of the LeetTopic pipeline. This allows users to construct a query their data. |
6 | 8 |
|
7 | 9 | # Installation |
8 | 10 |
|
@@ -66,12 +68,44 @@ leet_df, topic_data = leet_topic.LeetTopic(df, |
66 | 68 | max_distance=.5) |
67 | 69 | ``` |
68 | 70 |
|
| 71 | +## Create an Annoy Index |
| 72 | +As of 0.0.10, users can also return an Annoy Index. |
| 73 | + |
| 74 | +```python |
| 75 | +import pandas as pd |
| 76 | +from leet_topic import leet_topic |
| 77 | + |
| 78 | +df = pd.read_json("data/vol7.json") |
| 79 | +leet_df, topic_data, annoy_index = leet_topic.LeetTopic(df, "descriptions", |
| 80 | + "demo.html", |
| 81 | + build_annoy=True) |
| 82 | +``` |
| 83 | + |
| 84 | +To leverage the Annoy Index, one can easily create a semantic search engine. One can query the index, for example, by encoding a new text with the same model. |
| 85 | + |
| 86 | +```python |
| 87 | +import pandas as pd |
| 88 | +from leet_topic import leet_topic |
| 89 | +from sentence_transformers import SentenceTransformer |
| 90 | + |
| 91 | + |
| 92 | +model = SentenceTransformer('all-MiniLM-L6-v2') |
| 93 | + |
| 94 | +emb = model.encode("An individual who was arrested.") |
| 95 | + |
| 96 | +res = annoy_index.get_nns_by_vector(emb, 10) |
| 97 | + |
| 98 | +print(df.iloc[res].descriptions.tolist()) |
| 99 | + |
| 100 | +``` |
| 101 | + |
| 102 | + |
69 | 103 | # Outputs |
70 | 104 | This code above will generate a new DataFrame with the UMAP Projection (x, y), hdbscan_labels, and leet_labels, and top-n words for each document. It will also output data about each topic including the central plot of each vector, the documents assigned to it, top-n words associated with it. |
71 | 105 |
|
72 | 106 | Finally, the output will create an HTML file that is a self-contained Bokeh application like the image below. |
73 | 107 |
|
74 | | - |
| 108 | + |
75 | 109 |
|
76 | 110 | # Steps |
77 | 111 |
|
|
0 commit comments