Views
No views yet
1from transformers import MT5Model, T5Tokenizer
2
3model = MT5Model.from_pretrained('dumitrescustefan/mt5-base-romanian')
4tokenizer = T5Tokenizer.from_pretrained('dumitrescustefan/mt5-base-romanian')
5input_text = "Acesta este un test."
6target_text = "Acesta este"
7inputs = tokenizer(input_text, return_tensors="pt")
8labels = tokenizer(text_target=target_text, return_tensors="pt")
9
10outputs = model(input_ids=inputs["input_ids"], decoder_input_ids=labels["input_ids"])
11hidden_states = outputs.last_hidden_state
12print(hidden_states.shape) # this will print [1, 4, 768]ş and ţ cedilla-letters to comma-letters with :text = text.replace("ţ", "ț").replace("ş", "ș").replace("Ţ", "Ț").replace("Ş", "Ș")ş and ţs. If you don't, you will have decreased performance due to <UNK>s and increased number of tokens per word.