Package: kogito
kogitoA Python NLP Commonsense Knowledge Inference ToolkitSystem Description available here:https://arxiv.org/abs/2211.08451InstallationInstallation with pipkogitocan be installed using pip.pipinstallkogitoIt requires a minimumpythonversion of3.8.SetupInferencekogitousesspacyunder the hood for various text processing purposes, so, aspacylanguage package has to be installed before running the inference module.python-mspacydownloaden_core_web_smBy default,CommonsenseInferencemodule usesen_core_web_smto initializespacypipeline, but a different language pipeline can be specified as well.EvaluationIf you also would like evaluate knowledge models usingMETEORscore, then you need to download the followingnltklibraries:importnltknltk.download("punkt")nltk.download("wordnet")nltk.download("omw-1.4")Quickstartkogitoprovides an easy interface to interact with knowledge inference or commonsense reasoning models such asCOMETto generate inferences from a text input.
Here is a sample usage of the library where you can initialize an inference module, a custom commonsense reasoning model, and generate a knowledge graph from text on the fly.fromkogito.models.bart.cometimportCOMETBARTfromkogito.inferenceimportCommonsenseInference# Load pre-trained model from HuggingFacemodel=COMETBART.from_pretrained("mismayil/comet-bart-ai2")# Initialize inference module with a spacy language pipelinecsi=CommonsenseInference(language="en_core_web_sm")# Run inferencetext="PersonX becomes a great basketball player"kgraph=csi.infer(text,model)# Save output knowledge graph to JSON filekgraph.to_jsonl("kgraph.json")Here is an excerpt from the result of the above code sample:{"head":"PersonX becomes a great basketball player","relation":"Causes","tails":[" PersonX practices every day."," PersonX plays basketball every day"," PersonX practices every day"]}{"head":"basketball","relation":"ObjectUse","tails":[" play with friends"," play basketball with"," play basketball"]}{"head":"player","relation":"CapableOf","tails":[" play game"," win game"," play football"]}{"head":"great basketball player","relation":"HasProperty","tails":[" good at basketball"," good at sports"," very good"]}{"head":"become player","relation":"isAfter","tails":[" play game"," become coach"," play with"]}This is just one way to generate commonsense inferences andkogitooffers much more. For complete documentation, check out thekogito docs.DevelopmentSetupkogitousesPoetryto manage its dependencies.Install poetry from the official repository first:curl-sSLhttps://install.python-poetry.org|python3-Then run the following command to install package dependencies:poetryinstallDataIf you need the ATOMIC2020 data to train your knowledge models, you can download it from AI2:For ATOMIC:wgethttps://storage.googleapis.com/ai2-mosaic/public/atomic/v1.0/atomic_data.tgzFor ATOMIC 2020:wgethttps://ai2-atomic.s3-us-west-2.amazonaws.com/data/atomic2020_data-feb2021.zipPaperIf you want to learn more about the library design, models and data used for this toolkit, check out ourpaper. The paper can be cited as:@article{Ismayilzada2022kogito,
  title={kogito: A Commonsense Knowledge Inference Toolkit},
  author={Mete Ismayilzada and Antoine Bosselut},
  journal={ArXiv},
  volume={abs/2211.08451},
  year={2022}
}If you work with knowledge models, consider citing the following papers:@article{Hwang2020COMETATOMIC,
 author = {Jena D. Hwang and Chandra Bhagavatula and Ronan Le Bras and Jeff Da and Keisuke Sakaguchi and Antoine Bosselut and Yejin Choi},
 booktitle = {Proceedings of the 35th AAAI Conference on Artificial Intelligence (AAAI)},
 title = {COMET-ATOMIC 2020: On Symbolic and Neural Commonsense Knowledge Graphs},
 year = {2021}
}

@inproceedings{Bosselut2019COMETCT,
 author = {Antoine Bosselut and Hannah Rashkin and Maarten Sap and Chaitanya Malaviya and Asli Çelikyilmaz and Yejin Choi},
 booktitle = {Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics (ACL)},
 title = {COMET: Commonsense Transformers for Automatic Knowledge Graph Construction},
 year = {2019}
}AcknowledgementsSignificant portion of the model training and evaluation code has been adapted from the originalcodebasefor the paper(Comet-) Atomic 2020: On Symbolic and Neural Commonsense Knowledge Graphs.