Kann jemand einen Weg finden, meine CoreNLP-Sentiment-Analyse (unten) zu beschleunigen?Beschleunigung der CoreNLP-Sentiment-Analyse
ich initialisieren die CoreNLP Pipeline einmal auf Serverstart:
// Initialize the CoreNLP text processing pipeline
public static Properties props = new Properties();
public static StanfordCoreNLP pipeline;
// Set text processing pipeline's annotators
props.setProperty("annotators", "tokenize, ssplit, pos, parse, sentiment");
// Use Shift-Reduce Constituency Parsing (O(n),
// http://nlp.stanford.edu/software/srparser.shtml) vs CoreNLP's default
// Probabilistic Context-Free Grammar Parsing (O(n^3))
props.setProperty("parse.model", "edu/stanford/nlp/models/srparser/englishSR.ser.gz");
pipeline = new StanfordCoreNLP(props);
Dann rufe ich die Pipeline von meinem Controller:
String text = 'A sample string.'
Annotation annotation = pipeline.process(text);
List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
for (CoreMap sentence : sentences) {
Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class);
int sentiment = RNNCoreAnnotations.getPredictedClass(tree);
...
}
ich den Code profiliert haben - die Linie Annotation annotation = pipeline.process(text)
, die ist CoreNLPs Hauptverarbeitungsaufruf, ist sehr langsam. Eine Anfrage mit 100 Anrufen an meinen Controller dauert durchschnittlich 1,07 Sekunden. Die Anmerkung dauert ~ 7ms pro Anruf. Ich muss das auf ~ 2ms reduzieren.
Ich kann keine der Annotatoren entfernen, weil die Stimmung von allen abhängt. Ich verwende bereits den Shift-Reduce Constituency Parser, da dieser viel schneller ist als der Standard Context-Free Grammar Parser.
Gibt es weitere Parameter, die ich einstellen kann, um diese Geschwindigkeit deutlich zu erhöhen?
Ich gehe davon aus Sie die Standardmodelle verwenden, ist es sehr wahrscheinlich nicht machbar ohne einen großen annotierten Korpus, aber höchstwahrscheinlich könnten Sie kleinere Modelle speziell für Ihre Domäne umschulen. –