🚀 T5 Model for Multilingual Text Summary
This T5-based model is designed to handle the generation of summary text content in a multitasking mode. It comes with a built - in translation function supporting Russian, Chinese, and English. The model can understand text in these languages and translate the results among them.
✨ Features
- Multilingual Support: Understands text in Russian, Chinese, and English, and can generate summaries or translate results into any of these languages.
- Conditional Summary Generation: Offers 3 types of summary generation in the source language: simple concise, shortened, and elongated. You can also limit the output to a specific number of words.
- Translation Function: Translates the summary into the target language by specifying the target - language identifier as a prefix.
📦 Installation
No installation steps are provided in the original document, so this section is skipped.
💻 Usage Examples
Basic Usage
from transformers import T5ForConditionalGeneration, T5Tokenizer
device = 'cuda'
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
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."""
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)
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)
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)
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)
Advanced Usage
from transformers import T5ForConditionalGeneration, T5Tokenizer
device = 'cuda'
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
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位出场。网友:看比赛时我比谷爱凌紧张,加油!"""
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)
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)
📚 Documentation
The model can understand the following task prefixes:
Task Prefix |
Description |
"summary: " |
Generate simple concise content in the source language |
"summary brief: " |
Generate a shortened summary content in the source language |
"summary big: " |
Generate elongated summary content in the source language |
"summary 20 words: " |
Generate simple concise content in the source language with a 20 - word limit |
"summary brief 4 words: " |
Generate a shortened summary content in the source language with a 4 - word limit |
"summary big 100 words: " |
Generate elongated summary content in the source language with a 100 - word limit |
"summary to en: " |
Generate summary content in English from multilingual text |
"summary brief to en: " |
Generate a shortened summary of the content in English from multilingual text |
"summary big to en: " |
Generate elongated summary content in English from multilingual text |
"summary to ru: " |
Generate summary content in Russian from multilingual text |
"summary brief to ru: " |
Generate a shortened summary of the content in Russian from multilingual text |
"summary big to ru: " |
Generate elongated summary content in Russian from multilingual text |
"summary to zh: " |
Generate summary content in Chinese from multilingual text |
"summary brief to zh: " |
Generate a shortened summary of the content in Chinese from multilingual text |
"summary big to zh: " |
Generate elongated summary content in Chinese from multilingual text |
🔧 Technical Details
The model is trained to compress a context of 2048 tokens. It outputs a summary of up to 200 tokens in big tasks, 50 tokens in normal summary tasks, and 20 tokens in brief tasks.
📄 License
This project is licensed under the apache - 2.0
license.