Gutenberg Children Books 2019-02-17 MSL=10 LGParseError with 20 clusters

LG-E-clean corpus, ALE clustering, 2000/1000/500/50/20 clusters, server 94.130.238.118
trash filter off, min_word_count = 1, max_sentence_length' = 10

This notebook is shared as static GCB-LG-E-clean-ALE-MWC=1-MSL=10-2019-02-17_LGParseError.html.
Output data shared via GCB-LG-E-clean-ALE-MWC=1-MSL=10-2019-02-17_LGParseError directory.

Basic settings

In [1]:
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, test_stats
from src.grammar_learner.read_files import check_dir, check_corpus
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, params, wide_rows
tmpath = module_path + '/tmp/'
check_dir(tmpath, True, 'none')
start = time.time()
runs = (1,1)
print(UTC(), ':: module_path:', module_path)
2019-02-17 11:17:09 UTC :: module_path: /home/obaskov/94/language-learning

Corpus test settings

In [2]:
corpus = 'GCB' # 'Gutenberg-Children-Books-Caps' 
dataset = 'LG-E-clean'
kwargs = {
    'max_sentence_length'   :   10  ,
    'max_unparsed_words'    :   0   ,
    'left_wall'     :   ''          ,
    'period'        :   False       ,
    'context'       :   1           ,
    'min_word_count':   1           ,
    'word_space'    :   'sparse'    ,
    'clustering'    :   ['agglomerative', 'ward'],
    'clustering_metric' : ['silhouette', 'cosine'],
    'cluster_range' :   2000        ,   # 2000/1000/500/50/20
    'top_level'     :   0.01        ,
    'grammar_rules' :   2           ,
    'max_disjuncts' :   1000000     ,   # off
    'stop_words'    :   []          ,
    'tmpath'        :   tmpath      ,
    'verbose'       :   'log+'      ,
    'template_path' :   'poc-turtle',
    'linkage_limit' :   1000        }
rp = module_path + '/data/' + corpus + '/LG-E-clean/GCB-LG-English-clean.ull'
cp = rp  # corpus path = reference_path
runs = (1,1)
out_dir = module_path + '/output/' + 'GCB-LG-E-clean-MWC=1-MSL=10-' + str(UTC())[:10]
print(UTC(), '\n', out_dir)
2019-02-17 11:17:09 UTC 
 /home/obaskov/94/language-learning/output/GCB-LG-E-clean-MWC=1-MSL=10-2019-02-17

Tests: min_word_count = 1; 2000/1000/500/50/20 clusters

Passed tests: 2000/1000/500/50 clusters

In [3]:
%%capture
table = []
kwargs['cluster_range'] = 2000
line = [['ALE2000', corpus, dataset, 0, 0, 'none']]
a, _, header, log, rules = wide_rows(line, out_dir, cp, rp, runs, **kwargs)
header[0] = 'Cell'
table.extend(a)
In [4]:
display(html_table([header] + a)); print(test_stats(log))
CellCorpusParsingSpaceLinkageAffinityG12nThresholdRulesMWCNNSIPAPQF1Top 5 cluster sizes
ALE2000GCBLG-E-cleancALWEdwardeuclideannone---20001---0.052%47%0.53[1547, 343, 294, 233, 204]
Cleaned dictionary: 13104 words, grammar learn time: 00:55:10, grammar test time: 00:39:12
In [5]:
%%capture
kwargs['cluster_range'] = 1000
line = [['ALE1000', corpus, dataset, 0, 0, 'none']]
a, _, h, log, rules = wide_rows(line, out_dir, cp, rp, runs, **kwargs)
table.extend(a)
In [6]:
display(html_table([header] + a)); print(test_stats(log))
CellCorpusParsingSpaceLinkageAffinityG12nThresholdRulesMWCNNSIPAPQF1Top 5 cluster sizes
ALE1000GCBLG-E-cleancALWEdwardeuclideannone---10001---0.057%47%0.53[2294, 513, 348, 343, 330]
Cleaned dictionary: 13104 words, grammar learn time: 00:37:29, grammar test time: 00:46:25
In [7]:
%%capture
kwargs['cluster_range'] = 500
line = [['ALE500', corpus, dataset, 0, 0, 'none']]
a, _, header, log, rules = wide_rows(line, out_dir, cp, rp, runs, **kwargs)
header[0] = 'Cell'
table.extend(a)
In [8]:
display(html_table([header] + a)); print(test_stats(log))
CellCorpusParsingSpaceLinkageAffinityG12nThresholdRulesMWCNNSIPAPQF1Top 5 cluster sizes
ALE500GCBLG-E-cleancALWEdwardeuclideannone---5001---0.061%49%0.53[3141, 653, 453, 372, 371]
Cleaned dictionary: 13104 words, grammar learn time: 00:29:58, grammar test time: 00:52:52
In [9]:
display(html_table([header] + table))
CellCorpusParsingSpaceLinkageAffinityG12nThresholdRulesMWCNNSIPAPQF1Top 5 cluster sizes
ALE2000GCBLG-E-cleancALWEdwardeuclideannone---20001---0.052%47%0.53[1547, 343, 294, 233, 204]
ALE1000GCBLG-E-cleancALWEdwardeuclideannone---10001---0.057%47%0.53[2294, 513, 348, 343, 330]
ALE500GCBLG-E-cleancALWEdwardeuclideannone---5001---0.061%49%0.53[3141, 653, 453, 372, 371]
In [10]:
print(UTC(), ':: 2000/100/500 finished, elapsed', str(round((time.time()-start)/3600.0, 1)), 'hours')
table_str = list2file(table, out_dir + '/all_tests_table.txt')
print('Results saved to', out_dir + '/all_tests_table.txt')
2019-02-17 15:38:19 UTC :: 2000/100/500 finished, elapsed 4.4 hours
Results saved to /home/obaskov/94/language-learning/output/GCB-LG-E-clean-MWC=1-MSL=10-2019-02-17/all_tests_table.txt
In [11]:
%%capture
kwargs['cluster_range'] = 50
line = [['ALE50', corpus, dataset, 0, 0, 'none']]
a, _, h, log, rules = wide_rows(line, out_dir, cp, rp, runs, **kwargs)
table.extend(a)
In [12]:
display(html_table([header] + a)); print(test_stats(log))
CellCorpusParsingSpaceLinkageAffinityG12nThresholdRulesMWCNNSIPAPQF1Top 5 cluster sizes
ALE50GCBLG-E-cleancALWEdwardeuclideannone---501---0.089%58%0.58[6402, 2893, 1702, 899, 292]
Cleaned dictionary: 13104 words, grammar learn time: 00:24:45, grammar test time: 02:39:54
In [13]:
display(html_table([header] + table))
CellCorpusParsingSpaceLinkageAffinityG12nThresholdRulesMWCNNSIPAPQF1Top 5 cluster sizes
ALE2000GCBLG-E-cleancALWEdwardeuclideannone---20001---0.052%47%0.53[1547, 343, 294, 233, 204]
ALE1000GCBLG-E-cleancALWEdwardeuclideannone---10001---0.057%47%0.53[2294, 513, 348, 343, 330]
ALE500GCBLG-E-cleancALWEdwardeuclideannone---5001---0.061%49%0.53[3141, 653, 453, 372, 371]
ALE50GCBLG-E-cleancALWEdwardeuclideannone---501---0.089%58%0.58[6402, 2893, 1702, 899, 292]
In [14]:
print(UTC(), ':: 2000/1000/500/50 finished, elapsed', str(round((time.time()-start)/3600.0, 1)), 'hours')
table_str = list2file(table, out_dir + '/all_tests_table.txt')
print('Results saved to', out_dir + '/all_tests_table.txt')
2019-02-17 18:42:59 UTC :: 2000/1000/500/50 finished, elapsed 7.4 hours
Results saved to /home/obaskov/94/language-learning/output/GCB-LG-E-clean-MWC=1-MSL=10-2019-02-17/all_tests_table.txt

Test failed with 20 clusters

In [15]:
%%capture
kwargs['cluster_range'] = 20
line = [['ALE20', corpus, dataset, 0, 0, 'none']]
a, _, h, log, rules = wide_rows(line, out_dir, cp, rp, runs, **kwargs)
table.extend(a)
---------------------------------------------------------------------------
LGParseError                              Traceback (most recent call last)
<ipython-input-15-d1ec7b15a3c4> in <module>()
      1 kwargs['cluster_range'] = 20
      2 line = [['ALE20', corpus, dataset, 0, 0, 'none']]
----> 3 a, _, h, log, rules = wide_rows(line, out_dir, cp, rp, runs, **kwargs)
      4 table.extend(a)

~/94/language-learning/src/grammar_learner/pqa_table.py in wide_rows(lines, out_dir, cp, rp, runs, **kwargs)
    427                 for k in range(runs[1]):
    428                     a, f1, precision, q = pqa_meter(re['grammar_file'],
--> 429                                                     og, cp, rp, **kwargs)
    430                     pa.append(a)
    431                     pq.append(q)

~/94/language-learning/src/grammar_learner/pqa_table.py in pqa_meter(dict_path, op, cp, rp, **kwargs)
    112                                              dict_path, grammar_path,
    113                                              template_path, linkage_limit,
--> 114                                              options, reference_path)
    115     return float(pa), float(f1), float(precision), float(recall)
    116 

~/94/language-learning/src/grammar_tester/grammartester.py in test_grammar(corpus_path, output_path, dict_path, grammar_path, template_path, linkage_limit, options, reference_path, timeout)
    372 
    373     # pm, pq = gt.test(dict_path, corpus_path, output_path, reference_path, options, None)
--> 374     pm, pq = gt.test(dict_path, corpus_path, output_path, reference_path, options, TextProgress)
    375 
    376     return \

~/94/language-learning/src/grammar_tester/grammartester.py in test(self, dict_path, corpus_path, output_path, reference_path, options, progress)
    327                 self._options &= (~BIT_DPATH_CREATE)
    328 
--> 329             self._on_dict_file(dict_path, parse_args)
    330 
    331         if self._parser is not None:

~/94/language-learning/src/grammar_tester/grammartester.py in _on_dict_file(self, dict_file_path, args)
    224 
    225         if os.path.isfile(corp_path):
--> 226             self._on_corpus_file(corp_path, [dest_path, lang_path] + args)
    227 
    228         elif os.path.isdir(corp_path):

~/94/language-learning/src/grammar_tester/grammartester.py in _on_corpus_file(self, corpus_file_path, args)
    181 
    182         file_metrics, file_quality = self._parser.parse(dict_path, corpus_file_path, out_file,
--> 183                                                         ref_file, self._options, self._progress)
    184 
    185         if self._options & (BIT_SEP_STAT | BIT_OUTPUT) == BIT_SEP_STAT:

~/94/language-learning/src/grammar_tester/lginprocparser.py in parse(self, dict_path, corpus_path, output_path, ref_file, options, progress)
    298                 # Take an action depending on the output format specified by 'options'
    299                 ret_metrics, ret_quality = self._handle_stream_output(raw.decode("utf-8-sig"), options,
--> 300                                                                       out_stream, ref_file)
    301 
    302                 if progress is not None:

~/94/language-learning/src/grammar_tester/lginprocparser.py in _handle_stream_output(self, text, options, out_stream, ref_path)
    159                     raise LGParseError("Number of sentences in corpus and reference files missmatch. "
    160                                        "Reference file '{}' does not match "
--> 161                                        "its corpus counterpart {} != {}.".format(ref_path, len_ref, len_par))
    162 
    163             sentence_count = 0

LGParseError: Number of sentences in corpus and reference files missmatch. Reference file '/home/obaskov/94/language-learning/data/GCB/LG-E-clean/GCB-LG-English-clean.ull' does not match its corpus counterpart 104341 != 104340.
In [ ]:
display(html_table([header] + a)); print(test_stats(log))

*Test with 20 clusters failed in ~74 hours, finished 20:28:08 2019-02-20

Save results

In [17]:
display(html_table([header] + table))
CellCorpusParsingSpaceLinkageAffinityG12nThresholdRulesMWCNNSIPAPQF1Top 5 cluster sizes
ALE2000GCBLG-E-cleancALWEdwardeuclideannone---20001---0.052%47%0.53[1547, 343, 294, 233, 204]
ALE1000GCBLG-E-cleancALWEdwardeuclideannone---10001---0.057%47%0.53[2294, 513, 348, 343, 330]
ALE500GCBLG-E-cleancALWEdwardeuclideannone---5001---0.061%49%0.53[3141, 653, 453, 372, 371]
ALE50GCBLG-E-cleancALWEdwardeuclideannone---501---0.089%58%0.58[6402, 2893, 1702, 899, 292]
In [18]:
print(UTC(), ':: finished, elapsed', str(round((time.time()-start)/3600.0, 1)), 'hours')
table_str = list2file(table, out_dir + '/all_tests_table.txt')
print('Results saved to', out_dir + '/all_tests_table.txt')
2019-02-20 20:28:08 UTC :: finished, elapsed 81.2 hours
Results saved to /home/obaskov/94/language-learning/output/GCB-LG-E-clean-MWC=1-MSL=10-2019-02-17/all_tests_table.txt

Test with 20 clusters might take several days to fulfil or fail... Please check results in all_tests_table.txt file.