T5 model for multilingual text Summary in English, Russian and Chinese language
This model is designed to perform the task of controlled generation of summary text content in multitasking mode with a built-in translation function for languages: Russian, Chinese, English.
This is the T5 multitasking model. Which has a conditionally controlled ability to generate summary text content, and translate this. In total, she understands 12 commands, according to the set prefix:
- "summary: " - to generate simple concise content in the source language
- "summary brief: " - to generate a shortened summary content in the source language
- "summary big: " - to generate elongated summary content in the source language
You can conditionally limit the output to a given N number of words, just add the phrase "N words" after the task.
- "summary 20 words: " - to generate simple concise content in the source language
- "summary brief 4 words: " - to generate a shortened summary content in the source language
- "summary big 100 words: " - to generate elongated summary content in the source language
The word-level restriction works better with small meanings than with large ones.
The model can understand text in any language from the list: Russian, Chinese or English. It can also translate the result into any language from the list: Russian, Chinese or English.
For translation into the target language, the target language identifier is specified as a prefix "... to :". Where lang can take the values: ru, en, zh. The source language may not be specified, in addition, the source text may be multilingual.
task prefix:
- "summary to en: " - to generate summary content in English from multilingual text
- "summary brief to en: " - to generate a shortened summary of the content in English from multilingual text
- "summary big to en: " - to generate elongated summary content in English from multilingual text
- "summary to ru: " - to generate summary content in Russian from multilingual text
- "summary brief to ru: " - to generate a shortened summary of the content in Russian from multilingual text
- "summary big to ru: " - to generate elongated summary content in Russian from multilingual text
- "summary to zh: " - to generate summary content in Chinese from multilingual text
- "summary brief to zh: " - to generate a shortened summary of the content in Chinese from multilingual text
- "summary big to zh: " - to generate elongated summary content in Chinese from multilingual text
A training model for compressing a context of 2048 tokens and outputs a summary of up to 200 tokens in big task, 50 tokens in summary, and 20 tokens in brief task.
A prefix in a translation task with a length restriction based on the number of words will look like this: "summary brief to en 4 words: "
Example resume for English:
from transformers import T5ForConditionalGeneration, T5Tokenizer
device = 'cuda' #or 'cpu' for translate on cpu
model_name = 'utrobinmv/t5_summary_en_ru_zh_large_2048'
model = T5ForConditionalGeneration.from_pretrained(model_name)
model.eval()
model.to(device)
generation_config = model.generation_config
# for quality generation
generation_config.length_penalty = 0.6
generation_config.no_repeat_ngram_size = 2
generation_config.num_beams = 10
tokenizer = T5Tokenizer.from_pretrained(model_name)
text = """Videos that say approved vaccines are dangerous and cause autism, cancer or infertility are among those that will be taken down, the company said. The policy includes the termination of accounts of anti-vaccine influencers. Tech giants have been criticised for not doing more to counter false health information on their sites. In July, US President Joe Biden said social media platforms were largely responsible for people's scepticism in getting vaccinated by spreading misinformation, and appealed for them to address the issue. YouTube, which is owned by Google, said 130,000 videos were removed from its platform since last year, when it implemented a ban on content spreading misinformation about Covid vaccines. In a blog post, the company said it had seen false claims about Covid jabs "spill over into misinformation about vaccines in general". The new policy covers long-approved vaccines, such as those against measles or hepatitis B. "We're expanding our medical misinformation policies on YouTube with new guidelines on currently administered vaccines that are approved and confirmed to be safe and effective by local health authorities and the WHO," the post said, referring to the World Health Organization."""
# text summary generate
prefix = 'summary: '
src_text = prefix + text
input_ids = tokenizer(src_text, return_tensors="pt")
generated_tokens = model.generate(**input_ids.to(device), generation_config=generation_config)
result = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
print(result)
#YouTube to remove videos claiming approved COVID-19 vaccines cause harm, including autism, cancer, and infertility. It will terminate accounts of anti-vaccine influencers and expand its medical misinformation policies.
# text brief summary generate
prefix = 'summary brief: '
src_text = prefix + text
input_ids = tokenizer(src_text, return_tensors="pt")
generated_tokens = model.generate(**input_ids.to(device), generation_config=generation_config)
result = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
print(result)
#YouTube has announced a crackdown on misinformation about Covid-19 vaccines.
# generate a 4-word summary of the text
prefix = 'summary brief 4 words: '
src_text = prefix + text
input_ids = tokenizer(src_text, return_tensors="pt")
generated_tokens = model.generate(**input_ids.to(device), generation_config=generation_config)
result = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
print(result)
#YouTube removes vaccine misinformation.
# text big summary generate
prefix = 'summary big: '
src_text = prefix + text
input_ids = tokenizer(src_text, return_tensors="pt")
generated_tokens = model.generate(**input_ids.to(device), generation_config=generation_config)
result = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
print(result)
#YouTube, owned by Google, is removing videos claiming approved vaccines are dangerous and cause autism, cancer, or infertility. The company will terminate accounts of anti-vaccine influencers and expand its medical misinformation policies. This follows criticism of tech giants for not doing more to combat false health information on their sites. In July, US President Joe Biden called for social media platforms to address the issue of vaccine skepticism. Since implementing a ban on Covid vaccine content in 2021, 13 million videos have been removed. New policies cover long-approved vaccinations, such as those against measles or hepatitis B.
Example resume for Chinese text on English language:
from transformers import T5ForConditionalGeneration, T5Tokenizer
device = 'cuda' #or 'cpu' for translate on cpu
model_name = 'utrobinmv/t5_summary_en_ru_zh_large_2048'
model = T5ForConditionalGeneration.from_pretrained(model_name)
model.eval()
model.to(device)
generation_config = model.generation_config
# for quality generation
generation_config.length_penalty = 0.6
generation_config.no_repeat_ngram_size = 2
generation_config.num_beams = 10
tokenizer = T5Tokenizer.from_pretrained(model_name)
text = """在北京冬奥会自由式滑雪女子坡面障碍技巧决赛中,中国选手谷爱凌夺得银牌。祝贺谷爱凌!今天上午,自由式滑雪女子坡面障碍技巧决赛举行。决赛分三轮进行,取选手最佳成绩排名决出奖牌。第一跳,中国选手谷爱凌获得69.90分。在12位选手中排名第三。完成动作后,谷爱凌又扮了个鬼脸,甚是可爱。第二轮中,谷爱凌在道具区第三个障碍处失误,落地时摔倒。获得16.98分。网友:摔倒了也没关系,继续加油!在第二跳失误摔倒的情况下,谷爱凌顶住压力,第三跳稳稳发挥,流畅落地!获得86.23分!此轮比赛,共12位选手参赛,谷爱凌第10位出场。网友:看比赛时我比谷爱凌紧张,加油!"""
# text summary generate
prefix = 'summary to en: '
src_text = prefix + text
input_ids = tokenizer(src_text, return_tensors="pt")
generated_tokens = model.generate(**input_ids.to(device), generation_config=generation_config)
result = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
print(result)
#In the women's freestyle skiing final at the Beijing Winter Olympics, Chinese skater Gu Ailing won silver. She scored 69.90 in the first jump, ranked 3rd among 12 competitors. Despite a fall, she managed to land smoothly, earning 86.23 points.
# text brief summary generate
prefix = 'summary brief to en: '
src_text = prefix + text
input_ids = tokenizer(src_text, return_tensors="pt")
generated_tokens = model.generate(**input_ids.to(device), generation_config=generation_config)
result = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
print(result)
#"Chinese Skier Wins Silver in Beijing"
# generate a 4-word summary of the text
prefix = 'summary brief to en 4 words: '
src_text = prefix + text
input_ids = tokenizer(src_text, return_tensors="pt")
generated_tokens = model.generate(**input_ids.to(device), generation_config=generation_config)
result = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
print(result)
#"Chinese Skier Wins Silver"
# text big summary generate
prefix = 'summary big to en: '
src_text = prefix + text
input_ids = tokenizer(src_text, return_tensors="pt")
generated_tokens = model.generate(**input_ids.to(device), generation_config=generation_config)
result = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
print(result)
#In the women's freestyle ski slope obstacle technique final at the Beijing Winter Olympics, Chinese skater Gu Ailing won silver. She scored 69.90 in her first jump, placing third among the 12 competitors. Despite a fall in the second round, she managed to land smoothly, earning 86.23 points. The final was held in three rounds.
and Example resume for Russian:
from transformers import T5ForConditionalGeneration, T5Tokenizer
device = 'cuda' #or 'cpu' for translate on cpu
model_name = 'utrobinmv/t5_summary_en_ru_zh_large_2048'
model = T5ForConditionalGeneration.from_pretrained(model_name)
model.eval()
model.to(device)
generation_config = model.generation_config
# for quality generation
generation_config.length_penalty = 0.6
generation_config.no_repeat_ngram_size = 2
generation_config.num_beams = 10
tokenizer = T5Tokenizer.from_pretrained(model_name)
text = """Высота башни составляет 324 метра (1063 фута), примерно такая же высота, как у 81-этажного здания, и самое высокое сооружение в Париже. Его основание квадратно, размером 125 метров (410 футов) с любой стороны. Во время строительства Эйфелева башня превзошла монумент Вашингтона, став самым высоким искусственным сооружением в мире, и этот титул она удерживала в течение 41 года до завершения строительство здания Крайслер в Нью-Йорке в 1930 году. Это первое сооружение которое достигло высоты 300 метров. Из-за добавления вещательной антенны на вершине башни в 1957 году она сейчас выше здания Крайслер на 5,2 метра (17 футов). За исключением передатчиков, Эйфелева башня является второй самой высокой отдельно стоящей структурой во Франции после виадука Мийо."""
# text summary generate
prefix = 'summary: '
src_text = prefix + text
input_ids = tokenizer(src_text, return_tensors="pt")
generated_tokens = model.generate(**input_ids.to(device), generation_config=generation_config)
result = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
print(result)
#Эйфелева башня - самое высокое здание в Париже, высотой 324 метра. Ее основание квадратное, размером 125 метров с каждой стороны. Во время строительства она превзошла монумент Вашингтона, став самым высоким искусственным сооружением в мире.
# text brief summary generate
prefix = 'summary brief: '
src_text = prefix + text
input_ids = tokenizer(src_text, return_tensors="pt")
generated_tokens = model.generate(**input_ids.to(device), generation_config=generation_config)
result = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
print(result)
#Эйфелева башня - самое высокое здание в Париже, высотой 324 метра.
# generate a 4-word summary of the text
prefix = 'summary brief 4 words: '
src_text = prefix + text
input_ids = tokenizer(src_text, return_tensors="pt")
generated_tokens = model.generate(**input_ids.to(device), generation_config=generation_config)
result = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
print(result)
#Эйфелева башня - самая высокая.
# text big summary generate
prefix = 'summary big: '
src_text = prefix + text
input_ids = tokenizer(src_text, return_tensors="pt")
generated_tokens = model.generate(**input_ids.to(device), generation_config=generation_config)
result = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
print(result)
#Эйфелева башня - самое высокое здание в Париже, высотой 324 метра. Ее основание квадратное, размером 125 метров с каждой стороны. Во время строительства она превзошла монумент Вашингтона, став самым высоким искусственным сооружением в мире. Из-за добавления вещательной антенны на вершине башни она сейчас выше здания Крайслер на 5,2 метра (17 футов). За исключением передатчиков, башня является второй самой высокой отдельно стоящей структурой во Франции после виадука Мийо.
Languages covered
Russian (ru_RU), Chinese (zh_CN), English (en_US)
- Downloads last month
- 51
Model tree for utrobinmv/t5_summary_en_ru_zh_large_2048
Base model
utrobinmv/t5_translate_en_ru_zh_large_1024