Views
No views yet
multilingual-summarization-mBart model is a fine-tuned mBART-Large model specializing in abstractive summarization across multiple languages. It is capable of taking long-form text (e.g., news articles, reports) in one of 25 supported languages and generating a fluent, concise summary in the specified target language.max_position_embeddings=1024). Longer documents must be truncated or segmented, which may result in loss of context.1from transformers import MBartForConditionalGeneration, MBart50TokenizerFast
2
3# Define model and language codes
4model_name = "YourOrg/multilingual-summarization-mBart"
5model = MBartForConditionalGeneration.from_pretrained(model_name)
6tokenizer = MBart50TokenizerFast.from_pretrained(model_name)
7
8# Set source and target language codes
9SRC_LANG = "en_XX"
10TGT_LANG = "fr_XX"
11
12# English Article
13article = "The global shift toward electric vehicles gained significant momentum this quarter, driven by new regulatory mandates in Europe and strong consumer demand in China. Tesla reported record deliveries, while established automakers like Volkswagen and GM announced accelerated phase-out dates for gasoline models. This trend is putting immense pressure on lithium and cobalt supply chains."
14
15# 1. Encode the source text
16tokenizer.src_lang = SRC_LANG
17encoded_input = tokenizer(article, return_tensors="pt", max_length=1024, truncation=True)
18
19# 2. Generate the summary
20generated_ids = model.generate(
21 **encoded_input,
22 forced_bos_token_id=tokenizer.lang_code_to_id[TGT_LANG],
23 max_length=150,
24 min_length=20,
25 num_beams=4,
26)
27
28# 3. Decode the French summary
29summary = tokenizer.decode(generated_ids.squeeze(), skip_special_tokens=True)
30
31print(f"Original Text (EN): {article[:50]}...")
32print(f"Generated Summary (FR): {summary}")