Skip to main content
Paper·arxiv.org
llmmachine-learningresearchragcontext-engineering

Using Large Language Models and Knowledge Graphs to Improve the Interpretability of Machine Learning Models in Manufacturing

Integrate Large Language Models (LLMs) with Knowledge Graphs (KGs) to enhance the interpretability of Machine Learning (ML) models, especially in manufacturing. This approach provides transparent, context-rich explanations for complex ML outcomes, improving trust and adoption in critical industrial settings.

advancedseveral hours5 steps
The play
  1. Identify ML Model & Interpretability Gaps
    Pinpoint the specific ML model outputs or predictions that require clear, human-understandable explanations. Define the domain-specific context and knowledge critical for these explanations (e.g., manufacturing processes, equipment, failure modes).
  2. Design and Populate the Knowledge Graph
    Model the relevant domain entities (e.g., machines, sensors, processes, failure modes) and their relationships (e.g., 'monitors', 'causes', 'is_part_of'). Populate the KG with structured data from your manufacturing environment.
  3. Link ML Model Outputs to KG Entities
    Develop a mechanism to map specific ML model predictions, feature importances, or anomaly detections to corresponding nodes or relationships within your Knowledge Graph. This creates a contextual bridge between ML results and domain knowledge.
  4. Develop LLM Prompting Strategy
    Craft targeted prompts that feed the LLM with the ML model's output *and* the relevant, linked context from the Knowledge Graph. Instruct the LLM to generate clear, concise, and domain-appropriate explanations for the ML decision.
  5. Generate and Refine Explanations
    Execute the LLM with the structured prompts to produce explanations. Continuously evaluate these explanations with domain experts to ensure accuracy, completeness, and clarity, iteratively refining the KG structure and LLM prompts for better interpretability.
Starter code
```python
# Step 1: Define a simplified Knowledge Graph snippet (e.g., using Python dict)
knowledge_graph_context = {
    "entities": {
        "CNC_Lathe_A1": {"type": "Machine", "location": "Assembly Line 3", "status": "Operational"},
        "Vibration_Sensor_001": {"type": "Sensor", "monitors": "CNC_Lathe_A1", "threshold_high_G": 0.5},
        "Bearing_Wear": {"type": "FailureMode", "symptoms": "High Vibration", "causes": "Lack of Lubrication"}
    },
    "relationships": [
        {"subject": "Vibration_Sensor_001", "predicate": "monitors", "object": "CNC_Lathe_A1"},
        {"subject": "Bearing_Wear", "predicate": "has_symptom", "object": "High Vibration"}
    ]
}

# Step 2: Define a hypothetical ML prediction
ml_prediction_data = {
    "machine_id": "CNC_Lathe_A1",
    "prediction": "High likelihood of Bearing Wear in next 7 days",
    "confidence": 0.92,
    "key_features": {"Vibration_Sensor_001_reading": 0.65, "Temperature_Sensor_005_reading": 35.2}
}

# Step 3: Construct the LLM prompt using both ML output and KG context
prompt = f"""
Given the following manufacturing knowledge graph:
{knowledge_graph_context}

And the following machine learning prediction:
{ml_prediction_data}

Explain why the 'CNC Lathe A1' is predicted to have 'Bearing Wear'. Focus on the most relevant sensor readings and relate them to known failure modes and machine components. Explain it in simple terms for a factory floor manager.
"""

print(prompt)
# This 'prompt' string is what you would send to an LLM API (e.g., OpenAI, Anthropic)
```
Source
Using Large Language Models and Knowledge Graphs to Improve the Interpretability of Machine Learning Models in Manufacturing — Action Pack