Any interest in an improved parser?

A while back, I added some hacks to the standard Inform 6 parser to fix various issues with it (or things I considered to be issues, at least). I’m not referring to simply adding new verbs or tokens here, but slightly more low-level stuff like having the parser try all lines of grammar for a given verb before returning an error. My last game was in Inform 7, which makes it much harder to get at lower-level features, and so I put those changes back on the drawing board.

Is there any interest, though, in revising the parser for Inform? I get the impression from reading various IF blogs that the consensus is that this is an inherent problem with parser-based text-adventures, and the options are just to accept it as an inherent limitation or to switch to a choice-based approach. I’m not sure how representative those blogs are, though, so: Is this an active problem in IF that people care about, or is it just something that we’re resigned to?

I also like the idea in princple of using machine learning to solve the general parsing problem, but it’s very difficult to pull off in practice. The scope of the problem is broad even if restricting to a IF settings, and it’s tricky to ensure predictability in the system output.

1 Like

I think that there has been a lot of room for new explorations in the Inform6 standard library lately. We have PunyInform, for example, showing that there’s demand for I6 games that use different underlying core behaviours to meet specific needs.

I think that coming up with a different pattern-matching strategy for verb rules could be an interesting exercise, if nothing else.

2 Likes

Dialog does this, right? It’s certainly not an inherent limitation of parser IF.

1 Like

That part definitely isn’t an inherent limitation; like I said, I have a hack in my local version of Inform 6 to do just that. I was referring to the idea that wrestling with the parser is just an inherent part of parser IF, in the same way that we’re certainly not at the point of technology where, say, Amazon Echo can be trusted to always correctly interpret voice commands.

This kind of thing is what interests me right now, although not in the context of Inform :slightly_smiling_face:.

There are scientists and there are synthesists. In other words; theoreticians, and those who make implementations.

Is there anyone here who can access academic papers without paying for them?
I am tantalised by this from a 2018 paper:

Our results argue for a generative mechanism that assigns new meanings a specific place in a rich inferential typology, which might have consequences for the structure of semantic theory and the nature of acquisition algorithms.

It’s just that I think you need to be a researcher to get a copy of the details.

Just in case it’s not clear what I’m talking about :laughing:
A parser will spot the structural differences between these phrases:

  • shrug shoulders
  • shrug it off

But the interpretation of meaning will require an understanding of the social significance of the gesture.

1 Like

Very often you can get articles directly from the researchers’ homepages. It’s fairly common that they upload pre-print versions there (which are nearly identical to the published versions in the journals, except for layout and minor details). Or if that fails, write a friendly email.

In this case, we’re lucky:

Homepage: PHILIPPE SCHLENKER - ARTICLES

Linked article:

PDF download: Gestural Semantics - lingbuzz/003485

Online view: Gestural semantics

6 Likes

Thank you. What I can’t quite understand is why these researchers don’t use IF as a laboratory for their work.

1 Like

Not knowing the internals of I6; how easy would it be to completely replace the existing parser with a new one. Say something new, from the ground up?

An important point here, is that when you talk of a “parser” for IF, you’re really talking about the whole syntax+semantics problem. Thinking of an IF parser in terms of grammar and syntax alone is only the tip of the iceberg.

So a replacement “parser” would also need access to the world model for semantic resolution as well as the currently referenced scope.

2 Likes

Bodily replacing the I6 parser is feasible but nontrivial. The I6 parser code is, to be frank, almost illegible in places, with a complicated series of goto statements, no real indication of what state exactly it’s keeping between the different functions, and functions that aren’t normally encountered in developing an I6 game and don’t have much documentation in the Inform Design Manual.

As for resolving the semantic content of commands, that’s actually not that bad with such a restricted grammar and world model. The general problem of parsing natural language is certainly very hard; I’ve given up on finding any consistency in what the I7 compiler expects, for example, and that’s geared towards a very specific task. On the other hand, the default I6 library of verbs is pretty straightforward in syntax and scope (at least, if you’re not getting into topics and other loosely constrained input), and we’re usually just looking at imperative sentences that have no adverbs, only a few heavily constrained prepositional phrases, no subordinate clauses, a few heavily constrained pronouns, refer only to things in scope, etc. It’s certainly not easy, but it’s not impossible.

Ultimately, the point of the parser is to take text from the user and turn it into a function that acts on the world state, and there aren’t that many of those functions for a given game. I wouldn’t want to take on the task of modeling conversation with this sort of parser, but it’s not incredibly daunting to work out a way for a user to interact with a Zork-style environment.

1 Like

For whatever it’s worth, I’ve done a bit of ML research in my real-life career, but I haven’t really seen anything in my own studies that would apply to something like this just out of the box. One of the main problems is that you want the user to be reasonably confident that their commands will be parsed correctly. For predictive text on a cell phone, for example, you can also train on a large corpus of text, but ultimately you’re suggesting something to the user that they can use or ignore. If a player tries to KILL TROLL WITH AXE and instead winds up trying to kill the axe with the troll, they’re going be justifiably annoyed. There are ways of solving this problem in ML, but they tend to far more time and effort beyond the coding level, and you’re still unlikely to wind up with something that is foolproof for simple, expected commands. I think this sort of thing is probably the long-term solution to improving parsing in IF, but I’m doubtful it’s feasible for what’s at least for most people a hobby rather than a full-time job.

1 Like

Copy that. I wish 1% of the people consuming Netflix daily would allocate some time to maybe creating something. Cos we are thin on the ground right now. :confused:

1 Like

Difficult to say. Academia and commercial development often follow different paths (in cases where the latter isn’t helping to fund the former), but a lot of IF these days is not commercial. The specific case of academic study of IF being separate from IF as people like us practise it has existed for decades (it’s not even clear if the Eastgate school in 1987 was the first example ) . Although some recent work has been done to use IF for teaching purposes (particularly for material typically taught before university), I haven’t seen much evidence of academia using it to assist their research or help communicate similarly advanced concepts.

1 Like

A while back whilst thinking about parsers, i started looking into the “sister” problem of, general knowledge representation.

Amazingly, i can find hardly anything on this topic, academic or otherwise. ie the general representation of knowledge.

Yes, there have been some minor attempts at some of the domain, but nothing really solid. Usually, people start talking about conceptual graphs and that sort of thing, but all these systems have serious drawbacks. Notably anything based on first order logic, is bound to fail. That’s because you need a system that can accommodate contradictions.

How to represent knowledge is important to parsing because the output of the parser is not a function but a knowledge statement, irrespective of whether the input is imperative.

So i realised, in my search for parsing that you have to start by thinking about how to represent information, and only then move onto how to parse it.

3 Likes

Yes, and at the right level of abstraction.

What does it mean to say, make the tea? You may model an entire kitchen, with mugs and milk and teabags, and kettles which heat water incrementally. And have a system where boiling water causes other things to get wet and hot.

But even if you do that, the reference tea does not relate to teabags. It is a reference to a process of creating an infusion of tea, in as many mugs and with sufficient milk as to be acceptable to the recipients.

So the knowledge model has to embrace social contracts, which we might think of as promises or gestures rather than physical objects.

1 Like

This brings back some old memories…

Many years ago, I and several fellow employees were writing an adventure game. ( The sysadmin liked to play them, so we were very quietly allocated lots of processor time and lots of disk space )

To manipulate objects, we used bit arrays. Each object had a number, and a corresponding location in arrays. This meant that any adjective could be treated as an array,

For example if the brass lantern was the third object, and the brass dagger was the fifth object, then the concept of ‘brass’ was represented by flipping the third and fifth bits in an array, like this: 0010100000.
( I’m using a mere 10 digits for clarity here. In practice we used 64 bits. That was enough objects for a challenging game )

A silver dagger might be the second object. Thus the word ‘dagger’ would be represented by flipping the second bit and the fifth bit ( 010010000 ).

To parse the noun portion of a sentence, we simply bitwise ANDed the appropriate arrays. IOW, when the player typed ‘brass dagger’, we pulled up the corresponding arrays for the words ‘brass’ and ‘dagger’ ( 0010100000 and 010010000 ) performed a bitwise AND operation on them ( which resulted in 000010000 ) and we had a unique index into our array of objects.

We began to slowly realize that there was no fundamental difference between nouns and adjectives. The noun ‘dagger’ was essentially an adjective that meant daggerlike objects. It was an array of bits.

This was followed by the realization that a list of objects in a particular room was also functionally the same: an array of bits noting all-the-objects-in-the-octagonal-room was functionally just another adjective.

This representation as bit arrays allows for some fast parsing and realistic conversations. If the player said GET DAGGER, we could simply AND the array for dagger with the array of objects in the current room.
If the result was an array with no bits set, we could echo I SEE NO DAGGER HERE.
If the result was an array with only one bit set, it allowed us to recognize a unique object.
If there were multiple daggers in the room, the resulting array would have more than one bit set, each bit could be used as an index to an array of objects, and it was easy to generate the question DO YOU MEAN THE BRASS DAGGER OR THE SILVER DAGGER?
When the player answered that with one word, we ANDed his reply to get an array with only one bit set which allowed us to recognize a unique object.

Another use was the ‘reasonableness’ arrays, one for each verb. IOW, every verb had a corresponding bit array of objects for which it was unreasonable to try to parse. So it was quick and easy to generate an error message like YOU CANNOT DRINK A DAGGER.

So far, this is simple, and there are no unexpected behaviors. Every reference to an object is turned into a bit array. We can parse the player’s reference to any object in the cave, and even have limited conversations about those objects.

Our success with bit arrays led us to try to represent knowledge - not in the absolute sense, but what particular characters know.
For example, the troll might know about the silver dagger but not the brass dagger. What-the-troll-knows was another adjective, represented as bits.
When the player asks the troll about daggers, the troll might reply THE BRASS DAGGER WILL NOT PIERCE DRAGON HIDE. The troll can’t say that the silver dagger can do the job, because he doesn’t know.

This naturally led to concealed knowledge, and thus to lying. There could be a bit array called what-the-troll-will-reveal. The troll might know about the silver dagger, but won’t say so.
If the player bribes the troll with a few zorkmids, this is documented in flipping a few bits in the array.
Then, when asked, the troll reveals what he knows.

We soon found out that we needed an array for what objects the player knows. Otherwise, a clever player will say LOOK FOR WAND. ( When outdoors, the verb ‘look’ cannot easily be constrained by the list of objects in the immediate room. )
A gullible parser will then ask DO YOU MEAN THE SILVER WAND OR THE BLUE WAND? This tells the player that wands do indeed exist, and what colors they are.
A better parser will have an array of bits labeled what-the-player-knows. It will reply WANDS? IVE NEVER HEARD OF THEM.

This soon leads into states of mind and associated cognitive quagmires. We tried arrays like what-the-player-wants, which was natural enough. A slight grasp of storytelling structure led us to try what-the-player-needs. That led us to inadvertently make the parser goal oriented, which, of course, was a mistake.

In summary, we learned that some knowledge can be represented in simple bit arrays, and they give surprisingly good results - as long as they are kept to simple concepts. More complicated concepts require more complicated forms of storing knowledge.

7 Likes

Holy cow, this is totally sick! But i like it :slight_smile:

Thanks for posting this idea.

What you’ve really got is a compact way of managing property lists. For small games, with limited objects, i agree a bit array can be a compact way to represent a list.

You’re right about adjectives and nouns, they’re the same thing really. Nouns can work as adjectives as well as adjectives as nouns. The idea of a set union for resolution is interesting. Usually, you’d have a list of adjectives and a list of nouns per object. Mainly because you might want to stop things like “get the red” from resolving to red things and also so you know to use a noun to textify the object name.

Things you can refer to depends on the verb and this is the current scope. Usually this would be a list, but your bit array would indeed work for small games.

Accidentally revealing objects that exist elsewhere is a good one. ASK X ABOUT Y would not bind Y to to interactive scope, so ASK WIZARD ABOUT WAND could run the risk of revealing the wands in the game. Systems need a method for this.

1 Like