The ability to solve the complicated and interconnected systemic CNC machine tool faults of traditional machine tool fault diagnosis systems are limited. As a research hot-spot in the field of artificial intelligence, the knowledge map has the ability to standardize the non -structured data such as expert knowledge and use it for fault diagnosis, which can realize the explanation of the cause of fault. This article proposes a method to construct self-optimizing diagnostic system of CNC machine tool based on knowledge graph. First of all, expert knowledge was used to build the ontology of the knowledge map, and clarify the entity and relationship type in the knowledge map. Then, BiLSTM-CRF Model was used for named entity recognition from non-structured text. After that, Attention-based BiLSTM Model was used for relation detection and classification based on the previous result. Eventually, the extracted entity and relationship can build a knowledge graph for the diagnosis of CNC machine tool fault. Based on this as a premise, the diagnostic system of CNC machine tool is realized.