def _make_bert_vocab_productions(vocab: Collection[str]) -> List[str]:
  """Generates productions for the `unconstrained` vocabulary setting.

  To ensure that non-initial word-pieces never begin a word, we use a grammar
  corresponding to the following rule:

    Word -->  InitialWordPiece (NonInitialWordPiece)*

  We use the following non-terminals:

    _W_:   corresponds to `Word`
    _Vsh_: pre-terminal corresponidng to `NonInitialWordPiece`
    _Vw_:  pre-terminal corresponding to `InitialWordPiece`
    _W-_:  helper non-terminal, implementing the generation of
           `NonInitialWordPiece`s.


  Args:
    vocab:  Iterable comprising all valid terminals.  This spans both wordpieces
      and `full` words.

  Returns:
    A list of productions in textual form which jointly define the "vocabulary"
    part of a grammar that expands the _W_(ord) non-terminal to terminal symbols
    in `vocab`.
  """

  productions = []

  productions.append('_W_ -> _Vw_ _W-_')
  productions.append('_W_ -> _Vw_')
  productions.append('_W-_ -> _Vsh_')
  productions.append('_W-_ -> _Vsh_ _W-_')

  for word in vocab:
    word = state_tree.NQStateTree.clean_escape_characters(word)
    if word.startswith('##'):
      productions.append("_Vsh_ -> '{}'".format(word))
    else:
      # No point in having the agent generate these "fake" tokens.
      if word.startswith('[unused') or word in ('[pos]', '[neg]', '[contents]',
                                                '[title]', '[UNK]', '[PAD]',
                                                '[SEP]', '[CLS]', '[MASK]'):
        continue
      productions.append("_Vw_ -> '{}'".format(word))

  return productions
Generates productions for the `unconstrained` vocabulary setting.

  To ensure that non-initial word-pieces never begin a word, we use a grammar
  corresponding to the following rule:

    Word -->  InitialWordPiece (NonInitialWordPiece)*

  We use the following non-terminals:

    _W_:   corresponds to `Word`
    _Vsh_: pre-terminal corresponidng to `NonInitialWordPiece`
    _Vw_:  pre-terminal corresponding to `InitialWordPiece`
    _W-_:  helper non-terminal, implementing the generation of
           `NonInitialWordPiece`s.


  Args:
    vocab:  Iterable comprising all valid terminals.  This spans both wordpieces
      and `full` words.

  Returns:
    A list of productions in textual form which jointly define the "vocabulary"
    part of a grammar that expands the _W_(ord) non-terminal to terminal symbols
    in `vocab`.
  
language/search_agents/muzero/grammar_lib.py