File size: 861 Bytes
fcfbc2c
 
 
 
 
 
 
 
 
 
 
9fedaf9
fcfbc2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import pandas as pd
import gradio as gr
import pyterrier as pt
pt.init()
from pyterrier_gradio import Demo, MarkdownFile, interface, df2code, code2md, EX_R
from pyterrier_t5 import MonoT5ReRanker

model = MonoT5ReRanker()

COLAB_NAME = 'pyterrier_t5.ipynb'
COLAB_INSTALL = '''
!pip install -q git+https://github.com/terrierteam/pyterrier_t5
'''.strip()

def predict(input):
  code = f'''import pandas as pd
import pyterrier as pt ; pt.init()
from pyterrier_t5 import MonoT5ReRanker

model = MonoT5ReRanker()

model({df2code(input)})
'''
  res = model(input)
  res['score'] = res['score'].map(lambda x: round(x, 4))
  res = res.sort_values(['qid', 'rank'])
  return (res, code2md(code, COLAB_INSTALL, COLAB_NAME, colab=False))

interface(
  MarkdownFile('README.md'),
  Demo(
    predict,
    EX_R,
    []
  ),
  MarkdownFile('wrapup.md'),
).launch(share=False)