Views
No views yet
1from transformers import AutoModel, AutoTokenizer
2
3tokenizer = AutoTokenizer.from_pretrained('google-t5/t5-small')
4model = AutoModel.from_pretrained('google-t5/t5-small')
5
6input_text = "(CNN)The Palestinian Authority officially became the 123rd member of the International Criminal Court on Wednesday, a step that gives the court jurisdiction over alleged crimes in Palestinian territories.
7 The formal accession was marked with a ceremony at The Hague, in the Netherlands, where the court is based.
8 The Palestinians signed the ICC's founding Rome Statute in January, when they also accepted its jurisdiction over alleged crimes committed "in the occupied Palestinian territory, including East Jerusalem, since June 13, 2014."
9inputs = tokenizer.encode(input_text, return_tensors='pt')
10
11max_chunk_length = 512
12for i in range(0, len(inputs), max_chunk_length):
13 chunk = inputs[:, i:i+max_chunk_length]
14 chunks.append(chunk)
15
16summary = ""
17for chunk in chunks:
18 chunk_summary = model(tokenizer.decode(chunk[0]),
19 max_new_tokens=150,
20 min_length=10,
21 num_beams=3,
22 do_sample=True,
23 top_p=0.8)[0]['summary_text']
24 summary += chunk_summary + " "
25print(summary)