How AI Language Models Work ยท Inside a Language Model
A model reads only a fixed number of tokens at once. As a chat grows, the oldest words fall out of the window, and the model can no longer see them.
# A model can only read a fixed number of tokens at once: its context window.
window = 6
chat = []
for message in ["my name is asha", "i like tea", "what is my name"]:
chat += message.split(" ")
seen = chat[-window:] # anything older falls out of the window
print(seen)
remembers = "asha" in seen
print("can it still see the name?", remembers)['my', 'name', 'is', 'asha'].message changes from 'my name is asha' to 'i like tea'.['name', 'is', 'asha', 'i', 'like', 'tea'].message changes from 'i like tea' to 'what is my name'.['like', 'tea', 'what', 'is', 'my', 'name'].for message in ["my name is asha", "i like tea", "what is my name"].