Class LMDirichletSimilarity


public class LMDirichletSimilarity extends LMSimilarity
Bayesian smoothing using Dirichlet priors. From Chengxiang Zhai and John Lafferty. 2001. A study of smoothing methods for language models applied to Ad Hoc information retrieval. In Proceedings of the 24th annual international ACM SIGIR conference on Research and development in information retrieval (SIGIR '01). ACM, New York, NY, USA, 334-342.

The formula as defined the paper assigns a negative score to documents that contain the term, but with fewer occurrences than predicted by the collection language model. The Lucene implementation returns 0 for such documents.

WARNING: This API is experimental and might change in incompatible ways in the next release.
  • Constructor Details

    • LMDirichletSimilarity

      public LMDirichletSimilarity(LMSimilarity.CollectionModel collectionModel, float mu)
      Instantiates the similarity with the provided μ parameter.
    • LMDirichletSimilarity

      public LMDirichletSimilarity(float mu)
      Instantiates the similarity with the provided μ parameter.
    • LMDirichletSimilarity

      public LMDirichletSimilarity(LMSimilarity.CollectionModel collectionModel)
      Instantiates the similarity with the default μ value of 2000.
    • LMDirichletSimilarity

      public LMDirichletSimilarity()
      Instantiates the similarity with the default μ value of 2000.
  • Method Details

    • score

      protected double score(BasicStats stats, double freq, double docLen)
      Description copied from class: SimilarityBase
      Scores the document doc.

      Subclasses must apply their scoring formula in this class.

      Specified by:
      score in class SimilarityBase
      Parameters:
      stats - the corpus level statistics.
      freq - the term frequency.
      docLen - the document length.
      Returns:
      the score.
    • explain

      protected void explain(List<Explanation> subs, BasicStats stats, double freq, double docLen)
      Description copied from class: SimilarityBase
      Subclasses should implement this method to explain the score. expl already contains the score, the name of the class and the doc id, as well as the term frequency and its explanation; subclasses can add additional clauses to explain details of their scoring formulae.

      The default implementation does nothing.

      Overrides:
      explain in class LMSimilarity
      Parameters:
      subs - the list of details of the explanation to extend
      stats - the corpus level statistics.
      freq - the term frequency.
      docLen - the document length.
    • explain

      protected Explanation explain(BasicStats stats, Explanation freq, double docLen)
      Description copied from class: SimilarityBase
      Explains the score. The implementation here provides a basic explanation in the format score(name-of-similarity, doc=doc-id, freq=term-frequency), computed from:, and attaches the score (computed via the SimilarityBase.score(BasicStats, double, double) method) and the explanation for the term frequency. Subclasses content with this format may add additional details in SimilarityBase.explain(List, BasicStats, double, double).
      Overrides:
      explain in class SimilarityBase
      Parameters:
      stats - the corpus level statistics.
      freq - the term frequency and its explanation.
      docLen - the document length.
      Returns:
      the explanation.
    • getMu

      public float getMu()
      Returns the μ parameter.
    • getName

      public String getName()
      Description copied from class: LMSimilarity
      Returns the name of the LM method. The values of the parameters should be included as well.

      Used in LMSimilarity.toString().

      Specified by:
      getName in class LMSimilarity