May 01, 2025

Grid annotation game to demonstrate grounded language

0 [ ][ ][7][ ][ ][ ]   annotation: ['center', 'greater5', 'odd']
1 [ ][ ][ ][ ][ ][2]   annotation: ['right', 'smaller5', 'even']
2 [ ][0][ ][ ][ ][ ]   annotation: ['left', 'smaller5', 'even']
3 [ ][3][ ][ ][ ][ ]   annotation: ['left', 'smaller5', 'odd']

 

The symbol grounding problem is a major challenge in Artificial Intelligence because it allows to reduce the state space of games drastically. A beginner friendly example consists of a grid filled with random numbers and the computer has to find the correct semantic annotation.

For example, if the number occurs on the left, the correct tagging would be [left]. In other words, the AI Commentator translates the current scene into textual description. The textual output of the computer is realized with [tags]. These tags are similar to the word2vec model and describing the situation in a simplified mathematical state space.

 
The source code can be realized in around 30 lines of code in Python. 

 import random

class Game:
  def __init__(self):
    for trial in range(4):
      self.newrnd()
      print(trial,self.getgrid(),"  annotation:",self.gettag())
  def newrnd(self): # new random number
    self.pos=random.randint(0,5)
    self.value=random.randint(0,9)
  def getgrid(self):
    result=""
    for i in range(6):
      if i==self.pos:
        temp=str(self.value)
      else:
        temp=' '
      result+="["+temp+"]"
    return result
  def gettag(self): # tagging
    result=[]
    # position
    if self.pos<2: result.append("left")
    elif self.pos<4: result.append("center")
    elif self.pos<6: result.append("right")
    # value range
    if self.value<=5: result.append("smaller5")
    elif self.value>5: result.append("greater5")
    # odd
    if self.value%2==0: result.append("even")
    else: result.append("odd")
    return (result)

if __name__ == '__main__':
  g=Game()

No comments:

Post a Comment