Update README.md
Browse files
README.md
CHANGED
@@ -16,11 +16,31 @@ This is a sample reference model.
|
|
16 |
|
17 |
Here is an example of how to use the model from Python
|
18 |
```python
|
|
|
19 |
from transformers import T5ForConditionalGeneration, AutoTokenizer
|
20 |
-
model = T5ForConditionalGeneration.from_pretrained('
|
21 |
tokenizer = AutoTokenizer.from_pretrained(".") # Or tokenizer = AutoTokenizer.from_pretrained("google/mt5-base")
|
22 |
-
|
|
|
|
|
|
|
23 |
outputs = model.generate(inputs, max_length=255, num_beams=4, early_stopping=True)
|
|
|
|
|
24 |
print(tokenizer.decode(outputs[0]))
|
25 |
|
26 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
Here is an example of how to use the model from Python
|
18 |
```python
|
19 |
+
# Import libraries
|
20 |
from transformers import T5ForConditionalGeneration, AutoTokenizer
|
21 |
+
model = T5ForConditionalGeneration.from_pretrained('andrek/nb2nn',from_flax=True)
|
22 |
tokenizer = AutoTokenizer.from_pretrained(".") # Or tokenizer = AutoTokenizer.from_pretrained("google/mt5-base")
|
23 |
+
|
24 |
+
#Encode the text
|
25 |
+
text = "Hun vil ikke gi bort sine personlige data."
|
26 |
+
inputs = tokenizer.encode(text, return_tensors="pt")
|
27 |
outputs = model.generate(inputs, max_length=255, num_beams=4, early_stopping=True)
|
28 |
+
|
29 |
+
#Decode and print the result
|
30 |
print(tokenizer.decode(outputs[0]))
|
31 |
|
32 |
+
```
|
33 |
+
|
34 |
+
Or if you like to use the pipeline instead
|
35 |
+
```python
|
36 |
+
# Set up the pipeline
|
37 |
+
from transformers import pipeline, T5ForConditionalGeneration, AutoTokenizer
|
38 |
+
model = T5ForConditionalGeneration.from_pretrained('andrek/nb2nn')
|
39 |
+
tokenizer = AutoTokenizer.from_pretrained("google/mt5-base")
|
40 |
+
translator = pipeline("translation", model=model, tokenizer=tokenizer)
|
41 |
+
|
42 |
+
# Do the translation
|
43 |
+
text = "Hun vil ikke gi bort sine personlige data."
|
44 |
+
print(translator(text, max_length=255))
|
45 |
+
|
46 |
+
```python
|