Skip to content

Commit 0ab7cc5

Browse files
authored
Merge pull request #19 from wjbmattingly/0.0.10
0.0.10 - Optimize LeetTopic Functions for Efficiency and Readability
2 parents 30705de + 484db18 commit 0ab7cc5

7 files changed

Lines changed: 461 additions & 290 deletions

File tree

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
annoy_index.ann
3+
demo.html
4+
embeddings.npy
5+
leet_topic.egg-info/dependency_links.txt
6+
leet_topic.egg-info/PKG-INFO
7+
leet_topic.egg-info/requires.txt
8+
leet_topic.egg-info/SOURCES.txt
9+
leet_topic.egg-info/top_level.txt
10+
leet_topic/__pycache__/__init__.cpython-310.pyc
11+
leet_topic/__pycache__/bokeh_app.cpython-310.pyc
12+
testing.ipynb
13+
leet_topic/__pycache__/leet_topic.cpython-310.pyc

README.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
[![PyPI - PyPi](https://img.shields.io/pypi/v/leet-topic)](https://pypi.org/project/leet-topic/)
2+
13
![Leet Topic Logo](https://github.com/wjbmattingly/LeetTopic/raw/main/images/LeeTopic.png)
24

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.
46

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.
68

79
# Installation
810

@@ -66,12 +68,44 @@ leet_df, topic_data = leet_topic.LeetTopic(df,
6668
max_distance=.5)
6769
```
6870

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+
69103
# Outputs
70104
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.
71105

72106
Finally, the output will create an HTML file that is a self-contained Bokeh application like the image below.
73107

74-
![demo](https://github.com/wjbmattingly/LeetTopic/raw/main/images/leet-demo.png)
108+
![demo](https://github.com/wjbmattingly/LeetTopic/raw/main/images/demo-new.JPG)
75109

76110
# Steps
77111

images/demo-new.JPG

447 KB
Loading

images/demo-search.jpg

386 KB
Loading

0 commit comments

Comments
 (0)