essyntax 0.1.0-dev.3

Fast Spanish dependency parser: heads and Universal Dependencies relations
Documentation
  • Coverage
  • 100%
    23 out of 23 items documented1 out of 12 items with examples
  • Size
  • Source code size: 91.7 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 466.5 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • SergeyShk/esSyntax
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • SergeyShk

essyntax

Fast Spanish dependency parser written in Rust, the core of the esSyntax library for Python: the head and the Universal Dependencies relation of every word of a sentence.

  • The input is the words of a sentence with their UD part of speech and features, for example from the morphological analyzer esMorph; the output is the number of the head of every word (0 for the root) and its relation.
  • The model is a BiLSTM over the words, their endings and tags; the heads come from a biaffine score and the tree of the maximum weight with one root (non-projective trees too), the relations from the pair "dependent - head". In degenerate sentences (more than 16 cycles or 8 root candidates among the best heads) and in sentences longer than 1024 words the tree is assembled faster: the extra roots and the nodes of cycles are attached to the best root; in long sentences the head is looked for among 64 words on each side and the root, and the time grows linearly with the length.
  • The part of speech is one of the 17 UD parts of speech in capitals (an unknown one is parsed as X), the features are in the CoNLL-U notation. A Relation has the head, the relation, its number in Parser::relations and the probabilities of the head and the relation by the model (head_prob, deprel_prob); Parser::checksum is the CRC32 of the model.
  • Sentences of close length are parsed four at once: Parser::parse_many.

The model is not part of the crate: the parser reads it from a file, such as data/es-syntax.bin of the repository, trained on the treebanks UD Spanish AnCora and GSD (CC BY-SA 4.0, LICENSE-MODEL.txt).

Example

use essyntax::{Parser, Word};

fn main() -> Result<(), essyntax::Error> {
    let parser = Parser::from_path("es-syntax.bin")?;
    let words = [
        Word::new("La", "DET", "Definite=Def|Gender=Fem|Number=Sing|PronType=Art"),
        Word::new("niña", "NOUN", "Gender=Fem|Number=Sing"),
        Word::new("lee", "VERB", "Mood=Ind|Number=Sing|Person=3|Tense=Pres|VerbForm=Fin"),
        Word::new("un", "DET", "Definite=Ind|Gender=Masc|Number=Sing|PronType=Art"),
        Word::new("libro", "NOUN", "Gender=Masc|Number=Sing"),
        Word::new(".", "PUNCT", "_"),
    ];
    for (word, relation) in words.iter().zip(parser.parse(&words)) {
        println!("{} -> {} {}", word.form, relation.head, relation.deprel);
    }
    Ok(())
}

The model is loaded and checked on every call of Parser::from_path and Parser::from_bytes: create the parser once and parse all the text with it, from several threads too.

Model file

The header is the signature ESSYNTAX, the format version and the CRC32 of the rest of the file; then come entries by name: lists of strings, matrices of f32 or of int8 by rows with a scale per row, numbers. A file of another format version, a damaged one or one with weights of disagreeing sizes is not loaded: Error::Format.

License

The code is distributed under the MIT license.