Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2: Python and dependencies upgrade, use new codenames interface #9

Merged
merged 6 commits into from
Nov 12, 2024
Merged
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
6 changes: 3 additions & 3 deletions .github/actions/lint-install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ description: "A reusable action to install linting tools"
runs:
using: "composite"
steps:
- name: Set up python 3.10
uses: actions/setup-python@v4
- name: Set up python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.12"
- name: Install dependencies
shell: bash
run: |
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ jobs:
- name: Checkout repo
uses: actions/checkout@v4
- uses: ./.github/actions/lint-install
- name: Install requests
run: |
pip install requests==2.30.0
- name: Install dependencies
run: |
make install-dev SYNC=""
Expand All @@ -67,11 +70,11 @@ jobs:
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up python 3.10
uses: actions/setup-python@v4
- name: Set up python 3.12
uses: actions/setup-python@v5
with:
cache: "pip"
python-version: "3.10"
python-version: "3.12"
- name: Install dependencies
run: |
make install-ci
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/video.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up python 3.10
uses: actions/setup-python@v4
- name: Set up python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.12"
- name: Install video dependencies
run: |
make install-ci
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ upgrade-pip:
pip install --upgrade pip

install-ci: upgrade-pip
pip install poetry==1.7.1
pip install poetry==1.8.3
poetry config virtualenvs.create false

install-test:
Expand Down Expand Up @@ -111,12 +111,12 @@ gource-all:
# Lint

format:
ruff . --fix
ruff check --fix
black .
isort .

check-ruff:
ruff .
ruff check

check-black:
black --check .
Expand All @@ -128,7 +128,7 @@ check-mypy:
mypy .

check-pylint:
pylint solvers/ --fail-under=10
pylint solvers/ --fail-under=8.8

lint: format
pre-commit run --all-files
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Given the board:
+-------------+------------+----------+--------------+----------------+
```

A `NaiveHinter` playing for the blue team will output `"role", 4`. \
A `NaiveSpymaster` playing for the blue team will output `"role", 4`. \
From the logs:

```
Expand All @@ -54,7 +54,7 @@ Best 5 proposals:
('drama', 'musical', 'series') = ('comic', 8.04)
('drama', 'commitment', 'teaching') = ('focuses', 7.88)
('musical', 'commitment', 'teaching') = ('educational', 7.87)
Hinter: [role] 4 card(s)
Spymaster: [role] 4 card(s)
```

Some extra data from the solver about the picked hint:
Expand Down Expand Up @@ -93,7 +93,7 @@ Find usage examples in the `playground` directory.

Based on [Google's word2vec](https://code.google.com/archive/p/word2vec/) embedding.

*Hint generation*:
*Clue generation*:

1. For each card subset `group` of size `{4, 3, 2, 1}` from my unrevealed cards, collect hint proposal:
1. Find the mean of `group`'s word embeddings.
Expand Down
2 changes: 1 addition & 1 deletion etc/visualizer/make_lynx_graph.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# %% Taken from sna_hinter
# %% Taken from sna_spymaster
from typing import Dict

import community
Expand Down
68 changes: 34 additions & 34 deletions playground/asaf.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import logging\n",
Expand All @@ -16,19 +19,19 @@
"configure_logging()\n",
"\n",
"log = logging.getLogger(__name__)"
],
"metadata": {
"collapsed": false
}
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from solvers.models import ModelIdentifier, HEBREW_SUFFIX_ADAPTER, load_model_async, DEFAULT_MODEL_ADAPTER\n",
"from codenames.game import GameRunner\n",
"from solvers.naive import NaiveHinter, NaiveGuesser\n",
"from solvers.naive import NaiveSpymaster, NaiveOperative\n",
"\n",
"model_id = ModelIdentifier(language=\"english\", model_name=\"wiki-50\", is_stemmed=False)\n",
"# model_id = ModelIdentifier(\"english\", \"google-300\", False)\n",
Expand All @@ -43,35 +46,35 @@
"adapter = HEBREW_SUFFIX_ADAPTER if model_id.language == \"hebrew\" and model_id.is_stemmed else DEFAULT_MODEL_ADAPTER\n",
"load_model_async(model_id)\n",
"\n",
"blue_hinter = NaiveHinter(\"Leonardo\", model_identifier=model_id, model_adapter=adapter)\n",
"blue_guesser = NaiveGuesser(\"Bard\", model_identifier=model_id, model_adapter=adapter)\n",
"red_hinter = NaiveHinter(\"Adam\", model_identifier=model_id, model_adapter=adapter)\n",
"red_guesser = NaiveGuesser(\"Eve\", model_identifier=model_id, model_adapter=adapter)\n",
"blue_hinter = NaiveSpymaster(\"Leonardo\", model_identifier=model_id, model_adapter=adapter)\n",
"blue_guesser = NaiveOperative(\"Bard\", model_identifier=model_id, model_adapter=adapter)\n",
"red_hinter = NaiveSpymaster(\"Adam\", model_identifier=model_id, model_adapter=adapter)\n",
"red_guesser = NaiveOperative(\"Eve\", model_identifier=model_id, model_adapter=adapter)\n",
"\n",
"game_runner = GameRunner(blue_hinter, red_hinter, blue_guesser, red_guesser)"
],
"metadata": {
"collapsed": false
}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"r = game_runner.run_game()"
],
"metadata": {
"collapsed": false
}
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": "Winner(team_color=<TeamColor.RED: 'Red'>, reason=<WinningReason.TARGET_SCORE_REACHED: 'Target score reached'>)"
"text/plain": "Winner(team=<ClassicTeam.RED: 'Red'>, reason=<WinningReason.TARGET_SCORE_REACHED: 'Target score reached'>)"
},
"execution_count": 22,
"metadata": {},
Expand All @@ -81,14 +84,14 @@
"source": [
"# game_runner.run_game(language=\"english\", board=english_board)\n",
"result = game_runner.run_game(language=\"hebrew\", board=HEBREW_BOARD_1)"
],
"metadata": {
"collapsed": false
}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from codenames.online import NamecodingGameRunner, NamecodingLanguage\n",
Expand All @@ -107,14 +110,14 @@
" log.info(f\"Winner: {online_runner.winner}\")\n",
" online_runner.close()\n",
"log.info(\"Done\")"
],
"metadata": {
"collapsed": false
}
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
Expand Down Expand Up @@ -142,22 +145,19 @@
" # log.info(\"Checking %s\", word)\n",
" try:\n",
" x = model[adapter.to_model_format(word)]\n",
" except Exception as e:\n",
" except Exception:\n",
" errors.append(word)\n",
"print(\"Done with %d errors\" % len(errors))"
],
"metadata": {
"collapsed": false
}
]
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [],
"metadata": {
"collapsed": false
}
},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading
Loading