Sabe lo que piensas, con sólo unas preguntas es capaz de adivinar el personaje en el que has pensado.
¿Te atreves?
Algunos conoceréis el juego Akinator, en el que un genio es capaz de adivinar el personaje en el que has pensado, mientras respondes «sí» o «no» a unas simples preguntas.
No hay una IA analizando tus redes sociales, No hay micrófonos escuchando... ¿Y cómo lo hace?
El secreto es un sencillo algoritmo y mucha gente jugando y alimentando la base de datos.
¿Cómo funciona?
Definamos un término: Nodo.
Un nodo puede ser una pregunta o el nombre del personaje.
Si es una pregunta, tendrá dos respuestas: Sí o No.
Ahora vamos a darle un valor.
A la pregunta le daremos el Id 1, a la respuesta afirmativa, le daremos el Id 2 y a la respuesta negativa, el Id 3.
Ahora imaginemos que tanto la respuesta afirmativa como la negativa devuelven otra pregunta, con los personajes correspondientes para «sí» y «no».
Podemos ver un patrón entre las preguntas y las respuestas.
Las respuestas afirmativas son el doble del identificador de la pregunta, y las negativas son el doble del identificador de la pregunta más uno.
Entonces, si tenemos el nodo n, el siguiente nodo a mostrar será el nodo n*2 si la respuesta es "sí" o el nodo (n*2)+1 si la respuesta es "no".
Pongamos un ejemplo:
Supongamos que pienso en Snoopy, y la pregunta es «¿Tu personaje es ficticio?», la respuesta “sí” nos dirá que el personaje en el que hemos pensado es «Superman», pero no es correcta.
¿Cómo convertimos nuestra respuesta en una pregunta que nos lleve a Snoopy?
Necesitamos una característica que nos diferencie de Superman, en este caso preguntaremos «¿Tu personaje es un perro?», entonces, la respuesta afirmativa sería “Snoopy” y la negativa «Superman».
Esta nueva pregunta sustituirá el Id del nodo «Superman», el personaje “Snoopy” tendrá el doble del nodo de la nueva pregunta y el personaje «Superman» tendrá el doble del nodo de la nueva pregunta más uno.
De este modo, si creamos muchas preguntas y respuestas, nuestro Iris-nator podrá adivinar cualquier personaje que se te haya ocurrido.
¿Cómo funciona Iris-nator?
Crear una tabla con información de los nodos:
Class Irisnator.Data.Nodes Extends%Persistent
{
/// NodeIdProperty NodeId As%Numeric;/// Text of the nodeProperty Text As%String(MAXLEN = "");/// Type of node (0 = text, 1 = question)Property Question As%Boolean [ InitialExpression = 0 ];/// Verb of the questionProperty Verb As%String(MAXLEN = "");
}
Nota: ¿Por qué hay un campo llamado «verbo»? porque está pensado para responder en inglés, la pregunta se muestra como {verbo} su personaje {texto} ? por lo tanto, necesita saber cual es el verbo (is, had, does, etc...) que va al inicio de la frase.
El front-end está creado con Angular19, para comunicarme con IRIS, he creado varios métodos API:
GET localhost:52773/irisnator/api/node/:nodeId
Devuelve la información sobre el nodo, también el NodId para la respuesta Sí y No
Cuando Iris-nator no ha sido capaz de adivinar tu personaje, rellenamos un formulario con los datos del nuevo personaje, y cuál sería la pregunta a realizar para diferenciarlo del personaje al que había llegado.
Entonces, movemos el personaje actual a respuesta «no», y ponemos el id a la nueva pregunta.
He knows what you think, with just a few questions he is able to guess the character you have thought of.
Do you dare?
Some of you may know the game Akinator, where a genie is able to guess the character you have thought of, while you answer “yes” or “no” to a simple question.
No AI analyzing your social networks, no microphones listening in... So how does it do it?
The secret is a simple algorithm and a lot of people playing and feeding the database.
How does it work?
Let's define a term: Node.
A node can be a question or the name of the character.
If it is a question, it will have two answers: Yes or No.
Now let's give it a value.
To the question we will give the Id 1, to the affirmative answer, we will give the Id 2 and to the negative answer, the Id 3.
Now let's imagine that both the affirmative and negative answers return another question, with corresponding characters for “yes” and “no”.
We can see a pattern between the questions and the answers.
Affirmative answers are twice the question identifier, and negative answers are twice the question identifier plus one.
Then, if we have the node n, the next node to display will be node n*2 if the answer is "yes" or node (n*2)+1 if the anser is "no".
Let's give an example:
Suppose I think of Snoopy, and the question is "Is your character fictional?", the answer "yes" will tell us that the character we have thought of is "Superman", but it is not correct.
How do we turn our answer into a question that leads us to Snoopy?
We need a characteristic that differentiates us from Superman, in this case we will ask “Is your character a dog?”, then, the affirmative answer would be ‘Snoopy’ and the negative answer would be “Superman”.
This new question will replace the Id of the node “Superman”, the character “Snoopy” will have the double of the node of the new question and the character "Superman" will have the double of the node of the new question plus one.
This way, if we create a lot of questions and answers, our Iris-nator will be able to guess any character you have thought of.
How does Iris-nator works?
Create a table with information of nodes:
Class Irisnator.Data.Nodes Extends%Persistent
{
/// NodeIdProperty NodeId As%Numeric;/// Text of the nodeProperty Text As%String(MAXLEN = "");/// Type of node (0 = text, 1 = question)Property Question As%Boolean [ InitialExpression = 0 ];/// Verb of the questionProperty Verb As%String(MAXLEN = "");
}
Note: Why is there a field called "verb"? because, the question is shown as {verb} your character {text} ? therefore, it needs to know what is the verb (is, had, does, etc...)
The front-end is created with Angular19, to communicate with IRIS, I have created several API methods:
GET localhost:52773/irisnator/api/node/:nodeId
Returns the information about the node, also the NodId for answer Yes and No
When Iris-nator has not been able to guess your character, we fill in a form with the data of the new character, and what would be the question to ask to differentiate him/her from the character he/she had arrived at.
Then, move the current character to "no" answer, and put the id to the new question.