Row 2136

Row ID: 2136 | Dataset Entry | Axioma AXP Content Repository

Content Data

This page contains data entry 2136 from the Axioma AXP content repository. The structured data below represents the complete record for this entry.

I've been working on building a Sudoku Solver AI. The goal is to take an unsolved Sudoku board (represented as a 1D array of length 81) as input and return a solved board (also a 1D array of length 81) as output. However, I'm encountering some issues. Here's my code:

import tensorflow as tf import numpy as np from sklearn.model_selection import train_test_split model = tf.keras.models.Sequential() model.add(tf.keras.layers.Dense(81, activation="relu")) model.add(tf.keras.layers.Dense(128, activation="relu")) model.add(tf.keras.layers.Dense(128, activation="relu")) model.add(tf.keras.layers.Dense(128, activation="relu")) model.add(tf.keras.layers.Dense(81)) model.compile(optimizer="adam", loss="mse", metrics="accuracy") model = tf.keras.models.load_model("sodoku_1m_10e_adam_mse.h5") """ Soduko training data """ quizzes = np.zeros((1000000, 81), np.int32) solutions = np.zeros((1000000, 81), np.int32) for i, line in enumerate(open('sudoku.csv', 'r').read().splitlines()[1:]): quiz, solution = line.split(",") for j, q_s in enumerate(zip(quiz, solution)): q, s = q_s quizzes[i, j] = q solutions[i, j] = s quizzes = quizzes.reshape((-1, 81)) solutions = solutions.reshape((-1, 81)) x_train, x_test, y_train, y_test = train_test_split(quizzes, solutions, test_size=0.2, random_state=42) def train(model): model.fit(x_train, y_train, batch_size=32, epochs=10) def test(model): loss, accuracy = model.evaluate(x_test, y_test) print("LOSS: ", loss) print("ACCURACY: ", accuracy) def make_move(input_board): input_data = np.array(input_board).reshape(1, -1) output_data = model.predict(input_data) output_board = output_data[0] output_board = output_data[0] output_board = np.round(output_board).clip(1, 9) output_board = output_board.astype(int) return output_board

​

I trained the model using the train() function, then tested it with the test() function. I thought the make\_move() function would output a solved board, but instead, I'm getting random floats. I then modified the function to output integers between 1 and 9, but the output still seems random. I realized that I haven't explicitly implemented the rules of Sudoku in any way, so even if the output was in the correct format, it might not be a valid solution. I'm not sure how to implement these rules besides repeatedly rejecting invalid boards until a valid one is generated, which doesn't seem efficient.

So the question is: What is wrong with this code? What do I need to do to fix it and make it properly solve sodoku puzzles?

FieldValue
text I've been working on building a Sudoku Solver AI. The goal is to take an unsolved Sudoku board (represented as a 1D array of length 81) as input and return a solved board (also a 1D array of length 81) as output. However, I'm encountering some issues. Here's my code: import tensorflow as tf import numpy as np from sklearn.model_selection import train_test_split model = tf.keras.models.Sequential() model.add(tf.keras.layers.Dense(81, activation="relu")) model.ad…
label r/tensorflow
dataType post
communityName r/tensorflow
datetime 2023-06-29
username_encoded Z0FBQUFBQm5LakwwbjRFU2pPcERrUlRoMFRvSHM4VW9oNHk0Qlc4Z1QxVzhNZGxwYWRoRGJxdlYyNXJtWGhqQzZXUjkwTXRVNU5iSks3MTlBbC1BNkZXQVFNTDMyUHlpMVE9PQ==
url_encoded Z0FBQUFBQm5Lak9FY3ZaR3hFZUtwOGlLMnZPanRBQ1k5V2ZWdnp5dVgwTC14cjducldUVmprSDJxS2hnSDk5UU1hMmM1ZW5GdnRJVFBhTWtEVEM0Wmt1emVGQU1KOVBkNFVaa2dtb19SekxDVE44N0h6NWstS19GSGk2OFNLaFVQUHdYV3h1R1FQTWJneEpOSVNFN3ZIYnpLMUZIc3lvdFRhX0tPNEx5dTdoR0FEa3RPdmRCd0hQVUtwbl9OWWF4TFAwVlpuMFNoSjZt

Raw Record

{
  "text": "I've been working on building a Sudoku Solver AI. The goal is to take an unsolved Sudoku board (represented as a 1D array of length 81) as input and return a solved board (also a 1D array of length 81) as output. However, I'm encountering some issues. Here's my code:\n\n    import tensorflow as tf\n    import numpy as np\n    from sklearn.model_selection import train_test_split\n    \n    \n    model = tf.keras.models.Sequential()\n    model.add(tf.keras.layers.Dense(81, activation=\"relu\"))\n    model.add(tf.keras.layers.Dense(128, activation=\"relu\"))\n    model.add(tf.keras.layers.Dense(128, activation=\"relu\"))\n    model.add(tf.keras.layers.Dense(128, activation=\"relu\"))\n    model.add(tf.keras.layers.Dense(81))\n    \n    model.compile(optimizer=\"adam\", loss=\"mse\", metrics=\"accuracy\")\n    \n    model = tf.keras.models.load_model(\"sodoku_1m_10e_adam_mse.h5\")\n    \n    \"\"\"\n    Soduko training data\n    \"\"\"\n    quizzes = np.zeros((1000000, 81), np.int32)\n    solutions = np.zeros((1000000, 81), np.int32)\n    for i, line in enumerate(open('sudoku.csv', 'r').read().splitlines()[1:]):\n        quiz, solution = line.split(\",\")\n        for j, q_s in enumerate(zip(quiz, solution)):\n            q, s = q_s\n            quizzes[i, j] = q\n            solutions[i, j] = s\n    quizzes = quizzes.reshape((-1, 81))\n    solutions = solutions.reshape((-1, 81))\n    \n    x_train, x_test, y_train, y_test = train_test_split(quizzes, solutions, test_size=0.2, random_state=42)\n    \n    \n    \n    def train(model):\n        model.fit(x_train, y_train, batch_size=32, epochs=10)\n    \n    \n    def test(model):\n        loss, accuracy = model.evaluate(x_test, y_test)\n        print(\"LOSS: \", loss)\n        print(\"ACCURACY: \", accuracy)\n    \n    \n    \n    \n    def make_move(input_board):\n        input_data = np.array(input_board).reshape(1, -1)\n    \n        output_data = model.predict(input_data)\n    \n        output_board = output_data[0]\n    \n        output_board = output_data[0]\n    \n        output_board = np.round(output_board).clip(1, 9)\n    \n        output_board = output_board.astype(int)\n    \n        return output_board\n\n​\n\nI trained the model using the train() function, then tested it with the test() function. I thought the make\\_move() function would output a solved board, but instead, I'm getting random floats. I then modified the function to output integers between 1 and 9, but the output still seems random. I realized that I haven't explicitly implemented the rules of Sudoku in any way, so even if the output was in the correct format, it might not be a valid solution. I'm not sure how to implement these rules besides repeatedly rejecting invalid boards until a valid one is generated, which doesn't seem efficient.\n\nSo the question is: What is wrong with this code? What do I need to do to fix it and make it properly solve sodoku puzzles?",
  "label": "r/tensorflow",
  "dataType": "post",
  "communityName": "r/tensorflow",
  "datetime": "2023-06-29",
  "username_encoded": "Z0FBQUFBQm5LakwwbjRFU2pPcERrUlRoMFRvSHM4VW9oNHk0Qlc4Z1QxVzhNZGxwYWRoRGJxdlYyNXJtWGhqQzZXUjkwTXRVNU5iSks3MTlBbC1BNkZXQVFNTDMyUHlpMVE9PQ==",
  "url_encoded": "Z0FBQUFBQm5Lak9FY3ZaR3hFZUtwOGlLMnZPanRBQ1k5V2ZWdnp5dVgwTC14cjducldUVmprSDJxS2hnSDk5UU1hMmM1ZW5GdnRJVFBhTWtEVEM0Wmt1emVGQU1KOVBkNFVaa2dtb19SekxDVE44N0h6NWstS19GSGk2OFNLaFVQUHdYV3h1R1FQTWJneEpOSVNFN3ZIYnpLMUZIc3lvdFRhX0tPNEx5dTdoR0FEa3RPdmRCd0hQVUtwbl9OWWF4TFAwVlpuMFNoSjZt"
}

Entry Information