Views
No views yet
1def highlight_answer(context, answer):
2 context_splits = context.split(answer)
3
4 text = ""
5 for split in context_splits:
6 text += split
7 text += ' <h> '
8 text += answer
9 text += ' <h> '
10 text += split
11
12 return text
13
14def prepare_instruction(answer_highlighted_context):
15 instruction_prompt = f"""Generate a question whose answer is highlighted by <h> from the context delimited by the triple backticks.
16 context:
17 ```
18 {answer_highlighted_context}
19 ```
20 """
21
22 return instruction_prompt1from transformers import pipeline
2
3pipe = pipeline('text2text-generation', model='mohammedaly22/t5-small-squad-qg-v2')
4
5context = """During the 2011–12 season, he set the La Liga and European records\
6for most goals scored in a single season, while establishing himself as Barcelona's\
7all-time top scorer. The following two seasons, Messi finished second for the Ballon\
8d'Or behind Cristiano Ronaldo (his perceived career rival), before regaining his best\
9form during the 2014–15 campaign, becoming the all-time top scorer in La Liga and \
10leading Barcelona to a historic second treble, after which he was awarded a fifth \
11Ballon d'Or in 2015. Messi assumed captaincy of Barcelona in 2018, and won a record \
12sixth Ballon d'Or in 2019. Out of contract, he signed for French club Paris Saint-Germain\
13in August 2021, spending two seasons at the club and winning Ligue 1 twice. Messi \
14joined American club Inter Miami in July 2023, winning the Leagues Cup in August of that year.
15"""
16
17answer_highlighted_context = highlight_answer(context=context, answer='Inter Miami')
18prompt = prepare_instruction(answer_highlighted_context)Generate a question whose answer is highlighted by <h> from the context delimited by the triple backticks
context:
```During the 2011–12 season, he set the La Liga and European records\
for most goals scored in a single season, while establishing himself as Barcelona's\
all-time top scorer. The following two seasons, Messi finished second for the Ballon\
d'Or behind Cristiano Ronaldo (his perceived career rival), before regaining his best\
form during the 2014–15 campaign, becoming the all-time top scorer in La Liga and \
leading Barcelona to a historic second treble, after which he was awarded a fifth \
Ballon d'Or in 2015. Messi assumed captaincy of Barcelona in 2018, and won a record\
sixth Ballon d'Or in 2019. Out of contract, he signed for French club Paris Saint-Germain\
in August 2021, spending two seasons at the club and winning Ligue 1 twice. Messi \
joined American club <h> Inter Miami <h> in July 2023, winning the Leagues Cup in August of that year.```pipeline to generate questions their answer is Inter Miami:1outputs = pipe(prompt, num_return_sequences=3, num_beams=5, num_beam_groups=5, diversity_penalty=1.0)
2for output in outputs:
3 print(output['generated_text'])1. What club did Messi join in the 2023 season?
2. What was Messi's name of the club that won the Leagues Cup on July 20?
3. What club did Messi join in the Leagues Cup in July 2023?| Training Loss | Epoch | Step | Validation Loss |
|---|---|---|---|
| 2.6867 | 0.73 | 500 | 1.9647 |
| 2.0737 | 1.46 | 1000 | 1.8141 |
| 1.9364 | 2.19 | 1500 | 1.7515 |
| 1.8745 | 2.92 | 2000 | 1.7215 |
| 1.8282 | 3.65 | 2500 | 1.7042 |
| 1.803 | 4.38 | 3000 | 1.6913 |
| 1.7797 | 5.11 | 3500 | 1.6796 |
| 1.7592 | 5.84 | 4000 | 1.6749 |
| 1.7435 | 6.57 | 4500 | 1.6697 |
| 1.7427 | 7.3 | 5000 | 1.6667 |
| 1.7245 | 8.04 | 5500 | 1.6614 |
| 1.7211 | 8.77 | 6000 | 1.6621 |
| 1.7137 | 9.5 | 6500 | 1.6608 |