LLM Sessions : https://gemini.google.com/share/4bf368e3dbbf
Automated pipeline for extracting knowledge graphs from unstructured text with Big Five personality trait inference
This project implements an intelligent NLP pipeline that automatically constructs Knowledge Graphs (KGs) from unstructured text documents. The system goes beyond basic entity and relationship extraction by inferring and modeling Big Five (OCEAN) personality traits of individuals mentioned in the text.
Key Capabilities:
- π Entity Recognition & Linking
- π Relationship Extraction (SPO triples)
- π§ Personality Trait Inference (Big Five/OCEAN)
- π Comprehensive Evaluation Metrics
- π¨ Interactive Graph Visualization
- Supports plain text files (
.txt) - Multi-document batch processing
- UTF-8 and Latin-1 encoding support
- NER Engine: spaCy
en_core_web_smmodel - Entity Types: PERSON, ORG, GPE, PRODUCT, LOCATION
- Smart Detection: Handles proper nouns and capitalized names
- Unifies name variations (e.g., "Dr. Vance" β "Elias Vance")
- Resolves pronouns to canonical names (He/She β Person)
- Handles titles, prefixes, and possessives
- Advanced substring matching for compound names
Uses spaCy's dependency parser to extract:
- Subject-Predicate-Object (SPO) triples
- IS_A relationships (e.g., "Alice is a scientist")
- OWNS relationships (possessive constructs)
- HAS_TRAIT personality connections
- Verb-based and prepositional relationships
Infers Big Five (OCEAN) personality traits:
- Openness to Experience
- Conscientiousness
- Extraversion / Introversion
- Agreeableness
- Neuroticism
Scoring: 1-5 scale based on configurable keyword matching with contextual evidence tracking.
- Graph Coherence (95.4%): Structure quality and connectivity
- Information Richness (100%): Extraction efficiency per sentence
- Semantic Completeness (95.4%): Personality profile completeness
- Entity Recognition (85%): Detection quality
- Relationship Diversity (86%): Variety of relationship types
- Overall Score: 94.1/100 βββββ
- Entity Precision/Recall/F1-Score
- Relation Precision/Recall/F1-Score (with partial matching)
- Matched vs Expected relations analysis
See EVALUATION_METRICS.md for detailed documentation.
- Color-coded nodes: Person (blue), Trait (green), Concept (gold), etc.
- Labeled edges: Relationship types with scores
- Responsive layout: Spring-layout algorithm for optimal positioning
| Technology | Purpose | Version |
|---|---|---|
| Python | Core language | 3.7+ |
| spaCy | NLP (NER, POS, parsing) | 3.0+ |
| NetworkX | Graph construction | Latest |
| Matplotlib | Static visualization | Latest |
| Pandas | Evaluation reports | Latest |
# Clone the repository
git clone https://github.com/DerickAmadeus/Knowledge-Graph-Challenge.git
cd Knowledge-Graph-Challenge
# Install dependencies
pip install spacy networkx pandas matplotlib
# Download spaCy model
python -m spacy download en_core_web_sm
# Run the pipeline
python main.py
and the result is automatically popped up# Ensure Python 3.7+ is installed
python --version
# Install required packages
pip install spacy networkx pandas matplotlibpython -m spacy download en_core_web_smCreate text files with your documents:
project/
βββ main.py
βββ text
βββ 1.txt # Your first document
βββ 2.txt # Your second document
βββ 3.txt # Your third document
Example content (1.txt):
Alice is a kind and brilliant scientist who works with Bob in London.
She often leads meetings and enjoys collaborating with her colleagues.
python main.pyConsole Output:
[GRAPH STRUCTURE]
* Total Nodes: 10
* Total Edges: 13
* Persons: 2
* Trait Coverage: 100.0%
[INTRINSIC QUALITY METRICS]
* Graph Coherence: 95.4%
* Information Richness: 100.0%
* Intrinsic Score: 94.1/100
Edit DEFAULT_TRAIT_CLUES in main.py:
DEFAULT_TRAIT_CLUES = {
"Conscientiousness": {
"keywords": ["focused", "methodical", "organized", "diligent"],
"score_mod": 1.0
},
"Extraversion": {
"keywords": ["leads meetings", "networking", "talkative"],
"score_mod": 1.0
},
# Add your custom keywords...
}Customize name cleaning patterns:
TITLE_PREFIXES = r'(Dr\.|Prof\.|Professor|Mr\.|Ms\.|Mrs\.|President|CEO)'Define expected entities and relations for supervised evaluation:
GROUND_TRUTH = {
"1.txt": {
"persons": ["Alice", "Bob"],
"relations": [
("Alice", "IS_A", "scientist"),
("Alice", "HAS_TRAIT", "Openness"),
]
}
}File: 1.txt
βββββββββββββββββββββββββββββββββββββββββ
Graph Coherence: 95.4% β
Information Richness: 100.0% β
Semantic Completeness: 95.4% β
Entity Recognition: 85.0% β
Relationship Diversity: 86.0% β
βββββββββββββββββββββββββββββββββββββββββ
INTRINSIC SCORE: 94.1/100 βββββ
Intellumina/
βββ main.py # Main pipeline script
βββ 1.txt, 2.txt, 3.txt # Input documents
βββ knowledge_graph_*.html # Generated visualizations
βββ evaluation_report.csv # Metrics summary
βββ EVALUATION_METRICS.md # Detailed metrics documentation
βββ README.md # This file
βββ lib/ # JavaScript libraries
βββ vis-9.1.2/
βββ tom-select/
Perfect for production use when you don't have annotated data:
| Metric | Weight | Description |
|---|---|---|
| Graph Coherence | 20% | Structural quality, connectivity |
| Information Richness | 25% | Extraction efficiency |
| Semantic Completeness | 30% | Personality profile completeness |
| Entity Recognition | 15% | Detection quality |
| Relationship Diversity | 10% | Variety of relations |
For research and benchmarking:
- Entity Precision/Recall/F1
- Relation Precision/Recall/F1 (partial matching supported)
- Comprehensive accuracy analysis
π Full documentation: EVALUATION_METRICS.md
- π Research Papers: Extract author relationships and expertise
- πΌ Business Documents: Identify key stakeholders and roles
- π° News Articles: Map people, organizations, and events
- π Academic Analysis: Study personality traits in literature
- π HR & Recruitment: Analyze candidate profiles
- π€ Social Network Analysis: Understand relationship dynamics
| Area | Limitation | Impact |
|---|---|---|
| Relation Extraction | Rule-based dependency patterns | May miss complex/implicit relations |
| Coreference | Heuristic name mapping | Occasional fragmentation |
| Personality Model | Keyword matching | Limited context sensitivity |
| Negation | Not handled | "not organized" β still scores high |
| Sarcasm | Not detected | Misinterprets ironic statements |
- Author: Derick Amadeus Budiono
- Repository: Knowledge-Graph-Challenge
- Issues: Report bugs
- Discussions: Q&A and Ideas
Language: Python
Lines of Code: ~800
Functions: 15+
Evaluation Metrics: 10+
Supported Entities: 7 types
Personality Traits: 5 (Big Five)
If you find this project useful, please consider giving it a star β!