Views
No views yet
1from transformers import T5Tokenizer, T5Model
2
3tokenizer = T5Tokenizer.from_pretrained('dumitrescustefan/t5-v1_1-large-romanian')
4model = T5Model.from_pretrained('dumitrescustefan/t5-v1_1-large-romanian')
5
6input_ids = tokenizer("Acesta este un test", return_tensors="pt").input_ids # Batch size 1
7decoder_input_ids = tokenizer("Acesta este", return_tensors="pt").input_ids # Batch size 1
8
9# preprocess: Prepend decoder_input_ids with start token which is pad token for T5Model.
10# This is not needed for torch's T5ForConditionalGeneration as it does this internally using labels arg.
11decoder_input_ids = model._shift_right(decoder_input_ids)
12
13# forward pass
14outputs = model(input_ids=input_ids, decoder_input_ids=decoder_input_ids)
15last_hidden_states = outputs.last_hidden_state
16
17print(last_hidden_states.shape) # this will print [1, 3, 1024]ş 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.