WHU Bruisefree分享 http://blog.sciencenet.cn/u/bruisefree Link together

博文

Lemur 平滑支撑文件生成命令(GenerateSmoothSupport)

已有 3665 次阅读 2013-1-6 21:11 |个人分类:lemur Indri|系统分类:科研笔记| 信息检索, 语言模型, Lemur, indri

  

该命令是GenerateSmoothSupport,为语言模型检索方法生成两个支撑文件。两个文件都包含一些预计算的数值,用于加速检索过程。一个文件是平滑一元语言模型检索时用到的,其名字由参数smoothSupportFile提供。如果运行基于Markov链查询模型,则另一个文件则是需要的,并带有后缀"<tt>.mc</tt>"。这个文件中的每一行都包含了一个词和文档库中所有文本中该词的概率值之和,即所有dp(w|d)值之和。

按照Lemur命令的一般步骤执行该命令,并在参数文件中设置如下的变量:

index:索引文件,记录了索引内容

smoothSupportFile:生成的平滑支持文件路径位置,例如/usr0/mydata/index.supp

 

实例:

GenerateSmoothSupport e:/ir_exp/genSmoothSupport.txt

 

参数文件:

<parameters>

       <index>e:indexohsumed4</index>

       <smoothSupportFile>E:IR_EXPsmoothSupportFile.txt</smoothSupportFile>

       <tt>.mc</tt>

</parameters>

通过运行以上命令,共生成两个文件:

smoothSupportFile.txtsmoothSupportFile.txt.mc

其中smoothSupportFile.txt格式为:

1 97 0.0655744

2 104 0.0690776

3 114 0.0909539

第一列为文档ID,第二列为文档中词的种类数,即不同的词的个数,第三列为该文档在文档库中的权重,计算公式为:

 

smoothSupportFile.txt.mc格式如下:

1 1991

2 4122.48

3 2604.25

4 2500.84

第一列为词ID,第二列为所有文档中该词的MLE值,计算公式为:

p(t)=∑p(t|d)

 

 

具体计算方法,可以参见GenerateSmoothSupport源代码:
//平滑文件

  ofs.open(LocalParameter::smoothSupportFile.c_str());

 
  //MC平滑文件

  char mcSuppFileName[500];

  strcpy(mcSuppFileName, LocalParameter::smoothSupportFile.c_str());

  strcat(mcSuppFileName, ".mc");

 

  ofstream mcOFS;

  mcOFS.open(mcSuppFileName);

 
  TERMID_T i;
 
  // 所有d下p(w|d)值之和

  double *wdPr = new double[ind->termCountUnique()+1];

  for (i=1; i<=ind->termCountUnique();i++)

    wdPr[i]=0;
 
  //文档中所有词在语料库中出现的总频次与语料库中词的总频次之比

  double prSum=0;

 

  for (i=1; i<= ind->docCount(); i++) {

    prSum =  0;

    TermInfoList *tList = ind->termInfoList(i);

    tList->startIteration();

    int size=0;//文档中包含的不同词的个数,与文档长度docLength不一样

    while (tList->hasMore()) {

      TermInfo *info = tList->nextEntry();

 

      //sum of p(t|d)

      wdPr[info->termID()] += info->count()/(double)ind->docLength(i);

      // compute Markov chain support
      // 所有词在语料库中出现的次数之和

      prSum += ind->termCount(info->termID());

       
 

      // cout << i << "t" <<  ind->termCount(info->id()) << "t" << ind->term(info->id()) << endl;

 
      size++;
    }
    // should be ML here

    //    prSum = prSum / (double)(ind->termCount()+ind->termCountUnique());

    prSum = prSum/(double)ind->termCount();

    ofs << i << " " << size << " "<< prSum << endl;

    delete tList;

  }
 

  for (i=1;i<=ind->termCountUnique();i++)

    mcOFS << i << " " << wdPr[i] << endl;

  mcOFS.close();
 
  ofs.close();
 


https://blog.sciencenet.cn/blog-563898-650313.html

上一篇:Indri查询命令(Indri Query Retrieval)及JAVA调用
下一篇:Lemur查询语言模型生成命令
收藏 IP: 202.114.66.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-10-19 22:34

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部