-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upload preprocessed kg and update README
- Loading branch information
Showing
5 changed files
with
121 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
#!/bin/bash | ||
let num_runs=32 | ||
let num_runs=$1 | ||
let gpu_id=$2 | ||
|
||
for i in $(seq 0 $((num_runs-1))); | ||
do | ||
CUDA_VISIBLE_DEVICES=2 python parlai/tasks/redial/train_kbrd.py -mf saved/both_rgcn_$i | ||
CUDA_VISIBLE_DEVICES=$gpu_id python parlai/tasks/redial/train_kbrd.py -mf saved/both_rgcn_$i | ||
done | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import argparse | ||
import numpy as np | ||
from tqdm import tqdm | ||
|
||
|
||
def generate_n_grams(x, n): | ||
n_grams = set(zip(*[x[i:] for i in range(n)])) | ||
# print(x, n_grams) | ||
# for n_gram in n_grams: | ||
# x.append(' '.join(n_gram)) | ||
return n_grams | ||
|
||
|
||
def distinct_n_grams(tokenized_lines, n): | ||
|
||
n_grams_all = set() | ||
for line in tokenized_lines: | ||
n_grams = generate_n_grams(line, n) | ||
# print(line, n_grams) | ||
n_grams_all |= n_grams | ||
|
||
return len(set(n_grams_all)), len(set(n_grams_all)) / len(tokenized_lines) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('input', type=str) | ||
args = parser.parse_args() | ||
with open(args.input) as f: | ||
lines = f.read().strip().split('\n') | ||
# tokenized = [line.split()[3:-1] for line in lines] | ||
tokenized = [line.split()[1:] for line in lines] | ||
print(tokenized[:5]) | ||
|
||
for n in range(1, 6): | ||
cnt, percent = distinct_n_grams(tokenized, n) | ||
print(f'Distinct {n}-grams (cnt, percentage) = ({cnt}, {percent:.3f})') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import pickle as pkl | ||
|
||
if __name__ == "__main__": | ||
subkg = pkl.load(open('data/redial/subkg.pkl', 'rb')) | ||
entity2entityId = pkl.load(open('data/redial/entity2entityId.pkl', 'rb')) | ||
entityId2entity = dict([(entity2entityId[k], k) for k in entity2entityId]) | ||
relation2relationId = pkl.load(open('data/redial/relation2relationId.pkl', 'rb')) | ||
relationId2relation = dict([(relation2relationId[k], k) for k in relation2relationId]) | ||
|
||
triples = [] | ||
for headId in subkg: | ||
for relationId, tailId in subkg[headId]: | ||
head = entityId2entity[headId] | ||
relation = relationId2relation[relationId] | ||
tail = entityId2entity[tailId] | ||
if relation == 'self_loop': | ||
continue | ||
triples.append(f"{head} {relation} {tail} \n") | ||
|
||
print(len(triples)) | ||
with open('triples.txt', 'w') as f: | ||
f.writelines(triples) | ||
|
This file was deleted.
Oops, something went wrong.