RajSang commited on
Commit
fd87b44
1 Parent(s): d03baf9

Added diverse beam search

Browse files
Files changed (1) hide show
  1. app.py +16 -7
app.py CHANGED
@@ -3,21 +3,30 @@ from transformers import pipeline
3
 
4
  pipe = pipeline("summarization", model="RajSang/pegasus-sports-titles")
5
 
6
- def sportyify(article):
7
- gen_kwargs = {"length_penalty":0.6,"num_beams":4}
8
- return pipe(article, **gen_kwargs)[0]["summary_text"]
 
 
 
 
9
 
10
 
11
  article = "<p style='text-align: center'><a href='https://huggingface.co/RajSang/pegasus-sports-titles' target='_blank'>Model Page </a></p> "
12
- examples = [["""After Pat Cummins side bowled England out for 188 on day two, Australia struggled once again early on in their second innings, with David Warner, Marnus Labuschagne and Usman Khawaja all falling in the final minutes of day two. But Steve Smith managed to steady the Australia ship and is currently leading Australia to an overall lead past 150, with the Hobart hosts looking to end their exceptional series in style.""", """Australia lead England by 150 on day three of the fourth Test in Hobart"""]]
 
 
13
 
14
  iface = gr.Interface(fn=sportyify,
15
- inputs=gr.inputs.Textbox(lines=20, placeholder="Paste Article Text Here"),
 
 
 
16
  outputs="text",
17
  title="SPORT-Y Titles",
18
- description="Generate titles for sports articles and sports news",
19
  article=article,
20
  examples=examples,
21
- allow_flagging=False)
22
 
23
  iface.launch(enable_queue=True)
 
3
 
4
  pipe = pipeline("summarization", model="RajSang/pegasus-sports-titles")
5
 
6
+ def sportyify(article,length_penalty=0.6,diversity_penalty=2.0):
7
+ gen_kwargs = {"length_penalty":length_penalty,"num_beams":4, "num_return_sequences": 4,"num_beam_groups":4,"diversity_penalty":float(diversity_penalty)}
8
+ titles=[i["summary_text"]+'\n\n' for i in pipe(article, **gen_kwargs)]
9
+ returnable=''
10
+ for i,title in enumerate(titles):
11
+ returnable+='Title '+str(i+1)+' :\n\n'+title
12
+ return returnable
13
 
14
 
15
  article = "<p style='text-align: center'><a href='https://huggingface.co/RajSang/pegasus-sports-titles' target='_blank'>Model Page </a></p> "
16
+ examples = [["""After Pat Cummins side bowled England out for 188 on day two, Australia struggled once again early on in their second innings, with David Warner, Marnus Labuschagne and Usman Khawaja all falling in the final minutes of day two. But Steve Smith managed to steady the Australia ship and is currently leading Australia to an overall lead past 150, with the Hobart hosts looking to end their exceptional series in style.""",
17
+ 0.6,
18
+ 2.0]]
19
 
20
  iface = gr.Interface(fn=sportyify,
21
+ inputs=[gr.inputs.Textbox(lines=15, placeholder="Paste Article Text Here"),
22
+ gr.inputs.Slider(minimum=0.1,maximum=0.6,default=0.6,step=0.1),
23
+ gr.inputs.Slider(minimum=1.0,maximum=3.0,default=2.0,step=1.0)
24
+ ],
25
  outputs="text",
26
  title="SPORT-Y Titles",
27
+ description="<h3 style='text-align: center'>Generate titles for sports articles and sports news.</h3><h6 style='text-align: center'>Created by <a href='https://rajsangani.me' target='_blank'>Raj</a></h6><p>Decreasing the length penalty ranks shorter titles higher.</p><p>Increasing the diversity penalty creates unique titles.</p><p>Read more <a href='https://arxiv.org/pdf/1610.02424.pdf' target='_blank'>here</a></p>",
28
  article=article,
29
  examples=examples,
30
+ allow_flagging='never')
31
 
32
  iface.launch(enable_queue=True)