Narrativa commited on
Commit
db5131d
1 Parent(s): 325f416

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +10 -8
README.md CHANGED
@@ -70,23 +70,25 @@ pip install -q ./transformers
70
  ```
71
 
72
  ```python
73
- from transformers import AutoTokenizer, T5ForConditionalGeneration
74
 
75
- ckpt = 'Narrativa/byt5-base-tweet-hate-detection'
76
 
77
- tokenizer = AutoTokenizer.from_pretrained(ckpt)
78
- model = T5ForConditionalGeneration.from_pretrained(ckpt).to("cuda")
79
 
80
- def classify_tweet(tweet):
81
 
82
- inputs = tokenizer([tweet], padding='max_length', truncation=True, max_length=512, return_tensors='pt')
 
 
83
  input_ids = inputs.input_ids.to('cuda')
84
  attention_mask = inputs.attention_mask.to('cuda')
85
- output = model.generate(input_ids, attention_mask=attention_mask)
86
  return tokenizer.decode(output[0], skip_special_tokens=True)
87
 
88
 
89
- classify_tweet('here goes your tweet...')
90
  ```
91
 
92
  Created by: [Narrativa](https://www.narrativa.com/)
 
70
  ```
71
 
72
  ```python
73
+ from transformers import MBart50TokenizerFast, MBartForConditionalGeneration
74
 
75
+ ckpt = 'mbart-large-50-finetuned-opus-en-pt-translation'
76
 
77
+ tokenizer = MBart50TokenizerFast.from_pretrained(ckpt)
78
+ model = MBartForConditionalGeneration.from_pretrained(ckpt).to("cuda")
79
 
80
+ tokenizer.src_lang = 'en_XX'
81
 
82
+ def translate(text):
83
+
84
+ inputs = tokenizer(text, return_tensors='pt')
85
  input_ids = inputs.input_ids.to('cuda')
86
  attention_mask = inputs.attention_mask.to('cuda')
87
+ output = model.generate(input_ids, attention_mask=attention_mask, forced_bos_token_id=tokenizer.lang_code_to_id['pt_XX'])
88
  return tokenizer.decode(output[0], skip_special_tokens=True)
89
 
90
 
91
+ translate('here your English text to be translated to Portuguese...')
92
  ```
93
 
94
  Created by: [Narrativa](https://www.narrativa.com/)