Updated usage example
Browse files
README.md
CHANGED
@@ -23,6 +23,7 @@ Usage example:
|
|
23 |
---
|
24 |
|
25 |
``` python
|
|
|
26 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
27 |
from IPython.display import display, Math, Latex
|
28 |
|
@@ -36,16 +37,16 @@ model.to(device)
|
|
36 |
def get_latex(text):
|
37 |
inputs = tokenizer(text, return_tensors='pt').to(device)
|
38 |
with torch.no_grad():
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
for h in hypotheses:
|
48 |
-
|
49 |
|
50 |
text = '''лямбда прописная квадрат минус три равно десять игрек куб
|
51 |
При этом шинус икс равен интеграл от экспоненты до трёх игрек штрих'''
|
|
|
23 |
---
|
24 |
|
25 |
``` python
|
26 |
+
import torch
|
27 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
28 |
from IPython.display import display, Math, Latex
|
29 |
|
|
|
37 |
def get_latex(text):
|
38 |
inputs = tokenizer(text, return_tensors='pt').to(device)
|
39 |
with torch.no_grad():
|
40 |
+
hypotheses = model.generate(
|
41 |
+
**inputs,
|
42 |
+
do_sample=True, num_return_sequences=1,
|
43 |
+
repetition_penalty=1.2,
|
44 |
+
max_length=len(text),
|
45 |
+
num_beams=10,
|
46 |
+
early_stopping=True
|
47 |
+
)
|
48 |
for h in hypotheses:
|
49 |
+
display(Latex(tokenizer.decode(h, skip_special_tokens=True)))
|
50 |
|
51 |
text = '''лямбда прописная квадрат минус три равно десять игрек куб
|
52 |
При этом шинус икс равен интеграл от экспоненты до трёх игрек штрих'''
|