From c63817131937e3ad6495b49665bcbb06581b9549 Mon Sep 17 00:00:00 2001 From: Himanshu Naidu Date: Fri, 15 Dec 2023 15:38:45 -0800 Subject: [PATCH 1/3] Updated gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index d27caad5..418fdadf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ checkpoint *.npy *.log +models +data/wikidata_5m \ No newline at end of file From 053ebc258d05bfdf0b9ecdee46c5fd2d95d5b81e Mon Sep 17 00:00:00 2001 From: Himanshu Naidu Date: Fri, 15 Dec 2023 15:39:50 -0800 Subject: [PATCH 2/3] Add commands --- commands/command1.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 commands/command1.txt diff --git a/commands/command1.txt b/commands/command1.txt new file mode 100644 index 00000000..72a29907 --- /dev/null +++ b/commands/command1.txt @@ -0,0 +1,2 @@ +set CUDA_VISIBLE_DEVICES=2,3 & python "C:\E Drive\AI DRG Code Base\KnowledgeGraphEmbedding\codes\run.py" --do_train --cuda --data_path "C:\E Drive\AI DRG Code Base\KnowledgeGraphEmbedding\data\countries_S1" --model RotatE -n 256 -b 1024 -d 1000 -g 24.0 -a 1.0 -adv -lr 0.0001 --max_steps 200 -save "C:\E Drive\AI DRG Code Base\KnowledgeGraphEmbedding\models\countries_S1" -de --save_checkpoint_steps 10 --log_steps 1 +python "C:\E Drive\AI DRG Code Base\KnowledgeGraphEmbedding\codes\run.py" --do_train --cuda --data_path "C:\E Drive\AI DRG Code Base\KnowledgeGraphEmbedding\data\countries_S1" --model RotatE -n 128 -b 1024 -d 256 -g 24.0 -a 1.0 -adv -lr 0.0001 --max_steps 100 -save "C:\E Drive\AI DRG Code Base\KnowledgeGraphEmbedding\models\countries_S1" -de --save_checkpoint_steps 10 --log_steps 5 From 29732064098d26ce65fa8227cba4c937364b1a5c Mon Sep 17 00:00:00 2001 From: Himanshu Naidu Date: Fri, 15 Dec 2023 15:42:37 -0800 Subject: [PATCH 3/3] Add wikidata files --- .gitignore | 3 +- data/wikidata_5m/add_graph.py | 68 +++++++++++++++++++++++++++++++++++ data/wikidata_5m/test.txt | 0 data/wikidata_5m/train.txt | 0 data/wikidata_5m/valid.txt | 0 5 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 data/wikidata_5m/add_graph.py create mode 100644 data/wikidata_5m/test.txt create mode 100644 data/wikidata_5m/train.txt create mode 100644 data/wikidata_5m/valid.txt diff --git a/.gitignore b/.gitignore index 418fdadf..4dc448d6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ checkpoint *.npy *.log models -data/wikidata_5m \ No newline at end of file +data/wikidata_5m/*.dict +data/wikidata_5m/*.json diff --git a/data/wikidata_5m/add_graph.py b/data/wikidata_5m/add_graph.py new file mode 100644 index 00000000..edc4d11d --- /dev/null +++ b/data/wikidata_5m/add_graph.py @@ -0,0 +1,68 @@ +import os +import json + +path = os.path.join(os.getcwd(), 'KnowledgeGraphEmbedding\data\wikidata_5m') +print(path) + +class Graph(): + def __init__(self, graph): + self.graph = graph + + def getGraph(self): + return self.graph + + def getId2Entity(self): + return self.graph['id2entity'] + + def getEntity2Id(self): + return self.graph['entity2id'] + + def getId2Relation(self): + return self.graph['id2relation'] + + def getRelation2Id(self): + return self.graph['relation2id'] + +def readId2Entity(graph: Graph, path=path): + id_entity = graph.getId2Entity() + print(len(id_entity)) + + entity_file = open(os.path.join(path, 'entities.dict'), 'a+') + # counter = 10 + i = 0 + for entity in id_entity: + entity_file.write(f'{i}\t{entity}\n') + i = i+1 + +def readEntity2Id(graph: Graph, path=path): + entity_id = graph.getEntity2Id() + print(type(entity_id)) + +def readId2Relation(graph: Graph, path=path): + id_relation = graph.getId2Relation() + print(len(id_relation)) + + relation_file = open(os.path.join(path, 'relations.dict'), 'a+') + # counter = 10 + i = 0 + for relation in id_relation: + relation_file.write(f'{i}\t{relation}\n') + i = i+1 + +def readRelation2Id(graph: Graph, path=path): + relation_id = graph.getRelation2Id() + print(type(relation_id)) + +def run(path): + graph_path = os.path.join(path, 'graph_id.json') + graph_file = open(graph_path, 'r') + graph: Graph = Graph(json.load(graph_file)) + + print(graph.getGraph().keys()) + readId2Entity(graph, path) + # readEntity2Id(graph, path) + readId2Relation(graph, path) + # readRelation2Id(graph, path) + +if __name__=='__main__': + run(path=path) \ No newline at end of file diff --git a/data/wikidata_5m/test.txt b/data/wikidata_5m/test.txt new file mode 100644 index 00000000..e69de29b diff --git a/data/wikidata_5m/train.txt b/data/wikidata_5m/train.txt new file mode 100644 index 00000000..e69de29b diff --git a/data/wikidata_5m/valid.txt b/data/wikidata_5m/valid.txt new file mode 100644 index 00000000..e69de29b