NLP Pipeline - VforVitorio/F1_Strat_Manager GitHub Wiki

🗣️ Natural Language Processing

Radio transcription, sentiment analysis, and entity recognition

Data Processing Utilities

Model Artifacts and Deployment

Development Environment

NLP Pipeline Relevant source files

The NLP Pipeline is a comprehensive natural language processing system designed to analyze Formula 1 team radio communications. It transforms raw radio messages (text or audio) into structured data containing sentiment, intent, and named entities that can be consumed by the F1 strategy decision engine.

For information about the Expert System that consumes NLP pipeline outputs, see Expert System. For details about radio data collection and preprocessing, see Developer Guide.

System Architecture

The NLP Pipeline implements a four-stage processing workflow that converts unstructured radio communications into structured JSON data:

Configuration

CONFIG Dictionary

sentiment_model_path intent_model_path ner_model_path

sentiment_labels intent_labels entity_mapping

Model Loading

load_sentiment_model()

load_intent_model()

load_bert_ner_model()

Audio Files (.mp3)

transcribe_audio()

Text Messages

predict_sentiment()

predict_intent()

analyze_f1_radio()

Structured JSON Output

NLP Pipeline Architecture

The system uses three specialized transformer models that process radio messages sequentially, with a unified configuration system managing model paths and label mappings.

Sources: scripts/NLP_radio_processing/N06_model_merging.ipynb 82-118

scripts/NLP_radio_processing/NLP_utils/N06_model_merging.py 82-118

Model Components and Data Flow

Output Processing

Model Inference

Input Processing

Radio Message Text

RobertaTokenizer

RobertaTokenizer

BertTokenizer

RobertaForSequenceClassification (sentiment)

RobertaForSequenceClassification (intent)

BertForTokenClassification (NER)

Sentiment: positive|neutral|negative

Intent:

INFORMATION|PROBLEM|ORDER WARNING|QUESTION

Entities:

ACTION|SITUATION|INCIDENT STRATEGY_INSTRUCTION|etc.

analyze_radio_message()

Model Processing Workflow

Each model processes the same input text independently using different tokenizers and architectures, producing complementary analysis outputs that are combined into structured JSON.

Sources: scripts/NLP_radio_processing/N06_model_merging.ipynb 125-258

scripts/NLP_radio_processing/NLP_utils/N06_model_merging.py 125-258

Audio Transcription

The pipeline supports direct audio input through Whisper-based transcription:

Component Implementation Purpose

Model Whisper "turbo" Convert MP3 radio files to text

Function transcribe_audio() Audio processing entry point

Input Format MP3 files Team radio recordings Output Raw text string Transcribed message content

The transcribe_audio() function loads the Whisper model and processes audio files to extract text for downstream NLP analysis.

Sources: scripts/NLP_radio_processing/N06_model_merging.ipynb 678-700

scripts/NLP_radio_processing/NLP_utils/N06_model_merging.py 413-431

Sentiment Analysis

Sentiment analysis uses a fine-tuned RoBERTa-base model to classify radio message emotional tone:

Model Configuration

Base Model: roberta-base

Training Data: 530 labeled F1 radio messages

Classes: positive (0), neutral (1), negative (2) Performance: 87.50% test accuracy, 87.46% weighted F1-score Implementation Details

The predict_sentiment() function tokenizes input text with a maximum length of 128 tokens and returns predictions with confidence scores.

Label Mapping

0: positive

1: neutral

2: negative

Radio Message

tokenizer(text, max_length=128)

model(input_ids, attention_mask)

torch.nn.functional.softmax()

sentiment + confidence

Sentiment Analysis Processing Flow

Sources: scripts/NLP_radio_processing/N06_model_merging.ipynb 244-289

scripts/NLP_radio_processing/NLP_utils/N03_bert_sentiment.py 917-939

Intent Classification

Intent classification identifies the purpose of radio communications using a fine-tuned RoBERTa-large model:

Intent Categories

Intent Description Example

INFORMATION Factual updates about race conditions "Hamilton is 2 seconds behind"

PROBLEM Driver-reported issues "Losing grip on the rear"

ORDER Direct instructions requiring action "Box this lap"

WARNING Alerts about potential issues "Watch your fuel consumption"

QUESTION Queries requiring driver input "How are the tyres feeling?"

Implementation

The predict_intent() function uses the same tokenization approach as sentiment analysis but with RoBERTa-large for improved contextual understanding of F1-specific terminology.

Sources: scripts/NLP_radio_processing/N04_radio_info.ipynb 15-26

scripts/NLP_radio_processing/N06_model_merging.ipynb 295-340

Named Entity Recognition

The NER system extracts F1-specific entities using a fine-tuned BERT-large model with BIO tagging:

Entity Types

Entity Description Example Phrases

ACTION Direct commands or actions "follow my instruction"

SITUATION Racing context descriptions "yellows in turn 7"

INCIDENT Accidents or on-track events "Ferrari in the wall"

STRATEGY_INSTRUCTION Strategic directives "Plan B"

POSITION_CHANGE References to overtakes "Hamilton catching up"

PIT_CALL Specific pit stop calls "Box this lap"

TRACK_CONDITION Track state mentions "DRS enabled"

TECHNICAL_ISSUE Mechanical problems "brake failure"

WEATHER Weather conditions "rain incoming"

BIO Tagging Format

The system converts character-level entity spans to token-level BIO (Beginning-Inside-Outside) format:

BIO Format

B-ENTITY: Beginning

I-ENTITY: Inside

O: Outside

Character-level Entity Spans

create_ner_tags()

BIO Tagged Tokens

F1RadioNERDataset

BertForTokenClassification

analyze_f1_radio()

NER Processing Pipeline

Sources: scripts/NLP_radio_processing/N05_ner_models.ipynb 336-366

scripts/NLP_radio_processing/NLP_utils/N05_ner_models.py 208-246

Integrated Pipeline

The analyze_radio_message() function orchestrates all three models to produce comprehensive analysis:

Processing Flow

Model Loading: Load all three pre-trained models using configuration paths

Parallel Processing: Execute sentiment, intent, and NER analysis independently

Result Aggregation: Combine outputs into structured JSON format

File Output: Save timestamped analysis results

JSON Output Format { "message": "Box this lap for softs, Hamilton is catching up", "analysis": { "sentiment": "neutral", "intent": "ORDER", "entities": { "action": ["Box this lap"], "situation": ["Hamilton is catching up"] } } } Configuration Management

The CONFIG dictionary centralizes model paths, label mappings, and entity configurations:

Configuration Key Purpose Example Value sentiment_model_path Sentiment model location "../../outputs/week4/models/best_roberta_sentiment_model.pt" intent_model_path Intent model location "../../outputs/week4/models/best_roberta_large_intent_model.pt" ner_model_path NER model location "../../outputs/week4/models/best_focused_bert_model.pt" sentiment_labels Sentiment class names ["positive", "negative", "neutral"] intent_labels Intent class names ["INFORMATION", "PROBLEM", "ORDER", "WARNING", "QUESTION"] entity_mapping BIO tag to entity mapping {"B-ACTION": "action", "I-ACTION": "action", ...}

Sources: scripts/NLP_radio_processing/N06_model_merging.ipynb 343-410

scripts/NLP_radio_processing/NLP_utils/N06_model_merging.py 82-118


Data Processing Utilities

Model Artifacts and Deployment

Development Environment

Radio Transcription

Relevant source files

Purpose and Scope

This document provides a technical overview of the Radio Transcription component within the F1 Strategy Manager's NLP pipeline. The system is responsible for converting Formula 1 team radio audio messages into text transcriptions, which serve as the foundation for downstream NLP analysis including sentiment analysis, intent classification, and named entity recognition (for more information on these components, see Sentiment and Intent Analysis and Named Entity Recognition).

The radio transcription module processes raw audio files from race communications and produces structured text data that becomes a critical input for the strategy engine's radio-based rules.

Sources: scripts/NLP_radio_processing/N01_radio_transcription.ipynb 1-1741

System Architecture

The radio transcription system processes audio files extracted by the data extraction pipeline and transforms them into structured text data for downstream NLP analysis. The system leverages OpenAI's Whisper speech recognition model to handle the challenges of F1 team radio communications including background noise, varying accents, and radio transmission quality.

Transcription Pipeline Architecture

Output Files

Processing Libraries

N01_radio_transcription.ipynb

Data Input

f1-strategy/data/audio/driver_*/ .mp3 Files from OpenF1 API

load_audio_files() Directory Traversal

transcribe_audio_files() Whisper Processing

whisper.load_model() Model: turbo/medium/small

librosa.load() 16kHz Audio Loading

torch.cuda.is_available() GPU Detection

outputs/week4/radios_raw.csv Structured Transcriptions

Integration with NLP Pipeline

NLP Analysis

Data Preparation

Radio Transcription

Data Extraction

extract_radios.ipynb OpenF1 API → MP3 Files

N01_radio_transcription.ipynb Whisper → radios_raw.csv

N00_data_labeling.ipynb Manual Labeling → Clean Dataset

N02_sentiment_analysis.ipynb RoBERTa Models

N03_ner_analysis.ipynb BERT NER

Intent Classification

Pipeline Integration

Sources: scripts/NLP_radio_processing/N01_radio_transcription.ipynb 92-139

scripts/NLP_radio_processing/N01_radio_transcription.ipynb 196-251

scripts/data_extraction/extract_radios.ipynb 95-119

Audio File Management

The transcription process begins with loading and organizing audio files from a directory structure. The system is designed to work with F1 team radio files organized by driver.

File Loading Implementation

The load_audio_files() function in scripts/NLP_radio_processing/N01_radio_transcription.ipynb 92-139 systematically processes the directory structure created by the data extraction pipeline.

Directory Structure Processing

load_audio_files() Processing

Audio Directory Structure

f1-strategy/data/audio/

driver_(1,)/ Max Verstappen

driver_(11,)/ Sergio Perez

driver_(N,)/ Other Drivers

*.mp3 files

*.mp3 files

*.mp3 files

glob.glob(driver_*) Directory Discovery

driver_num = basename.replace() Number Extraction

glob.glob(*.mp3, *.wav, *.m4a, *.ogg) Multi-format Support

audio_files.append({ driver, file_path, filename})

Audio File Metadata Structure

The function returns a list of dictionaries with this exact structure:

driver: Driver number extracted from directory name using os.path.basename(driver_dir).replace('driver_(', '').replace(',)', '') file_path: Full path to audio file for librosa.load() filename: Base filename for tracking and output naming

This metadata structure enables systematic batch processing while maintaining traceability between transcriptions and their audio sources.

Sources: scripts/NLP_radio_processing/N01_radio_transcription.ipynb 92-139

Whisper Transcription Process

Model Selection

The system uses OpenAI's Whisper model for audio transcription. The implementation allows for different model sizes to be selected based on available computational resources and accuracy requirements.

Model Size (GB) Parameters VRAM Required Speed Use Case tiny ~0.07 GB 39M ~1 GB Fastest Quick testing, resource-constrained environments base ~0.14 GB 74M ~1.5 GB Very Fast Basic transcription needs small ~0.46 GB 244M ~2.5 GB Fast Better accuracy with reasonable resources medium ~1.5 GB 769M ~5 GB Moderate Good accuracy-resource balance turbo ~2.9 GB 809M ~6 GB ~8x faster than large Optimized performance, preferred for this system large-v1 ~2.9 GB 1550M ~10 GB Slow Highest accuracy, resource intensive large-v2 ~2.9 GB 1550M ~12 GB Slow Latest high-accuracy model

For the F1 Strategy Manager's implementation, the turbo model is used as the primary choice, optimizing for both accuracy and speed with consideration for typical GPU memory constraints.

Sources: scripts/NLP_radio_processing/N01_radio_transcription.ipynb 59-74

Transcription Process

Transcription Implementation Details

The transcribe_audio_files() function in scripts/NLP_radio_processing/N01_radio_transcription.ipynb 196-251 implements the core transcription logic with specific parameter configurations.

Transcription Workflow "df.to_csv(output_csv, index=False)" "pd.DataFrame(results)" "results.append({driver, filename, file_path, text, duration})" "' '.join([segment['text'].strip() for segment in result['segments']])" "model.transcribe(audio, task='transcribe', language='en', fp16=torch.cuda.is_available())" "librosa.get_duration(y=audio, sr=sr)" "librosa.load(file_path, sr=16000, mono=True)" "audio_files list" "df.to_csv(output_csv, index=False)" "pd.DataFrame(results)" "results.append({driver, filename, file_path, text, duration})" "' '.join([segment['text'].strip() for segment in result['segments']])" "model.transcribe(audio, task='transcribe', language='en', fp16=torch.cuda.is_available())" "librosa.get_duration(y=audio, sr=sr)" "librosa.load(file_path, sr=16000, mono=True)" "audio_files list"

Process each audio file

Calculate duration

Pass audio array

Extract segments

Combine full text

Build results list

Export structured data

Key Implementation Parameters Parameter Value Purpose sr=16000 16kHz sampling rate Whisper's expected input format mono=True Single channel audio Reduces processing complexity task="transcribe" Transcription mode As opposed to translation language="en" English language F1 radio communications language fp16=torch.cuda.is_available() Half-precision when GPU available Memory optimization Output CSV Structure

The transcribe_audio_files() function produces a CSV with these exact columns:

driver: Driver number from directory structure filename: Original MP3 filename for tracking file_path: Full path for audio source reference text: Combined transcription from all Whisper segments duration: Audio length in seconds from librosa.get_duration()

This structured output becomes the input for N00_data_labeling.ipynb where post-race messages are filtered and sentiment labels are applied.

Sources: scripts/NLP_radio_processing/N01_radio_transcription.ipynb 196-251

scripts/NLP_radio_processing/N01_radio_transcription.ipynb 217-235

Performance Optimizations

GPU Acceleration

The system is designed to utilize GPU acceleration through PyTorch's CUDA support. Before processing, it verifies CUDA availability and selects the appropriate device.

CUDA verification code

if torch.cuda.is_available(): gpu_name = torch.cuda.get_device_name(0) print(f"✅ GPU available: {gpu_name}") print(f"CUDA version: {torch.version.cuda}") use_gpu = True else: print("❌ No GPU detected. Using CPU (will be much slower)") use_gpu = False Mixed Precision

To optimize GPU memory usage, the system employs FP16 (half-precision) when running on GPU. This is implemented via the fp16=torch.cuda.is_available() parameter in the Whisper transcription call, which:

Reduces VRAM requirements by approximately 50%

Speeds up computation with minimal impact on transcription quality Allows for larger batch sizes or models on the same hardware

Sources: scripts/NLP_radio_processing/N01_radio_transcription.ipynb 313-326

scripts/NLP_radio_processing/N01_radio_transcription.ipynb 223

Output Format and Integration

Transcription Output Structure

The transcribe_audio_files() function outputs to outputs/week4/radios_raw.csv with this exact structure:

Column Data Type Source Example driver int Directory name parsing 1 (Max Verstappen) filename string Original MP3 file driver_(1,)belgium_radio_39.mp3 file_path string Full file path ../../f1-strategy/data/audio/driver(1,)/... text string Whisper transcription "So don't forget Max, use your head please..." duration float librosa.get_duration() 15.168 seconds Data Flow Through NLP Pipeline

Expert System Integration

NLP Analysis Stage

Data Preparation Stage

Transcription Stage

684 MP3 Files (6 Grand Prix)

N01_radio_transcription.ipynb whisper.load_model('turbo')

outputs/week4/radios_raw.csv 684 transcribed messages

N00_data_labeling.ipynb Post-race message filtering

Manual sentiment labeling 530 clean messages

radio_labeled_data.csv Sentiment labels applied

RoBERTa sentiment model

Positive/Negative/Neutral

BERT NER model

F1-specific entities

Intent classification

Strategy-relevant intents

RadioFact instances

Structured radio data

F1RadioRules engine

Strategy recommendations

Integration with Expert System

The transcribed radio data eventually becomes RadioFact instances in the expert system, containing:

sentiment: Emotional tone classification intent: Strategic intent detection entities: F1-specific named entities driver_number: Source driver identification message_text: Original transcribed text

These facts trigger rules in the F1RadioRules engine for weather adjustments, incident reactions, and grip issue responses.

Sources: scripts/NLP_radio_processing/N01_radio_transcription.ipynb 244-248

scripts/NLP_radio_processing/N00_data_labeling.ipynb 232-238

scripts/data_extraction/extract_radios.ipynb 78-85

Limitations and Future Enhancements

The current implementation has several limitations and potential areas for improvement:

Audio Quality Variations: F1 team radios often contain background noise, engine sounds, and transmission artifacts that can impact transcription quality.

Terminology and Jargon: Specialized F1 terminology may not be well-represented in the base Whisper model's training data.

Processing Time: Transcribing large volumes of audio files can be time-consuming, especially without GPU acceleration.

Potential enhancements could include:

Fine-tuning the Whisper model on F1-specific audio data

Implementing post-processing to correct common F1 terminology errors

Adding batch processing for parallel transcription of multiple files

Creating a custom vocabulary for F1-specific terms and driver/team names

Sources: scripts/NLP_radio_processing/N01_radio_transcription.ipynb 1-1741


Data Processing Utilities

Model Artifacts and Deployment

Development Environment

Sentiment and Intent Analysis Relevant source files

This page explains the sentiment analysis system for F1 team radio communications, focusing on the RoBERTa-based model implementation and its comparison to VADER baseline analysis. The system classifies radio messages into sentiment categories to provide emotional context for strategic decision-making. For information about the full NLP pipeline including radio transcription and named entity recognition, see NLP Pipeline.

Overview

The sentiment analysis system processes F1 team radio messages to classify their emotional tone, providing context for strategic decision-making. The implementation compares a fine-tuned RoBERTa-base model against VADER baseline analysis to determine the most effective approach for motorsport communications.

Sentiment Analysis Pipeline

Sentiment Analysis Comparison

Raw Radio Message

VADER Sentiment (Baseline)

RoBERTa-base (Fine-tuned)

VADER Results (pos/neu/neg scores)

RoBERTa Classification (positive/neutral/negative)

Performance Comparison

Expert System Integration

Sources:

scripts/NLP_radio_processing/N02_sentiment_analysis_vader.ipynb 257-266 scripts/NLP_radio_processing/N03_bert_sentiment.ipynb 166-175 RoBERTa Sentiment Model

The system implements a fine-tuned RoBERTa-base model for classifying F1 radio messages into three sentiment categories. RoBERTa was selected for its superior contextual understanding and improved training methodology compared to BERT.

Model Architecture and Implementation

Label Mapping

positive: 0

neutral: 1

negative: 2

RoBERTaForSequenceClassification

radio_message

RobertaTokenizer.from_pretrained ('roberta-base')

input_ids, attention_mask

RobertaForSequenceClassification (num_labels=3)

logits

CrossEntropyLoss (with class_weights)

loss.backward()

The model uses RobertaForSequenceClassification with 3 output classes and implements class weighting to handle dataset imbalance.

Sources:

scripts/NLP_radio_processing/N03_bert_sentiment.ipynb 166-175 scripts/NLP_radio_processing/N03_bert_sentiment.ipynb 284-292

Dataset and Training Configuration

Dataset Distribution

The model was trained on 530 manually labeled F1 radio messages from radio_labeled_data.csv:

Sentiment Label Count Percentage

Positive 0 50 9.4% Neutral 1 379 71.5% Negative 2 101 19.1%

Sources:

scripts/NLP_radio_processing/N03_bert_sentiment.ipynb 249-261 Training Process

Training Setup

AdamW optimizer (lr=2e-5, weight_decay=0.01)

get_linear_schedule_with_warmup (warmup_steps=0)

CrossEntropyLoss (class_weights)

Model Configuration

RobertaTokenizer (max_length=128)

TensorDataset (input_ids, attention_mask, labels)

DataLoader (batch_size=16)

Data Preparation

radio_labeled_data.csv (530 samples)

train_test_split (test_size=0.3, stratify=labels)

train: 371 samples val: 79 samples test: 80 samples

Key training parameters:

Epochs: 6

Learning rate: 2e-5

Batch size: 16

Max sequence length: 128 tokens Class weights: [3.5333, 0.4667, 1.7418] for [positive, neutral, negative]

Sources:

scripts/NLP_radio_processing/N03_bert_sentiment.ipynb 321-336 scripts/NLP_radio_processing/N03_bert_sentiment.ipynb 654-658 scripts/NLP_radio_processing/N03_bert_sentiment.ipynb 792-805 Training Loop Implementation

The training process implements class-weighted loss and validation monitoring:

Validation Loop

model.eval()

torch.no_grad()

flat_accuracy(predictions, labels)

Training Epoch Loop

model.train()

for batch in train_dataloader

b_input_ids, b_attention_mask, b_labels

model.zero_grad()

outputs = model(b_input_ids, attention_mask)

loss = loss_fn(logits, b_labels)

loss.backward()

torch.nn.utils.clip_grad_norm_(model.parameters(), 1.0)

optimizer.step()

scheduler.step()

The training uses gradient clipping and implements class weights through compute_class_weight('balanced') to address dataset imbalance.

Sources:

scripts/NLP_radio_processing/N03_bert_sentiment.ipynb 885-942 scripts/NLP_radio_processing/N03_bert_sentiment.ipynb 708-716 VADER Baseline Analysis

The system implements VADER (Valence Aware Dictionary and sEntiment Reasoner) as a baseline comparison for the RoBERTa model. VADER provides rule-based sentiment analysis optimized for social media text.

VADER Implementation

SentimentIntensityAnalyzer

radio_message

sid.polarity_scores(text)

{'neg': score, 'neu': score, 'pos': score, 'compound': score}

categorize_sentiment(compound)

positive: compound >= 0.05 neutral: -0.05 < compound < 0.05 negative: compound <= -0.05

The get_sentiment_scores() function handles edge cases for empty or null radio messages, returning zero scores for invalid inputs.

Sources:

scripts/NLP_radio_processing/N02_sentiment_analysis_vader.ipynb 257-266 scripts/NLP_radio_processing/N02_sentiment_analysis_vader.ipynb 324-331 VADER Results Analysis

VADER analysis of the F1 radio dataset revealed significant limitations for motorsport communications:

Sentiment Count Percentage

Positive 231 43.67% Neutral 175 33.08% Negative 123 23.25% VADER Limitations in F1 Context

Key observations from VADER analysis indicate domain-specific challenges:

Overestimation of Positive Sentiment: 43.67% positive classification seems high for primarily technical communications

Misclassification of Technical Terms: Racing terminology like "push now" registers as positive encouragement rather than neutral instruction

Context Insensitivity: Acknowledgments like "copy that, understood" classified as positive instead of neutral

These limitations motivated the development of the domain-specific RoBERTa model for more accurate F1 radio sentiment analysis.

Sources:

scripts/NLP_radio_processing/N02_sentiment_analysis_vader.ipynb 585-591 scripts/NLP_radio_processing/N02_sentiment_analysis_vader.ipynb 598-617

Model Performance and Comparison

Training Metrics

The RoBERTa sentiment model demonstrates effective learning with decreasing training loss over epochs:

Epoch Training Loss 1/6 1.1074 2/6 1.0646 3/6 0.8629 4/6 0.5280 5/6 0.3271 6/6 0.2314

The model shows consistent improvement with training loss decreasing from 1.1074 to 0.2314, indicating successful adaptation to F1 radio communication patterns.

Sources:

scripts/NLP_radio_processing/N03_bert_sentiment.ipynb 858-880 Model Architecture Comparison

RoBERTa (Fine-tuned)

VADER (Baseline)

Rule-based lexicon

Sentiment intensity scores

Compound score thresholding

pos/neu/neg classification

Pre-trained roberta-base

Domain-specific fine-tuning

Contextual embeddings

Classification head with softmax

Performance Comparison

The RoBERTa approach provides contextual understanding of F1-specific terminology, while VADER relies on general sentiment lexicons that may misinterpret technical racing communications.

Sources:

scripts/NLP_radio_processing/N03_bert_sentiment.ipynb 23-98 scripts/NLP_radio_processing/N02_sentiment_analysis_vader.ipynb 11-40 Integration with Strategy Engine

The sentiment and intent analysis system feeds directly into the F1 Strategy Engine, providing critical context for strategic decision-making during races.

Expert System

NLP Pipeline

Data Sources

Radio Transcription (Whisper)

Telemetry Data (FastF1 API)

Gap Data (YOLO Vision)

Sentiment Analysis (RoBERTa-base)

Intent Classification (RoBERTa-large)

Named Entity Recognition (BERT-large)

RadioAnalysisPipeline

RadioFact

TelemetryFact

GapFact

F1RadioRules

F1LapTimeRules

F1GapRules

F1CompleteStrategyEngine

Strategy Recommendations

Sources:

scripts/NLP_radio_processing/NLP_utils/N06_model_merging.py 436-476 Key Use Cases

Radio analysis enhances strategic decision-making in several key ways:

Driver Mood Detection: Sentiment analysis identifies driver stress or confidence levels, allowing appropriate strategy adjustments

Action Prioritization: Intent classification distinguishes between urgent orders and routine information

Information Extraction: Entity recognition pulls out specific information like track conditions or technical issues

Competitor Intelligence: Analysis of team radio from other drivers can reveal strategy intentions

Sources:

scripts/NLP_radio_processing/NLP_utils/N04_radio_info.py 15-35 Model Loading and Inference

The system defines utility functions to load and run inference with the trained models:

Model Loading

The load_sentiment_model(), load_intent_model(), and load_bert_ner_model() functions handle model loading with appropriate configurations:

load_sentiment_model()

Load RoBERTa-base Tokenizer

Initialize Model with 3 Classes

Load Trained Weights

Move to GPU/CPU

Return Model + Tokenizer

Sources:

scripts/NLP_radio_processing/NLP_utils/N06_model_merging.py 125-162 scripts/NLP_radio_processing/NLP_utils/N06_model_merging.py 169-206 scripts/NLP_radio_processing/NLP_utils/N06_model_merging.py 213-238 Prediction Process

The overall prediction process is streamlined through the analyze_radio_message() function:

analyze_radio_message(radio_message)

Load All Models

Get Sentiment Prediction

Get Intent Prediction

Get NER Entities

Structure as JSON

Save to File

Return Filename

Sources:

scripts/NLP_radio_processing/NLP_utils/N06_model_merging.py 343-411 Audio Transcription Integration

For live audio feeds, the system can directly transcribe radio messages using Whisper before performing analysis:

Audio File

transcribe_audio()

Whisper Turbo Model

Transcribed Text

analyze_radio_message()

Structured JSON

Sources:

scripts/NLP_radio_processing/NLP_utils/N06_model_merging.py 413-432


Data Processing Utilities

Model Artifacts and Deployment

Development Environment

Named Entity Recognition Relevant source files

The Named Entity Recognition (NER) system extracts structured F1-specific entities from team radio communications to support strategic decision-making. This system identifies and classifies racing-specific terms, actions, and situations mentioned in radio messages between drivers and race engineers.

For information about sentiment analysis and intent classification of radio messages, see Sentiment and Intent Analysis. For the complete integrated NLP pipeline, see Integrated NLP Pipeline.

System Architecture

The NER system operates as a token classification pipeline that processes F1 radio messages and identifies domain-specific entities using BERT-based transformer models.

Integration

Entity Extraction

Model Architecture

Input Processing

Radio Message Text

BERT Tokenizer

BIO Tag Conversion

BertForTokenClassification

Classification Head (19 labels)

Entity Decoder

F1-Specific Entities

analyze_radio_message()

Structured JSON Output

NER System Data Flow

Sources: scripts/NLP_radio_processing/N05_ner_models.ipynb 1-100

scripts/NLP_radio_processing/N06_model_merging.ipynb 280-305

F1-Specific Entity Types

The system recognizes nine specialized entity types tailored for Formula 1 racing contexts:

Entity Type Description Example Phrases

ACTION Direct commands or actions "Box this lap", "Push now", "Keep to your protocol"

SITUATION Racing context descriptions "We've got yellows in turn 7", "Expecting aborted start"

INCIDENT Accidents or on-track events "Ferrari in the wall", "Charles stopped"

STRATEGY_INSTRUCTION Strategic directives "Plan B", "Target plus 5 on tyre management"

POSITION_CHANGE Overtakes or position references "Hamilton is catching up", "You're P4"

PIT_CALL Specific pit stop calls "Box for softs", "Stay out"

TRACK_CONDITION Track state mentions "DRS enabled", "Track is drying"

TECHNICAL_ISSUE Mechanical problems "Losing grip on rear", "My tires are dead"

WEATHER Weather conditions "Rain expected", "Track is wet"

Sources: scripts/NLP_radio_processing/N05_ner_models.ipynb 120-149

BIO Tagging Format

The system uses the Beginning-Inside-Outside (BIO) tagging scheme to handle multi-token entities:

BIO Tags

Token Sequence

keep

to

your

protocol

at

the

moment

B-ACTION

I-ACTION

I-ACTION

I-ACTION

I-ACTION

I-ACTION

I-ACTION

BIO Tagging Example for Multi-Token Entity

The tagging format includes:

B-{ENTITY}: Beginning of an entity

I-{ENTITY}: Inside/continuation of an entity O: Outside any entity (not part of named entities)

This results in 19 total labels: 9 B-tags, 9 I-tags, and 1 O-tag.

Sources: scripts/NLP_radio_processing/N05_ner_models.ipynb 418-459

scripts/NLP_radio_processing/N05_ner_models.ipynb 608-659

Model Architecture and Training

Core Model Components

The NER system is built on BertForTokenClassification with the following configuration:

Model Artifacts

Training Configuration

Model Training

F1RadioNERDataset

Token Alignment

tag2id mapping

dbmdz/bert-large-cased-finetuned-conll03-english

WeightedCrossEntropyLoss

compute_class_weight()

AdamW optimizer

get_linear_schedule_with_warmup()

clip_grad_norm_()

best_focused_bert_model.pt

BertConfig (19 labels)

NER Model Training Pipeline

Key Training Features

Class Weighting: Uses compute_class_weight('balanced') to handle entity class imbalance

Custom Dataset: F1RadioNERDataset class handles tokenization and label alignment

Gradient Clipping: Prevents exploding gradients with torch.nn.utils.clip_grad_norm_(model.parameters(), 1.0) Learning Rate Scheduling: Linear warmup with decay using get_linear_schedule_with_warmup()

Sources: scripts/NLP_radio_processing/N05_ner_models.ipynb 823-922

scripts/NLP_radio_processing/N05_ner_models.ipynb 1149-1248

Data Processing Pipeline

Text to BIO Conversion

The create_ner_tags() function converts character-based entity spans to token-based BIO tags:

Character-to-Word Mapping: Maps character positions to word indices

Entity Span Processing: Converts entity character spans to word-level tags

BIO Tag Assignment: Assigns B-tags to entity starts, I-tags to continuations

Dataset Preparation

The prepare_datasets() function creates train/validation/test splits:

Training: 319 examples (80%)

Validation: 40 examples (10%) Test: 40 examples (10%)

Sources: scripts/NLP_radio_processing/N05_ner_models.ipynb 418-502

scripts/NLP_radio_processing/N05_ner_models.ipynb 692-737

Model Loading and Prediction

Model Loading Function

The load_bert_ner_model() function initializes the trained NER model:

def load_bert_ner_model(CONFIG, device="cuda"): config = BertConfig.from_pretrained( "dbmdz/bert-large-cased-finetuned-conll03-english", num_labels=len(CONFIG["entity_mapping"]) ) model = BertForTokenClassification(config) model.load_state_dict(torch.load(CONFIG["ner_model_path"], map_location=device)) Entity Extraction

The analyze_f1_radio() function processes radio messages and extracts entities, returning structured output with entity types and text spans.

Sources: scripts/NLP_radio_processing/N06_model_merging.ipynb 281-304

scripts/NLP_radio_processing/N06_model_merging.ipynb 636-645

Integration with NLP Pipeline

The NER system integrates with the broader radio analysis pipeline through the analyze_radio_message() function, which combines:

Sentiment Analysis: predict_sentiment() using RoBERTa-base

Intent Classification: predict_intent() using RoBERTa-large Entity Recognition: analyze_f1_radio() using BERT-large

The output follows this JSON structure:

{ "message": "Box this lap for softs, Hamilton is catching up", "analysis": { "sentiment": "neutral", "intent": "order", "entities": { "action": "box", "situation": "catching up" } } }

Sources: scripts/NLP_radio_processing/N06_model_merging.ipynb 604-670

scripts/NLP_radio_processing/N04_radio_info.ipynb 44-71


Data Processing Utilities

Model Artifacts and Deployment

Development Environment

Integrated NLP Pipeline Relevant source files

The Integrated NLP Pipeline combines multiple specialized machine learning models to transform F1 team radio communications into structured, actionable data. This system processes raw radio messages through sentiment analysis, intent classification, and named entity recognition to extract strategic insights for the expert system.

For individual NLP model components, see Sentiment and Intent Analysis and Named Entity Recognition. For audio transcription capabilities, see Radio Transcription.

Pipeline Architecture

The integrated pipeline orchestrates three distinct transformer models to provide comprehensive analysis of radio communications:

Integration Layer

Prediction Layer

Model Loading Layer

Transcription Layer

Input Layer

Audio File (MP3)

Text Message

whisper.load_model('turbo')

transcribe_audio()

load_sentiment_model()

load_intent_model()

load_bert_ner_model()

RoBERTa-base + fine-tuned weights

RoBERTa-large + fine-tuned weights

BERT-large + CoNLL-03 + fine-tuned weights

predict_sentiment()

predict_intent()

analyze_f1_radio()

analyze_radio_message()

Structured JSON Output

Sources: scripts/NLP_radio_processing/NLP_utils/N06_model_merging.py 17-477

Model Components and Configuration

The pipeline configuration defines the three core models and their label mappings:

Model Loading Functions

CONFIG Dictionary

sentiment_model_path: best_roberta_sentiment_model.pt

intent_model_path: best_roberta_large_intent_model.pt

ner_model_path: best_focused_bert_model.pt

whisper_model_size: turbo

sentiment_labels: [positive, negative, neutral]

intent_labels: [INFORMATION, PROBLEM, ORDER, WARNING, QUESTION]

entity_mapping: B-ACTION, I-ACTION, B-INCIDENT, etc.

load_sentiment_model()

load_intent_model()

load_bert_ner_model()

Model Specifications

Model Type Base Architecture Fine-tuned Weights Output Classes Sentiment roberta-base best_roberta_sentiment_model.pt positive, negative, neutral Intent roberta-large best_roberta_large_intent_model.pt INFORMATION, PROBLEM, ORDER, WARNING, QUESTION NER dbmdz/bert-large-cased-finetuned-conll03-english best_focused_bert_model.pt 9 F1-specific entity types

Sources: scripts/NLP_radio_processing/NLP_utils/N06_model_merging.py 82-118

Core Integration Function

The analyze_radio_message function serves as the primary entry point, orchestrating all three models:

def analyze_radio_message(radio_message): """ Analyzes a radio message using sentiment, intent, and NER models. Returns the path to the generated JSON file. """ Processing Flow "JSON Output" "analyze_f1_radio()" "predict_intent()" "predict_sentiment()" "analyze_radio_message()" "JSON Output" "analyze_f1_radio()" "predict_intent()" "predict_sentiment()" "analyze_radio_message()" radio_message + sentiment_model {"sentiment": "positive", "confidence": 85.2} radio_message + intent_model {"intent": "ORDER", "confidence": 92.1} radio_message + ner_model {"ACTION": ["box this lap"], "STRATEGY_INSTRUCTION": ["for softs"]}

Structured response dictionary

JSON file path with timestamp

Sources: scripts/NLP_radio_processing/NLP_utils/N06_model_merging.py 343-411

Entity Recognition Integration

The NER component uses the specialized extract_entities_from_radio function and analyze_f1_radio wrapper:

Entity Extraction Process

Entity Categories

extract_entities_from_radio()

Radio Message Text

tokens = radio_message.split()

tokenizer(tokens, is_split_into_words=True)

model(**inputs)

BIO tag processing

Entity reconstruction

ACTION: 'box this lap'

STRATEGY_INSTRUCTION: 'change to softs'

INCIDENT: 'car ahead crashed'

TECHNICAL_ISSUE: 'engine overheating'

Sources: scripts/NLP_radio_processing/NLP_utils/N05_ner_models.py 1910-2029

scripts/NLP_radio_processing/NLP_utils/N05_ner_models.py 2031-2091

Output Format

The integrated pipeline produces structured JSON containing all analysis results:

{ "message": "Box this lap for softs, Hamilton is catching up", "analysis": { "sentiment": "neutral", "intent": "ORDER", "entities": { "ACTION": ["Box this lap"], "STRATEGY_INSTRUCTION": ["for softs"], "POSITION_CHANGE": ["Hamilton is catching up"] } } } File Output Management

The system generates timestamped JSON files using the pattern:

Output directory: ../../outputs/week4/json/ Filename format: radio_analysis_{YYYYMMDD_HHMMSS}.json Function: os.makedirs(os.path.dirname(json_filename), exist_ok=True)

Sources: scripts/NLP_radio_processing/NLP_utils/N06_model_merging.py 387-410

Audio Transcription Integration

The pipeline supports direct audio input through Whisper integration:

def transcribe_audio(audio_path): """ Transcribe F1 team radio audio using the Whisper model. Returns transcribed text for further NLP processing. """ model = whisper.load_model("turbo") result = model.transcribe(audio_path) return result["text"] Complete Audio-to-Analysis Workflow

team_radio.mp3

transcribe_audio()

Transcribed Text

analyze_radio_message()

JSON Analysis Results

Sources: scripts/NLP_radio_processing/NLP_utils/N06_model_merging.py 413-432

Usage in Expert System Integration

The structured JSON output directly feeds into the expert system's radio analysis rules through the transform_radio_analysis function, enabling automated strategic decision-making based on communication analysis.

For expert system integration details, see Radio Message Rules and Facts and Data Transformation.

Sources: scripts/NLP_radio_processing/NLP_utils/N06_model_merging.py 474-477


📝 This documentation is automatically generated using browser automation.
🕒 Last updated: $(date '+%Y-%m-%d %H:%M:%S UTC')