0
0
Prompt Engineering / GenAIml~12 mins

Factual consistency checking in Prompt Engineering / GenAI - Model Pipeline Trace

Choose your learning style9 modes available
Model Pipeline - Factual consistency checking

This pipeline checks if the facts in a generated text match the original source. It helps make sure AI outputs are truthful and reliable.

Data Flow - 5 Stages
1Input data
1000 text pairs (source and generated) x 2 columnsLoad pairs of original source text and AI-generated text1000 text pairs x 2 columns
Source: 'The Eiffel Tower is in Paris.' Generated: 'The Eiffel Tower is located in Paris, France.'
2Text preprocessing
1000 text pairs x 2 columnsClean text, tokenize sentences, remove stop words1000 text pairs x 2 columns (cleaned tokens)
Source tokens: ['Eiffel', 'Tower', 'Paris'] Generated tokens: ['Eiffel', 'Tower', 'Paris', 'France']
3Feature extraction
1000 text pairs x 2 columns (tokens)Convert tokens to embeddings using language model1000 pairs x 2 embeddings (each 768 dimensions)
Source embedding: [0.12, -0.05, ..., 0.33] Generated embedding: [0.10, -0.04, ..., 0.30]
4Model training
1000 pairs x 2 embeddingsTrain classifier to predict if generated text is factually consistentTrained model
Model learns to output 1 if consistent, 0 if not
5Evaluation
200 test pairs x 2 embeddingsPredict consistency and compare with true labels200 predictions with accuracy metric
Accuracy: 85% correct factual consistency predictions
Training Trace - Epoch by Epoch

Loss
0.7 |    
0.6 |*   
0.5 |**  
0.4 |*** 
0.3 |****
     1 2 3 4 5 Epochs
EpochLoss ↓Accuracy ↑Observation
10.650.60Model starts learning basic patterns
20.500.72Accuracy improves as model learns fact matching
30.400.80Model better distinguishes consistent vs inconsistent
40.350.83Loss decreases steadily, accuracy improves
50.300.85Model converges with good factual consistency detection
Prediction Trace - 4 Layers
Layer 1: Input pair
Layer 2: Text preprocessing
Layer 3: Feature extraction
Layer 4: Model prediction
Model Quiz - 3 Questions
Test your understanding
What does the model predict when the generated text matches the source facts?
APrediction 0 (inconsistent)
BPrediction 2 (unknown)
CPrediction 1 (consistent)
DNo prediction
Key Insight
Factual consistency checking uses a model to compare original and generated texts. The model learns to spot if the generated text keeps the facts right by turning words into numbers and training on many examples. As training goes on, the model gets better and more accurate at this task.