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
Modifier and TypeFieldDescriptionprotected boolean
private static final org.slf4j.Logger
private static final String
Fields inherited from class de.uni_mannheim.informatik.dws.melt.matching_ml.python.nlptransformers.TransformersFilter
batchSizeOptimization, changeClass
Fields inherited from class de.uni_mannheim.informatik.dws.melt.matching_ml.python.nlptransformers.TransformersBase
cudaVisibleDevices, extractor, modelName, multipleTextsToMultipleExamples, multiProcessing, trainingArguments, transformersCache, usingTensorflow
Fields inherited from class de.uni_mannheim.informatik.dws.melt.matching_base.MatcherFile
FILE_PREFIX, FILE_SUFFIX
-
Constructor Summary
ConstructorDescriptionRelationTypePredictor
(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 RelationTypePredictionResult
getFinalBestPrediction
(List<RelationTypePredictionResult> predictions, int negativeClass) private Map<Correspondence,
List<RelationTypePredictionResult>> getSortedResults
(List<List<Double>> predictions, Map<Correspondence, List<Integer>> map) boolean
match
(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) void
setAllowFiltering
(boolean allowFiltering) void
setChangeClass
(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, setOptimizeBatchSize
Methods 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, writeExamplesToFile
Methods inherited from class de.uni_mannheim.informatik.dws.melt.matching_jena.MatcherYAAAJena
getModelSpec, match, readOntology
Methods inherited from class de.uni_mannheim.informatik.dws.melt.matching_jena.MatcherYAAA
match
Methods inherited from class de.uni_mannheim.informatik.dws.melt.matching_base.MatcherFile
match
Methods inherited from class de.uni_mannheim.informatik.dws.melt.matching_base.MatcherURL
align, align, canExecute, getType
Methods inherited from class eu.sealsproject.platform.res.tool.impl.AbstractPlugin
getId, getVersion, setId, setVersion
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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:MatcherYAAAJena
Aligns 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:
match
in interfaceIMatcher<org.apache.jena.ontology.OntModel,
Alignment, Properties> - Overrides:
match
in 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:TransformersFilter
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.- Overrides:
createPredictionFile
in 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:TransformersFilter
If set to true, the class is changed in the classification. This is useful if a pretrained model predict exactly the opposite class.- Overrides:
setChangeClass
in classTransformersFilter
- Parameters:
changeClass
- true if the class should be changed in the classification.
-
predictConfidences
Description copied from class:TransformersFilter
Run huggingface transformers library.- Overrides:
predictConfidences
in 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)
-