How does ERG's demo handle out-of-vocabulary words?

Hi everyone, I am Chia-Hsiang Hsu, a master’s student at UW who has taken LING 567. My recent aim regarding HPSG is to build a more realistic grammar of Kalaallisut (West Greenlandic, ISO 639-3: kal) than the toy grammar in the course, and I now have an IGT corpus of around 1,500 sentences to work with.

My current question is: How does the ERG demo handle out-of-vocabulary words, such as proper nouns and large numbers? I’ve noticed that the downloaded version of ERG-2025 does not employ this function – there will be no parses for sentences like “Abrahamingtonsfled hired two competent programmers” in my local VM, but I do get parses on the demo.

I think I’m facing a similar issue – there are many place and person names showing up only once or twice in my corpus, and putting them into the lexicon does not seem wise. Is that handled inside the grammar (I mean the TDL files) or outside (like a morphological analyzer or some frontend code)? I suspect that I need to write something here for it to work:

Update: I find that probably the parser lies in the following url from resource.js, but I still have no idea what that parser is doing.

    'erg2018-uw': {
        grammar: 'ERG 2018',
        lang: 'eng',
        server: 'pydelphin',
        location: 'UW',
        url: 'https://chimpanzee.ling.washington.edu/bottlenose/erg-2018/parse',
        inputs: ['Abrams knew that it rained.']
    },

Hi Alex,

It’s been a while so I forget some of the details, but basically you configure the grammar to classify and associate unknown words with generic feature structures with a process called “token mapping”. So you might have better luck searching the wiki for terms like “generic”, “token mapping”, or “chart mapping” (I think token mapping is an application of chart mapping). For instance, I found these, but they look like they are for the PET processor instead of ACE or the LKB:

You can also see the relevant ACE config parameters here: AceConfiguration (scroll down to the “Token Mapping” section).

Here is the relevant section in the ERG’s default ace/config.tdl:

I think the grammar also needs to be compiled with a part-of-speech tagger for this to work.

The METADATA file is, as I recall, only for documentation and would not affect how the grammar is compiled or used. The resource.json file is for the client side of the web demo of the grammars. The server side accepts requests to those URLs and processes them with the appropriate grammar. Whether the grammar parses unknown words or not depends on how the grammar was compiled.

Sorry I don’t have a direct answer for you, but hopefully the above will help steer you toward one.

The ERG uses a combination of strategies for introducing lexical entries for unknown words, employing a part-of-speech tagger along with a regular-expression pre-processor and so-called token-mapping rules as #goodmami observed. For unknown proper names, a lexical entry is proposed whenever there is a (non-initial) capitalized word in the sentence. For other ordinary unknown open-class words (nouns, verbs, adjectives, adverbs), we use the POS tagger to guide the addition of lexical entries. For words that serve as units of measure (“22km”) or dates (“09-09-2025”) or other productive patterns, we use token-mapping rules to add appropriate lexical entries. These facilities are always active, whether the parsing engine you are using is ACE, PET, or the LKB, but of course each of these facilities is less than perfect, so you may well run into instances where the parser does not do what you expect. You’ll find a description of the mechanisms in this paper:

https://aclanthology.org/L08-1024/

I don’t have a good guess about why your VM version using the 2018 ERG grammar and (presumably) the ACE parser behaves differently from the demo, so some additional testing of your VM system might be need to track down the relevant differences in configuration. But if your main aim is to enable treatment of unknown tokens in your Kalaallisut grammar, maybe you can set aside that question. You would need to add some files to your grammar in order to get chart-mapping to work, We don’t have a good “recipe” page for how to add this facility to a Matrix grammar, but I can point you to one example where I did the minimum additions to add punctuation to a grammar of Portuguese which you’ll find in Github:

You can also browse the ERG’s files to see how the machinery works. The erg/ace/config.tdl file sets the (regular expression) “preprocessor” and “preprocessor-modules” with relevant files in the erg/rpp directory. This config file also sets the “english-pos-tagger” to use the one built into ACE, but you can instead specify an external tagger as you would have to for any language other than English. And the config file sets the “token-mapping” and related token paths to enable the facility. The token mapping rules are loaded via the file erg/english.tdl, starting with the file “tmt.tdl”. I would start by simply copying this file to your grammar, and then see how you might adapt it and variants of the rule defintiions in the files in erg/tmr.

I hope this gives you a place to start!

@goodmami @Dan

Thanks a lot for the very informative replies, and they look really useful! I’ll probably need a couple of days to fully digest them (there’s quite a lot of content new to me), but I’ll get back to you once I’ve worked something out.

@goodmami @Dan

I have obtained some understanding recently, and I would use the number 297 as an example to illustrate my understanding. Could you see if my understanding is correct? (I’m using ERG-2025 and I have checked that LKB can map OOV numerals with this grammar, but somehow the identification of proper nouns seems to be stricter than ERG-2018)

  • ACE first uses rpp/tokenizer.rpp to tokenize/pre-process the text, and 297 becomes a token (other .rpps seem unrelated to plain numbers);
  • The token-mapping files particularly for numbers are in tmr/ne?.tdl. 297 is captured by card_ne_2_tmr in ne2.tdl to get the features [ +CLASS card_ne, +ONSET c-onset ] .
  • In gle.tdl, generic_card_ne identifies [ +CLASS card_ne, +ONSET c-onset ] and gives 297 a lexical type aj_-_i-crd-gen_le.

Besides, by the ordering in english.tdl:

;;
;;  Lexical rules
;;

:include "lexrules".

;; Dependency annotation support for rule types

;;:include "dts".

;; Delimiters (strong and weak brackets)

:include "delims".

:include "auxverbs".

:include "letypes".

:end :type.

;;
;; Lexicon entries (instances of status lex-entry or generic-lex-entry)
;;

:begin :instance :status lex-entry.
:include "lexicon".
:include "lexicon-rbst".
:include "ple".
:end :instance.

:begin :instance :status generic-lex-entry.
:include "gle".
:include "gle-gen".
:end :instance.

It looks like gle.tdl might be executed after all the lexical types.

In particular, I’m not sure whether the understanding of ordering is correct here; we know that HPSG calculates at the speed of math, but what about file inclusion and preprocessing?

Given this understanding, I want to discuss the subtleties involved in enabling token-mapping of numerals and tokens containing numerals in Kalaallisut. I pick a real example from [1] to present what challenges there are:

14-iniit 18-inut 19-inulluunniit
14-niit 18-nut 19-nut=luunniit
14-PL.ABL 18-PL.ALL 19-PL.ALL=or.CONJ
“from 14 to 18 or 19”

In reality, the token-mapping rules should tackle the second line. I have written a Python script to go from the first line to the second. The questions are:

  • 14, 18 and 19 are actually base morphemes, and -niit, -nut are case inflections. How to ensure that token-mapping will map only 14 but not 14-niit to a lexical type that can take further lexical rules? I see the following type in lfr.tdl, and I assume that lexical filtering will take place between token-mapping and lexical rule applications, but I’m not sure whether it is related to this case:
;; DPF 2018-04-09 - Special case rules for numerals, since they are no longer
;; unk-onset (in order to get |*a 11-year stay|

numeral_right_punct_lfr := lexical_filtering_rule &
[ +CONTEXT < >,
  +INPUT < [ ORTH [ CLASS card_or_dom_or_year_or_time_ne,
                    FORM ^[0-9.,]+[])}”",;\.!?-]$ ],
             SYNSEM [ PUNCT.RPUNCT no_punct ] ] >,
  +OUTPUT < > ].
  • Is it possible to set up a pipeline from a Python script as a morphological analyzer (currently it provides morpheme segmentations without POS tags) to LKB as a syntactic parser? Or should I go for ACE in this case? I just find the visualizations in LKB quite helpful to me. A potential complication is that one original sentence may have multiple distinct morpheme segmentations.

Reference:
[1] Berthelsen, C. (1996). Kalaallisut Sungiusaatit. Atuakkiorfik Ilinniusiorfik.

Hi @goodmami and @Dan,

I’ve made token mapping in my language start to work, and thanks for your help!

I list a couple of points that may help people facing issues on the same topic. If you find anywhere that looks wrong, please let me know!

  • If you are using LKB rather than ACE, the parameters about TMR can be found in globals.lsp of ERG (it seems that the five parameters starting with *chart-mapping- are all required), and changes in ace/config.tdl do not seem related:
(def-lkb-parameter *token-type* 'token)

(def-lkb-parameter *token-form-path* '(+FORM))
(def-lkb-parameter *token-id-path* '(+ID))
(def-lkb-parameter *token-from-path* '(+FROM))
(def-lkb-parameter *token-to-path* '(+TO))
;;(def-lkb-parameter *token-postags-path* '(+TNT +TAGS))
;;(def-lkb-parameter *token-posprobs-path* '(+TNT +PRBS))


(def-lkb-parameter *chart-mapping-context-path* '(+CONTEXT))
(def-lkb-parameter *chart-mapping-input-path* '(+INPUT))
(def-lkb-parameter *chart-mapping-output-path* '(+OUTPUT))
(def-lkb-parameter *chart-mapping-position-path* '(+POSITION))
(def-lkb-parameter *chart-mapping-jump-path* '(+JUMP))

(setf *lexicon-tokens-path* '(TOKENS +LIST))
(setf *lexicon-last-token-path* '(TOKENS +LAST))
(setf *token-id-path* '(+ID))
  • tmt.tdl, tmr files and gle.tdl must be separated as they require different commands in script (that is, you cannot put all the type definitions in a single file).
  • Note that native lexicons also need to pass token-mapping rules to avoid overgeneration by types in gle.tdl. Some catch-all tmr’s are in tmr/finis.tdl of ERG. If LKB fails to parse anything, try a minimally working tmr modified from examples there to see if the native lexicons are able to get a meaningful +CLASS value, for example they should get [ +CLASS non_ne ] by the following tmr from finis.tdl:
default_class_tmr := one_one_tmt &
[ +INPUT < [ +FORM #form, +TRAIT #trait, +CLASS no_class,
             +PRED #pred, +CARG #carg ] >,
  +OUTPUT < [ +FORM #form, +TRAIT #trait, +CLASS non_ne,
              +PRED #pred, +CARG #carg ] >,
  +CONTEXT < > ].
  • The +OUTPUT of tmr’s seems to aim at word entries and lexical entries, which means that lexical stems will receive +TOKEN of the whole word. To make things working, try to develop a regex such that +FORM in +OUTPUT can match the fully inflected word.
  • Information about +POSITION is mostly in the slides from the ChartMapping DELPH-IN doc shared by @goodmami above. This is important, as tmr’s do not seem to function without specifying +POSITION values. You will see notions like O1@I1 or C1@I1 in the slides. I guess that O stands for +OUTPUT, I for +INPUT, and C for +CONTEXT.
  • In ERG, +TRAIT.+UW aims to classify if a word is an unknown (oov) word or not. It is related to native_token_list in tmt.tdl:
native_token_list := *list*.
native_token_cons := native_token_list & *cons* &
[ FIRST.+TRAIT.+UW -, REST native_token_list ].
native_token_null := native_token_list & *null*.

generic_token_list := *list*.
generic_token_cons := generic_token_list & *cons* &
[ FIRST.+TRAIT.+UW +, REST generic_token_list ].
generic_token_null := generic_token_list & *null*.
  • If the oov word needs a CARG or any string value that comes from a part of the original word, you can use +CARG or the like to extract the value in tmr and then use tag identifiers to pass the value in gle.tdl.

Good detective work!

There’s more information about LKB-FOS and chart mapping in my presentation at the 2022 DELPH-IN Summit: LKB-FOS Update

Hi John Carroll, thanks for your sharing!