2018-12-21_
¶«Re-generate tests (with trees production) for POCE & CDS for all baseline parse&WSD variants»
Link Grammar 5.5.1, test_grammar
updated 2018-10-19 , server 94.130.238.118
This notebook is shared as static Child-Directed-Speech-2018-12-21.html;
The "All tests" table is shared as 'short_table.txt' in Child-Directed-Speech-2018-12-21 directory.
Previous tests:
Child-Directed-Speech-2018-12-05.html,
Child-Directed-Speech-2018-10-24.html,
Child-Directed-Speech-2018-10-19.html,
Child-Directed-Speech-2018-08-14.html,
Child-Directed-Speech-2018-08-06.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, wide_rows
tmpath = module_path + '/tmp/'
check_dir(tmpath, True, 'none')
table = []
long_table = []
start = time.time()
out_dir = module_path + '/output/Child-Directed-Speech-' + str(UTC())[:10]
print(UTC(), ':: out_dir:\n', out_dir)
runs = (1,1)
kwargs = {
'left_wall' : '' ,
'period' : False ,
'min_word_count': 1 ,
'min_link_count': 1 ,
'min_co-occurrence_count': 1 ,
'word_space' : 'vectors' ,
'clustering' : ['kmeans', 'kmeans++', 10],
'cluster_range' : [30,120,3,3],
'cluster_criteria' : 'silhouette',
'clustering_metric' : ['silhouette', 'cosine'],
'cluster_level' : 1 ,
'rules_merge' : 0.8 , # grammar rules merge threshold
'rules_aggregation' : 0.1 , # grammar rules aggregation threshold
'top_level' : 0.01 , # top-level rules generalization threshold
'tmpath' : tmpath ,
'verbose' : 'log+' ,
'template_path' : 'poc-turtle',
'linkage_limit' : 1000 }
lines = [
[33, 'CDS' , 'LG-English' ,0,0, 'none'],
[34, 'CDS' , 'LG-English' ,0,0, 'rules' ],
[35, 'CDS' , 'R=6-W=6:R-MW=+1:R' ,0,0, 'none'],
[36, 'CDS' , 'R=6-W=6:R-MW=+1:R' ,0,0, 'rules' ]]
cp = rp = module_path + '/data/CDS/LG-E-clean' # clean: both files, 100% parsed
cp = rp # test corpus path = reference_path
%%capture
kwargs['context'] = 1
kwargs['word_space'] = 'vectors'
kwargs['clustering'] = 'kmeans'
kwargs['cluster_range'] = [30,120,3,3]
kwargs['grammar_rules'] = 1
average21, long21, header = table_rows(lines, out_dir, cp, rp, runs, **kwargs)
# average21, long21, header, log, rules = wide_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['word_space'] = 'vectors'
kwargs['clustering'] = 'kmeans'
kwargs['grammar_rules'] = 2
average22, long22, header = table_rows(lines, out_dir, cp, rp, runs, **kwargs)
# average22, long22, header, log, rules = wide_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['word_space'] = 'vectors'
kwargs['clustering'] = 'kmeans'
kwargs['grammar_rules'] = 2
average23, long23, header = table_rows(lines, out_dir, cp, rp, runs, **kwargs)
# average23, long23, header, log, rules = wide_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)
# average24, long24, header, log, rules = wide_rows(lines, out_dir, cp, rp, runs, **kwargs)
table.extend(average24)
long_table.extend(long24)
display(html_table([header] + average24))
kwargs['word_space'] = 'sparse'
kwargs['min_word_count'] = 1
%%capture
kwargs['clustering'] = ['agglomerative', 'ward']
kwargs['cluster_range'] = 50
average, long, header = table_rows(lines, out_dir, cp, rp, runs, **kwargs)
# average, long, header, log, rules = wide_rows(lines, out_dir, cp, rp, runs, **kwargs)
table.extend(average)
long_table.extend(long)
display(html_table([header] + average))
%%capture
kwargs['cluster_range'] = 400
average, long, header = table_rows(lines, out_dir, cp, rp, runs, **kwargs)
# average, long, header, log, rules = wide_rows(lines, out_dir, cp, rp, runs, **kwargs)
table.extend(average)
long_table.extend(long)
display(html_table([header] + average))
%%capture
kwargs['clustering'] = ['agglomerative', 'complete', 'cosine']
kwargs['cluster_range'] = 50
average, long, header = table_rows(lines, out_dir, cp, rp, runs, **kwargs)
# average, long, header, log, rules = wide_rows(lines, out_dir, cp, rp, runs, **kwargs)
table.extend(average)
long_table.extend(long)
display(html_table([header] + average))
%%capture
kwargs['cluster_range'] = 400
average, long, header = table_rows(lines, out_dir, cp, rp, runs, **kwargs)
# average, long, header, log, rules = wide_rows(lines, out_dir, cp, rp, runs, **kwargs)
table.extend(average)
long_table.extend(long)
display(html_table([header] + average))
%%capture
kwargs['cluster_range'] = 50
kwargs['clustering'] = ['agglomerative', 'complete', 'cosine']
average, long, header = table_rows(lines, out_dir, cp, rp, runs, **kwargs)
# average, long, header, log, rules = wide_rows(lines, out_dir, cp, rp, runs, **kwargs)
table.extend(average)
long_table.extend(long)
display(html_table([header] + average))
%%capture
kwargs['cluster_range'] = 400
average, long, header = table_rows(lines, out_dir, cp, rp, runs, **kwargs)
# average, long, header, log, rules = wide_rows(lines, out_dir, cp, rp, runs, **kwargs)
table.extend(average)
long_table.extend(long)
display(html_table([header] + average))
display(html_table([header]+long_table))
print(UTC(), ':: finished, elapsed', str(round((time.time()-start)/3600.0, 1)), 'hours')
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')