Beispiel #1
0
def main(args, samplegraph):
    t1 = time.time()
    g = Graph()
    print("Reading...")
    g.read_edgelist(samplegraph, weighted=args.weighted)
    model = GraRep(graph=g, Kstep=args.kstep, dim=args.representation_size)
    t2 = time.time()
    print(t2 - t1)
    print("Saving embeddings...")
    model.save_embeddings(args.output)
Beispiel #2
0
def learn_model(args):
    """
    Method to create adjacency matrix powers, read features, and learn embedding.
    :param args: Arguments object.
    """
    A = read_graph(args.edge_path)
    model = GraRep(A, args)
    model.optimize()
    model.save_embedding()
Beispiel #3
0
model_lable = Model(input=sentence_input, output=lable_ls)
low_encoder = Model(sentence_input, p_t)

###############################################################################################################################
## Training1 GRArep
t1 = time.time()
g = Graph()
print "Reading data..."
if args.graph_format == 'adjlist':
    g.read_adjlist(filename=args.input)
elif args.graph_format == 'edgelist':
    g.read_edgelist(filename=args.input,
                    weighted=args.weighted,
                    directed=args.directed)

model = GraRep(graph=g, Kstep=args.kstep)
vectors = model.vectors
X, Y = read_node_label(args.label_file)
node_size = len(vectors)
train_x = np.array([vectors[x] for x in X])
print("train_x.shape", train_x.shape)

# ###############################################################################################################################
# ## Prepare data


def sentence_batch_generator(data, batch_size):
    n_batch = len(data) / batch_size
    batch_count = 0
    np.random.shuffle(data)
Beispiel #4
0
from data_utils_cora import *
from grarep import GraRep

parser = argparse.ArgumentParser(description='Train and test LINE on tencent dataset')
parser.add_argument('--embsize', default=50, type=int)
parser.add_argument('--K', default=6, type=int)
parser.add_argument('--C', default=2, type=float)
args = parser.parse_args()

random.seed(616)

X_, A, y = load_data(path='../cora/')
_, _, _, idx_train, idx_val, idx_test = get_splits(y)

grarep = GraRep(A, emb_size_per_K=args.embsize, K=args.K)
grarep.train(verbose=True)


pca = PCA(n_components=args.embsize * args.K)
X_pca = pca.fit_transform(X_)

X = np.hstack([normalize(X_pca), normalize(grarep.emb)])
X_trn, X_val, X_tst = X[idx_train], X[idx_val], X[idx_test]
y_trn, y_val, y_tst = y[idx_train], y[idx_val], y[idx_test]
y_trn = np.argmax(y_trn, axis=1)
y_val = np.argmax(y_val, axis=1)
y_tst = np.argmax(y_tst, axis=1)

print('Testing...')
clf = LogisticRegression(C=args.C)