示例#1
0
def predict_missing_links(train_file_path, evaluation_file_path, model_path,
                          tensorboard_visualizations_path):
    graph = load_from_csv('.', train_file_path, sep=',')
    evaluation_samples = load_from_csv('.', evaluation_file_path, sep=',')

    print('Head of the loaded graph: ')
    print(graph[:5])

    train_samples, test_samples = split(graph)
    print(
        f'Divided into train and test subsets with shapes {train_samples.shape} and {test_samples.shape} respectively.'
    )

    if not os.path.isfile(model_path):
        model = train_transe(train_samples)  # train_complex(train_samples)
        save_model(model, model_path)
    else:
        model = restore_model(model_path)

    metrics = compute_metrics(model, train_samples, test_samples)
    print(f'{"metric":10s}: {"score":5s}')
    for metric, score in metrics.items():
        print(f'{metric:10s}: {score:<5.2f}')

    scores, ranks = score_samples(model, evaluation_samples, train_samples)
    evaluation_summary = summarize(scores, evaluation_samples, ranks)

    print(evaluation_summary)

    if tensorboard_visualizations_path:
        os.makedirs(tensorboard_visualizations_path, exist_ok=True)
        create_tensorboard_visualizations(model,
                                          tensorboard_visualizations_path)
示例#2
0
def main():
    network = read_network()
    positives_filter = load_from_csv('.', 'network.csv', sep=',')
    #generate_model(positives_filter)
    model = load_model()

    window = Tk()

    window.title("Match Makers")

    window.geometry('350x200')

    lbl = Label(window, text="Name")

    lbl.grid(column=0, row=0)

    target = Entry(window, width=30)

    target.grid(column=1, row=0)

    lbl2 = Label(window, text="Topic")

    lbl2.grid(column=0, row=1)

    topic = Entry(window, width=30)

    topic.grid(column=1, row=1)

    lbl3 = Label(window, text="Results")

    lbl3.grid(column=0, row=3)

    results = scrolledtext.ScrolledText(window, width=40, height=10)

    results.grid(column=0, row=4)

    def clicked():

        #res = "Welcome to " + target.get()
        reccomendations = generate_reccomendations(network, model,
                                                   positives_filter,
                                                   target.get(), topic.get())
        if len(reccomendations) > 5:
            reccomendations = reccomendations[:5]
        final_result = "\n".join(reccomendations)

        results.delete(1.0, END)
        results.insert(INSERT, final_result)

    btn = Button(window, text="Process", command=clicked)

    btn.grid(column=0, row=2)

    window.mainloop()
示例#3
0
# !pip install ampligraph;

import numpy as np
import pandas as pd
import ampligraph

ampligraph.__version__

"""## 1. Dataset exploration"""

import requests
from ampligraph.datasets import load_from_csv

url = 'https://ampligraph.s3-eu-west-1.amazonaws.com/datasets/GoT.csv'
open('GoT.csv', 'wb').write(requests.get(url).content)
X = load_from_csv('.', 'GoT.csv', sep=',')
X[:5, ]

"""Subject and object entities in the dataset:"""

entities = np.unique(np.concatenate([X[:, 0], X[:, 2]]))
entities

"""Relationships that link subject and object"""

relations = np.unique(X[:, 1])
relations

"""---
# 2. Defining train and test datasets
"""
示例#4
0
import numpy as np
import pandas as pd
import requests

from ampligraph.datasets import load_from_csv
from ampligraph.latent_features import HolE, ComplEx
from ampligraph.evaluation import evaluate_performance
from ampligraph.evaluation import mr_score, mrr_score, hits_at_n_score
from ampligraph.evaluation import train_test_split_no_unseen

# International football matches triples
url = 'https://ampligraph.s3-eu-west-1.amazonaws.com/datasets/football.csv'
open('football.csv', 'wb').write(requests.get(url).content)
X = load_from_csv('.', 'football.csv', sep=',')[:, 1:]

# Train test split
X_train, X_test = train_test_split_no_unseen(X, test_size=10000)

# ComplEx model
model = HolE(batches_count=50,
             epochs=300,
             k=100,
             eta=20,
             optimizer='adam',
             optimizer_params={'lr': 1e-4},
             loss='multiclass_nll',
             regularizer='LP',
             regularizer_params={
                 'p': 3,
                 'lambda': 1e-5
             },