From 685e65d2252ef8bd15552522bffb180123065256 Mon Sep 17 00:00:00 2001 From: Richard Eckart de Castilho Date: Tue, 14 Nov 2023 19:11:18 +0100 Subject: [PATCH] #4292 - ollama-based recommender - Added another preset - Allow accessing the surrounding sentence in the per-annotation processing mode --- inception/inception-imls-ollama/pom.xml | 4 ++++ .../recommendation/imls/ollama/OllamaRecommender.java | 8 +++++++- .../inception/recommendation/imls/ollama/presets.yaml | 10 ++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/inception/inception-imls-ollama/pom.xml b/inception/inception-imls-ollama/pom.xml index 2ca84d38e39..5cef7b91223 100644 --- a/inception/inception-imls-ollama/pom.xml +++ b/inception/inception-imls-ollama/pom.xml @@ -107,6 +107,10 @@ wicket-spring + + com.fasterxml.jackson.core + jackson-core + com.fasterxml.jackson.core jackson-annotations diff --git a/inception/inception-imls-ollama/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/ollama/OllamaRecommender.java b/inception/inception-imls-ollama/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/ollama/OllamaRecommender.java index bf4e29fd3a2..d75184825c7 100644 --- a/inception/inception-imls-ollama/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/ollama/OllamaRecommender.java +++ b/inception/inception-imls-ollama/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/ollama/OllamaRecommender.java @@ -54,6 +54,8 @@ public class OllamaRecommender extends NonTrainableRecommenderEngineImplBase { private static final String VAR_TEXT = "text"; + private static final String VAR_SENTENCE = "sentence"; + private static final String VAR_DOCUMENT = "document"; private final static Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); @@ -300,7 +302,11 @@ private Range predictPerAnnotation(RecommenderContext aContext, CAS aCas, int aB var predictedType = getPredictedType(aCas); for (var candidate : selectOverlapping(aCas, predictedType, aBegin, aEnd)) { - var bindings = Map.of(VAR_TEXT, candidate.getCoveredText()); + String sentence = aCas.select(Sentence.class).covering(candidate) + .map(Sentence::getCoveredText).findFirst().orElse(""); + var bindings = Map.of( // + VAR_TEXT, candidate.getCoveredText(), // + VAR_SENTENCE, sentence); var prompt = jinjava.render(traits.getPrompt(), bindings); try { diff --git a/inception/inception-imls-ollama/src/main/resources/de/tudarmstadt/ukp/inception/recommendation/imls/ollama/presets.yaml b/inception/inception-imls-ollama/src/main/resources/de/tudarmstadt/ukp/inception/recommendation/imls/ollama/presets.yaml index 193d5e8f532..222a9e45e46 100644 --- a/inception/inception-imls-ollama/src/main/resources/de/tudarmstadt/ukp/inception/recommendation/imls/ollama/presets.yaml +++ b/inception/inception-imls-ollama/src/main/resources/de/tudarmstadt/ukp/inception/recommendation/imls/ollama/presets.yaml @@ -27,3 +27,13 @@ ``` {{ text }} ``` + +- name: Disambiguate in sentence + processingMode: per-annotation + extractionMode: response-as-label + prompt: |- + Very briefly describe the meaning of `{{ text }}` in the following sentence. + + ``` + {{ sentence }} + ```