Spaces:
Sleeping
Sleeping
Javierss
commited on
Commit
·
1f86619
1
Parent(s):
38c926b
Add strans models and adaptations for conditions
Browse files- .gitattributes +3 -0
- __pycache__/app.cpython-311.pyc +0 -0
- __pycache__/game.cpython-311.pyc +0 -0
- __pycache__/hints.cpython-311.pyc +0 -0
- __pycache__/tracking.cpython-311.pyc +0 -0
- app.py +42 -89
- config/condition.json +19 -0
- config/lang.json +2 -6
- config/secret.json +1 -8
- config/{w2v_models/esp_w2v_model → strans_models/esp_strans_model} +2 -2
- config/{w2v_models/eng_w2v_model → strans_models/esp_strans_model.vectors.npy} +2 -2
- config/w2v_models/eng_w2v_model.vectors.npy +0 -3
- config/w2v_models/esp_w2v_model.vectors.npy +0 -3
- game.py +28 -36
.gitattributes
CHANGED
@@ -40,3 +40,6 @@ config/words.txt filter=lfs diff=lfs merge=lfs -text
|
|
40 |
config/words.gz filter=lfs diff=lfs merge=lfs -text
|
41 |
config/w2v_models/words.gz filter=lfs diff=lfs merge=lfs -text
|
42 |
config/possible_words.json filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
40 |
config/words.gz filter=lfs diff=lfs merge=lfs -text
|
41 |
config/w2v_models/words.gz filter=lfs diff=lfs merge=lfs -text
|
42 |
config/possible_words.json filter=lfs diff=lfs merge=lfs -text
|
43 |
+
config/strans_models/. filter=lfs diff=lfs merge=lfs -text
|
44 |
+
config/strans_models/esp_strans_model filter=lfs diff=lfs merge=lfs -text
|
45 |
+
config/strans_models/esp_strans_model.vectors.npy filter=lfs diff=lfs merge=lfs -text
|
__pycache__/app.cpython-311.pyc
CHANGED
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
|
|
__pycache__/game.cpython-311.pyc
CHANGED
Binary files a/__pycache__/game.cpython-311.pyc and b/__pycache__/game.cpython-311.pyc differ
|
|
__pycache__/hints.cpython-311.pyc
CHANGED
Binary files a/__pycache__/hints.cpython-311.pyc and b/__pycache__/hints.cpython-311.pyc differ
|
|
__pycache__/tracking.cpython-311.pyc
CHANGED
Binary files a/__pycache__/tracking.cpython-311.pyc and b/__pycache__/tracking.cpython-311.pyc differ
|
|
app.py
CHANGED
@@ -65,6 +65,17 @@ from game import Semantrix
|
|
65 |
config_file_path = "config/lang.json"
|
66 |
logo_path = "config/images/logo.png"
|
67 |
logo_win_path = "config/images/logo_win.gif"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
# Loading the configuration file
|
70 |
with open(config_file_path, "r") as file:
|
@@ -132,7 +143,7 @@ with gr.Blocks() as demo:
|
|
132 |
hint = gr.State(False) # State variable to track if the hint is provided
|
133 |
|
134 |
# Initializing the game using the Semantrix class with default parameters
|
135 |
-
game = Semantrix(lang=0, model_type=
|
136 |
|
137 |
# Creating a Markdown component to display the header
|
138 |
header = gr.Markdown(
|
@@ -144,30 +155,30 @@ with gr.Blocks() as demo:
|
|
144 |
)
|
145 |
|
146 |
# Function to reset the game
|
147 |
-
def reset(difficulty
|
148 |
-
global Config, game, Menu # Declare global variables to modify them within the function
|
149 |
|
150 |
# Determine the language based on the input parameter
|
151 |
-
language =
|
152 |
-
|
153 |
-
# Initialize the game object based on the selected model
|
154 |
-
if model == "Word2Vec":
|
155 |
-
|
156 |
-
else:
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
# Set the configuration and menu based on the selected language
|
162 |
-
if language == 1:
|
163 |
-
|
164 |
-
|
165 |
-
else:
|
166 |
-
|
167 |
-
|
168 |
|
169 |
# Prepare the game with the selected difficulty level
|
170 |
-
game.prepare_game(
|
171 |
|
172 |
# Define the initial output components for the UI
|
173 |
output = [
|
@@ -201,10 +212,10 @@ with gr.Blocks() as demo:
|
|
201 |
|
202 |
# Function to update the game state based on the current state of the game
|
203 |
def update(state, radio, inp, hint):
|
204 |
-
global difficulty
|
205 |
|
206 |
# Define the difficulty state
|
207 |
-
dif_state =
|
208 |
|
209 |
# Initialize the output component list with the current state
|
210 |
output = [state]
|
@@ -234,7 +245,9 @@ with gr.Blocks() as demo:
|
|
234 |
output.extend(
|
235 |
[
|
236 |
gr.Button(visible=False),
|
237 |
-
gr.Radio(
|
|
|
|
|
238 |
gr.Textbox(
|
239 |
Config[list(Config.keys())[state_int]], visible=True, label=""
|
240 |
),
|
@@ -286,36 +299,6 @@ with gr.Blocks() as demo:
|
|
286 |
|
287 |
# Define UI components for the difficulty state, ask the user to select the difficulty level
|
288 |
elif state_int == dif_state:
|
289 |
-
output.extend(
|
290 |
-
[
|
291 |
-
gr.Button(Menu["Next"], visible=False),
|
292 |
-
gr.Radio(
|
293 |
-
[Menu["Easy"], Menu["Normal"], Menu["Hard"], Menu["Expert"]],
|
294 |
-
visible=True,
|
295 |
-
),
|
296 |
-
gr.Textbox(
|
297 |
-
Config[list(Config.keys())[state_int]], visible=True, label=""
|
298 |
-
),
|
299 |
-
gr.Button(Menu["Give_up"], visible=False),
|
300 |
-
gr.Textbox(visible=False),
|
301 |
-
gr.Image(interactive=False, visible=False),
|
302 |
-
gr.Textbox(visible=False),
|
303 |
-
gr.Button(visible=False),
|
304 |
-
gr.Markdown(visible=False),
|
305 |
-
]
|
306 |
-
)
|
307 |
-
|
308 |
-
# Define UI components for the difficulty state + 1, prepare the game based on the selected difficulty level, and start the game
|
309 |
-
elif state_int == dif_state + 1:
|
310 |
-
if radio == Menu["Easy"]:
|
311 |
-
difficulty = 1
|
312 |
-
elif radio == Menu["Normal"]:
|
313 |
-
difficulty = 2
|
314 |
-
elif radio == Menu["Hard"]:
|
315 |
-
difficulty = 3
|
316 |
-
else:
|
317 |
-
difficulty = 4
|
318 |
-
|
319 |
output.extend(
|
320 |
[
|
321 |
gr.Button(Menu["Start"], visible=True, variant="primary"),
|
@@ -333,9 +316,9 @@ with gr.Blocks() as demo:
|
|
333 |
)
|
334 |
|
335 |
# Define UI components for the difficulty state + 2, play the game based on the selected difficulty level and prepare the game for the word guessing
|
336 |
-
elif state_int == dif_state +
|
337 |
|
338 |
-
game.prepare_game(
|
339 |
|
340 |
output.extend(
|
341 |
[
|
@@ -357,7 +340,7 @@ with gr.Blocks() as demo:
|
|
357 |
)
|
358 |
|
359 |
# Define UI components for the state greater than the difficulty state + 2, play the game and provide feedback based on the user input
|
360 |
-
elif state_int > dif_state +
|
361 |
|
362 |
# Send the user input to the game and get the feedback from the game
|
363 |
feed = game.play_game(inp)
|
@@ -470,26 +453,6 @@ with gr.Blocks() as demo:
|
|
470 |
give_up = gr.Button("Pista", visible=False)
|
471 |
reload = gr.Button(Menu["Play_again"], visible=False)
|
472 |
|
473 |
-
# Define the settings components for the game
|
474 |
-
with gr.Accordion("Configuración/Settings", open=False):
|
475 |
-
with gr.Row():
|
476 |
-
|
477 |
-
# Dropdown to select the model engine for the game
|
478 |
-
model = (
|
479 |
-
gr.Dropdown(
|
480 |
-
["Sentence Transformers", "Word2Vec"],
|
481 |
-
value="Sentence Transformers",
|
482 |
-
label="Embedding Model",
|
483 |
-
),
|
484 |
-
)
|
485 |
-
|
486 |
-
# Dropdown to select the language for the game
|
487 |
-
lang = (
|
488 |
-
gr.Dropdown(
|
489 |
-
["Español", "English"], value="Español", label="Idioma/Language"
|
490 |
-
),
|
491 |
-
)
|
492 |
-
|
493 |
# Define the UI events for the game
|
494 |
|
495 |
# Define events that trigger the game state change
|
@@ -508,22 +471,12 @@ with gr.Blocks() as demo:
|
|
508 |
# Define events that trigger the game reset
|
509 |
reload.click(
|
510 |
reset,
|
511 |
-
inputs=[difficulty
|
512 |
outputs=[state, out, inp, img, but, radio, hint_out, reload, header],
|
513 |
)
|
514 |
demo.load(
|
515 |
reset,
|
516 |
-
inputs=[difficulty
|
517 |
-
outputs=[state, out, inp, img, but, radio, hint_out, reload, header],
|
518 |
-
)
|
519 |
-
lang[0].select(
|
520 |
-
reset,
|
521 |
-
inputs=[difficulty, lang[0], model[0]],
|
522 |
-
outputs=[state, out, inp, img, but, radio, hint_out, reload, header],
|
523 |
-
)
|
524 |
-
model[0].select(
|
525 |
-
reset,
|
526 |
-
inputs=[difficulty, lang[0], model[0]],
|
527 |
outputs=[state, out, inp, img, but, radio, hint_out, reload, header],
|
528 |
)
|
529 |
|
|
|
65 |
config_file_path = "config/lang.json"
|
66 |
logo_path = "config/images/logo.png"
|
67 |
logo_win_path = "config/images/logo_win.gif"
|
68 |
+
condition_config_path = "config/condition.json"
|
69 |
+
|
70 |
+
condition_name = "condition_1"
|
71 |
+
|
72 |
+
lang = "Español" # Default language
|
73 |
+
|
74 |
+
with open(condition_config_path, "r") as file:
|
75 |
+
condition_config = json.load(file)
|
76 |
+
|
77 |
+
model = condition_config[condition_name]["model"]
|
78 |
+
hints_enabled = condition_config[condition_name]["hints"]
|
79 |
|
80 |
# Loading the configuration file
|
81 |
with open(config_file_path, "r") as file:
|
|
|
143 |
hint = gr.State(False) # State variable to track if the hint is provided
|
144 |
|
145 |
# Initializing the game using the Semantrix class with default parameters
|
146 |
+
game = Semantrix(lang=0, model_type=model)
|
147 |
|
148 |
# Creating a Markdown component to display the header
|
149 |
header = gr.Markdown(
|
|
|
155 |
)
|
156 |
|
157 |
# Function to reset the game
|
158 |
+
def reset(difficulty):
|
159 |
+
global Config, game, Menu, model, lang # Declare global variables to modify them within the function
|
160 |
|
161 |
# Determine the language based on the input parameter
|
162 |
+
# language = 2 if lang == "English" else 0
|
163 |
+
|
164 |
+
# # # Initialize the game object based on the selected model
|
165 |
+
# # if model == "Word2Vec":
|
166 |
+
# # game = Semantrix(language, "word2vec") # Use Word2Vec model
|
167 |
+
# # else:
|
168 |
+
# # game = Semantrix(
|
169 |
+
# # language, "SentenceTransformer"
|
170 |
+
# # ) # Use Sentence Transformers model
|
171 |
+
|
172 |
+
# # Set the configuration and menu based on the selected language
|
173 |
+
# if language == 1:
|
174 |
+
# Config = Config_full["ENG"]["Game"]
|
175 |
+
# Menu = Config_full["ENG"]["Menu"]
|
176 |
+
# else:
|
177 |
+
# Config = Config_full["SPA"]["Game"]
|
178 |
+
# Menu = Config_full["SPA"]["Menu"]
|
179 |
|
180 |
# Prepare the game with the selected difficulty level
|
181 |
+
# game.prepare_game(1 if hints_enabled else 4)
|
182 |
|
183 |
# Define the initial output components for the UI
|
184 |
output = [
|
|
|
212 |
|
213 |
# Function to update the game state based on the current state of the game
|
214 |
def update(state, radio, inp, hint):
|
215 |
+
global difficulty, hints_enabled
|
216 |
|
217 |
# Define the difficulty state
|
218 |
+
dif_state = 3
|
219 |
|
220 |
# Initialize the output component list with the current state
|
221 |
output = [state]
|
|
|
245 |
output.extend(
|
246 |
[
|
247 |
gr.Button(visible=False),
|
248 |
+
gr.Radio(
|
249 |
+
[Menu["Yes"], Menu["No"]], value=None, label="", visible=True
|
250 |
+
),
|
251 |
gr.Textbox(
|
252 |
Config[list(Config.keys())[state_int]], visible=True, label=""
|
253 |
),
|
|
|
299 |
|
300 |
# Define UI components for the difficulty state, ask the user to select the difficulty level
|
301 |
elif state_int == dif_state:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
302 |
output.extend(
|
303 |
[
|
304 |
gr.Button(Menu["Start"], visible=True, variant="primary"),
|
|
|
316 |
)
|
317 |
|
318 |
# Define UI components for the difficulty state + 2, play the game based on the selected difficulty level and prepare the game for the word guessing
|
319 |
+
elif state_int == dif_state + 1:
|
320 |
|
321 |
+
game.prepare_game(2 if hints_enabled else 4)
|
322 |
|
323 |
output.extend(
|
324 |
[
|
|
|
340 |
)
|
341 |
|
342 |
# Define UI components for the state greater than the difficulty state + 2, play the game and provide feedback based on the user input
|
343 |
+
elif state_int > dif_state + 1:
|
344 |
|
345 |
# Send the user input to the game and get the feedback from the game
|
346 |
feed = game.play_game(inp)
|
|
|
453 |
give_up = gr.Button("Pista", visible=False)
|
454 |
reload = gr.Button(Menu["Play_again"], visible=False)
|
455 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
456 |
# Define the UI events for the game
|
457 |
|
458 |
# Define events that trigger the game state change
|
|
|
471 |
# Define events that trigger the game reset
|
472 |
reload.click(
|
473 |
reset,
|
474 |
+
inputs=[difficulty],
|
475 |
outputs=[state, out, inp, img, but, radio, hint_out, reload, header],
|
476 |
)
|
477 |
demo.load(
|
478 |
reset,
|
479 |
+
inputs=[difficulty],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
480 |
outputs=[state, out, inp, img, but, radio, hint_out, reload, header],
|
481 |
)
|
482 |
|
config/condition.json
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"condition_0" : {
|
3 |
+
"model" : "SentenceTransformer",
|
4 |
+
"hints" : true
|
5 |
+
},
|
6 |
+
"condition_1" : {
|
7 |
+
"model" : "SentenceTransformer",
|
8 |
+
"hints" : false
|
9 |
+
},
|
10 |
+
"condition_2" : {
|
11 |
+
"model" : "word2vec",
|
12 |
+
"hints" : true
|
13 |
+
},
|
14 |
+
"condition_3" : {
|
15 |
+
"model" : "word2vec",
|
16 |
+
"hints" : false
|
17 |
+
}
|
18 |
+
}
|
19 |
+
|
config/lang.json
CHANGED
@@ -3,10 +3,8 @@
|
|
3 |
"Game": {
|
4 |
"Introduction_0": "Bienvenido a Semantrix, el emocionante Juego de la adivinanza semántica. \n\nTu misión es adivinar una palabra secreta que yo he escogido, pero no te preocupes, te ayudaré en el camino. \n\nLanza al aire la primera palabra que se te ocurra. Te daré pistas diciéndote si estás caliente, es decir muy cerca de adivinarla o frío, es decir, muy lejos de la palabra.",
|
5 |
"Introduction_1": "¿Quieres saber cómo se juega?",
|
6 |
-
"Rules": "Cada palabra que propongas recibirá una puntuación semántica entre 0 y 10, un puntaje alto significa que estás muy cerca de adivinar la palabra secreta\n\nSi veo que estás un poco perdido, estaré aquí para darte pistas que te ayudarán a acercarte a la palabra secreta.\n\nComo ayuda extra, mostraré un ranking de todas las palabras que has propuesto, ordenadas según su puntuación. Así podrás tener una idea mejor de qué tan cerca están y qué palabras funcionan mejor.\n\
|
7 |
-
"
|
8 |
-
"Difficulty": "Elige tu nivel de dificultad",
|
9 |
-
"Begin": "¡Enciende tu mente, confía en tus ideas y por sobre todo, pasa un buen rato! Este es un juego en el que cada palabra, cada puntuación y cada pista te acerca a tu victoria. ¡Mucha suerte!",
|
10 |
"New_word": "Nueva palabra: ",
|
11 |
"Feedback_0": "Helado, puntuación: ",
|
12 |
"Feedback_1": "Frío, puntuación: ",
|
@@ -82,8 +80,6 @@
|
|
82 |
"Introduction_0": "Welcome to Semantrix, the exciting semantic guessing game.\n\nYour mission is to guess a secret word I've chosen, but don't worry, I'll help you along the way.\n\nThrow out the first word that comes to your mind. I'll give you clues by telling you if you're hot, meaning very close to guessing it, or cold, meaning far from the word.",
|
83 |
"Introduction_1": "Do you want to know how to play?",
|
84 |
"Rules": "Each word you propose will receive a semantic score between 0 and 10. A high score means you're very close to guessing the secret word.\n\nIf I see you're a bit lost, I'll be here to give you hints to help you get closer to the secret word.\n\nAs extra help, I'll show a ranking of all the words you've suggested, ordered by their score. This way, you can have a better idea of how close they are and which words work best.\n\nYou'll be the winner when you correctly guess the secret word. Don't give up, it's within your reach!",
|
85 |
-
"Difficulty_presentation_Full": "In this exciting semantic guessing challenge, you can choose how big you want the challenge to be. Here are the difficulty levels:\n\n- Easy: Obvious clues for quick guessing. Ideal for beginners.\n\n- Normal: Clues only when you're very lost. An intermediate challenge.\n\n- Hard: Minimal help and complex words. For sharp thinkers.\n\n- Expert: No clues and difficult words. For semantic champions.\n\nRemember, whether you win or lose, each level is designed to make you enjoy and improve your guessing and word comprehension skills. Choose your level and start playing!",
|
86 |
-
"Difficulty": "Choose your difficulty level",
|
87 |
"Begin": "Turn on your mind, trust your ideas, and above all, have a good time! This is a game where each word, each score, and each clue brings you closer to your victory. Good luck!",
|
88 |
"New_word": "New word: ",
|
89 |
"Feedback_0": "Ice-cold, score: ",
|
|
|
3 |
"Game": {
|
4 |
"Introduction_0": "Bienvenido a Semantrix, el emocionante Juego de la adivinanza semántica. \n\nTu misión es adivinar una palabra secreta que yo he escogido, pero no te preocupes, te ayudaré en el camino. \n\nLanza al aire la primera palabra que se te ocurra. Te daré pistas diciéndote si estás caliente, es decir muy cerca de adivinarla o frío, es decir, muy lejos de la palabra.",
|
5 |
"Introduction_1": "¿Quieres saber cómo se juega?",
|
6 |
+
"Rules": "Cada palabra que propongas recibirá una puntuación semántica entre 0 y 10, un puntaje alto significa que estás muy cerca de adivinar la palabra secreta\n\nSi veo que estás un poco perdido, estaré aquí para darte pistas que te ayudarán a acercarte a la palabra secreta.\n\nComo ayuda extra, mostraré un ranking de todas las palabras que has propuesto, ordenadas según su puntuación. Así podrás tener una idea mejor de qué tan cerca están y qué palabras funcionan mejor.\n\nGanarás cuando adivines correctamente la palabra secreta. ¡No desistas, lo tienes al alcance!",
|
7 |
+
"Begin": "¡Enciende tu mente, confía en tus ideas y sobre todo, pasa un buen rato! Este es un juego en el que cada palabra, cada puntuación y cada pista te acerca a tu victoria. ¡Mucha suerte!",
|
|
|
|
|
8 |
"New_word": "Nueva palabra: ",
|
9 |
"Feedback_0": "Helado, puntuación: ",
|
10 |
"Feedback_1": "Frío, puntuación: ",
|
|
|
80 |
"Introduction_0": "Welcome to Semantrix, the exciting semantic guessing game.\n\nYour mission is to guess a secret word I've chosen, but don't worry, I'll help you along the way.\n\nThrow out the first word that comes to your mind. I'll give you clues by telling you if you're hot, meaning very close to guessing it, or cold, meaning far from the word.",
|
81 |
"Introduction_1": "Do you want to know how to play?",
|
82 |
"Rules": "Each word you propose will receive a semantic score between 0 and 10. A high score means you're very close to guessing the secret word.\n\nIf I see you're a bit lost, I'll be here to give you hints to help you get closer to the secret word.\n\nAs extra help, I'll show a ranking of all the words you've suggested, ordered by their score. This way, you can have a better idea of how close they are and which words work best.\n\nYou'll be the winner when you correctly guess the secret word. Don't give up, it's within your reach!",
|
|
|
|
|
83 |
"Begin": "Turn on your mind, trust your ideas, and above all, have a good time! This is a game where each word, each score, and each clue brings you closer to your victory. Good luck!",
|
84 |
"New_word": "New word: ",
|
85 |
"Feedback_0": "Ice-cold, score: ",
|
config/secret.json
CHANGED
@@ -1,8 +1,6 @@
|
|
1 |
{
|
2 |
"ENG": {
|
3 |
"basic": [
|
4 |
-
"joy",
|
5 |
-
"cricket",
|
6 |
"ant",
|
7 |
"tree",
|
8 |
"glass",
|
@@ -522,12 +520,7 @@
|
|
522 |
},
|
523 |
"SPA": {
|
524 |
"basic": [
|
525 |
-
"alegría",
|
526 |
-
"cricket",
|
527 |
-
"hormiga",
|
528 |
"árbol",
|
529 |
-
"vaso",
|
530 |
-
"montañas",
|
531 |
"vestido",
|
532 |
"lluvia",
|
533 |
"jabón",
|
@@ -549,7 +542,7 @@
|
|
549 |
"planeta",
|
550 |
"fiesta",
|
551 |
"hijo",
|
552 |
-
"teléfono
|
553 |
"visita",
|
554 |
"pestaña",
|
555 |
"elegancia",
|
|
|
1 |
{
|
2 |
"ENG": {
|
3 |
"basic": [
|
|
|
|
|
4 |
"ant",
|
5 |
"tree",
|
6 |
"glass",
|
|
|
520 |
},
|
521 |
"SPA": {
|
522 |
"basic": [
|
|
|
|
|
|
|
523 |
"árbol",
|
|
|
|
|
524 |
"vestido",
|
525 |
"lluvia",
|
526 |
"jabón",
|
|
|
542 |
"planeta",
|
543 |
"fiesta",
|
544 |
"hijo",
|
545 |
+
"teléfono",
|
546 |
"visita",
|
547 |
"pestaña",
|
548 |
"elegancia",
|
config/{w2v_models/esp_w2v_model → strans_models/esp_strans_model}
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b563a5788817d9cc01a0e2e0f626a6ea0814f9f6ad43a96bee396c91fc705d89
|
3 |
+
size 29214117
|
config/{w2v_models/eng_w2v_model → strans_models/esp_strans_model.vectors.npy}
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4e585fc39a5a629ca8d4b8fe9bdbc2885b1357c934c39648b7e9bb7b52a2711f
|
3 |
+
size 3074006144
|
config/w2v_models/eng_w2v_model.vectors.npy
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:61ddfe7841ca1c326e3b023e8f96a807dbd61f0bb3d711a99cd7c8920dc87d24
|
3 |
-
size 3600000128
|
|
|
|
|
|
|
|
config/w2v_models/esp_w2v_model.vectors.npy
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:e36596ce82587daf0dc04174e86c73148657782e7e2b507745a9056eab3cab5e
|
3 |
-
size 1200783728
|
|
|
|
|
|
|
|
game.py
CHANGED
@@ -39,6 +39,7 @@
|
|
39 |
import json
|
40 |
import random
|
41 |
from datetime import datetime
|
|
|
42 |
import numpy as np
|
43 |
from gensim.models import KeyedVectors
|
44 |
from hints import curiosity, hint
|
@@ -83,18 +84,29 @@ class Semantrix:
|
|
83 |
self.model_type = model_type
|
84 |
|
85 |
if self.lang == 1:
|
86 |
-
self.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
self.Config = self.DictWrapper(self.Config_full["ENG"]["Game"])
|
88 |
self.secret_dict = self.secret["ENG"]
|
89 |
else:
|
90 |
-
self.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
self.Config = self.DictWrapper(self.Config_full["SPA"]["Game"])
|
92 |
self.secret_dict = self.secret["SPA"]
|
93 |
|
94 |
-
# Create empty KeyedVectors model with predefined size where the embeddings will be stored if Sentence Transformer used
|
95 |
-
if self.model_type == "SentenceTransformer":
|
96 |
-
self.model_trans = KeyedVectors(768)
|
97 |
-
|
98 |
self.model_st = SentenceTransformer(
|
99 |
"sentence-transformers/paraphrase-multilingual-mpnet-base-v2"
|
100 |
)
|
@@ -107,15 +119,18 @@ class Semantrix:
|
|
107 |
def prepare_game(self, difficulty):
|
108 |
|
109 |
# Set the secret list depending on the difficulty
|
110 |
-
self.secret_list = (
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
)
|
|
|
115 |
|
116 |
# Select a random secret word from the secret list
|
117 |
-
self.secret = self.secret_list.pop(random.randint(0, len(self.secret_list) - 1))
|
|
|
118 |
self.secret = self.secret.lower()
|
|
|
119 |
|
120 |
# Store the secret word in the words list
|
121 |
self.words = [self.Config.secret_word]
|
@@ -123,16 +138,6 @@ class Semantrix:
|
|
123 |
# Store the score in the scores list
|
124 |
self.scores = [10]
|
125 |
|
126 |
-
# Store the embedding of the secret word in the embeddings dictionary
|
127 |
-
if self.model_type == "SentenceTransformer":
|
128 |
-
# Add the secret word to the KeyedVectors model if the model type is SentenceTransformer
|
129 |
-
# If the model type is word2vec, the secret word is already in the model
|
130 |
-
if self.secret not in self.model_trans.key_to_index.keys():
|
131 |
-
self.model_trans.add_vector(
|
132 |
-
self.secret,
|
133 |
-
self.model_st.encode(self.secret, convert_to_tensor=True).tolist(),
|
134 |
-
)
|
135 |
-
|
136 |
# Initialize the game variables
|
137 |
self.win = False
|
138 |
self.n = 0
|
@@ -206,20 +211,7 @@ class Semantrix:
|
|
206 |
)
|
207 |
return feedback
|
208 |
|
209 |
-
|
210 |
-
if (
|
211 |
-
self.model_type == "SentenceTransformer"
|
212 |
-
and word not in self.model_trans.key_to_index.keys()
|
213 |
-
):
|
214 |
-
self.model_trans.add_vector(
|
215 |
-
word, self.model_st.encode(word, convert_to_tensor=True).tolist()
|
216 |
-
)
|
217 |
-
|
218 |
-
# Calculate the score of the word, apply logarithmic scaling, interpolate the score to a range from 0 to 10, and round it to two decimal places
|
219 |
-
if self.model_type == "word2vec":
|
220 |
-
similarity = self.model.similarity(self.secret, word)
|
221 |
-
else:
|
222 |
-
similarity = self.model_trans.similarity(self.secret, word)
|
223 |
|
224 |
log_similarity = np.log10(similarity * 10) if similarity > 0 else 0
|
225 |
score = round(
|
|
|
39 |
import json
|
40 |
import random
|
41 |
from datetime import datetime
|
42 |
+
from tqdm import tqdm
|
43 |
import numpy as np
|
44 |
from gensim.models import KeyedVectors
|
45 |
from hints import curiosity, hint
|
|
|
84 |
self.model_type = model_type
|
85 |
|
86 |
if self.lang == 1:
|
87 |
+
if self.model_type == "word2vec":
|
88 |
+
self.model = KeyedVectors.load(
|
89 |
+
"config/w2v_models/eng_w2v_model", mmap="r"
|
90 |
+
)
|
91 |
+
elif self.model_type == "SentenceTransformer":
|
92 |
+
self.model = KeyedVectors.load(
|
93 |
+
"config/strans_models/eng_strans_model", mmap="r"
|
94 |
+
)
|
95 |
self.Config = self.DictWrapper(self.Config_full["ENG"]["Game"])
|
96 |
self.secret_dict = self.secret["ENG"]
|
97 |
else:
|
98 |
+
if self.model_type == "word2vec":
|
99 |
+
self.model = KeyedVectors.load(
|
100 |
+
"config/w2v_models/esp_w2v_model", mmap="r"
|
101 |
+
)
|
102 |
+
elif self.model_type == "SentenceTransformer":
|
103 |
+
self.model = KeyedVectors.load(
|
104 |
+
"config/strans_models/esp_strans_model", mmap="r"
|
105 |
+
)
|
106 |
+
|
107 |
self.Config = self.DictWrapper(self.Config_full["SPA"]["Game"])
|
108 |
self.secret_dict = self.secret["SPA"]
|
109 |
|
|
|
|
|
|
|
|
|
110 |
self.model_st = SentenceTransformer(
|
111 |
"sentence-transformers/paraphrase-multilingual-mpnet-base-v2"
|
112 |
)
|
|
|
119 |
def prepare_game(self, difficulty):
|
120 |
|
121 |
# Set the secret list depending on the difficulty
|
122 |
+
# self.secret_list = (
|
123 |
+
# self.secret_dict["basic"]
|
124 |
+
# if difficulty <= 2
|
125 |
+
# else self.secret_dict["advanced"]
|
126 |
+
# )
|
127 |
+
self.secret_list = self.secret_dict["basic"]
|
128 |
|
129 |
# Select a random secret word from the secret list
|
130 |
+
# self.secret = self.secret_list.pop(random.randint(0, len(self.secret_list) - 1))
|
131 |
+
self.secret = self.secret_list.pop(0)
|
132 |
self.secret = self.secret.lower()
|
133 |
+
print(self.secret)
|
134 |
|
135 |
# Store the secret word in the words list
|
136 |
self.words = [self.Config.secret_word]
|
|
|
138 |
# Store the score in the scores list
|
139 |
self.scores = [10]
|
140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
# Initialize the game variables
|
142 |
self.win = False
|
143 |
self.n = 0
|
|
|
211 |
)
|
212 |
return feedback
|
213 |
|
214 |
+
similarity = self.model.similarity(self.secret, word)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
|
216 |
log_similarity = np.log10(similarity * 10) if similarity > 0 else 0
|
217 |
score = round(
|