Skip to content

Commit

Permalink
Merge branch 'main' into refactoring/Upgrade-to-Spring-Boot-3
Browse files Browse the repository at this point in the history
* main:
  #2696 - Document-level recommendations
  #2696 - Document-level recommendations
  #2696 - Document-level recommendations
  #2696 - Document-level recommendations
  #2696 - Document-level recommendations
  #2696 - Document-level recommendations
  #2696 - Document-level recommendations
  #2696 - Document-level recommendations
  #2696 - Document-level recommendations
  #4292 - ollama-based recommender
  #4292 - ollama-based recommender
  #4383 - Hide negative scores in annotation sidebar but still sort by it
  #4383 - Hide negative scores in annotation sidebar but still sort by it
  • Loading branch information
reckart committed Dec 26, 2023
2 parents b1ca0fe + 5ec948d commit b83e285
Show file tree
Hide file tree
Showing 94 changed files with 1,952 additions and 1,395 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import de.tudarmstadt.ukp.inception.recommendation.api.evaluation.DataSplitter;
import de.tudarmstadt.ukp.inception.recommendation.api.evaluation.EvaluationResult;
import de.tudarmstadt.ukp.inception.recommendation.api.model.Recommender;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.PredictionContext;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommendationEngine;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommendationException;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommenderContext;
Expand Down Expand Up @@ -90,7 +91,7 @@ public void train(RecommenderContext aContext, List<CAS> aCasList)
}

@Override
public Range predict(RecommenderContext aContext, CAS aCas, int aBegin, int aEnd)
public Range predict(PredictionContext aContext, CAS aCas, int aBegin, int aEnd)
throws RecommendationException
{
Type predictedType = getPredictedType(aCas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import de.tudarmstadt.ukp.inception.kb.graph.KBHandle;
import de.tudarmstadt.ukp.inception.kb.model.KnowledgeBase;
import de.tudarmstadt.ukp.inception.recommendation.api.model.Recommender;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.PredictionContext;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommenderContext;
import de.tudarmstadt.ukp.inception.schema.api.feature.FeatureSupport;
import de.tudarmstadt.ukp.inception.schema.api.feature.FeatureSupportRegistry;
Expand Down Expand Up @@ -146,7 +147,7 @@ public void thatPredictionWorks() throws Exception
sut.train(context, Collections.singletonList(cas));
RecommenderTestHelper.addScoreFeature(cas, NamedEntity.class, "value");

sut.predict(context, cas);
sut.predict(new PredictionContext(context), cas);

List<NamedEntity> predictions = getPredictions(cas, NamedEntity.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonFormat.Shape;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand All @@ -32,11 +34,13 @@ public class CompactAnnotationAttributes
public static final String ATTR_COLOR = "c";
public static final String ATTR_COMMENTS = "cm";
public static final String ATTR_SCORE = "s";
public static final String ATTR_HIDE_SCORE = "hs";

private @JsonProperty(ATTR_LABEL) String labelText;
private @JsonProperty(ATTR_COLOR) String color;
private @JsonProperty(ATTR_COMMENTS) List<CompactComment> comments;
private @JsonProperty(ATTR_SCORE) double score;
private @JsonProperty(ATTR_HIDE_SCORE) boolean hideScore;

@JsonInclude(Include.NON_DEFAULT)
@JsonSerialize(using = ScoreSerializer.class)
Expand All @@ -50,6 +54,18 @@ public void setScore(double aScore)
score = aScore;
}

@JsonFormat(shape = Shape.NUMBER)
@JsonInclude(Include.NON_DEFAULT)
public boolean isHideScore()
{
return hideScore;
}

public void setHideScore(boolean aHideScore)
{
hideScore = aHideScore;
}

public void setLabelText(String aLabelText)
{
labelText = aLabelText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ private CompactRelation renderRelation(VArc varc)
getArgument(varc.getSource(), varc.getTarget()), varc.getLabelHint(),
varc.getColorHint());
carc.getAttributes().setScore(varc.getScore());
carc.getAttributes().setHideScore(varc.isHideScore());
return carc;
}

Expand All @@ -152,6 +153,7 @@ private CompactSpan renderSpan(RenderRequest aRequest, VSpan vspan)
vspan.getColorHint());
}
cspan.getAttributes().setScore(vspan.getScore());
cspan.getAttributes().setHideScore(vspan.isHideScore());
return cspan;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
{#if showText}
<span class="label">{renderLabel(annotation)}</span>
{/if}
{#if annotation.score}
<!-- Negative scores used only for sorting/ranking but not shown -->
{#if annotation.score && !annotation.hideScore}
<span class="small font-monospace score"
>{annotation.score.toFixed(2)}</span
>
Expand All @@ -88,7 +89,8 @@
{#if showText}
<span class="label">{renderLabel(annotation)}</span>
{/if}
{#if annotation.score}
<!-- Negative scores used only for sorting/ranking but not shown -->
{#if annotation.score && !annotation.hideScore}
<span class="small font-monospace score"
>{annotation.score.toFixed(2)}</span
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import de.tudarmstadt.ukp.inception.recommendation.api.evaluation.EvaluationResult;
import de.tudarmstadt.ukp.inception.recommendation.api.evaluation.LabelPair;
import de.tudarmstadt.ukp.inception.recommendation.api.model.Recommender;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.PredictionContext;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommendationEngine;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommendationException;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommenderContext;
Expand Down Expand Up @@ -133,7 +134,7 @@ private DataMajorityModel trainModel(List<Annotation> aAnnotations)

// tag::predict1[]
@Override
public Range predict(RecommenderContext aContext, CAS aCas, int aBegin, int aEnd)
public Range predict(PredictionContext aContext, CAS aCas, int aBegin, int aEnd)
throws RecommendationException
{
DataMajorityModel model = aContext.get(KEY_MODEL).orElseThrow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import de.tudarmstadt.ukp.inception.recommendation.api.evaluation.IncrementalSplitter;
import de.tudarmstadt.ukp.inception.recommendation.api.evaluation.PercentageBasedSplitter;
import de.tudarmstadt.ukp.inception.recommendation.api.model.Recommender;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.PredictionContext;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommenderContext;
import de.tudarmstadt.ukp.inception.support.test.recommendation.DkproTestHelper;
import de.tudarmstadt.ukp.inception.support.test.recommendation.RecommenderTestHelper;
Expand Down Expand Up @@ -104,7 +105,7 @@ public void thatPredictionWorks() throws Exception

sut.train(context, asList(cas));

sut.predict(context, cas);
sut.predict(new PredictionContext(context), cas);

Collection<NamedEntity> predictions = getPredictions(cas, NamedEntity.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

import de.tudarmstadt.ukp.inception.recommendation.api.model.Recommender;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.NonTrainableRecommenderEngineImplBase;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.PredictionContext;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommendationException;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommenderContext;
import de.tudarmstadt.ukp.inception.recommendation.imls.elg.model.ElgAnnotation;
import de.tudarmstadt.ukp.inception.recommendation.imls.elg.model.ElgAnnotationsResponse;
import de.tudarmstadt.ukp.inception.recommendation.imls.elg.model.ElgServiceResponse;
Expand Down Expand Up @@ -67,7 +67,7 @@ public ElgRecommender(Recommender aRecommender, ElgRecommenderTraits aTraits,
}

@Override
public Range predict(RecommenderContext aContext, CAS aCas, int aBegin, int aEnd)
public Range predict(PredictionContext aContext, CAS aCas, int aBegin, int aEnd)
throws RecommendationException
{
ElgServiceResponse response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import de.tudarmstadt.ukp.inception.recommendation.api.evaluation.DataSplitter;
import de.tudarmstadt.ukp.inception.recommendation.api.evaluation.EvaluationResult;
import de.tudarmstadt.ukp.inception.recommendation.api.model.Recommender;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.PredictionContext;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommendationEngine;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommendationException;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommenderContext;
Expand Down Expand Up @@ -216,7 +217,7 @@ else if (response.statusCode() >= HTTP_BAD_REQUEST) {
}

@Override
public Range predict(RecommenderContext aContext, CAS aCas, int aBegin, int aEnd)
public Range predict(PredictionContext aContext, CAS aCas, int aBegin, int aEnd)
throws RecommendationException
{
var client = getClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,11 @@ public boolean isEvaluable()
{
return false;
}

@Override
public boolean isRanker(Recommender aRecommender)
{
var traits = readTraits(aRecommender);
return traits.isRanker();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class ExternalRecommenderTraits
private String remoteUrl;
private boolean trainable;
private boolean verifyCertificates = true;
private boolean ranker;

public String getRemoteUrl()
{
Expand Down Expand Up @@ -60,4 +61,14 @@ public boolean isVerifyCertificates()
{
return verifyCertificates;
}

public void setRanker(boolean aRanker)
{
ranker = aRanker;
}

public boolean isRanker()
{
return ranker;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@
</div>
</div>
</div>
<div class="row form-row" wicket:enclosure="ranker">
<div class="offset-sm-3 col-sm-9">
<div class="form-check">
<input wicket:id="ranker" class="form-check-input" type="checkbox"/>
<label wicket:for="ranker" class="form-check-label">
<wicket:label key="ranker"/>
</label>
</div>
</div>
</div>
</form>
</wicket:extend>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ protected void onSubmit()

getTrainingStatesChoice().add(visibleWhen(() -> trainable.getModelObject() == true));

var ranker = new CheckBox("ranker");
ranker.setOutputMarkupId(true);
form.add(ranker);

add(form);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@

remoteUrl=Remote URL
trainable=Trainable
ranker=Ranker
verifyCertificates=Verify certificates
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import de.tudarmstadt.ukp.inception.annotation.storage.CasMetadataUtils;
import de.tudarmstadt.ukp.inception.annotation.storage.CasStorageSession;
import de.tudarmstadt.ukp.inception.recommendation.api.model.Recommender;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.PredictionContext;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommenderContext;
import de.tudarmstadt.ukp.inception.recommendation.imls.external.v1.config.ExternalRecommenderPropertiesImpl;
import de.tudarmstadt.ukp.inception.recommendation.imls.external.v1.messages.PredictionRequest;
Expand Down Expand Up @@ -133,7 +134,7 @@ public void thatPredictingWorks() throws Exception

var cas = casses.get(0);
RecommenderTestHelper.addScoreFeature(cas, NamedEntity.class, "value");
sut.predict(context, cas);
sut.predict(new PredictionContext(context), cas);

var predictions = getPredictions(cas, NamedEntity.class);

Expand Down Expand Up @@ -180,7 +181,7 @@ public void thatPredictingSendsCorrectRequest() throws Exception

var cas = casses.get(0);
RecommenderTestHelper.addScoreFeature(cas, NamedEntity.class, "value");
sut.predict(context, cas);
sut.predict(new PredictionContext(context), cas);

var request = fromJsonString(PredictionRequest.class, requestBodies.get(1));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.xml.sax.SAXException;

import de.tudarmstadt.ukp.inception.recommendation.api.model.Recommender;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.PredictionContext;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommendationException;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommenderContext;
import de.tudarmstadt.ukp.inception.recommendation.imls.external.v1.messages.PredictionRequest;
Expand Down Expand Up @@ -93,7 +94,7 @@ public String predict(String aPredictionRequestJson)
}
}

recommendationEngine.predict(context, cas);
recommendationEngine.predict(new PredictionContext(context), cas);

return buildPredictionResponse(cas);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

import de.tudarmstadt.ukp.inception.recommendation.api.model.Recommender;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.NonTrainableRecommenderEngineImplBase;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.PredictionContext;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommendationException;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommenderContext;
import de.tudarmstadt.ukp.inception.recommendation.imls.hf.client.HfInferenceClient;
import de.tudarmstadt.ukp.inception.recommendation.imls.hf.model.HfEntityGroup;
import de.tudarmstadt.ukp.inception.rendering.model.Range;
Expand All @@ -53,7 +53,7 @@ public HfRecommender(Recommender aRecommender, HfRecommenderTraits aTraits,
}

@Override
public Range predict(RecommenderContext aContext, CAS aCas, int aBegin, int aEnd)
public Range predict(PredictionContext aContext, CAS aCas, int aBegin, int aEnd)
throws RecommendationException
{
List<HfEntityGroup> response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import de.tudarmstadt.ukp.inception.recommendation.api.evaluation.DataSplitter;
import de.tudarmstadt.ukp.inception.recommendation.api.evaluation.EvaluationResult;
import de.tudarmstadt.ukp.inception.recommendation.api.model.Recommender;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.PredictionContext;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommendationEngine;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommendationException;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommenderContext;
Expand Down Expand Up @@ -67,7 +68,7 @@ public void train(RecommenderContext aContext, List<CAS> aCasses)
}

@Override
public Range predict(RecommenderContext aContext, CAS aCas, int aBegin, int aEnd)
public Range predict(PredictionContext aContext, CAS aCas, int aBegin, int aEnd)
throws RecommendationException
{
// FIXME: Ignores begin/end - always fetches predictions for the entire CAS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer;
import de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS;
import de.tudarmstadt.ukp.inception.recommendation.api.model.Recommender;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.PredictionContext;
import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommenderContext;
import de.tudarmstadt.ukp.inception.recommendation.imls.lapps.traits.LappsGridRecommenderTraits;
import okhttp3.mockwebserver.MockResponse;
Expand Down Expand Up @@ -83,7 +84,7 @@ public void thatPredictingPosWorks() throws Exception
RecommenderContext context = new RecommenderContext();
CAS cas = loadData();

sut.predict(context, cas);
sut.predict(new PredictionContext(context), cas);

Collection<POS> predictions = JCasUtil.select(cas.getJCas(), POS.class);

Expand Down
12 changes: 12 additions & 0 deletions inception/inception-imls-ollama/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
<groupId>de.tudarmstadt.ukp.inception.app</groupId>
<artifactId>inception-api-render</artifactId>
</dependency>
<dependency>
<groupId>de.tudarmstadt.ukp.inception.app</groupId>
<artifactId>inception-api-annotation</artifactId>
</dependency>
<dependency>
<groupId>de.tudarmstadt.ukp.inception.app</groupId>
<artifactId>inception-layer-docmetadata</artifactId>
</dependency>
<dependency>
<groupId>de.tudarmstadt.ukp.inception.app</groupId>
<artifactId>inception-support</artifactId>
Expand Down Expand Up @@ -96,6 +104,10 @@
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-spring</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.wicket-jquery-ui</groupId>
<artifactId>wicket-kendo-ui</artifactId>
</dependency>
<dependency>
<groupId>org.danekja</groupId>
<artifactId>jdk-serializable-functional</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,24 @@

import com.fasterxml.jackson.annotation.JsonProperty;

import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer;
import de.tudarmstadt.ukp.inception.annotation.layer.span.SpanLayerSupport;

public enum ExtractionMode
{
@JsonProperty("response-as-label")
RESPONSE_AS_LABEL, //

@JsonProperty("mentions-from-json")
MENTIONS_FROM_JSON
MENTIONS_FROM_JSON;

public boolean accepts(AnnotationLayer aLayer)
{
if (this == MENTIONS_FROM_JSON) {
// Mention extraction only makes sense for span layers
return SpanLayerSupport.TYPE.equals(aLayer.getType());
}

return true;
}
}
Loading

0 comments on commit b83e285

Please sign in to comment.