2018-10-21
¶Updated 2018-10-19 test_grammar
(F1), fixed grammar induction, Link Grammar 5.4.4, server 88.99.210.144
This notebook is shared as POC-Turtle-2018-10-21.html.
The "All tests" table is shared as 'short_table.txt' in POC-Turtle-2018-10-21 folder.
Previous (reference) tests:
POC-Turtle-2018-10-19.html,
POC-Turtle-2018-08-05.html.
import os, sys, time
module_path = os.path.abspath(os.path.join('..'))
if module_path not in sys.path: sys.path.append(module_path)
from src.grammar_learner.utl import UTC
from src.grammar_learner.read_files import check_dir
from src.grammar_learner.write_files import list2file
from src.grammar_learner.widgets import html_table
from src.grammar_learner.pqa_table import table_rows
tmpath = module_path + '/tmp/'
check_dir(tmpath, True, 'none')
table = []
long_table = []
start = time.time()
print(UTC(), ':: module_path =', module_path)
corpus = 'POC-Turtle'
out_dir = module_path + '/output/'+ corpus + '-' + str(UTC())[:10]
runs = (1,1) # (attempts to learn grammar per line, grammar tests per attempt)
if runs != (1,1): out_dir += '-multi'
kwargs = {
'left_wall' : '' ,
'period' : False ,
'context' : 1 ,
'word_space' : 'vectors' ,
'clustering' : ('kmeans', 'kmeans++', 18),
'cluster_range' : (20,2,9) ,
'grammar_rules' : 1 ,
'tmpath' : '' ,
'template_path' : 'poc-turtle',
'linkage_limit' : 1000 ,
'verbose' : 'min' }
lines = [
[5, 'POC-Turtle' , 'MST-fixed-manually' , 0 , 0 , 'none' ],
[6, 'POC-Turtle' , 'R=6-Weight=6:R-mst-weight=+1:R' , 0 , 0 , 'none' ],
[7, 'POC-Turtle' , 'R=6-Weight=1-no-mst-weighting' , 0 , 0 , 'none' ],
[8, 'POC-Turtle' , 'LG-ANY-all-parses' , 0 , 0 , 'none' ]]
# cp,rp :: (test) corpus_path and reference_path:
cp = module_path + '/data/POC-Turtle/poc-turtle-corpus.txt'
rp = module_path + '/data/POC-Turtle/MST-fixed-manually/poc-turtle-parses-gold.txt'
Comments on new 2018-08-04 optimal clustering search algorithm:
'cluster_range': (50,2,9)
: max, min, proof
proof: number of top results in silhouette index for the given number of clusters necessary to prove the best choice.
'clustering': ('kmeans','kmeans++',18)
: algorithm, initialization, number of initializations
proof = 9
and n_init=18
sound awkward, but was necessary to provide reproducibility for line 10 'POC-Turtle','LG-ANY-all-parses','LW','.', 'none' connectors-DRK-connectors settings.
%%capture
kwargs['context'] = 1
kwargs['grammar_rules'] = 1
average21, long21, header = table_rows(lines, out_dir, cp, rp, runs, **kwargs)
table.extend(average21)
long_table.extend(long21)
display(html_table([header]+average21))
%%capture
kwargs['context'] = 1
kwargs['grammar_rules'] = 2
average22, long22, header = table_rows(lines, out_dir, cp, rp, runs, **kwargs)
table.extend(average22)
long_table.extend(long22)
display(html_table([header]+average22))
%%capture
kwargs['context'] = 2
kwargs['grammar_rules'] = 2
average23, long23, header = table_rows(lines, out_dir, cp, rp, runs, **kwargs)
table.extend(average23)
long_table.extend(long23)
display(html_table([header]+average23))
%%capture
kwargs['context'] = 2
kwargs['word_space'] = 'discrete'
kwargs['clustering'] = 'group'
kwargs['grammar_rules'] = 2
average24, long24, header = table_rows(lines, out_dir, cp, rp, runs, **kwargs)
table.extend(average24)
long_table.extend(long24)
display(html_table([header]+average24))
runs > (1.1)
)¶display(html_table([header]+long_table))
print(UTC(), ':: finished, elapsed', str(round((time.time()-start)/60, 1)), 'min')
table_str = list2file(table, out_dir+'/short_table.txt')
if runs == (1,1):
print('Results saved to', out_dir + '/short_table.txt')
else:
long_table_str = list2file(long_table, out_dir+'/long_table.txt')
print('Average results saved to', out_dir + '/short_table.txt\n'
'Detailed results for every run saved to', out_dir + '/long_table.txt')