Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

88
LINES

< > BotCompany Repo | #1011018 // Train GAC-36K parser [OK]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 3874K of libraries. Click here for Pure Java version (13300L/95K).

1  
!7
2  
3  
concept Example {
4  
  S input;
5  
  S verb;
6  
  transient S verb_guessed;
7  
}
8  
9  
static F1<S, S> guesser;
10  
static JLabel lblStatus;
11  
static SS examples, errors;
12  
13  
p-subst {
14  
  dbIndexing(Example, 'input);
15  
  autoRestart();
16  
  for (S s : keys(gac36k()))
17  
    uniq(Example, input := s);
18  
    
19  
  print("Making CRUD");
20  
  sexyTable_drag = false;
21  
  final SimpleCRUD<Example> crud = simpleCRUD(Example);
22  
  swing {
23  
    tablePopupMenuItemFirst(crud.table, "Accept", voidfunc(int row) {
24  
      for (Example e : crud.selectedConcepts())
25  
        cset(e, verb := e.verb_guessed);
26  
    });
27  
    
28  
    containerAddFirst(crud.buttons, jbutton("Set multi...", r {
29  
      final L<Example> l = crud.selectedConcepts();
30  
      showTextFieldForm("Set multi (" + l(l) + ")", "Verb", first(l).verb_guessed, voidfunc(S s) {
31  
        for (Example e : l) cset(e, verb := s);
32  
      });
33  
    }), jbutton("Show errors", f showErrors));
34  
  }
35  
  
36  
  addToFrame(crud.panel, lblStatus = jlabel());
37  
  
38  
  thread { guessLoop(); }
39  
}
40  
41  
static SS examples() {
42  
  ret mapFromKeyAndValueField([Example e : list(Example) | nempty(e.verb)], 'input, 'verb);
43  
}
44  
45  
svoid guessLoop {
46  
  repeat with sleep 5 {
47  
    int changes = 0;
48  
    new HashMap<S> guessedMap;
49  
    Window anim = miniLoadingAnim();
50  
    try {
51  
      examples = examples();
52  
      int nTrain = l(examples)/2;
53  
      SS trainExamples = keysToMap(examples, selectRandom_fast(keysList(examples), nTrain));
54  
      
55  
      //guesser = cheatGuesser(trainExamples);
56  
      guesser = new F1<S, S>() {
57  
        S get(S s) {
58  
          s = unquoteIfNotContainingOtherQuotes(s);
59  
          try answer ai_guessVerb(s);
60  
          //ret firstWordPlusQuestionMark(s);
61  
          null;
62  
        }
63  
      };
64  
65  
      for (Example e) {
66  
        S s = unnullStr(pcallF(guesser, e.input));
67  
        changes += cset(e, verb_guessed := s);
68  
        guessedMap.put(e.input, s);
69  
      }
70  
      if (changes > 0) change();
71  
      
72  
      Pair<Double, SS> p = scoreGuesserIC_1_returnErrors(mapGetter(guessedMap), examples);
73  
      double score = p.a;
74  
      errors = p.b;
75  
      
76  
      setText(lblStatus, n(examples, "example") + ", trained with " + l(trainExamples) + ", score: " + formatDouble(score*100, 1) + "% ("
77  
      + iround((1-score)*l(examples)) + " missing)");
78  
    } finally {
79  
      disposeWindow(anim);
80  
    }
81  
  }
82  
}
83  
84  
svoid showErrors {
85  
  showTable(map(keys(errors), func(S input) {
86  
    litorderedmap(Input := input, Verb := examples.get(input), Guessed := errors.get(input))
87  
  }), "Errors");
88  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1011018
Snippet name: Train GAC-36K parser [OK]
Eternal ID of this version: #1011018/43
Text MD5: fe75b44a32d514815660b61d7ba76fbb
Transpilation MD5: 07b69dec1da3b06f05fb0cd1ceb89d3c
Author: stefan
Category: javax / a.i.
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-10-12 02:32:35
Source code size: 2527 bytes / 88 lines
Pitched / IR pitched: No / No
Views / Downloads: 394 / 3215
Version history: 42 change(s)
Referenced in: [show references]