Views
No views yet
7-Sky/skyopus-pol-rus, is a fine-tuned version of the Helsinki-NLP/opus-mt-sla-sla model, designed specifically for translating text from Polish (pl) to Russian (ru). It is based on the Transformer architecture and uses normalization and SentencePiece tokenization (spm32k) for preprocessing.pol)rus)>>rus<< to specify the target language.sla-sla family, originally developed for translations between Slavic languages, but this variant is fine-tuned for the specific pol -> rus pair.transformers library in Python. The code supports generating multiple translation variants using beam search.1from transformers import MarianMTModel, MarianTokenizer
2
3# Model name on Hugging Face Hub
4model_name = "7-Sky/skyopus-pol-rus"
5
6# Load the tokenizer and model
7tokenizer = MarianTokenizer.from_pretrained(model_name)
8model = MarianMTModel.from_pretrained(model_name)
9
10# Function to translate text from Polish to Russian
11def translate_text(source_text, num_translations=3):
12 # Add the required language token for Russian
13 text_with_token = ">>rus<< " + source_text
14
15 # Tokenize the input text
16 inputs = tokenizer(text_with_token, return_tensors="pt", padding=True)
17
18 # Generate translations with multiple variants
19 translated_tokens = model.generate(
20 **inputs,
21 num_return_sequences=num_translations, # Number of translation variants
22 num_beams=num_translations, # Use beams for diversity
23 max_length=512 # Limit output length
24 )
25
26 # Decode the translated tokens into readable text
27 translations = [tokenizer.decode(tokens, skip_special_tokens=True) for tokens in translated_tokens]
28 return translations
29
30# Main loop for text input and translation output
31print("Enter a Polish phrase to translate into Russian or !q to quit.")
32
33while True:
34 # Get input phrase from the user
35 source_text = input("Enter a phrase: ")
36
37 # Check for the quit command
38 if source_text == "!q":
39 print("Exiting the program.")
40 break
41
42 # Translate the phrase with multiple variants
43 translations = translate_text(source_text)
44
45 if translations:
46 # Output all translation variants
47 for idx, translation in enumerate(translations, 1):
48 print(f"Variant {idx}: {translation}")
49
50# Example Output:
51# Enter a Polish phrase to translate into Russian or !q to quit.
52# Enter a phrase: Powiedzieć a zrobić to nie to samo.
53# Variant 1: Сказать и сделать — не одно и то же.
54# Variant 2: Сказать и сделать — это не одно и то же.
55# Variant 3: Сказать и сделать — не то же самое.
56#
57# Enter a phrase: O jego propozycji nawet nie warto mówić.
58# Variant 1: О его предложении даже не стоит говорить.
59# Variant 2: О его предложении не стоит даже говорить.
60# Variant 3: О его предложении и говорить не стоит.
61