Skip to content

Commit

Permalink
fix W504
Browse files Browse the repository at this point in the history
  • Loading branch information
horpto committed Nov 11, 2018
1 parent da0db8c commit 1968219
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 44 deletions.
6 changes: 3 additions & 3 deletions gensim/models/coherencemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,9 @@ def _relevant_ids_will_differ(self, new_topics):
return not self._accumulator.relevant_ids.issuperset(new_set)

def _topics_differ(self, new_topics):
return (new_topics is not None and
self._topics is not None and
not np.array_equal(new_topics, self._topics))
return (new_topics is not None
and self._topics is not None
and not np.array_equal(new_topics, self._topics))

def _get_topics(self):
"""Internal helper function to return topics from a trained topic model."""
Expand Down
8 changes: 4 additions & 4 deletions gensim/models/deprecated/doc2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ def train_document_dm(model, doc_words, doctag_indexes, alpha, work=None, neu1=N
if doctag_locks is None:
doctag_locks = model.docvecs.doctag_syn0_lockf

word_vocabs = [model.wv.vocab[w] for w in doc_words if w in model.wv.vocab and
model.wv.vocab[w].sample_int > model.random.rand() * 2**32]
word_vocabs = [model.wv.vocab[w] for w in doc_words if w in model.wv.vocab
and model.wv.vocab[w].sample_int > model.random.rand() * 2**32]

for pos, word in enumerate(word_vocabs):
reduced_window = model.random.randint(model.window) # `b` in the original doc2vec code
Expand Down Expand Up @@ -298,8 +298,8 @@ def train_document_dm_concat(model, doc_words, doctag_indexes, alpha, work=None,
if doctag_locks is None:
doctag_locks = model.docvecs.doctag_syn0_lockf

word_vocabs = [model.wv.vocab[w] for w in doc_words if w in model.wv.vocab and
model.wv.vocab[w].sample_int > model.random.rand() * 2**32]
word_vocabs = [model.wv.vocab[w] for w in doc_words if w in model.wv.vocab
and model.wv.vocab[w].sample_int > model.random.rand() * 2**32]
doctag_len = len(doctag_indexes)
if doctag_len != model.dm_tag_count:
return 0 # skip doc without expected number of doctag(s) (TODO: warn/pad?)
Expand Down
8 changes: 4 additions & 4 deletions gensim/models/deprecated/fasttext.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ def train_batch_cbow(model, sentences, alpha, work=None, neu1=None):
"""
result = 0
for sentence in sentences:
word_vocabs = [model.wv.vocab[w] for w in sentence if w in model.wv.vocab and
model.wv.vocab[w].sample_int > model.random.rand() * 2**32]
word_vocabs = [model.wv.vocab[w] for w in sentence if w in model.wv.vocab
and model.wv.vocab[w].sample_int > model.random.rand() * 2**32]
for pos, word in enumerate(word_vocabs):
reduced_window = model.random.randint(model.window)
start = max(0, pos - model.window + reduced_window)
Expand Down Expand Up @@ -211,8 +211,8 @@ def train_batch_sg(model, sentences, alpha, work=None, neu1=None):
"""
result = 0
for sentence in sentences:
word_vocabs = [model.wv.vocab[w] for w in sentence if w in model.wv.vocab and
model.wv.vocab[w].sample_int > model.random.rand() * 2**32]
word_vocabs = [model.wv.vocab[w] for w in sentence if w in model.wv.vocab
and model.wv.vocab[w].sample_int > model.random.rand() * 2**32]
for pos, word in enumerate(word_vocabs):
reduced_window = model.random.randint(model.window) # `b` in the original word2vec code
# now go over all words from the (reduced) window, predicting each one in turn
Expand Down
4 changes: 2 additions & 2 deletions gensim/models/deprecated/old_saveload.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ def _load_specials(self, fname, mmap, compress, subname):
"""
def mmap_error(obj, filename):
return IOError(
'Cannot mmap compressed object %s in file %s. ' % (obj, filename) +
'Use `load(fname, mmap=None)` or uncompress files manually.'
'Cannot mmap compressed object %s in file %s. ' % (obj, filename)
+ 'Use `load(fname, mmap=None)` or uncompress files manually.'
)

for attrib in getattr(self, '__recursive_saveloads', []):
Expand Down
8 changes: 4 additions & 4 deletions gensim/models/deprecated/word2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ def train_batch_sg(model, sentences, alpha, work=None, compute_loss=False):
"""
result = 0
for sentence in sentences:
word_vocabs = [model.wv.vocab[w] for w in sentence if w in model.wv.vocab and
model.wv.vocab[w].sample_int > model.random.rand() * 2**32]
word_vocabs = [model.wv.vocab[w] for w in sentence if w in model.wv.vocab
and model.wv.vocab[w].sample_int > model.random.rand() * 2**32]
for pos, word in enumerate(word_vocabs):
reduced_window = model.random.randint(model.window) # `b` in the original word2vec code

Expand Down Expand Up @@ -263,8 +263,8 @@ def train_batch_cbow(model, sentences, alpha, work=None, neu1=None, compute_loss
"""
result = 0
for sentence in sentences:
word_vocabs = [model.wv.vocab[w] for w in sentence if w in model.wv.vocab and
model.wv.vocab[w].sample_int > model.random.rand() * 2**32]
word_vocabs = [model.wv.vocab[w] for w in sentence if w in model.wv.vocab
and model.wv.vocab[w].sample_int > model.random.rand() * 2**32]
for pos, word in enumerate(word_vocabs):
reduced_window = model.random.randint(model.window) # `b` in the original word2vec code
start = max(0, pos - model.window + reduced_window)
Expand Down
8 changes: 4 additions & 4 deletions gensim/models/doc2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ def train_document_dm(model, doc_words, doctag_indexes, alpha, work=None, neu1=N
if doctag_locks is None:
doctag_locks = model.docvecs.doctag_syn0_lockf

word_vocabs = [model.wv.vocab[w] for w in doc_words if w in model.wv.vocab and
model.wv.vocab[w].sample_int > model.random.rand() * 2 ** 32]
word_vocabs = [model.wv.vocab[w] for w in doc_words if w in model.wv.vocab
and model.wv.vocab[w].sample_int > model.random.rand() * 2 ** 32]

for pos, word in enumerate(word_vocabs):
reduced_window = model.random.randint(model.window) # `b` in the original doc2vec code
Expand Down Expand Up @@ -314,8 +314,8 @@ def train_document_dm_concat(model, doc_words, doctag_indexes, alpha, work=None,
if doctag_locks is None:
doctag_locks = model.docvecs.doctag_syn0_lockf

word_vocabs = [model.wv.vocab[w] for w in doc_words if w in model.wv.vocab and
model.wv.vocab[w].sample_int > model.random.rand() * 2 ** 32]
word_vocabs = [model.wv.vocab[w] for w in doc_words if w in model.wv.vocab
and model.wv.vocab[w].sample_int > model.random.rand() * 2 ** 32]
doctag_len = len(doctag_indexes)
if doctag_len != model.dm_tag_count:
return 0 # skip doc without expected number of doctag(s) (TODO: warn/pad?)
Expand Down
8 changes: 4 additions & 4 deletions gensim/models/fasttext.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ def train_batch_cbow(model, sentences, alpha, work=None, neu1=None):
"""
result = 0
for sentence in sentences:
word_vocabs = [model.wv.vocab[w] for w in sentence if w in model.wv.vocab and
model.wv.vocab[w].sample_int > model.random.rand() * 2 ** 32]
word_vocabs = [model.wv.vocab[w] for w in sentence if w in model.wv.vocab
and model.wv.vocab[w].sample_int > model.random.rand() * 2 ** 32]
for pos, word in enumerate(word_vocabs):
reduced_window = model.random.randint(model.window)
start = max(0, pos - model.window + reduced_window)
Expand Down Expand Up @@ -199,8 +199,8 @@ def train_batch_sg(model, sentences, alpha, work=None, neu1=None):
"""
result = 0
for sentence in sentences:
word_vocabs = [model.wv.vocab[w] for w in sentence if w in model.wv.vocab and
model.wv.vocab[w].sample_int > model.random.rand() * 2 ** 32]
word_vocabs = [model.wv.vocab[w] for w in sentence if w in model.wv.vocab
and model.wv.vocab[w].sample_int > model.random.rand() * 2 ** 32]
for pos, word in enumerate(word_vocabs):
reduced_window = model.random.randint(model.window) # `b` in the original word2vec code
# now go over all words from the (reduced) window, predicting each one in turn
Expand Down
6 changes: 3 additions & 3 deletions gensim/models/hdpmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,13 +510,13 @@ def update_finished(self, start_time, chunks_processed, docs_processed):
"""
return (
# chunk limit reached
(self.max_chunks and chunks_processed == self.max_chunks) or
(self.max_chunks and chunks_processed == self.max_chunks)

# time limit reached
(self.max_time and time.clock() - start_time > self.max_time) or
or (self.max_time and time.clock() - start_time > self.max_time)

# no limits and whole corpus has been processed once
(not self.max_chunks and not self.max_time and docs_processed >= self.m_D))
or (not self.max_chunks and not self.max_time and docs_processed >= self.m_D))

def update_chunk(self, chunk, update=True, opt_o=True):
"""Performs lazy update on necessary columns of lambda and variational inference for documents in the chunk.
Expand Down
6 changes: 3 additions & 3 deletions gensim/models/ldamulticore.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ def process_result_queue(force=False):
if (force and merged_new and queue_size[0] == 0) or (not self.batch and (other.numdocs >= updateafter)):
self.do_mstep(rho(), other, pass_ > 0)
other.reset()
if self.eval_every is not None and \
((force and queue_size[0] == 0) or
(self.eval_every != 0 and (self.num_updates / updateafter) % self.eval_every == 0)):
if self.eval_every is not None \
and ((force and queue_size[0] == 0)
or (self.eval_every != 0 and (self.num_updates / updateafter) % self.eval_every == 0)):
self.log_perplexity(chunk, total_docs=lencorpus)

chunk_stream = utils.grouper(corpus, self.chunksize, as_numpy=chunks_as_numpy)
Expand Down
8 changes: 4 additions & 4 deletions gensim/models/word2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ def train_batch_sg(model, sentences, alpha, work=None, compute_loss=False):
"""
result = 0
for sentence in sentences:
word_vocabs = [model.wv.vocab[w] for w in sentence if w in model.wv.vocab and
model.wv.vocab[w].sample_int > model.random.rand() * 2 ** 32]
word_vocabs = [model.wv.vocab[w] for w in sentence if w in model.wv.vocab
and model.wv.vocab[w].sample_int > model.random.rand() * 2 ** 32]
for pos, word in enumerate(word_vocabs):
reduced_window = model.random.randint(model.window) # `b` in the original word2vec code

Expand Down Expand Up @@ -245,8 +245,8 @@ def train_batch_cbow(model, sentences, alpha, work=None, neu1=None, compute_loss
result = 0
for sentence in sentences:
word_vocabs = [
model.wv.vocab[w] for w in sentence if w in model.wv.vocab and
model.wv.vocab[w].sample_int > model.random.rand() * 2 ** 32
model.wv.vocab[w] for w in sentence if w in model.wv.vocab
and model.wv.vocab[w].sample_int > model.random.rand() * 2 ** 32
]
for pos, word in enumerate(word_vocabs):
reduced_window = model.random.randint(model.window) # `b` in the original word2vec code
Expand Down
6 changes: 3 additions & 3 deletions gensim/summarization/mz_entropy.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ def marginal_prob(n, m):
occurring m times in a given block"""

return numpy.exp(
__log_combinations(n, m) +
__log_combinations(n_words - n, blocksize - m) -
__log_combinations(n_words, blocksize)
__log_combinations(n, m)
+ __log_combinations(n_words - n, blocksize - m)
- __log_combinations(n_words, blocksize)
)

return numpy.frompyfunc(marginal_prob, 2, 1)
Expand Down
4 changes: 2 additions & 2 deletions gensim/test/test_doc2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ def test_similarity_unseen_docs(self):
model = doc2vec.Doc2Vec(min_count=1)
model.build_vocab(corpus)
self.assertTrue(
model.docvecs.similarity_unseen_docs(model, rome_str, rome_str) >
model.docvecs.similarity_unseen_docs(model, rome_str, car_str)
model.docvecs.similarity_unseen_docs(model, rome_str, rome_str)
> model.docvecs.similarity_unseen_docs(model, rome_str, car_str)
)

def model_sanity(self, model, keep_training=True):
Expand Down
3 changes: 1 addition & 2 deletions gensim/test/test_keyedvectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ def test_similarity_matrix(self):
similarity_matrix = self.vectors.similarity_matrix(dictionary).todense()
self.assertTrue((similarity_matrix.T == similarity_matrix).all())
self.assertTrue(
(np.diag(similarity_matrix) ==
np.ones(similarity_matrix.shape[0])).all())
(np.diag(similarity_matrix) == np.ones(similarity_matrix.shape[0])).all())

# checking that thresholding works as expected
similarity_matrix = self.vectors.similarity_matrix(dictionary, threshold=0.45).todense()
Expand Down
4 changes: 2 additions & 2 deletions gensim/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ def _load_specials(self, fname, mmap, compress, subname):
"""
def mmap_error(obj, filename):
return IOError(
'Cannot mmap compressed object %s in file %s. ' % (obj, filename) +
'Use `load(fname, mmap=None)` or uncompress files manually.'
'Cannot mmap compressed object %s in file %s. ' % (obj, filename)
+ 'Use `load(fname, mmap=None)` or uncompress files manually.'
)

for attrib in getattr(self, '__recursive_saveloads', []):
Expand Down

0 comments on commit 1968219

Please sign in to comment.