Skip to content

Commit

Permalink
#4292 - ollama-based recommender
Browse files Browse the repository at this point in the history
- Added another preset
- Allow accessing the surrounding sentence in the per-annotation processing mode
  • Loading branch information
reckart committed Nov 14, 2023
1 parent 598f95f commit 685e65d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions inception/inception-imls-ollama/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
<artifactId>wicket-spring</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
```

0 comments on commit 685e65d

Please sign in to comment.