An excitement score is an AI-generated integer from 1 to 10 that rates the dramatic intensity of a baseball play from its play-by-play commentary. It turns narrative language into a column that can travel with cleaned, canonically mapped pitch data and be used like any other analysis-ready feature. section 9.3.4 section 9.3.5
Score each play alongside a separate key-moment flag. The classification prompt gives the model a baseball-narrative role, requires structured JSON, and supplies criteria such as home runs, game-tying or go-ahead plays, critical strikeouts, bases-loaded situations, close games, extra innings, and standout defense. Routine outs and ordinary balls and strikes are treated as low-drama cases. section 9.3.4
Listing 9.7 Defining a Key Moment and Excitement Rating Prompt
from pydantic import BaseModel #A
class PlayAnalysis(BaseModel): #B
key_moment: bool #B
excitement: int #B # Scale of 1–10
system_prompt_analysis = """
You are a baseball narrative analyst. Analyze the provided
play-by-play commentary and determine:
1. key_moment (boolean): Is this a key moment in the game?
- TRUE for: home runs, game-tying hits, go-ahead runs,
critical strikeouts, bases-loaded situations, double plays
that end threats, extra-inning plays, close game situations,
or standout defensive plays.
- TRUE for any play where the commentary suggests high stakes,
tension, or game-changing impact.
- FALSE for routine outs, standard balls and strikes, and
typical fly outs or grounders with no drama.
- Look for phrases like "crucial", "pivotal", "clutch",
"ties the game", "takes the lead", and similar cues.
2. excitement (integer 1–10): Rate the excitement level of this play.
- 1–2: Routine play, minimal drama.
- 3–4: Somewhat notable (base hit, walk, or strikeout
in a normal situation).
- 5–6: Moderately exciting (extra-base hit, key defensive play,
close play at a base).
- 7–8: Very exciting (home run, bases loaded, clutch hit,
clear game-changing play).
- 9–10: Extremely exciting (walk-off hit, game-tying homer,
incredible defensive play, very high stakes moment).
Consider:
- Score (closer games usually mean higher stakes).
- Inning (later innings usually raise the stakes).
- Runners on base (more runners usually mean more tension).
- Outs (two outs usually means more pressure).
- Game impact (does this change the score or game state).
- Commentary tone (dramatic language and exclamation marks
usually imply higher excitement).
Return a JSON object with: key_moment (bool), excitement (int 1–10).
""" #C
The prompt defines the paired `key_moment` and 1–10 `excitement` fields and anchors scoring in explicit baseball situations and commentary cues. section 9.3.4
A practical enrichment pass follows this pattern:
- Define a Pydantic response model with a boolean `key_moment` field and integer `excitement` field. section 9.3.4
- Send each play-by-play string to the model with the analysis prompt and parse the result into structured fields. section 9.3.4
- Handle failures by appending a conservative fallback: `key_moment=False` and `excitement=1`. section 9.3.4
- Write the parsed values back to the enriched DataFrame as `key_moment` and `excitement` columns. section 9.3.4
The score is useful because it makes narrative intensity queryable at scale. Once stored in a table, it can support questions about pressure on pitchers, changes in excitement across innings, and the plays that defined a game. It also illustrates a broader pipeline move: generate semantic features from plain-language commentary, then use ordinary joins, DataFrames, and visualizations to analyze them. section 9.3.4 section 9.3.5
Build an excitement arc
For a World Series Game 7, plot `excitement` against `play_id` as a line, overlay red points where `key_moment` is true, and add a smoothed trend using a size-10 uniform filter. Keep the y-axis at 0–11 so the 1–10 rating scale remains visually consistent. The result shows how tension rises and falls over the game while separating explicitly flagged moments from the overall trend. section 9.3.5
Treat individual values as model-generated judgments rather than fixed measurements. Changes to the model version, prompt, or settings can shift scores and reshape the resulting arc; this is acceptable when the goal is to unlock useful analysis rather than reproduce an identical chart. Running the complete pipeline over all plays also makes those variations visible at realistic scale. section 9.3.5 section 9.4
