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

97
LINES

< > BotCompany Repo | #1011085 // Train Tripelizer [OK]

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

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

1  
!7
2  
3  
concept Example {
4  
  S input;
5  
  Triple<S> triple;
6  
  transient Triple<S> guessed;
7  
}
8  
9  
static F1<S, Triple<S>> guesser;
10  
static JLabel lblStatus;
11  
static Map<S, Triple<S>> 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 = new SimpleCRUD<Example>(Example) {
22  
    void saveComponent(Example c, S field, JComponent comp) {
23  
      if (eqOneOf(field, 'triple, 'guessed))
24  
        cset(c, field, unstructureOrNull(getTextTrim(comp)));
25  
      else
26  
        super.saveComponent(c, field, comp);
27  
    }
28  
  };
29  
  crud.renderer = func(Example e) {
30  
    litorderedmap(Input := e.input, Triple := ai_tripleToString(e.triple), Guessed := ai_tripleToString(e.guessed))
31  
  };
32  
  crud.showMaximized();
33  
  swing {
34  
    tablePopupMenuItemFirst(crud.table, "Accept", voidfunc(int row) {
35  
      for (Example e : crud.selectedConcepts())
36  
        cset(e, triple := e.guessed);
37  
    });
38  
    
39  
    containerAddFirst(crud.buttons, /*jbutton("Set multi...", r {
40  
      final L<Example> l = crud.selectedConcepts();
41  
      showTextFieldForm("Set multi (" + l(l) + ")", "Verb", first(l).verb_guessed, voidfunc(S s) {
42  
        for (Example e : l) cset(e, verb := s);
43  
      });
44  
    }),*/ jbutton("Show errors", f showErrors));
45  
    
46  
    containerAddFirst(crud.buttons, jbutton("Clear caches", f clearAllCaches));
47  
  }
48  
  
49  
  addToFrame(crud.panel, lblStatus = jlabel());
50  
  
51  
  thread { guessLoop(); }
52  
}
53  
54  
static Map<S, Triple<S>> examples() {
55  
  ret mapFromKeyAndValueField([Example e : list(Example) | e.triple != null], 'input, 'triple);
56  
}
57  
58  
svoid guessLoop {
59  
  repeat with sleep 5 {
60  
    int changes = 0;
61  
    new HashMap<S, Triple<S>> guessedMap;
62  
    Window anim = miniLoadingAnim();
63  
    try {
64  
      examples = examples();
65  
      int nTrain = l(examples)/2;
66  
      Map<S, Triple<S>> trainExamples = keysToMap(examples, selectRandom_fast(keysList(examples), nTrain));
67  
      
68  
      guesser = new F1<S, Triple<S>>() {
69  
        Triple<S> get(S s) {
70  
          ret ai_tripelize(unquoteIfNotContainingOtherQuotes(s));
71  
        }
72  
      };
73  
74  
      for (Example e) {
75  
        Triple<S> t = (Triple<S>) pcallF(guesser, e.input);
76  
        changes += cset(e, guessed := t);
77  
        guessedMap.put(e.input, t);
78  
      }
79  
      if (changes > 0) change();
80  
      
81  
      Pair<Double, Map<S, Triple<S>>> p = scoreTripelizer(mapGetter(guessedMap), examples);
82  
      double score = p.a;
83  
      errors = p.b;
84  
      
85  
      setText(lblStatus, n(examples, "example") + ", trained with " + l(trainExamples) + ", score: " + formatDouble(score*100, 1) + "% ("
86  
      + iround((1-score)*l(examples)) + " missing)");
87  
    } finally {
88  
      disposeWindow(anim);
89  
    }
90  
  }
91  
}
92  
93  
svoid showErrors {
94  
  showTable(map(keys(errors), func(S input) {
95  
    litorderedmap(Input := input, Real := ai_tripleToString(examples.get(input)), Guessed := ai_tripleToString(errors.get(input)))
96  
  }), "Errors");
97  
}

Author comment

Began life as a copy of #1011018

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1011085
Snippet name: Train Tripelizer [OK]
Eternal ID of this version: #1011085/16
Text MD5: b03547f870e1b14776e00f51bb759c6a
Transpilation MD5: 7db6b193230b856697bb65b1e2c5b841
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-25 21:10:06
Source code size: 3060 bytes / 97 lines
Pitched / IR pitched: No / No
Views / Downloads: 459 / 2724
Version history: 15 change(s)
Referenced in: [show references]