Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
Merge pull request #42 from gnes-ai/fix_weighting
Browse files Browse the repository at this point in the history
fix(weighting): add simple normalization to chunk search
  • Loading branch information
Larryjianfeng authored Jul 23, 2019
2 parents 0be85f3 + d3fbbca commit 5d65678
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion gnes/preprocessor/image/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def apply(self, doc: 'gnes_pb2.Document'):
c.doc_id = doc.doc_id
c.blob.CopyFrom(array2blob(self._crop_image_reshape(original_image, ele[0])))
c.offset_1d = ci
c.weight = ele[1]
c.weight = self._cal_area(ele[0]) / (original_image.size[0] * original_image.size[1])

c = doc.chunks.add()
c.doc_id = doc.doc_id
Expand All @@ -82,3 +82,7 @@ def apply(self, doc: 'gnes_pb2.Document'):
def _crop_image_reshape(self, original_image, coordinates):
return np.array(original_image.crop(coordinates).resize((self.target_img_size,
self.target_img_size)))

@classmethod
def _cal_area(cls, coordinate):
return (coordinate[2] - coordinate[0]) * (coordinate[3] - coordinate[1])
2 changes: 1 addition & 1 deletion gnes/service/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _handler_chunk_search(self, msg: 'gnes_pb2.Message'):
r.chunk.doc_id = _doc_id
r.chunk.offset_1d = _offset
r.chunk.weight = _weight
r.score = _weight * _relevance * qc_weight
r.score = _weight * qc_weight * (-1 / _relevance)
r.score_explained = '[chunk_score at doc: %d, offset: %d] = ' \
'(doc_chunk_weight: %.6f) * ' \
'(query_doc_chunk_relevance: %.6f) * ' \
Expand Down

0 comments on commit 5d65678

Please sign in to comment.