Class RelationTypePredictor
java.lang.Object
eu.sealsproject.platform.res.tool.impl.AbstractPlugin
de.uni_mannheim.informatik.dws.melt.matching_base.MatcherURL
de.uni_mannheim.informatik.dws.melt.matching_base.MatcherFile
de.uni_mannheim.informatik.dws.melt.matching_jena.MatcherYAAA
de.uni_mannheim.informatik.dws.melt.matching_jena.MatcherYAAAJena
de.uni_mannheim.informatik.dws.melt.matching_ml.python.nlptransformers.TransformersBase
de.uni_mannheim.informatik.dws.melt.matching_ml.python.nlptransformers.TransformersFilter
de.uni_mannheim.informatik.dws.melt.matching_ml.python.nlptransformers.relationprediction.RelationTypePredictor
- All Implemented Interfaces:
Filter,IMatcher<org.apache.jena.ontology.OntModel,,Alignment, Properties> eu.sealsproject.platform.res.domain.omt.IOntologyMatchingToolBridge,eu.sealsproject.platform.res.tool.api.IPlugin,eu.sealsproject.platform.res.tool.api.IToolBridge
This matcher predicts the relation type given a transformer model.
This component do not create new correspondences but refine the relation of given class correspondences.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprivate static final org.slf4j.Loggerprivate static final StringFields inherited from class de.uni_mannheim.informatik.dws.melt.matching_ml.python.nlptransformers.TransformersFilter
batchSizeOptimization, changeClassFields inherited from class de.uni_mannheim.informatik.dws.melt.matching_ml.python.nlptransformers.TransformersBase
cudaVisibleDevices, extractor, modelName, multipleTextsToMultipleExamples, multiProcessing, trainingArguments, transformersCache, usingTensorflowFields inherited from class de.uni_mannheim.informatik.dws.melt.matching_base.MatcherFile
FILE_PREFIX, FILE_SUFFIX -
Constructor Summary
ConstructorsConstructorDescriptionRelationTypePredictor(TextExtractorMap extractor, String modelName) RelationTypePredictor(TextExtractor extractor, String modelName) -
Method Summary
Modifier and TypeMethodDescriptioncreatePredictionFile(org.apache.jena.ontology.OntModel source, org.apache.jena.ontology.OntModel target, Alignment predictionAlignment, File outputFile, boolean append) Create the prediction file which is a CSV file with two columns.The first column is the text from the left resource and the second column is the text from the right resource.createPredictionFile(org.apache.jena.ontology.OntModel source, org.apache.jena.ontology.OntModel target, Alignment predictionAlignment, File outputFile, boolean append, boolean requiresSwitchExmaples) private RelationTypePredictionResultgetFinalBestPrediction(List<RelationTypePredictionResult> predictions, int negativeClass) private Map<Correspondence,List<RelationTypePredictionResult>> getSortedResults(List<List<Double>> predictions, Map<Correspondence, List<Integer>> map) booleanmatch(org.apache.jena.ontology.OntModel source, org.apache.jena.ontology.OntModel target, Alignment inputAlignment, Properties properties) Aligns two ontologies specified via a Jena OntModel, with an input alignment as Alignment object, and returns the mapping of the resulting alignment.predictConfidences(File predictionFilePath) Run huggingface transformers library.predictConfidencesMultiClass(File predictionFilePath) voidsetAllowFiltering(boolean allowFiltering) voidsetChangeClass(boolean changeClass) If set to true, the class is changed in the classification.Methods inherited from class de.uni_mannheim.informatik.dws.melt.matching_ml.python.nlptransformers.TransformersFilter
getBatchSizeOptimization, getMaximumPerDeviceEvalBatchSize, isChangeClass, isOptimizeAll, isOptimizeBatchSize, setBatchSizeOptimization, setOptimizeAll, setOptimizeBatchSizeMethods inherited from class de.uni_mannheim.informatik.dws.melt.matching_ml.python.nlptransformers.TransformersBase
addTrainingArgument, getCudaVisibleDevices, getCudaVisibleDevicesButOnlyOneGPU, getExamplesForBatchSizeOptimization, getExtractor, getExtractorMap, getModelName, getMultiProcessing, getTextualRepresentation, getTrainingArguments, getTransformersCache, isMultipleTextsToMultipleExamples, isOptimizeForMixedPrecisionTraining, isUsingTensorflow, setCudaVisibleDevices, setCudaVisibleDevices, setExtractor, setExtractorMap, setModelName, setMultipleTextsToMultipleExamples, setMultiProcessing, setOptimizeForMixedPrecisionTraining, setTrainingArguments, setTransformersCache, setUsingTensorflow, writeExamplesToFileMethods inherited from class de.uni_mannheim.informatik.dws.melt.matching_jena.MatcherYAAAJena
getModelSpec, match, readOntologyMethods inherited from class de.uni_mannheim.informatik.dws.melt.matching_jena.MatcherYAAA
matchMethods inherited from class de.uni_mannheim.informatik.dws.melt.matching_base.MatcherFile
matchMethods inherited from class de.uni_mannheim.informatik.dws.melt.matching_base.MatcherURL
align, align, canExecute, getTypeMethods inherited from class eu.sealsproject.platform.res.tool.impl.AbstractPlugin
getId, getVersion, setId, setVersionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface eu.sealsproject.platform.res.tool.api.IPlugin
getId, getVersion
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
NEWLINE
-
allowFiltering
protected boolean allowFiltering
-
-
Constructor Details
-
RelationTypePredictor
-
RelationTypePredictor
-
-
Method Details
-
match
public Alignment match(org.apache.jena.ontology.OntModel source, org.apache.jena.ontology.OntModel target, Alignment inputAlignment, Properties properties) throws Exception Description copied from class:MatcherYAAAJenaAligns two ontologies specified via a Jena OntModel, with an input alignment as Alignment object, and returns the mapping of the resulting alignment. Note: This method might be called multiple times in a row when using the evaluation framework. Make sure to return a mapping which is specific to the given inputs.- Specified by:
matchin interfaceIMatcher<org.apache.jena.ontology.OntModel,Alignment, Properties> - Overrides:
matchin classTransformersFilter- Parameters:
source- This OntModel represents the source ontology.target- This OntModel represents the target ontology.inputAlignment- This mapping represents the input alignment.properties- Additional properties.- Returns:
- The resulting alignment of the matching process.
- Throws:
Exception- Any exception which occurs during matching.
-
createPredictionFile
public Map<Correspondence,List<Integer>> createPredictionFile(org.apache.jena.ontology.OntModel source, org.apache.jena.ontology.OntModel target, Alignment predictionAlignment, File outputFile, boolean append) throws IOException Description copied from class:TransformersFilterCreate the prediction file which is a CSV file with two columns.The first column is the text from the left resource and the second column is the text from the right resource.- Overrides:
createPredictionFilein classTransformersFilter- Parameters:
source- The source modeltarget- The target modelpredictionAlignment- the alignment to process. All correspondences which have enough text are used.outputFile- the csv file to which the output should be written to.append- if true, then the training alignment is append to the given file.- Returns:
- the map which maps the the correspondence to (possibly multiple) row numbers. In case of multipleTextsToMultipleExamples is set to true, multiple rows can correspond to one correspondence, because each text (e.g. label, comment etc) of the two resources is used as an example.
- Throws:
IOException- in case the writing fails.
-
createPredictionFile
public Map<Correspondence,List<Integer>> createPredictionFile(org.apache.jena.ontology.OntModel source, org.apache.jena.ontology.OntModel target, Alignment predictionAlignment, File outputFile, boolean append, boolean requiresSwitchExmaples) throws IOException - Throws:
IOException
-
setChangeClass
public void setChangeClass(boolean changeClass) Description copied from class:TransformersFilterIf set to true, the class is changed in the classification. This is useful if a pretrained model predict exactly the opposite class.- Overrides:
setChangeClassin classTransformersFilter- Parameters:
changeClass- true if the class should be changed in the classification.
-
predictConfidences
Description copied from class:TransformersFilterRun huggingface transformers library.- Overrides:
predictConfidencesin classTransformersFilter- Parameters:
predictionFilePath- path to csv file with two columns (text left and text right).- Returns:
- a list of confidences
- Throws:
Exception- in case something goes wrong.
-
predictConfidencesMultiClass
- Throws:
Exception
-
getSortedResults
private Map<Correspondence,List<RelationTypePredictionResult>> getSortedResults(List<List<Double>> predictions, Map<Correspondence, List<Integer>> map) -
getFinalBestPrediction
private RelationTypePredictionResult getFinalBestPrediction(List<RelationTypePredictionResult> predictions, int negativeClass) -
isAllowFiltering
public boolean isAllowFiltering() -
setAllowFiltering
public void setAllowFiltering(boolean allowFiltering)
-