taolei87 / rcnn

Recurrent & convolutional neural network modules
Apache License 2.0
354 stars 128 forks source link

qa/api.py example usage #13

Closed christinazavou closed 7 years ago

christinazavou commented 7 years ago

Hi @taolei87 ,

I would like to run the code in qa/api.py to see how the model ranks instances. I used:

myqrapi = QRAPI(
   <model_path>,
   <corpus_path>,
   <emb_path>
)

results = myqrapi.rank(
    {
        "query": "why does n't ubuntu 12.04 upgrade libreoffice , as firefox ?  i use ubuntu 12.04 in a machine for working , and do n't know why libreoffice does n't upgrade to last version , and firefox does .",
        "candidates": [
            "why no menu bar in libreoffice   when you move your cursor to the top of the screen in libreoffice you do n't get a menu . you do for other applications like firefox and thunderbird but not for libreoffice .",
            "how do i install the latest stable version of libreoffice ?    libreoffice is seeing some dramatic improvements each version and subversion that goes out . i would like to have always the latest version of libreoffice on my machine ( s ) . i know of the ppa that exists but is it recommended to use it with 12.04 for daily use ? what are the pro and cons of using the ppa ? will it break my system/libreoffice installation ? does libreoffice get eventually also upgraded in the ubuntu repositories or does this upgrade happen only with new releases ? who manages the upgrades of libreoffice in ubuntu and in the ppa ?",
            "why does unity launcher start the wrong program ?  when i left click the libreoffice icon firefox launches instead . a right click gives me a choice of new document firefox lock to launcher . until some recent updates this never happened before . other programs do n't exhibit this behaviour . why ?",
            "ibreoffice version now , i use libreoffice writer 3.5.7.2 . according to http : //ask.libreoffice.org/en/question/34088/selecting-copying-pasting-text/ and further things i need libreoffice writer 4.0 or higher . when it may be in the ubuntu software center for my ubuntu 12.04 ? if it is there , is it offered by my upgrade manager without my request ? thanks .",
            "libreoffice-core seems to have corrupted   i had libreoffice version 3.x installed along with my ubuntu version 11 . after i did the upgrade to 12.04 , my libreoffice behavior changed . i decided to upgrade tto libre office 4x . during the setup since i was getting errors on desktop integration , i tried removing version 3 of libreoffice . this seems to have caused problem with some of libreoffice files , which seems to be essential to run different application . libreoffice-core- depends libreoffice-common has unmet dependencies now , my update manager does n't work and i having problems installing any new apps . is there a solution to fix this problem without having to re-install ubuntu ? i tried to do repair of libreoffice.. did n't work . cheers anil rao"
       ]
    }
)

With this, the batch shape created in QRAPI.rank() is (124,6) and gives 5 scores, therefore line assert len(scores) == len(batch)-1 gives an error.

I suppose this is a small bug, otherwise am I using the QRAPI wrongly?

Thanks

taolei87 commented 7 years ago

Hi @christinazavou ,

You are right. It is a small bug.

The batch should be size (max length, number of candidate+1). So the correct assertion should be like len(scores) == batch.shape[1]-1.

taolei87 commented 7 years ago

Also, you can change this line if you want to include question bodies for similarity computation, i.e. scores = score_func(title_batch, body_batch).