🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

Discourse Coherence: Modeling Text Structure

Natural Language ProcessingDiscourse Coherence: Modeling Text StructuređŸŸĸ Free Lesson

Discourse Coherence: Modeling Text Structure

Module: Natural Language Processing | Difficulty: Advanced

What You'll Learn

  • 1Represent a text as an entity grid of grammatical states
  • 2Compute transition probabilities and a coherence score for a passage
  • 3Apply Centering Theory to label Continue, Retain, and Shift transitions
  • 4Evaluate sentence ordering with Kendall tau distance

Coherence is what makes sentences hang together instead of merely being adjacent. The standard computational approach tracks discourse entities across sentences, on the theory that a coherent text keeps the same entities moving through similar grammatical roles.

The Entity Grid

Following Barzilay and Lapata (2008), each entity receives a state per sentence: subject (S), object (O), oblique or other case (X), or absent (-). Concatenating states across sentences yields a grid, and the distribution of adjacent-state pairs becomes the text's feature vector.

ResourceContentSize
Accidents corpusairline crash reports100 train and 100 test articles, 11.5 sentences average
Earthquakes corpusearthquake reports100 train and 100 test articles, 10.4 sentences average
Summary coherence ratingsummaries with human preferences144 train and 80 test pairs
Wikipedia articlesopen-domain paragraphsfar more varied structure than news

Barzilay and Lapata reported order discrimination accuracy of 90.4 on Accidents and 87.2 on Earthquakes, both corpora where article structure is highly repetitive. Later neural variants report 85.9 accuracy on sentence ordering and 86.3 on summary coherence rating, showing that open-domain data is genuinely harder than the classic pairs.

Centering Theory

Centering (Grosz, Joshi, and Weinstein, 1995) explains why some transitions feel smooth. For each utterance it defines a ranked list of realized entities, the forward-looking centers, and singles out the best link to the previous utterance.

The transition between consecutive utterances is labeled by comparing the continuing backward-looking center with the preferred center of the current utterance:

Coherent local sequences favour Continue, where the same entity stays most salient, and avoid Rough-Shift, where the utterance both changes and de-emphasizes the center.

Order Evaluation

Sentence ordering is evaluated by comparing a predicted permutation with the gold one using rank correlation:

where and are concordant and discordant pairs. A perfect order gives and ; a reversal gives .

Learning the ranker

Training pairs come from shuffling one document, so the label is a preference rather than a class. With the original order and a shuffled one, a linear ranker minimizes a hinge loss:

At convergence exceeds by at least one margin, which is what the discrimination task measures when it reports accuracy above chance.

Worked Code

python
import math
from collections import Counter

SENTS = [
    "The pilot reported the storm before the crash".split(),
    "The storm delayed the rescue team for hours".split(),
    "The team reached the site after midnight".split(),
    "Officials published the final report yesterday".split(),
]
LEXICON = ["pilot", "storm", "team", "site", "rescue", "report", "officials"]

def state_in(sentence, entity):
    words = [w.strip(".,?").lower() for w in sentence]
    if entity not in words:
        return "-"
    return "S" if words.index(entity) in (0, 1) else "O"

def entity_grid(sents):
    return {e: [state_in(s, e) for s in sents] for e in LEXICON}

def transitions(grid):
    pairs = Counter()
    for row in grid.values():
        for a, b in zip(row, row[1:]):
            pairs[(a, b)] += 1
    return pairs

def coherence_score(grid, alpha=1.0):
    pairs = transitions(grid)
    total = sum(pairs.values())
    if total == 0:
        return 0.0
    log_p = 0.0
    for count in pairs.values():
        log_p += count * math.log((count + alpha) / (total + alpha * 16))
    return log_p / total

grid = entity_grid(SENTS)
for entity, row in sorted(grid.items()):
    print(f"{entity:10s} {' '.join(row)}")
print("score:", round(coherence_score(grid), 3))

shuffled = [SENTS[0], SENTS[2], SENTS[1], SENTS[3]]
print("shuffled:", round(coherence_score(entity_grid(shuffled)), 3))

The second program implements Centering: it ranks realized entities, tracks the continuing center, and labels each transition.

python
SENTENCES = [
    "The pilot reported the storm before the crash".split(),
    "The storm delayed the rescue team for hours".split(),
    "The team reached the site after midnight".split(),
    "Officials published the final report yesterday".split(),
]
ROLE = {"pilot": "S", "storm": "S", "team": "S", "officials": "S", "report": "O"}

def forward_centers(sentence):
    text = " ".join(w.strip(".,?").lower() for w in sentence)
    realized = [e for e in ROLE if e in text.split()]
    realized.sort(key=lambda e: (0 if ROLE[e] == "S" else 1, e))
    return realized

def centering_step(previous_cf, current_cf):
    if not current_cf:
        return None, "none"
    cb = next((e for e in (previous_cf or []) if e in current_cf), None)
    if cb is None:
        label = "start" if not previous_cf else "no-cb"
    elif cb == current_cf[0]:
        label = "continue"
    else:
        label = "retain"
    return cb, label

previous_cf, labels = None, []
for sentence in SENTENCES:
    cf = forward_centers(sentence)
    cb, label = centering_step(previous_cf, cf)
    labels.append(label)
    print(f"{label:9s} Cf={cf} Cb={cb}")
    previous_cf = cf
print("continue rate:", round(labels.count("continue") / len(SENTENCES), 3))

Real-World Applications

  • Summarization: reorder sentences from multiple sources and score the draft with a coherence ranker before presenting it.
  • Essay scoring: coherence features separate well-organized student writing from lists of correct facts.
  • Machine translation: output that is locally fluent but jumps between topics scores poorly under grid models.
  • Generation control: decoding can prefer hypotheses whose transition distribution matches human text.

💡Structured corpora flatter the model

On Accidents and Earthquakes, where articles follow a fixed script, the entity grid reaches 90.4 and 87.2 accuracy. Report open-domain results too, since that is where generation and summarization actually run.

Common Mistakes

Using a full coreference system without checking

Fix: Barzilay and Lapata matched nouns by identity, and automatic coreference often lowers coherence accuracy

Treating coherence as binary classification

Fix: Train a ranker over permutations, since coherence is graded

Reporting only one corpus

Fix: Give both structured news and open-domain numbers, since they differ by tens of points

Best Practices

  • Train on permutations of the same documents to control length and topic
  • Report sentence ordering and summary coherence rating together
  • Compare against the plain entity grid before adding neural machinery

Key Takeaways

  • An entity grid records S, O, X, and absent states per entity per sentence
  • Coherence is scored as a ranking over permutations of one text
  • Centering ranks Continue above Retain and both above Rough-Shift
  • Kendall tau gives 0.667 for one swapped pair out of four sentences

Frequently Asked Questions

How are entities identified without a coreference system?

By identity of noun phrases, the original heuristic: two mentions count as the same entity only when they share a surface noun. That is crude but robust, and stronger coreference systems have repeatedly failed to improve coherence scores.

What tasks evaluate a coherence model?

Three standard ones: discrimination of original from permuted order, summary coherence rating against human preferences, and readability assessment. Sentence ordering is the most common because it needs no extra annotation.

Why does Centering matter if neural models exist?

It supplies the constraint that models learn implicitly: keep one entity most salient across adjacent sentences. Encoding it directly helps in decoding, where errors show up as topic jumps rather than ungrammatical text.

Interview Questions

Q1: What does the entity grid actually store?

For each entity, its grammatical state in each sentence, then probabilities of adjacent state pairs

Q2: Why is coherence framed as ranking?

Because human judgments compare two versions of the same content rather than labeling absolute quality

Q3: How is a predicted ordering scored?

With Kendall tau over sentence pairs, converted to a distance for minimization

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-07

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Continue Learning

Suggested next tutorials based on this topic

Need Expert NLP Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement