这是indexloc提供的服务,不要输入任何密码
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pandas
pandas==0.16.2
scikit-learn
statsmodels
gensim
Expand All @@ -7,3 +7,6 @@ pyth
pymongo
MySQL-python
scipy
unidecode
multiprocess
nltk
10 changes: 0 additions & 10 deletions rosetta/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,6 @@ def test_dirichlet_expectation(self):
[-0.13470677, -13.32429878]]).T
assert_allclose(result, benchmark, atol=1e-4)

def test_expElogbeta(self):
# Make sure equal to exponential of dirichlet_expectation when we
# pass in all ones
lda = self.choose_lda('lda')
lda._lambda_word_sums = pd.Series(
np.ones(lda.num_topics), index=lda.topics)
result = lda._expElogbeta
benchmark = np.exp(lda._dirichlet_expectation(lda.pr_token_topic))
assert_frame_equal(result, benchmark)

def test_predict_1(self):
# Use fact that w0 <--> topic_0, w1 <--> topic_1
lda = self.choose_lda('lda_2')
Expand Down
7 changes: 4 additions & 3 deletions rosetta/text/vw_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ def _set_probabilities(self, topics, predictions):
self.pr_doc = doc_sums / doc_sums.sum()
self.pr_doc_topic = predictions / predictions.sum().sum()

lam = self._lambda_word_sums * self.pr_token_topic
self._constExpElogbeta = np.exp(self._dirichlet_expectation(lam + EPS))

def prob_token_topic(self, token=None, topic=None, c_token=None,
c_topic=None):
"""
Expand Down Expand Up @@ -565,9 +568,7 @@ def _expElogbeta(self):
topic-word weights.
"""
# Get lambda, the dirichlet parameter originally returned by VW.
lam = self._lambda_word_sums * self.pr_token_topic

return np.exp(self._dirichlet_expectation(lam + EPS))
return self._constExpElogbeta

def _dirichlet_expectation(self, alpha):
"""
Expand Down