Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track/llm kg #58

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
checkpoint
*.npy
*.log
models
data/wikidata_5m/*.dict
data/wikidata_5m/*.json
2 changes: 2 additions & 0 deletions commands/command1.txt
Original file line number Diff line number Diff line change
@@ -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
68 changes: 68 additions & 0 deletions data/wikidata_5m/add_graph.py
Original file line number Diff line number Diff line change
@@ -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)
Empty file added data/wikidata_5m/test.txt
Empty file.
Empty file added data/wikidata_5m/train.txt
Empty file.
Empty file added data/wikidata_5m/valid.txt
Empty file.