AI Wiki中文/EN

AlphaZero: let search teach policy and value

AlphaZero

Use a small self-play loop to connect policy priors, value perspectives, search targets and neural updates.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

Keep something learned after search ends

Continue the game of taking one or two stones, with the last mover winning. Ordinary MCTS can spend many simulations choosing a move, but starting a new tree does not necessarily preserve those calculations as reusable judgment. AlphaZero adds a learning loop: a network advises search, search spends computation checking and revising that advice, and the resulting move distribution and eventual outcome train the network. Network–search loop

A later similar position can then receive a better prior for allocating simulations and a better value estimate for leaves. “Better” is the intended learning outcome, not a theorem that each finite search strictly improves the policy. Limited search, network error and changing self-play distributions can cause stagnation or regression.

We implement a complete small loop: known subtraction rules, neural policy and value heads, PUCT, root noise, self-play, replay and gradient updates. It uses NumPy and 259 parameters, not the paper’s board-game residual network or match system. The principle and the original experimental scale remain separate.

Visit counts become policy targets; actual self-play training reduces errors on this finite stone game. Counts and training budgets cover all eight seeds. Tables show three significant digits.
Visit counts become policy targets; actual self-play training reduces errors on this finite stone game. Counts and training budgets cover all eight seeds. Tables show three significant digits.

Rules expand branches; the network predicts

AlphaZero receives game rules, including legal moves, transitions, termination and scoring, along with input and action encodings. It does not learn chess by being denied how pieces move. Rules let search expand branches accurately. A network receives position ss and outputs action prior pp and value vv:

(p,v)=fθ(s),v≈E[z∣s],z∈{−1,0,1}.(p,v)=f_\theta(s),\qquad v\approx\mathbb E[z\mid s],\qquad z\in\{-1,0,1\}.

We define zz as the terminal outcome for the current player. Value is expected outcome, not generally win probability: with draws, v=P(win)−P(loss)v=P(\mathrm{win})-P(\mathrm{loss}). The AlphaZero paper uses expected outcome to distinguish this setting from a binary win/loss description and explicitly discusses supplied rule knowledge. Outcome target and rule knowledge

The policy head produces logits uau_a, normalized over legal actions A(s)\mathcal A(s):

p(a∣s)={eua∑b∈A(s)eub,a∈A(s),0,a∉A(s).p(a\mid s)=\begin{cases} \dfrac{e^{u_a}}{\sum_{b\in\mathcal A(s)}e^{u_b}},&a\in\mathcal A(s),\\ 0,&a\notin\mathcal A(s). \end{cases}

Masking illegal actions requires renormalization. With one stone left, taking two must have probability zero. Computation first subtracts the largest legal logit to avoid exponentiating large numbers; the program also floors extremely small exponentials. Gradient checks cover the ordinary finite parameter range used here, not every nondifferentiable saturation boundary introduced by clipping.

Search keeps MCTS visits and means but uses policy priors to allocate exploration. Our teaching score is:

asim∈arg max⁡a[Q(s,a)+c p(a∣s)N(s)+11+N(s,a)].a_{\mathrm{sim}}\in\operatorname*{arg\,max}_a \left[Q(s,a)+c\,p(a\mid s)\frac{\sqrt{N(s)+1}}{1+N(s,a)}\right].

This is a PUCT form, not UCT’s log⁡N/n\sqrt{\log N/n}. A larger prior receives more early attention; a prior is not an observed return. We fix c=1.5c=1.5 and use N+1N+1 for root startup. The original paper uses a slowly varying coefficient and its own visit convention. Substituting constants does not constitute a literal reproduction. Paper PUCT Implementation choices

At a new leaf, the network supplies value and outgoing priors instead of requiring a random rollout to termination. True terminal states use outcomes supplied by the rules. In a two-player zero-sum convention, backup must still convert values to each edge decision-maker’s perspective: near +1 means good for that player.

Training must also try alternative moves. Our program mixes Dirichlet noise once at the root, where η\eta is a random probability vector over legal actions:

proot′=(1−ε)proot+εη,η∼Dirichlet⁡(α1).p_{\mathrm{root}}'=(1-\varepsilon)p_{\mathrm{root}}+\varepsilon\eta, \qquad \eta\sim\operatorname{Dirichlet}(\alpha\mathbf1).

Here ε=0.25\varepsilon=0.25 and α=0.3\alpha=0.3. This changes search priors, not network weights or environmental rewards. Evaluation removes root noise; fixed randomness may still resolve tied search scores. The paper scales noise parameters with typical legal-move counts. A parameter chosen for one board game is not universally optimal. Training and evaluation configuration

Search counts become another distribution:

πτ(a∣s)=N(s,a)1/τ∑bN(s,b)1/τ,τ>0.\pi_\tau(a\mid s)=\frac{N(s,a)^{1/\tau}}{\sum_bN(s,b)^{1/\tau}},\qquad\tau>0.

Temperature τ\tau controls concentration when sampling from visit counts. It differs from root noise and the PUCT coefficient. Counts 30 and 10 yield 0.75 and 0.25 at temperature 1, or 0.9 and 0.1 at temperature 0.5. The zero-temperature limit concentrates on most-visited actions; code can implement an explicit greedy rule rather than divide by zero. Our training uses temperature 1 throughout, while evaluation selects the most visited move.

After a game, the target for state sts_t must belong to its current player. Let RiR_i be player ii‘s terminal payoff. In a two-player zero-sum game with alternating turns:

zt=Rplayer⁡(st),zt+1=−zt.z_t=R_{\operatorname{player}(s_t)},\qquad z_{t+1}=-z_t .

In our subtraction game, the last decision state receives +1 and earlier targets alternate signs. Giving both players’ states the winner’s same +1 is wrong. Another valid convention predicts the first player’s outcome throughout, then converts it into a player-payoff vector. The fixed OpenSpiel code follows that direction. Our current-player convention must not copy only half of its conversion. Fixed targets and evaluator

A training sample stores state, search distribution and outcome target. The network minimizes:

ℓ(θ)=(vθ(s)−z)2−∑aπ(a∣s)log⁡pθ(a∣s)+λ∥θ∥22.\ell(\theta)=(v_\theta(s)-z)^2 -\sum_a\pi(a\mid s)\log p_\theta(a\mid s) +\lambda\|\theta\|_2^2.

The search distribution is fixed during this update; gradients do not run through the entire search tree to differentiate visit counts. Replay targets generally come from earlier networks. Training changes later searches, so both targets and data distributions evolve. This approximate loop is not the monotonic-improvement guarantee of exact policy iteration in a finite MDP.

For the data losses, derivatives with respect to legal logits and value are:

∂ℓpolicy∂ua=pa−πa,∂ℓvalue∂v=2(v−z),∂ℓvalue∂ξv=2(v−z)(1−v2).\frac{\partial\ell_{\mathrm{policy}}}{\partial u_a}=p_a-\pi_a, \qquad \frac{\partial\ell_{\mathrm{value}}}{\partial v}=2(v-z), \qquad \frac{\partial\ell_{\mathrm{value}}}{\partial \xi_v}=2(v-z)(1-v^2).

The last expression includes the chain derivative of v=tanh⁡(ξv)v=\tanh(\xi_v); ξv\xi_v is the value head’s scalar preactivation. With predicted probability 0.5 and target 0.75, the first logit’s derivative is −0.25, so gradient descent increases it. The shared hidden layer receives both policy and value gradients; parameter regularization separately contributes 2λθ2\lambda\theta.

Turn a game into training samples

The program requires Python 3.12 or later and NumPy; we ran Python 3.12.4 with NumPy 1.26.4. The state is a remaining-stone count. A learned 16-dimensional embedding passes through tanh into policy and value heads. Including a placeholder zero-stone embedding gives 259 parameters. Rules handle terminal positions instead of asking the network to guess the winner.

Each seed trains for 60 iterations with four games per iteration, starting uniformly from 1–12 stones. Every move runs 24 simulations; its visit distribution selects the action and supplies the policy target. Completed games receive backward-filled current-player outcomes and enter a replay buffer capped at 2,048 states. Each iteration performs eight updates from batches of 32, with learning rate 0.08 and L2 coefficient 10−410^{-4}. Data, search and batch sampling have separate random streams. Evaluation changes neither weights nor training random streams.

"""Original small self-play learner; NumPy, not a chess AlphaZero reproduction."""
import json
import math
import numpy as np

MAX_STONES, HIDDEN = 12, 16


def legal_mask(stones):
    return np.array([stones >= 1, stones >= 2])


def init(seed):
    rng = np.random.default_rng(seed)
    return dict(E=rng.normal(0, .2, (MAX_STONES+1, HIDDEN)),
                Wp=rng.normal(0, .2, (HIDDEN, 2)), bp=np.zeros(2),
                Wv=rng.normal(0, .2, HIDDEN), bv=np.zeros(1))


def predict(weights, stones):
    if not isinstance(stones,(int,np.integer)) or not 1 <= stones <= MAX_STONES:
        raise ValueError('Network inference requires a nonterminal supported state.')
    hidden = np.tanh(weights['E'][stones])
    logits = hidden @ weights['Wp'] + weights['bp']
    mask = legal_mask(stones)
    shifted = logits - max(logits[mask])
    probs = np.where(mask, np.exp(np.clip(shifted, -700, 0)), 0)
    probs /= probs.sum()
    value = np.tanh(hidden @ weights['Wv'] + weights['bv'][0])
    return probs, float(value), hidden


def loss_grad(weights, batch, decay=1e-4):
    """Mean value-MSE plus policy cross entropy and explicit L2 penalty."""
    if not batch or decay < 0 or not math.isfinite(decay):
        raise ValueError('Nonempty training batch required.')
    gradients = {k: np.zeros_like(v) for k,v in weights.items()}
    loss = 0.
    for stones, target_policy, target_value in batch:
        probs, value, hidden = predict(weights, stones)
        target_policy = np.asarray(target_policy, dtype=float)
        mask = legal_mask(stones)
        if (target_policy.shape != (2,) or np.any(target_policy < 0)
                or not np.isclose(target_policy.sum(), 1)
                or np.any(target_policy[~mask] != 0) or not -1 <= target_value <= 1):
            raise ValueError('Invalid policy/value target.')
        loss += (value-target_value)**2 - np.sum(target_policy[mask]*np.log(probs[mask]))
        dlogits = probs-target_policy
        dv = 2*(value-target_value)*(1-value*value)
        gradients['Wp'] += np.outer(hidden, dlogits)
        gradients['bp'] += dlogits
        gradients['Wv'] += hidden*dv
        gradients['bv'][0] += dv
        dh = weights['Wp'] @ dlogits + weights['Wv']*dv
        gradients['E'][stones] += dh*(1-hidden*hidden)
    loss /= len(batch)
    for key in weights:
        loss += decay*np.sum(weights[key]**2)
        gradients[key] = gradients[key]/len(batch) + 2*decay*weights[key]
    return float(loss), gradients


class Node:
    def __init__(self, stones, prior=None):
        self.stones = stones
        self.prior = prior
        self.visits = 0
        self.edges = {}  # action index -> [child, edge count, current-player sum]


def expand(weights, stones):
    if stones == 0:
        return Node(0), -1.
    prior, value, _ = predict(weights, stones)
    return Node(stones, prior), value


def search(weights, stones, budget, rng, noise=False, c=1.5):
    if (not isinstance(stones,(int,np.integer)) or not 1 <= stones <= MAX_STONES or budget < 1
            or not isinstance(budget, int) or c < 0 or not math.isfinite(c)):
        raise ValueError('Valid nonterminal state, integer budget and finite c required.')
    root, _ = expand(weights, stones)
    if noise:
        legal = np.flatnonzero(legal_mask(stones))
        root.prior[legal] = .75*root.prior[legal] + .25*rng.dirichlet(np.full(len(legal), .3))
    for _ in range(budget):
        node, path = root, []
        while node.stones:
            legal = np.flatnonzero(legal_mask(node.stones))
            scores = []
            for a in legal:
                edge = node.edges.get(int(a))
                count, mean = (edge[1], edge[2]/edge[1]) if edge else (0, 0.)
                scores.append(mean+c*node.prior[a]*math.sqrt(node.visits+1)/(1+count))
            best = max(scores)
            a = int(rng.choice([a for a,s in zip(legal,scores) if s == best]))
            path.append((node, a))
            if a not in node.edges:
                child, value = expand(weights, node.stones-a-1)
                node.edges[a] = [child, 0, 0.]
                break
            node = node.edges[a][0]
        else:
            value = -1.  # terminal player-to-move lost
        for parent, a in reversed(path):
            value = -value
            edge = parent.edges[a]
            edge[1] += 1
            edge[2] += value
            parent.visits += 1
    counts = np.array([root.edges[a][1] if a in root.edges else 0 for a in range(2)])
    return counts/counts.sum(), dict(counts=counts.tolist(), simulations=budget,
                                    root_visits=root.visits, root_prior=root.prior.tolist())


def evaluate(weights, seed=9000, budget=24):
    rng = np.random.default_rng(seed)
    raw_wrong, search_wrong, values = [], [], []
    for stones in range(1, MAX_STONES+1):
        probs, value, _ = predict(weights, stones)
        improved, _ = search(weights, stones, budget, rng)
        # Independent subtraction-game invariant is used only for evaluation.
        optimal = -1 if stones % 3 == 0 else 1
        for distribution, failures in ((probs,raw_wrong),(improved,search_wrong)):
            action = int(np.argmax(distribution))+1
            successor = stones-action
            actual = 1 if successor % 3 == 0 else -1
            if actual < optimal:
                failures.append(stones)
        values.append(value)
    return dict(raw_wrong=raw_wrong, search_wrong=search_wrong, values=values)


def train(seed, iterations=60, games_per_iteration=4, updates=8, budget=24):
    if any(not isinstance(x,int) or x < 1 for x in (iterations,games_per_iteration,updates,budget)):
        raise ValueError('Positive integer training and search budgets required.')
    weights = init(seed)
    data_rng = np.random.default_rng(seed+1000)
    search_rng = np.random.default_rng(seed+2000)
    batch_rng = np.random.default_rng(seed+3000)
    before = evaluate(weights)
    replay, checkpoints = [], []
    real_moves = searches = 0
    for iteration in range(iterations):
        for _ in range(games_per_iteration):
            stones = int(data_rng.integers(1, MAX_STONES+1))
            trajectory = []
            while stones:
                target, _ = search(weights, stones, budget, search_rng, noise=True)
                searches += 1
                action = int(data_rng.choice(2, p=target))+1
                trajectory.append((stones, target.copy()))
                stones -= action
                real_moves += 1
            # Last mover won; alternate the target for earlier player-to-move states.
            value = 1.
            for state, target in reversed(trajectory):
                replay.append((state, target, value))
                value = -value
        replay = replay[-2048:]
        for _ in range(updates):
            indices = batch_rng.integers(len(replay), size=32)
            loss, gradients = loss_grad(weights, [replay[i] for i in indices])
            for k in weights:
                weights[k] -= .08*gradients[k]
        if (iteration+1) % 20 == 0:
            checkpoints.append(dict(iteration=iteration+1, last_minibatch_loss=loss,
                                    **evaluate(weights)))
    return dict(seed=seed, games=iterations*games_per_iteration, real_moves=real_moves,
                training_searches=searches, training_simulations=searches*budget,
                gradient_steps=iterations*updates, replay_size=len(replay),
                before=before, after=evaluate(weights), checkpoints=checkpoints,
                weights={k:v.tolist() for k,v in weights.items()})


if __name__ == '__main__':
    print(json.dumps(train(0), indent=2))
Inspect the complete recorded output
{
  "seed": 0,
  "games": 240,
  "real_moves": 1070,
  "training_searches": 1070,
  "training_simulations": 25680,
  "gradient_steps": 480,
  "replay_size": 1070,
  "before": {
    "raw_wrong": [
      4,
      5,
      7,
      11
    ],
    "search_wrong": [
      8,
      11
    ],
    "values": [
      -0.0697067033441806,
      0.15848701456425143,
      0.1826018413479544,
      0.1798203564580568,
      0.040721663608551076,
      -0.1389931391995167,
      0.17539028465395318,
      0.01608490068191491,
      -0.13124281815235053,
      -0.026517077610660897,
      -0.28714590840679266,
      0.027680767158235982
    ]
  },
  "after": {
    "raw_wrong": [],
    "search_wrong": [],
    "values": [
      0.9532724300114478,
      0.9296030698281584,
      -0.9494792562571434,
      0.8816008767988958,
      0.9073356335840035,
      -0.8926188198971143,
      0.8236973592542862,
      0.9136279020402025,
      -0.8769006066424958,
      0.7632379627374287,
      0.6977908065042859,
      -0.5561350158507968
    ]
  },
  "checkpoints": [
    {
      "iteration": 20,
      "last_minibatch_loss": 0.8907976289765376,
      "raw_wrong": [],
      "search_wrong": [],
      "values": [
        0.9041582530601894,
        0.8716744038928674,
        -0.8512486606417655,
        0.8611424518687054,
        0.8093916319579164,
        -0.7880454386681233,
        0.7619345205274567,
        0.8440439996922581,
        -0.7482428101596817,
        0.6750465820280714,
        0.5707833027297082,
        0.163919896488458
      ]
    },
    {
      "iteration": 40,
      "last_minibatch_loss": 0.5821538049188749,
      "raw_wrong": [],
      "search_wrong": [],
      "values": [
        0.9335918992930794,
        0.906892457631564,
        -0.9331692944381802,
        0.8447358605113867,
        0.8669025296273674,
        -0.8624882332840667,
        0.717741574550973,
        0.8845785978181765,
        -0.8513752397415376,
        0.7480998555942503,
        0.6779434080294158,
        -0.36914808322628345
      ]
    },
    {
      "iteration": 60,
      "last_minibatch_loss": 0.7765900573605946,
      "raw_wrong": [],
      "search_wrong": [],
      "values": [
        0.9532724300114478,
        0.9296030698281584,
        -0.9494792562571434,
        0.8816008767988958,
        0.9073356335840035,
        -0.8926188198971143,
        0.8236973592542862,
        0.9136279020402025,
        -0.8769006066424958,
        0.7632379627374287,
        0.6977908065042859,
        -0.5561350158507968
      ]
    }
  ],
  "weights": {
    "E": [
      [
        0.024953660758105855,
        -0.02621883517263863,
        0.12710460080315852,
        0.020819512716661135,
        -0.10631423137672305,
        0.07176572389320375,
        0.25880472070880706,
        0.18796703655545474,
        -0.1396702414514091,
        -0.2511480360879257,
        -0.12370120216200824,
        0.008201961788976695,
        -0.461448557856248,
        -0.04342355331117078,
        -0.24727578494807054,
        -0.14533300740744237
      ],
      [
        -0.05169976058542905,
        -0.1968928970726323,
        0.27845436389477446,
        0.27925336328663264,
        0.2542142130747649,
        0.2847409999800569,
        -0.08975214561815359,
        0.5232030251191034,
        0.14159327980728625,
        -0.09471792691538676,
        -0.025710272245525658,
        -0.17541160487178817,
        0.1432728095403907,
        -0.044962044542462984,
        -0.19605789325361145,
        0.21601364121243588
      ],
      [
        0.13847740641247977,
        0.30012148619795925,
        0.1389314118752076,
        0.1350889761974881,
        -0.25620714927615196,
        0.4703864157174916,
        8.026870732070351e-05,
        0.6049139012906448,
        -0.2134881672531249,
        0.2668398697775691,
        0.18728073535433226,
        0.2862300917718923,
        0.19302258203789685,
        -0.1303707261969579,
        0.43458752775021015,
        0.6461942149961275
      ],
      [
        0.23441335760477558,
        0.3535939613723984,
        -0.19850849822661124,
        -0.32522182495527147,
        -0.31317694735553997,
        -0.025003024537744487,
        -0.2532138349564801,
        -0.5587188359962308,
        0.11356013598194223,
        0.29108728068183876,
        -0.3469438622077557,
        -0.16739638970143372,
        -0.3839223922602914,
        -0.1048536641510794,
        0.2881529893663977,
        -0.45951716637117473
      ],
      [
        -0.06473874449938148,
        -0.32073309707618186,
        0.3418374615348733,
        0.23314077906683958,
        0.4262569010091317,
        -0.8148516143799134,
        0.18593943972380603,
        0.014158738965573663,
        0.1658324951985621,
        -0.16177333147254014,
        0.49842875838089123,
        -0.4101648492430243,
        -0.15062452538261367,
        0.20809314419985256,
        -0.15757786211864208,
        0.2129101554127071
      ],
      [
        0.16990011324303603,
        -0.030674414747776386,
        0.07705626450017385,
        -0.1282841315361929,
        -0.2498056422759748,
        0.4892487064480128,
        0.021019337760240498,
        0.6403074223785177,
        -0.1308982041579789,
        0.28238572307621135,
        -0.07232422060746711,
        0.40885092388679206,
        0.11124500237490614,
        -0.22124402046216046,
        0.1647225338942809,
        0.515373457362272
      ],
      [
        0.0010938218403108231,
        0.018862872928534946,
        -0.4251355668941471,
        -0.34298854008816704,
        -0.16192211114572844,
        0.22351830128644493,
        -0.08265943931241482,
        -0.5631452604709067,
        0.1966284099061004,
        -0.1655355664002302,
        -0.2522418445707861,
        0.13301277826306288,
        -0.5963222715948734,
        0.14274625343521033,
        -0.09959459196230823,
        -0.1843369016173763
      ],
      [
        -0.11125388568616443,
        -0.2186631150075775,
        0.19775843000242427,
        -0.17573696767745872,
        0.569924670998618,
        -0.3576949893864332,
        0.31408326046254254,
        0.14319730866797975,
        0.1471703060304145,
        0.1012782945921741,
        0.18535863960074453,
        -0.4495394361553707,
        -0.03642557186210214,
        -0.13298326094420793,
        -0.42144329517770884,
        -0.12047570891002768
      ],
      [
        -0.03520383707268398,
        -0.15770511684253607,
        -0.09174178207842627,
        0.13918573941651732,
        0.07736099309349853,
        0.5256677079606458,
        -0.05386591365214801,
        0.5633578791646268,
        0.2678909628934219,
        0.20264572375739598,
        -0.4762916587422158,
        0.3537944015522467,
        0.24324315990448475,
        0.01683036788243891,
        0.15529917597378023,
        0.3596469059348037
      ],
      [
        0.0699387666911937,
        0.06938641702720422,
        -0.5144765994613565,
        -0.10500684811459922,
        -0.3865305465887182,
        0.2765352059750092,
        -0.12310480617842567,
        -0.31426385172761273,
        -0.16096114247313797,
        -0.041523182073523755,
        -0.1160075467423956,
        -0.2781683343498991,
        -0.11097117481314205,
        0.022877442769610703,
        -0.1955981435085848,
        -0.6100369149570393
      ],
      [
        0.027337928998690985,
        -0.2655079507551158,
        0.01268077695623044,
        -0.004890046964386783,
        0.6026472176803573,
        -0.314417037399575,
        0.14235748961564312,
        -0.18358813455177522,
        0.3269089982680679,
        0.138343553866978,
        0.34918262948802786,
        -0.08885317525914431,
        0.26303699724040447,
        0.06885789219412736,
        0.008831982997175762,
        -0.023815445617883454
      ],
      [
        -0.23697743091713405,
        0.24160349197489883,
        -0.28753963476497085,
        0.03976801079140167,
        -0.03721562868686691,
        0.07889268871375354,
        0.08246056929783262,
        0.3533988560970871,
        -0.10313670769352272,
        0.09442882358091817,
        -0.10734237790299056,
        0.3971464407714076,
        0.24523648066256176,
        -0.1587499296491752,
        -0.3167258574877809,
        0.026786219982369654
      ],
      [
        0.22211428473476164,
        0.046516986774286305,
        -0.15516554654976783,
        0.2659085827094364,
        -0.36315587058635035,
        -0.15484831358812395,
        -0.12354990230847188,
        -0.13972437209902977,
        -0.1332807877337162,
        -0.11325239918910233,
        -0.3644093240100865,
        0.09919862886828627,
        0.028915101549798507,
        -0.06251626671570502,
        0.03481219180058497,
        -0.4073888451739285
      ]
    ],
    "Wp": [
      [
        -0.06318739964585304,
        0.24302845149713753
      ],
      [
        -0.1450622723241587,
        0.6305382767323502
      ],
      [
        0.09537335982497785,
        -0.13643842847735752
      ],
      [
        -0.02016108110416795,
        0.09365685973471888
      ],
      [
        0.4910908862697083,
        -0.6039030404552447
      ],
      [
        -0.7462528123645183,
        1.1825729410982198
      ],
      [
        0.035773535166043424,
        -0.4513705861817053
      ],
      [
        -0.4968676184801339,
        0.5027103966734857
      ],
      [
        0.2084786526089004,
        -0.03770767955352524
      ],
      [
        -0.018272968253217493,
        0.1869841947338602
      ],
      [
        0.1752677860783627,
        -0.4684111495342905
      ],
      [
        -0.7279894366072744,
        0.29669265131020667
      ],
      [
        0.09844114982795371,
        0.4563014067370567
      ],
      [
        -0.12044700717205023,
        -0.36338702117225624
      ],
      [
        -0.5826328044975285,
        0.04034045959069854
      ],
      [
        -0.8522413674674791,
        0.009019146170280665
      ]
    ],
    "bp": [
      -0.06613283285175399,
      0.06613283285175399
    ],
    "Wv": [
      -0.09959805459366877,
      -0.4071486105736086,
      0.6031852761576603,
      0.3318918021801824,
      0.8269519813731916,
      0.032876475446523355,
      0.2494077201010218,
      1.3628112644804942,
      0.054320949071008075,
      -0.03980885123834307,
      0.4066765909924753,
      0.14812771795386667,
      0.7089824235993732,
      -0.15202755650869626,
      -0.091970231889798,
      0.9088091688543142
    ],
    "bv": [
      0.3870338048515593
    ]
  }
}

Full validation retains seeds 0–7; the article program prints seed 0 by default. Before training, direct-policy wrong-state counts across the 12 test states are 4, 4, 5, 5, 4, 4, 4, 4; adding 24 simulations changes them to 2, 2, 2, 0, 2, 2, 2, 1. After training, both raw and searched policies make no wrong choices for all eight seeds. A forced-loss multiple of 3 is not counted as wrong just because it cannot be won: all actions have the same optimal outcome.

Every seed plays 240 games, but real move counts differ: 1,070, 1,041, 1,003, 1,050, 1,038, 1,014, 1,016 and 1,085. Training simulations equal each count times 24; all runs have 480 gradient updates. These results concern a tiny known-rule task, training coverage of these counts and independent modulo-3 evaluation. They establish neither arbitrary-size subtraction play nor the paper’s board-game strength.

Analytical gradients for all 259 parameters were checked by finite differences. Legal masks, terminal signs, visit budgets, root noise leaving model weights unchanged, evaluation leaving training state unchanged and all eight seeds were also checked. The program lacks parallel self-play, convolutional residual blocks, batched leaf inference, transposition tables and chess rules. It cannot be compared directly with the paper’s hardware or match scores.

With TT real moves per game, BB simulations per search and at most one new leaf per simulation, neural evaluations grow roughly with TBTB, plus internal tree-selection work. Learning costs depend on update count, batch size and model parameters. Replay turns expensive searches into reusable targets, without making target generation free.

Self-play can share a mistake

Having both sides generated by the current system does not ensure that every weakness is found. Policy priors can discourage checking some actions, leaf-value errors can be reused by search, and old replay can differ from new-policy positions. A search distribution is a finite computation’s output, not an automatically correct teacher label.

When the paper discusses MCTS averaging potentially canceling some network errors, the authors frame it as speculation. It is not a theorem that averaging is always safer than minimax: errors in the same direction can survive together. Qualified methodological discussion

Evaluation needs specified rules, starting positions, opponent versions, thinking budgets and randomness. Training uses root noise and self-play sampling; evaluation removes noise and selects most-visited actions. Combining them into an unexplained win rate obscures the comparison. Fixed OpenSpiel documentation also identifies the project as an illustrative reimplementation, not code used for the original paper’s matches. Mature projects can still have documentation that lags their current implementation. Project scope

Three different distributions

  1. Understanding: The network prior is 0.5, 0.5 and search counts are 30, 10. At temperature 1, what target does the policy head receive? Is it the prior?

    Answer: The target is 0.75, 0.25. Visits after search differ from its input prior. The target stays fixed during the gradient update; visit counts are not differentiated.

  2. Calculation: Win, draw and loss probabilities are 0.4, 0.4 and 0.2. What is expected outcome? Can it be converted into a 0.6 win probability?

    Answer: Expected outcome is 0.4−0.2=0.20.4-0.2=0.2, while win probability remains 0.4. The conversion (v+1)/2(v+1)/2 equals win probability only under a binary win/loss convention without draws.

  3. Boundary: One stone remains and both logits are zero. You obtain 0.5, 0.5 over both actions, delete the illegal action and do not renormalize. What breaks?

    Answer: Remaining probability sums to only 0.5 and is no longer an action distribution. The sole legal move needs probability 1; illegal moves must receive neither policy targets nor sampling probability.

  4. Transfer: Your network predicts the first player’s outcome, but search treats every evaluation as the current player’s value and negates each level. How should this be repaired?

    Answer: Choose one consistent convention. Keep first-player values and select the correct player’s payoff during selection/backup, or convert both targets and predictions to current-player values. Do not omit or duplicate the sign conversion.

AlphaZero and AlphaGo Zero differ beyond their names

We use UCL’s accepted 2018 AlphaZero manuscript, reading PDF pages 2, 3 and 16–19 plus first-page identity/abstract, and visually inspecting page 17. The paper discusses expected outcomes with draws, dropping Go rotation/reflection augmentation and search transformations, and continually updating one network rather than the earlier promotion scheme. It still receives rules, legal moves and representation structure. Learning from self-play does not eliminate task interfaces or design choices. We did not reproduce matches or audit every experimental table. Accepted manuscript

Implementation comparisons use OpenSpiel commit 48401890ee9857e611678302371378175a8e4c6b. Reading covers specified self-play-loop sections, all 80 evaluator lines, all 91 subdirectory README lines and the first 87 old documentation lines. Old TF1 documentation is kept separate from current JAX/Flax code; its installation description is not our runtime. Our program is original, without upstream execution or copying. Fixed implementation

Revisit MCTS for simulation allocation and player perspectives. Continue to MuZero to ask what model should be learned when search cannot call exact real transition rules.

Make a prediction, then check

What target does an AlphaZero policy head usually learn from?

Choose one answer

Learning objectives

  • Generate policy targets with PUCT and pair states with the correct player’s terminal outcome.
  • Separate root noise, visit temperature and evaluation rules, and explain the role of known game rules.

Prerequisites & connections

Explore related knowledge →

References

  1. A general reinforcement learning algorithm that masters chess, shogi, and Go through self-play — accepted manuscript
    David Silver; Thomas Hubert; Julian Schrittwieser; Ioannis Antonoglou; Matthew Lai; Arthur Guez; Marc Lanctot; Laurent Sifre; Dharshan Kumaran; Thore Graepel; Timothy Lillicrap; Karen Simonyan; Demis Hassabis · 2018
  2. OpenSpiel AlphaZero — fixed self-play loop and evaluator
    Google DeepMind; OpenSpiel contributors · 2026

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-23 · Single AI author. Scoped reading: UCL identifies an accepted manuscript, not publisher layout. Read PDF2/3/16–19 and first-page identity/abstract, viewed17: rule knowledge, PUCT, targets, noise/evaluation and differences from AlphaGo Zero. Error cancellation is author speculation; no full match-table audit or playing-strength replication. Read loop185–267/435–472, all80 evaluator lines, all91 subdirectory README lines and old docs1–87. Current JAX/Flax differs from old TF1 docs; first-player value becomes a two-player vector, unlike a current-player target convention. Not original paper code; no copying/execution. 8 paired equations and four explained exercises. Known-rule PUCT, legal masking, root noise, temperature targets and current-player returns checked. All259 parameter derivatives and eight complete self-play runs checked; separate real moves and480 updates recorded. Tiny no-draw game, fixed exploration coefficient and ordinary-parameter derivative checks do not reproduce board-game strength.

  • Known-rule PUCT, legal masking, root noise, temperature targets and current-player returns checked. All259 parameter derivatives and eight complete self-play runs checked; separate real moves and480 updates recorded. Tiny no-draw game, fixed exploration coefficient and ordinary-parameter derivative checks do not reproduce board-game strength.
  • Four computed SVG variants per topic;9 numeric/geometry tests and18 current responsive cases passed. All nine selected current captures directly viewed; separated visit counts and signed values correct the retained initial color-scale failure. Actual assets and manuscripts are SHA bound. Full article acceptance recorded separately.

Source locations checked:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.