Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Sequential Dependency Model query constructor #359

Merged
merged 18 commits into from
Aug 13, 2018
Merged

Conversation

Peilin-Yang
Copy link
Collaborator

It turns out that we can combine different query semantics from Lucene to construct SDM query.
For example, for ordered window and unordered window query, we can use SpanQuery.
We then use BooleanQuery together with BoostQuery to construct the complete query.

Please see the unit test for examples.

Test on Gov2 701-750: MAP - 0.2922 (0.2832 was reported in the original paper)

@lintool
Copy link
Member

lintool commented Jul 22, 2018

Would it make sense to have a generic QueryBuilder API instead of these static methods?

@Peilin-Yang
Copy link
Collaborator Author

You mean subclass Query and create an inner Builder class?

@Peilin-Yang
Copy link
Collaborator Author

After thinking about it and looking at the Query class code, I think we do not necessary need SDM as a query class.
The Query class and its subclasses mainly implements primitive query functions and SDM query can be constructed by leveraging the existing query semantics.
(From the discussion in Slack channel: Jimmy mentioned to also make query expansion as subclasses of Query. I don't think this is suitable too. Query mainly deal with raw text queries w/o interacting with other components, e.g. index but query expansion involves reading indexing which is complicated to reason about)

I think we could make a separated Query package under Search and wrap this up?

@lintool
Copy link
Member

lintool commented Jul 23, 2018

sg

@Peilin-Yang Peilin-Yang requested a review from lintool July 24, 2018 15:11
@Peilin-Yang Peilin-Yang added this to To do in v0.3.0 Jul 24, 2018
@Peilin-Yang Peilin-Yang moved this from To do to In progress in v0.3.0 Jul 24, 2018

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

public class AnalyzerUtils {
public abstract class QueryBase {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd still like to keep AnalyzerUtil for the tokenize method - which is used beyond just query formulation.

@lintool
Copy link
Member

lintool commented Jul 24, 2018

How about QueryGenerator as an abstract class? I don't quite like how QueryBase sounds.
Then we can have {X,Y,Z}QueryGenerator.
How about folding the field and the analyzer in the constructor? I think that'd make the API cleaner?

/*
* Bag of Terms query builder
*/
public class BagOfTermsQueryGenerator extends QueryGenerator {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename it BagOfWords since that's commonly known?

/* Build the Term Dependency query. See:
* D. Metzler and W. B. Croft. A markov random field model for term dependencies. In SIGIR ’05.
*/
public class TermDependencyQueryGenerator extends QueryGenerator {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"TermDependency" is vague. How about SdmQueryGenerator to make consistent with test case below?

@lintool
Copy link
Member

lintool commented Aug 12, 2018

@Peilin-Yang I know we were going to defer this until v0.3.0, but should we just move this up to v0.2.0 and get it merged in?

We'll need regressions in a separate PR?

@Peilin-Yang
Copy link
Collaborator Author

Actually, we do not need to move this to 2 in order to get it merged....
We just merge it and it will be marked as done in the project page.

@lintool
Copy link
Member

lintool commented Aug 12, 2018

Sure, either way is fine with me.
Fix conflicts and I'll do a CR now?

public boolean sdm = false;

@Option(name = "-sdm.tw", metaVar = "[value]", usage = "term weight in sdm")
public float sdm_tw = 0.85f;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"term weight in sdm" -> "SRM term weight"?
And below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SDM?

BagOfTerms,
SequentialDependenceModel
}
private final QueryConstructor qc;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add empty line?

Query termQuery = new BagOfWordsQueryGenerator().buildQuery(field, analyzer, sdmQueryStr);
TopDocs rsTerm = searcher.search(termQuery, 1);
assertEquals(rs1.scoreDocs[0].score, rsTerm.scoreDocs[0].score, 1e-6f);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kill extra empty line?

q = new SpanNearQuery(new SpanQuery[]{t2, t1}, 16, false);
rs = searcher.search(q, 1);
assertEquals(rs.scoreDocs.length, 1);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kill extra empty line?

Copy link
Member

@lintool lintool left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments, otherwise lgtm.

@lintool
Copy link
Member

lintool commented Aug 12, 2018

@Peilin-Yang you're changing the BoW code path, right? So please run all regressions before merging?

@Peilin-Yang Peilin-Yang merged commit 84d077d into master Aug 13, 2018
v0.3.0 automation moved this from In progress to Done Aug 13, 2018
@Peilin-Yang Peilin-Yang deleted the sdm branch August 13, 2018 17:24
@lintool lintool removed this from Done in v0.3.0 Sep 10, 2018
crystina-z pushed a commit to crystina-z/anserini that referenced this pull request Oct 28, 2022
* rename dense index

* underscores to dashes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants