Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Treebanks and universal dependencies

Notes on treebanks and Universal Dependencies (UD): what treebanks are, dependency vs constituency, UD annotation principles, evaluation (UAS/LAS), projectivity, and example annotations for exam preparation.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Two or three sentences: where an engineer uses this.

  • Treebanks are used by engineers when training or evaluating syntactic parsers, building downstream NLP systems (like machine translation, information extraction, and semantic parsing), and creating language resources for low-resource languages. They give supervised examples of sentence structure which modern parsers and many downstream models learn from.

Key ideas

(Explain plainly; define every term before using it.)

  • Treebank — a corpus (collection) of natural-language sentences annotated with syntactic structure. Define: corpus = an organized collection of text; annotated = labels added by human linguists or automatic tools. A treebank provides the gold-standard examples for training and testing parsers.

  • Two main styles of syntactic annotation (define before use):

    • Constituency (phrase-structure) treebanks — annotate how words group into constituents (phrases) like NP (noun phrase), VP (verb phrase). Example: the Penn Treebank (a widely used English constituency treebank built from Wall Street Journal text).
    • Dependency treebanks — annotate syntactic relations as directed links between words: one word is the head and another is a dependent. Define: head = the governing word of a relation; dependent = the governed word.
  • Dependency tree — a directed tree where nodes are tokens (words) in a sentence, edges go from head → dependent, there is exactly one node called the root that has no head among the sentence tokens (implementations often represent this by attaching it to an artificial ROOT token with index 0), and every other node has exactly one head. Formally: for a sentence of n tokens, a dependency tree has n-1 directed arcs between tokens forming a rooted tree over the tokens; many file formats add one extra arc from an artificial ROOT (index 0) to the sentence root.

  • Projectivity — a formal property of a dependency tree. Define: a dependency tree is projective if for every directed arc from head h to dependent d, every word that appears between h and d in the linear word order is also a descendant of h in the tree. Step-by-step: to test projectivity for arc (h,d) — list positions strictly between h and d; if any such position corresponds to a token that is not dominated by h (i.e., not in the subtree rooted at h), the arc is non-projective. Projective trees can be drawn without crossing arcs when tokens are placed left-to-right and arcs drawn above the sentence.

  • Non-projective — a tree that violates projectivity; arcs cross when drawn above the sentence. Non-projectivity occurs frequently in free-word-order languages and in certain constructions (e.g., long-distance dependencies, scramblings).

  • Universal Dependencies (UD) — an international initiative and framework providing a cross-linguistically consistent set of guidelines to create dependency treebanks for many languages. UD defines a set of universal part-of-speech tags, a core inventory of dependency relation labels (like nsubj, obj, amod, advmod, root), and principles for how to annotate morphological features and multiword expressions. UD aims for typological consistency while allowing language-specific extensions. UD treebanks are distributed in the CoNLL-U format (10 columns: ID, FORM, LEMMA, UPOS, XPOS, FEATS, HEAD, DEPREL, DEPS, MISC).

  • Token — the minimal unit in a treebank (usually a word or punctuation). Some treebanks (including UD) use multiword tokens when a single orthographic token expands into multiple syntactic words (e.g., contractions or cliticized forms like can't -> can + not); the multiword token itself is not a syntactic node, its components are.

  • Annotation scheme — the complete set of guidelines (POS tagset, dependency labels, morphological features, tokenization rules) used to annotate a treebank. A consistent scheme is necessary for comparing parsers and for cross-lingual models.

  • Evaluation metrics (define before use):

    • Unlabeled Attachment Score (UAS) — percentage of tokens whose predicted head is the same as the gold head, ignoring the dependency label.
    • Labeled Attachment Score (LAS) — percentage of tokens whose predicted head and dependency label both match the gold annotation.
  • Assumptions behind evaluation: sentence tokenization must match between gold and predicted data; punctuation can be included or excluded depending on the evaluation convention; some implementations ignore the root's HEAD or treat root specially.

  • Common conversion tasks: converting constituency trees (like Penn Treebank) to dependency trees requires head-finding rules (algorithms that select a head inside a phrase) — e.g., Collins head rules or other language-specific rules.

  • Annotation decisions that often appear in UD guidelines: how to treat coordination (which word is the head of a coordination), how to annotate copula constructions, and how to encode case marking and clitics. UD defines specific relation labels and principles (e.g., content words are heads over function words where possible), but local committees sometimes adapt a few choices for language-specific phenomena.

(Drawings to include in an exam answer: draw a sentence horizontally with tokens in order. Above the tokens draw directed arcs from head to dependent (arrows). Label each arc with the dependency relation. For a projection diagram, show two examples: one where arcs do not cross (projective) and one where two arcs cross (non-projective). Label the crossing arcs clearly.)

Formulas

(each formula on its own line, then symbol explanations, unitless scores where applicable)

UAS = (number of tokens with correct predicted head) / (total number of tokens) * 100

  • Symbols: UAS = Unlabeled Attachment Score in percent; numerator = count of tokens where predicted head index equals gold head index; denominator = total tokens evaluated (commonly excludes the artificial ROOT or includes punctuation per convention). Unit: percent (unitless fraction ×100). Applies when comparing predicted dependency trees to gold-standard trees.

LAS = (number of tokens with correct predicted head and correct label) / (total number of tokens) * 100

  • Symbols: LAS = Labeled Attachment Score in percent; numerator = count where both head index and relation label match gold; denominator = total tokens evaluated. Unit: percent. Applies as above.

(If you prefer fractions rather than percent, remove *100; units are unitless.)

Formal test for projectivity (predicate form):

A dependency tree is projective iff for every arc (h -> d), for every token position k such that min(h,d) < k < max(h,d), token k is dominated by h (i.e., is in the subtree rooted at h).

  • Symbols: h,d,k are token positions (integers 1..n). Applies to linear token order and tree dominance relation.

Worked examples

Provide model answers to typical long exam questions.

  1. Explain UD and how you would annotate the sentence: "The quick brown fox jumps over the lazy dog." Model answer (concise, exam style):
  • Step 1: tokenize: [The|quick|brown|fox|jumps|over|the|lazy|dog|.] — note punctuation is a token.
  • Step 2: POS tag with UD universal tags: The/DET quick/ADJ brown/ADJ fox/NOUN jumps/VERB over/ADP the/DET lazy/ADJ dog/NOUN ./PUNCT.
  • Step 3: choose heads and relations by UD v2 principles: jumps is root. fox is nsubj of jumps. The, quick, brown depend on fox as det, amod, amod. dog is obl dependent of jumps; over is case dependent of dog. the and lazy depend on dog as det and amod. . is punct dependent of jumps.
  • Step 4: draw dependency tree: Put words left-to-right; draw arrow from jumps to fox labeled nsubj, from jumps to dog labeled obl, from dog to over labeled case, etc. (Label arcs as above.)

(UD v2 guideline: adpositions like 'over' are annotated as case dependents of the nominal; the nominal attaches to the predicate as obl.)

  1. Compute UAS and LAS for a short example. Gold and predicted heads/labels for sentence with 5 tokens (ROOT excluded for simplicity):

Tokens 1..5. Gold heads: [2,0,2,3,3] meaning token1->2, token2->ROOT(0), token3->2, token4->3, token5->3. Gold labels: [nsubj,root,obj,det,amod] Predicted heads: [2,0,4,3,3]. Predicted labels: [nsubj,root,obl,det,amod].

Stepwise:

  • Compare each token:
    • token1: head correct (2), label correct (nsubj) -> counts for UAS and LAS.
    • token2: head correct (0), label correct (root) -> counts.
    • token3: head wrong (predicted 4 vs gold 2) -> UAS no; label doesn't matter, LAS no.
    • token4: head correct (3), label correct (det) -> counts.
    • token5: head correct (3), label correct (amod) -> counts.
  • UAS = 4/5 * 100 = 80%. LAS = 4/5 * 100 = 80% because all correctly-headed tokens also had correct labels in this case.

(Show formula before numbers as required.)

  1. Diagram question model answer: Describe what to draw when asked to show a non-projective example: Write sentence "What did John say Mary bought?" and show crossing arcs for wh-movement or use a free-order language example. Draw tokens left-to-right and draw arcs that cross; label which arcs cross and identify the non-projective arc.

Common mistakes

  • Mistreating punctuation in evaluation (include vs exclude) — always state the convention.
  • Mixing tokenization conventions: gold and predicted tokenization must match for UAS/LAS; otherwise scores are meaningless.
  • Wrong projectivity test: students sometimes check only local neighborhood instead of verifying dominance for all tokens between head and dependent.
  • In UD, mis-assigning prepositions as heads of prepositional phrases rather than as case dependents of the noun (check UD version/guidelines used by the course).
  • Mishandling coordination: in UD the first conjunct is the head; common errors are making the coordinator the head or mislabeling cc/conj attachments.

For your exam

Kinds of questions and what full-marks answers include:

  • Definitions: define treebank, dependency tree, projectivity, UD, UAS, LAS. A full answer gives formal definitions and a short example.
  • Short notes: explain differences between constituency and dependency treebanks; explain UD principles. Full marks require pros/cons, example sentences and mention of cross-linguistic aims.
  • Derivations/algorithms: convert a small constituency tree to a dependency tree using head-finding rules — show head rules applied step-by-step. Full marks need the rule list applied at every phrase node.
  • Numericals: compute UAS and LAS given gold and predicted annotations; show counting steps and final percent with units. Full marks need correct counts and explanation of punctuation/token conventions.
  • Programs/annotations: annotate a sentence in UD style or write a small script to compute UAS/LAS (if programming allowed). Full marks include correct tokenization, POS, heads, labels, and explanation of choices.
  • Diagrams: draw dependency trees (projective and non-projective); label heads, dependents, and relations. Full marks need clear tokens, arrows and labels, and identification of crossing arcs if non-projective.

Quick check

Three short questions:

  1. What is a treebank?
  2. Define Unlabeled Attachment Score (UAS) in one line.
  3. What does it mean for a dependency tree to be projective?

Answers: 1) A corpus of sentences annotated with syntactic structure (gold standard). 2) UAS = percentage of tokens whose predicted head equals the gold head. 3) Projective means no arcs cross when drawn above the sentence; equivalently, for every head→dependent arc, all words between them are in the head's subtree.

Note for reviewer: I have attempted to keep definitions formal and simple. Where I am unsure I mention it in the verify list below; please correct any UD-specific guideline choices and relation labels I used as examples.

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?