Update README.md
Browse files
README.md
CHANGED
@@ -20,6 +20,7 @@ Output:
|
|
20 |
|
21 |
- Python
|
22 |
|
|
|
23 |
```python
|
24 |
from transformers import GenerationConfig, T5ForConditionalGeneration, T5Tokenizer
|
25 |
|
@@ -29,11 +30,21 @@ model = T5ForConditionalGeneration.from_pretrained(model_name)
|
|
29 |
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
30 |
generation_config = GenerationConfig.from_pretrained(model_name)
|
31 |
|
32 |
-
tokenized_inputs = tokenizer(["
|
33 |
outputs = model.generate(**tokenized_inputs, generation_config=generation_config)
|
34 |
|
35 |
-
print(outputs)
|
36 |
|
37 |
-
# [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
```
|
39 |
|
|
|
20 |
|
21 |
- Python
|
22 |
|
23 |
+
### Using .generate()
|
24 |
```python
|
25 |
from transformers import GenerationConfig, T5ForConditionalGeneration, T5Tokenizer
|
26 |
|
|
|
30 |
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
31 |
generation_config = GenerationConfig.from_pretrained(model_name)
|
32 |
|
33 |
+
tokenized_inputs = tokenizer(["I like this model and hate this sentence ."], return_tensors="pt")
|
34 |
outputs = model.generate(**tokenized_inputs, generation_config=generation_config)
|
35 |
|
36 |
+
print(tokenizer.batch_decode(outputs, skip_special_tokens=True))
|
37 |
|
38 |
+
# ['like | hate']
|
39 |
+
```
|
40 |
+
|
41 |
+
### Using pipeline
|
42 |
+
|
43 |
+
```python
|
44 |
+
from transformers import pipeline
|
45 |
+
srl = pipeline("ahmeshaf/maven_ere_trigger_seq2seq")
|
46 |
+
print(srl(["I like this model and hate this sentence ."]))
|
47 |
+
|
48 |
+
# [{'generated_text': 'like | hate'}]
|
49 |
```
|
50 |
|