Skip to content

Commit

Permalink
Added example script
Browse files Browse the repository at this point in the history
  • Loading branch information
jefflund committed Mar 18, 2019
1 parent 28a323d commit f86cf89
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ankura/topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _sparse_topic_word(corpus, K, V, z_attr):
def pdists(corpus, theta_attr, metric='cosine'):
D = len(corpus.documents)
thetas = np.array([doc.metadata[theta_attr] for doc in corpus.documents])
dists = spatial.distance.pdist(thetas, metric)
dists = spatial.distance.pdist(thetas[:D], metric)
for ij in np.argsort(dists, axis=None):
i, j = ij // D, ij % D
if i == j:
Expand Down
11 changes: 5 additions & 6 deletions scripts/example_xref.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
Q = ankura.anchor.build_cooccurrence(bible)
anchors = ankura.anchor.doc_anchors(bible, Q, 3000)
topics = ankura.anchor.recover_topics(Q, anchors)

ankura.assign.variational(bible, topics, 'theta')

for i, j in itertools.islice(ankura.topic.pdists(bible, 'theta'), 1000):
print(
bible.documents[i].metadata['verse'],
bible.documents[j].metadata['verse'],
)
for i, j in itertools.islice(ankura.topic.pdists(bible, 'theta'), 5000):
verse_i = bible.documents[i].metadata['verse']
verse_j = bible.documents[j].metadata['verse']
correct = verse_j in bible.documents[i].metadata['xref-tske']
print(verse_i, verse_j, correct)

0 comments on commit f86cf89

Please sign in to comment.