Update readme with pipeline instructions
Browse files- README.md +32 -0
- config.json +1 -1
README.md
CHANGED
|
@@ -7,6 +7,38 @@ A translation system from English to European Portuguese.
|
|
| 7 |
|
| 8 |
## Usage
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
```python
|
| 11 |
import torch
|
| 12 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
| 7 |
|
| 8 |
## Usage
|
| 9 |
|
| 10 |
+
|
| 11 |
+
### Using the pipeline
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
```python
|
| 15 |
+
from transformers import pipeline
|
| 16 |
+
|
| 17 |
+
translator = pipeline("text-generation", model="liaad/Tradutor")
|
| 18 |
+
|
| 19 |
+
text = "Hello, how are you?"
|
| 20 |
+
chat = [
|
| 21 |
+
{
|
| 22 |
+
"role": "system",
|
| 23 |
+
"content": "You are a translator from English to European Portuguese",
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"role": "user",
|
| 27 |
+
"content": f"Translate this text from English to European Portuguese: {text}",
|
| 28 |
+
},
|
| 29 |
+
]
|
| 30 |
+
|
| 31 |
+
translated_text = translator(
|
| 32 |
+
chat,
|
| 33 |
+
max_length=1024,
|
| 34 |
+
pad_token_id=translator.model.config.eos_token_id # Not necessary. Just to avoid warning.
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
print(translated_text[-1]["generated_text"][-1]["content"])
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
### Using model and tokenizer
|
| 41 |
+
|
| 42 |
```python
|
| 43 |
import torch
|
| 44 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
config.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
{
|
| 2 |
-
"_name_or_path": "
|
| 3 |
"architectures": [
|
| 4 |
"LlamaForCausalLM"
|
| 5 |
],
|
|
|
|
| 1 |
{
|
| 2 |
+
"_name_or_path": "liaad/Tradutor",
|
| 3 |
"architectures": [
|
| 4 |
"LlamaForCausalLM"
|
| 5 |
],
|