Skip to content
Snippets Groups Projects
Commit a0854094 authored by Caron Olivier's avatar Caron Olivier
Browse files

limit solution size to 6

parent 964c2400
No related branches found
No related tags found
No related merge requests found
......@@ -48,7 +48,7 @@ class HillClimbing:
score = self.evaluate(self.current_sol, self.target_word)
for neighbor in self.model.neighbor_solutions(self.current_sol, self.vocab, self.target_word):
next_score = self.evaluate(neighbor, self.target_word)
if next_score - score > 0.05:
if next_score - score > 0.01:
score = next_score
self.set_current_solution(neighbor)
return score
......
......@@ -121,7 +121,8 @@ class WordEmbedding:
replaced.negative.append(v)
neighbors.append(replaced)
# part 3 : add a word
# part 3 : add a word if size of solution < 6
if solution.size() < 6:
for word in vocab:
if word not in (solution.positive + solution.negative) and word != eval_word:
s_copy = copy.deepcopy(solution)
......
......@@ -29,7 +29,11 @@ class Solution:
"""
:return: true if the solution contains no word, false otherwise
"""
return len(self.positive) == 0 and len(self.negative) == 0
return self.size() == 0
def size(self):
""" provides the number of words in the solution """
return len(self.positive) + len(self.negative)
def word_vector(self, map_word_vector, vector_size):
""" computes the corresponding word vector of the solution
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment