fkodom / semantle

Fastest 'Semantle' solver this side of the Mississippi.
MIT License
15 stars 1 forks source link

Solver.recommend() calls _get_words_closest_to_mean() with empty "words" tuple #1

Open xavierog opened 2 years ago

xavierog commented 2 years ago

Hello,

First, thanks for developing this tool, it is quite funny to see how fast it solves Semantle games :)

However, I stumble upon this behaviour:

$ .local/bin/solve-semantle
Semantle Solver!

Step 1
----------------
157244 solutions remaining
Recommended: object
Alternatives: [person, place, action, adjective]
----------------
Enter your guess: hello
What was the similarity? 4.04

Step 2
----------------
306 solutions remaining
Recommended: neuroanatomical
Alternatives: [mupirocin, lymphocytic, recombinants, amisulpride, bullae]
----------------
Enter your guess: neuroanatomical
What was the similarity? -0.68
~/.local/lib/python3.10/site-packages/semantle/solver.py:81: RuntimeWarning: Mean of empty slice.
  mean = vectors.mean(axis=0, keepdims=True)
~/.local/lib/python3.10/site-packages/numpy/core/_methods.py:181: RuntimeWarning: invalid value encountered in true_divide
  ret = um.true_divide(
Traceback (most recent call last):
  File "~/.local/bin/solve-semantle", line 8, in <module>
    sys.exit(main())
  File "~/.local/lib/python3.10/site-packages/semantle/solver.py", line 129, in main
    AssistiveSolver(uncertainty=args.uncertainty).solve()
  File "~/.local/lib/python3.10/site-packages/semantle/solver.py", line 118, in solve
    self.update(info)
  File "~/.local/lib/python3.10/site-packages/semantle/solver.py", line 52, in update
    return self.recommend().recommended
  File "~/.local/lib/python3.10/site-packages/semantle/solver.py", line 40, in recommend
    words = _get_words_closest_to_mean(words, max_words=max_alternatives + 1)
  File "~/.local/lib/python3.10/site-packages/semantle/solver.py", line 82, in _get_words_closest_to_mean
    dist = np.linalg.norm(vectors - mean, axis=1)
  File "<__array_function__ internals>", line 180, in norm
  File "~/.local/lib/python3.10/site-packages/numpy/linalg/linalg.py", line 2547, in norm
    return sqrt(add.reduce(s, axis=axis, keepdims=keepdims))
numpy.AxisError: axis 1 is out of bounds for array of dimension 1

Note: the secret word was "pace".

A brief print()-based debugging session reflects Solver.recommend() calls _get_words_closest_to_mean() with an empty "words" tuple. This seems to happen only when, at some point in the process, a negative similarity whose absolute value is greater than the uncertainty was submitted.