Update README.md
Browse files
README.md
CHANGED
|
@@ -43,6 +43,8 @@ You can use the raw model for text generation or fine-tune it to a downstream ta
|
|
| 43 |
|
| 44 |
Here is how to use the ONNX models of gpt2 to get the features of a given text:
|
| 45 |
|
|
|
|
|
|
|
| 46 |
```python
|
| 47 |
from transformers import AutoTokenizer, pipeline
|
| 48 |
from optimum.onnxruntime import ORTModelForCausalLM
|
|
@@ -54,3 +56,19 @@ onnx_gen = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
|
| 54 |
text = "My name is Philipp and I live in Germany."
|
| 55 |
gen = onnx_gen(text)
|
| 56 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
Here is how to use the ONNX models of gpt2 to get the features of a given text:
|
| 45 |
|
| 46 |
+
Example using transformers.pipelines:
|
| 47 |
+
|
| 48 |
```python
|
| 49 |
from transformers import AutoTokenizer, pipeline
|
| 50 |
from optimum.onnxruntime import ORTModelForCausalLM
|
|
|
|
| 56 |
text = "My name is Philipp and I live in Germany."
|
| 57 |
gen = onnx_gen(text)
|
| 58 |
```
|
| 59 |
+
|
| 60 |
+
Example of text generation:
|
| 61 |
+
|
| 62 |
+
```python
|
| 63 |
+
from transformers import AutoTokenizer
|
| 64 |
+
from optimum.onnxruntime import ORTModelForCausalLM
|
| 65 |
+
import torch
|
| 66 |
+
|
| 67 |
+
tokenizer = AutoTokenizer.from_pretrained("optimum/gpt2")
|
| 68 |
+
model = ORTModelForCausalLM.from_pretrained("optimum/gpt2")
|
| 69 |
+
|
| 70 |
+
inputs = tokenizer("My name is Arthur and I live in", return_tensors="pt")
|
| 71 |
+
|
| 72 |
+
gen_tokens = model.generate(**inputs,do_sample=True,temperature=0.9, min_length=20,max_length=20)
|
| 73 |
+
tokenizer.batch_decode(gen_tokens)
|
| 74 |
+
```
|