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

Commit

Permalink
feat(chunk scorer): add offset divergence
Browse files Browse the repository at this point in the history
  • Loading branch information
jemmyshin committed Aug 30, 2019
1 parent 64cea23 commit 8cdcb7e
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions gnes/indexer/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,30 +128,6 @@ def eq1(q_chunk: 'gnes_pb2.Chunk', d_chunk: 'gnes_pb2.Chunk',
})
return score


class DocScorer:

@staticmethod
def eq1(d: 'gnes_pb2.Document',
s: 'gnes_pb2.Response.QueryResponse.ScoredResult.Score') -> 'gnes_pb2.Response.QueryResponse.ScoredResult.Score':
"""
score *= d.weight
:param d:
:param s:
:return:
"""
s.value *= d.weight
s.explained = json.dumps({
'name': 'doc-eq1',
'operand': [json.loads(s.explained),
{'name': 'doc_weight',
'value': d.weight,
'doc_id': d.doc_id}],
'op': 'prod',
'value': s.value
})
return s

@staticmethod
def eq2(q_chunk: 'gnes_pb2.Chunk', d_chunk: 'gnes_pb2.Chunk',
relevance):
Expand Down Expand Up @@ -192,6 +168,30 @@ def _cal_divergence(q_chunk: 'gnes_pb2.Chunk', d_chunk: 'gnes_pb2.Chunk'):
return score


class DocScorer:

@staticmethod
def eq1(d: 'gnes_pb2.Document',
s: 'gnes_pb2.Response.QueryResponse.ScoredResult.Score') -> 'gnes_pb2.Response.QueryResponse.ScoredResult.Score':
"""
score *= d.weight
:param d:
:param s:
:return:
"""
s.value *= d.weight
s.explained = json.dumps({
'name': 'doc-eq1',
'operand': [json.loads(s.explained),
{'name': 'doc_weight',
'value': d.weight,
'doc_id': d.doc_id}],
'op': 'prod',
'value': s.value
})
return s


class JointIndexer(CompositionalTrainableBase):

@property
Expand Down

0 comments on commit 8cdcb7e

Please sign in to comment.