{"id":19066263,"url":"https://github.com/epfml/interpret-lm-knowledge","last_synced_at":"2026-02-14T00:42:37.802Z","repository":{"id":49399776,"uuid":"392933525","full_name":"epfml/interpret-lm-knowledge","owner":"epfml","description":"Extracting knowledge graphs from language models as a diagnostic benchmark of model performance (NeurIPS XAI 2021).","archived":false,"fork":false,"pushed_at":"2022-05-06T22:26:31.000Z","size":55,"stargazers_count":25,"open_issues_count":0,"forks_count":4,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-08-29T00:16:19.996Z","etag":null,"topics":["interpretable-deep-learning","knowledge-graph","language-model"],"latest_commit_sha":null,"homepage":"https://arxiv.org/pdf/2111.08546.pdf","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/epfml.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-05T06:44:33.000Z","updated_at":"2025-04-22T12:36:14.000Z","dependencies_parsed_at":"2022-09-04T15:41:44.792Z","dependency_job_id":null,"html_url":"https://github.com/epfml/interpret-lm-knowledge","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/epfml/interpret-lm-knowledge","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epfml%2Finterpret-lm-knowledge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epfml%2Finterpret-lm-knowledge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epfml%2Finterpret-lm-knowledge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epfml%2Finterpret-lm-knowledge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/epfml","download_url":"https://codeload.github.com/epfml/interpret-lm-knowledge/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epfml%2Finterpret-lm-knowledge/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29426750,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-13T22:20:51.549Z","status":"ssl_error","status_checked_at":"2026-02-13T22:20:49.838Z","response_time":78,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["interpretable-deep-learning","knowledge-graph","language-model"],"created_at":"2024-11-09T00:55:40.837Z","updated_at":"2026-02-14T00:42:37.779Z","avatar_url":"https://github.com/epfml.png","language":"Jupyter Notebook","readme":"# Interpreting Language Models Through Knowledge Graph Extraction\n\n**Idea**: How do we interpret what a language model learns at various stages of training? Language models have been recently described as [open knowledge bases](https://github.com/facebookresearch/LAMA). We can generate knowledge graphs by extracting relation triples from masked language models at sequential epochs or architecture variants to examine the knowledge acquisition process.  \n\n**Dataset**: Squad, Google-RE (3 flavors)  \n\n**Models**: BERT, RoBeRTa, DistilBert, training RoBERTa from scratch\n\n**Authors**: [Vinitra Swamy](https://github.com/vinitra), [Angelika Romanou](https://github.com/agromanou), [Martin Jaggi](https://github.com/martinjaggi)\n\nThis repository is the official implementation of the [NeurIPS 2021 XAI4Debugging](https://xai4debugging.github.io/) paper titled [\"Interpreting Language Models Through Knowledge Graph Extraction\"](https://arxiv.org/pdf/2111.08546.pdf). Found this work useful? Please [cite our paper](#citations).\n\n## Quick Start Guide\n### Pretrained Model (BERT, DistilBERT, RoBERTa) -\u003e Knowlege Graph\n1. Install requirements and clone repository  \n```\ngit clone https://github.com/epfml/interpret-lm-knowledge.git\npip install git+https://github.com/huggingface/transformers   \npip install textacy\ncd interpret-lm-knowledge/scripts\n```\n2. Generate knowledge graphs and dataframes\n`python run_knowledge_graph_experiments.py \u003cdataset\u003e \u003cmodel\u003e \u003cuse_spacy\u003e`  \ne.g. `squad Bert spacy`  \ne.g. `re-place-birth Roberta`    \n\noptional parameters:  \n```\ndataset=squad - \"squad\", \"re-place-birth\", \"re-date-birth\", \"re-place-death\"  \nmodel=Roberta - \"Bert\", \"Roberta\", \"DistilBert\"  \nextractor=spacy - \"spacy\", \"textacy\", \"custom\"\n```\nSee [`run_lm_experiments notebook`](scripts/run_lm_experiments.ipynb) for examples.\n\n### Train LM model from scratch -\u003e Knowledge Graph\n1. Install requirements and clone repository\n```\n!pip install git+https://github.com/huggingface/transformers\n!pip list | grep -E 'transformers|tokenizers'\n!pip install textacy\n```\n2. Run [`wikipedia_train_from_scratch_lm.ipynb`](scripts/wikipedia_train_from_scratch_lm.ipynb).\n3. As included in the last cell of the notebook, you can run the KG generation experiments by:\n```\nfrom run_training_kg_experiments import *\nrun_experiments(tokenizer, model, unmasker, \"Roberta3e\")\n```\n\n## Citations\n```bibtex\n@inproceedings{swamy2021interpreting,\n author = {Swamy, Vinitra and Romanou, Angelika and Jaggi, Martin},\n booktitle = {Advances in Neural Information Processing Systems (NeurIPS), 1st Workshop on eXplainable AI Approaches for Debugging and Diagnosis},\n title = {Interpreting Language Models Through Knowledge Graph Extraction},\n year = {2021}\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fepfml%2Finterpret-lm-knowledge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fepfml%2Finterpret-lm-knowledge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fepfml%2Finterpret-lm-knowledge/lists"}