File size: 1,117 Bytes
faf09ce |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
from model_factory.description_validator import Description_Validator
from model_factory.image_validator import Image_Validator
class Update_Validator:
def __init__(self, text_model=None, image_model=None, threshold=0.7):
self.description_validator = Description_Validator(model_name=text_model)
self.image_validator = Image_Validator(model_name=image_model)
self.threshold = threshold
def validate(self, text1, text2, image_path_1, image_path_2, threshold=None, return_score=False):
description_similarity = self.description_validator.similarity_score(text1, text2)
image_similarity = self.image_validator.similarity_score(image_path_1, image_path_2)
similarity_score = 0.75 * description_similarity + 0.25 * image_similarity
if threshold is None: threshold=self.threshold
label = True if similarity_score >= threshold else False
if return_score:
return {'score':similarity_score, 'label':label}
else:
return {'label':label} |