laya-snake

A copy of laya-multilingual (mmBERT-base, 322M) fine-tuned to play Snake. Each tick it answers one Laya choice question (up / down / left / right) about a text description of the board.

Code, game UI and training pipeline: https://github.com/Okbatti/SnakeGame_Laya

Usage

import laya

agent = laya.load("models/laya-snake")   # after: hf download OwaisAli10/laya-snake --local-dir models/laya-snake
state = ("heading: right | length: 3 | food: 5 up, 3 left | up: free, room 224 open, tail yes | "
         "down: free, room 224 open, tail yes | left: body | right: free, room 224 open, tail yes")
question = {"move": {"type": "choice",
                     "instructions": "Which direction should the snake move next to reach the food safely?",
                     "criteria": {"up": "move up", "down": "move down", "left": "move left", "right": "move right"}}}
print(agent.predict(state, question)["answers"]["move"])

The state text must come from snake/encode.py in the GitHub repo; the model only knows that format.

Training

  • Labels: a BFS teacher script (shortest path to food, only if the tail stays reachable), soft targets (0.85 on the teacher's move, the rest spread over other survivable moves).
  • Data: 114,476 train / 5,524 val states from teacher games on 10–20 wide boards, 12% random safe moves.
  • Loss: expected log score (a strictly proper scoring rule), full fine-tune, 2 epochs, Colab T4, 41 minutes.
  • Validation accuracy: 0.38 before, 0.90 after. Fitted temperature 0.54.

Results (10 games, 15×15, Apple M1 Pro GPU)

policy avg score best agrees with teacher latency p50
teacher (BFS) 200.5 219 100% 0.2 ms
laya-snake 89.9 143 77.7% 31.8 ms
laya-multilingual (untuned) 0.4 2 3.2% 31.8 ms

Limits

Trained only on the teacher's own trajectories, so it can drift into board layouts it never saw and trap itself. Scores vary a lot per game (46 to 143). It is not a general game-playing model.

Credits

Base model: Laya by Convai Innovations (Apache 2.0).

Downloads last month

-

Downloads are not tracked for this model. How to track
Safetensors
Model size
0.3B params
Tensor type
F32
·
F16
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for OwaisAli10/laya-snake

Finetuned
(40)
this model