Skip to content

Commit

Permalink
#4400 - Display recoomender name in log instead of RecommenderContext
Browse files Browse the repository at this point in the history
- Show the name
  • Loading branch information
reckart committed Dec 27, 2023
1 parent 00bbf4c commit 286160b
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import de.tudarmstadt.ukp.inception.recommendation.imls.ollama.response.ResponseAsLabelExtractor;
import de.tudarmstadt.ukp.inception.recommendation.imls.ollama.response.ResponseExtractor;
import de.tudarmstadt.ukp.inception.rendering.model.Range;
import de.tudarmstadt.ukp.inception.support.logging.LogMessage;

public class OllamaRecommender
extends NonTrainableRecommenderEngineImplBase
Expand Down Expand Up @@ -103,8 +104,9 @@ public Range predict(PredictionContext aContext, CAS aCas, int aBegin, int aEnd)
responseExtractor.extract(this, aCas, promptContext, response);
}
catch (IOException e) {
aContext.error("Ollama [%s] failed to respond: %s", traits.getModel(),
ExceptionUtils.getRootCauseMessage(e));
aContext.log(LogMessage.warn(getRecommender().getName(),
"Ollama [%s] failed to respond: %s", traits.getModel(),
ExceptionUtils.getRootCauseMessage(e)));
LOG.error("Ollama [{}] failed to respond: {}", traits.getModel(),
ExceptionUtils.getRootCauseMessage(e));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommenderContext.Key;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.TrainingCapability;
import de.tudarmstadt.ukp.inception.rendering.model.Range;
import de.tudarmstadt.ukp.inception.support.logging.LogMessage;
import opennlp.tools.doccat.DoccatFactory;
import opennlp.tools.doccat.DoccatModel;
import opennlp.tools.doccat.DocumentCategorizerME;
Expand Down Expand Up @@ -108,13 +109,14 @@ public void train(RecommenderContext aContext, List<CAS> aCasses) throws Recomme
var docSamples = extractSamples(aCasses);

if (docSamples.size() < 2) {
aContext.warn("Not enough training data: [%d] items", docSamples.size());
aContext.log(LogMessage.warn(getRecommender().getName(),
"Not enough training data: [%d] items", docSamples.size()));
return;
}

if (docSamples.stream().map(DocumentSample::getCategory).distinct().count() <= 1) {
aContext.warn("Training data requires at least two different labels",
docSamples.size());
aContext.log(LogMessage.warn(getRecommender().getName(),
"Training data requires at least two different labels", docSamples.size()));
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommenderContext.Key;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.TrainingCapability;
import de.tudarmstadt.ukp.inception.rendering.model.Range;
import de.tudarmstadt.ukp.inception.support.logging.LogMessage;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import opennlp.tools.ml.BeamSearch;
Expand Down Expand Up @@ -95,7 +96,8 @@ public void train(RecommenderContext aContext, List<CAS> aCasses) throws Recomme
var nameSamples = extractNameSamples(aCasses);

if (nameSamples.size() < 2) {
aContext.warn("Not enough training data: [%d] items", nameSamples.size());
aContext.log(LogMessage.warn(getRecommender().getName(),
"Not enough training data: [%d] items", nameSamples.size()));
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommenderContext.Key;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.TrainingCapability;
import de.tudarmstadt.ukp.inception.rendering.model.Range;
import de.tudarmstadt.ukp.inception.support.logging.LogMessage;
import opennlp.tools.ml.BeamSearch;
import opennlp.tools.postag.POSModel;
import opennlp.tools.postag.POSSample;
Expand Down Expand Up @@ -97,7 +98,8 @@ public void train(RecommenderContext aContext, List<CAS> aCasses) throws Recomme
var posSamples = extractPosSamples(aCasses);

if (posSamples.size() < 2) {
aContext.warn("Not enough training data: [%d] items", posSamples.size());
aContext.log(LogMessage.warn(getRecommender().getName(),
"Not enough training data: [%d] items", posSamples.size()));
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import de.tudarmstadt.ukp.inception.recommendation.imls.stringmatch.span.trie.Trie;
import de.tudarmstadt.ukp.inception.recommendation.imls.stringmatch.span.trie.WhitespaceNormalizingSanitizer;
import de.tudarmstadt.ukp.inception.rendering.model.Range;
import de.tudarmstadt.ukp.inception.support.logging.LogMessage;

public class StringMatchingRecommender
extends RecommendationEngine
Expand Down Expand Up @@ -138,7 +139,9 @@ public void pretrain(List<GazeteerEntry> aData, RecommenderContext aContext)
for (GazeteerEntry entry : aData) {
learn(dict, entry.text, entry.label);
}
aContext.info("Loaded [%d] entries from gazeteer", aData.size());

aContext.log(LogMessage.info(getRecommender().getName(),
"Loaded [%d] entries from gazeteer", aData.size()));
}

aContext.put(KEY_MODEL, dict);
Expand All @@ -159,8 +162,8 @@ public void train(RecommenderContext aContext, List<CAS> aCasses) throws Recomme
pretrain(gazeteerService.readGazeteerFile(gaz), aContext);
}
catch (IOException e) {
aContext.error("Unable to load gazeteer [%s]: %s", gaz.getName(),
e.getMessage());
aContext.log(LogMessage.error(getRecommender().getName(),
"Unable to load gazeteer [%s]: %s", gaz.getName(), e.getMessage()));
log.error(
"Unable to load gazeteer [{}] for recommender [{}]({}) in project [{}]({})",
gaz.getName(), gaz.getRecommender().getName(),
Expand Down Expand Up @@ -192,8 +195,9 @@ public void train(RecommenderContext aContext, List<CAS> aCasses) throws Recomme
}
}

aContext.info("Learned dictionary model with %d entries on %d documents", dict.size(),
aCasses.size());
aContext.log(LogMessage.info(getRecommender().getName(),
"Learned dictionary model with %d entries on %d documents", dict.size(),
aCasses.size()));

aContext.put(KEY_MODEL, dict);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,13 @@ synchronized public <T> Optional<T> get(Key<T> aKey)
return modelContext.get(aKey);
}

synchronized public void info(String aFormat, Object... aValues)
synchronized public void log(LogMessage aMessage)
{
if (closed) {
throw new IllegalStateException("Adding data to a closed context is not permitted.");
}

messages.add(LogMessage.info(this, aFormat, aValues));
}

synchronized public void warn(String aFormat, Object... aValues)
{
if (closed) {
throw new IllegalStateException("Adding data to a closed context is not permitted.");
}

messages.add(LogMessage.warn(this, aFormat, aValues));
}

synchronized public void error(String aFormat, Object... aValues)
{
if (closed) {
throw new IllegalStateException("Adding data to a closed context is not permitted.");
}

messages.add(LogMessage.error(this, aFormat, aValues));
messages.add(aMessage);
}

public List<LogMessage> getMessages()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,13 @@ synchronized public <T> void put(Key<T> aKey, T aValue)
store.put(aKey.name, aValue);
}

synchronized public void info(String aFormat, Object... aValues)
synchronized public void log(LogMessage aMessage)
{
if (closed) {
throw new IllegalStateException("Adding data to a closed context is not permitted.");
}

messages.add(LogMessage.info(this, aFormat, aValues));
}

synchronized public void warn(String aFormat, Object... aValues)
{
if (closed) {
throw new IllegalStateException("Adding data to a closed context is not permitted.");
}

messages.add(LogMessage.warn(this, aFormat, aValues));
}

synchronized public void error(String aFormat, Object... aValues)
{
if (closed) {
throw new IllegalStateException("Adding data to a closed context is not permitted.");
}

messages.add(LogMessage.error(this, aFormat, aValues));
messages.add(aMessage);
}

public List<LogMessage> getMessages()
Expand Down

0 comments on commit 286160b

Please sign in to comment.