Package: wordleaisql
WORDLE AI with SQL BackendThis package provides anWorldlesolver with SQL backend.How to use# Install this library via PyPIpipinstallwordleaisql# Then run the executable that comes with the librarywordleai-sql# Alternatively, clone this repository and run without pip-installpythonwordleai-sql.pySolver session example$wordleai-sql

Hi,thisisWordleAI(SQLitebackend,approx).12947remainingcandidates:['cigar','rebut','sissy','humph','awake','blush','focal','evade','naval','serve','...']Type:'[s]uggest <criterion>'toletAIsuggestaword(<criterion>isoptional)'[u]pdate <word> <result>'toprovidenewinformation'[e]xit'tofinishthesession

where<criterion>iseither'max_n','mean_n',or'mean_entropy'<result>isastringof0(nomatch),1(partialmatch),and2(exactmatch)>s[INFO]StartAIevaluation(2022-03-0900:37:13)[INFO]EndAIevaluation(2022-03-0900:37:18,elapsed:0:00:04.153101)*Top20candidatesorderedbymean_entropy
--------------------------------------------------------------------input_wordmax_nmean_nmean_entropyis_candidate
--------------------------------------------------------------------reais3012.03.0941laers3313.53.2181aeons3514.23.3121races3214.43.3231leads3415.13.3491strae3314.83.3761lines4316.43.3861soral3515.63.4271cries4817.43.4291scrae3416.23.4711rules4217.23.4781oared4117.93.5111losen5217.93.5151sedan4017.63.5161sured5219.13.5461artis4519.43.5471least4218.73.5491stire4618.53.5521stria4919.33.5561nails5518.73.5571--------------------------------------------------------------------12947remainingcandidates:['cigar','rebut','sissy','humph','awake','blush','focal','evade','naval','serve','...']Type:'[s]uggest <criterion>'toletAIsuggestaword(<criterion>isoptional)'[u]pdate <word> <result>'toprovidenewinformation'[e]xit'tofinishthesession

where<criterion>iseither'max_n','mean_n',or'mean_entropy'<result>isastringof0(nomatch),1(partialmatch),and2(exactmatch)>uraces00000896remainingcandidates:['humph','outdo','digit','pound','booby','loopy','lying','moult','guild','thumb','...']Type:'[s]uggest <criterion>'toletAIsuggestaword(<criterion>isoptional)'[u]pdate <word> <result>'toprovidenewinformation'[e]xit'tofinishthesession

where<criterion>iseither'max_n','mean_n',or'mean_entropy'<result>isastringof0(nomatch),1(partialmatch),and2(exactmatch)>s[INFO]StartAIevaluation(2022-03-0900:37:35)[INFO]EndAIevaluation(2022-03-0900:37:39,elapsed:0:00:03.439437)*Top20candidatesorderedbymean_entropy
--------------------------------------------------------------------input_wordmax_nmean_nmean_entropyis_candidate
--------------------------------------------------------------------monty4116.83.4541gipon6620.53.5461lofty5320.03.6861bilgy7024.23.7461bundt6923.23.7791limbo6923.63.7801bundy6323.53.7821found5623.73.8161youth5022.63.8271joint6523.93.8951downy6125.53.9021milko7827.53.9241fungo8629.63.9261lumbi7729.13.9761tupik6828.03.9811goopy7628.34.0121jolty5924.34.0151muhly6528.14.0341nouny5925.04.0411touzy4925.04.0661--------------------------------------------------------------------896remainingcandidates:['humph','outdo','digit','pound','booby','loopy','lying','moult','guild','thumb','...']Type:'[s]uggest <criterion>'toletAIsuggestaword(<criterion>isoptional)'[u]pdate <word> <result>'toprovidenewinformation'[e]xit'tofinishthesession

where<criterion>iseither'max_n','mean_n',or'mean_entropy'<result>isastringof0(nomatch),1(partialmatch),and2(exactmatch)>umonty22220'month'shouldbetheanswer!
Thankyou!Suggestion criteriaInput words are evaludated by the three criteria as follows:"max_n": Maximum number of the candidate words that would remain."mean_n": Average number of the candidate words that would remain."mean_entropy": Average of the log2 of number of the candidate words that would remain.Note that if there arencandidate words with the equal probability, then probability of each wordiisp_i = 1/n.
Then, the entropy is given by-sum(p_i log2(p_i)) = - n * (1/n) log2(1/n) = log2(n).
Hence, the average oflog2(n)can be seen as the average entropy."mean_entropy" is often used in practice and thus set as the default choice of the program.
"max_n" can be seen as a pessimistic criterion since it reacts to the worst case.
"mean_n" can seem an intutive criterion but does not work as well as "mean_entropy" perhaps due to the skewed distribution.See also the simulation results for a comparison of the criteria (notebook atsimulation/simulation-summary.ipynbor view onnbviewer).Play and challenge modeBy default,wordleai-sqlcommand starts an interactive solver session.wordleai-sql --playstarts a self-play game.wordleai-sql --challengestarts a competition against an AI.In the play and challenge mode, the answer word is chosen in accordance with the answer weight by default. One can set--no_answer_weightoption to make all words potentially become an answer word.Using a custom word setThe default word list is atwordleaisql/vocab/wordle-vocab.txt. The list perhaps is compatible withNew York Times version.One may use a custom word list by specifying--vocabfile=<file path>option.A file should contain words of the same length, separated by the line break ("\n").Each line may contain a nonnegative numeric value separated by a space, which is used as the relative probability that this word is chosen as the answer (in play and challenge mode). If not supecified, the word is given the weight one.A file can be gzip compressed, where the filename must end with ".gz".Although not tested thoroughly, the program would work with words containing multibyte characters (with utf8 encoding) or digits.By default, the file name without extension is used as thevocabname. One may change this by--vocabname.Seevocab-examples/folder for some examples.# Examplewordleai-sql--vocabnamemyvocab--vocabfilemy-vocab.txtBackend optionsSQLite with approximate evaluation (default)wordleai-sql-bapproxWith-b approxoption, we employ approximate evaluation of words by sampling input and/or answer words.The database setup completes quikckly since this does not require precompuation of the judge results.Evaluation also completes quickly since small numbers of input and/or answer words are involved in the calculation.Although approximate, the engine tends to provide close-to-optimal suggestions thanks to the law of large numbers.SQLite with full evaluationwordleai-sql-bsqliteThis engine evaluates all words using the all answer candidates.To enhance the calculation the engine precomputes all judge results for all word pairs on the setup.The file size becomes about 8.4GB.The process may take about an hour, depending on the CPU speed.The time for the setup will be significantly reduced if c++ compiler command (e.gg++orclang++) is available.Google bigquery backend# --vocabname is used as the dataset namewordleai-sql-bbq--bq_credential"gcp_credentials.json"--vocabname"wordle_dataset"With-bbqoption, we employ google bigquery as the backend SQL engine.We need to supply a credential json file of the GCP service account with the following permissions:bigquery.datasets.create
bigquery.datasets.get
bigquery.jobs.create
bigquery.jobs.get
bigquery.routines.create
bigquery.routines.delete
bigquery.routines.get
bigquery.routines.update
bigquery.tables.create
bigquery.tables.delete
bigquery.tables.get
bigquery.tables.getData
bigquery.tables.list
bigquery.tables.update
bigquery.tables.updateDataOther optionsSeewordleai-sql -hfor other options, which should mostly be self-explanatory.GUI applicationA browser application built onstreamlitis atstreamlit/app.py. This can be run with the following command:# install dependencies if notpipinstallpandasstreamlit
streamlitrun./streamlit/app.pyThe app is also deployed on thestreamlit cloud.