Thacio Garcia Scandaroli
commited on
Commit
•
3b27a9c
1
Parent(s):
5f45148
Update README.md
Browse files
README.md
CHANGED
@@ -43,7 +43,51 @@ Utilizou-se uma janela de contexto para 1024 tokens e um tokenizador do GPT2 com
|
|
43 |
|
44 |
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
45 |
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
### Direct Use
|
49 |
|
|
|
43 |
|
44 |
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
45 |
|
46 |
+
Exemplo de geração de texto com top_k de 30
|
47 |
+
|
48 |
+
```python
|
49 |
+
from transformers import GPT2TokenizerFast, AutoModelForSeq2SeqLM
|
50 |
+
|
51 |
+
tokenizer = GPT2TokenizerFast.from_pretrained("thacio/ult5-pt-small")
|
52 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("thacio/ult5-pt-small")
|
53 |
+
|
54 |
+
text='Um modelo de linguagem é um sistema de inteligência artificial que'
|
55 |
+
|
56 |
+
pred=model.generate(tokenizer.encode(text,return_tensors='pt'),max_new_tokens=30, eos_token_id=tokenizer.eos_token_id, top_k=30, do_sample=True)
|
57 |
+
print('input:',text)
|
58 |
+
print('generated:',tokenizer.batch_decode(pred, skip_special_tokens=True))
|
59 |
+
# input: Um modelo de linguagem é um sistema de inteligência artificial que
|
60 |
+
# generated: [' geraria a quantidade de informações por clique. Além das capacidades humanas, elas seriam muito mais produtivas do que as do cérebro humano.\nO que']
|
61 |
+
```
|
62 |
+
|
63 |
+
Embeddings:
|
64 |
+
|
65 |
+
```python
|
66 |
+
from transformers import T5EncoderModel, GPT2TokenizerFast
|
67 |
+
|
68 |
+
tokenizer = GPT2TokenizerFast.from_pretrained("thacio/ult5-pt-small")
|
69 |
+
model = T5EncoderModel.from_pretrained("thacio/ult5-pt-small")
|
70 |
+
|
71 |
+
text = 'Um modelo de linguagem é um sistema de inteligência artificial que aprende a gerar ou processar texto baseado em exemplos de treinamento.'
|
72 |
+
input_ids = tokenizer(text, return_tensors="pt").input_ids
|
73 |
+
outputs = model(input_ids)
|
74 |
+
last_hidden_states = outputs.last_hidden_state
|
75 |
+
print(last_hidden_states)
|
76 |
+
|
77 |
+
# tensor([[[-2.4537e-01, 7.9853e-02, 6.6387e-02, ..., 1.8083e-01,
|
78 |
+
# -4.8941e-02, 5.1888e-03],
|
79 |
+
# [-3.0077e-01, -3.1949e-05, -1.9432e-01, ..., -2.7167e-01,
|
80 |
+
# 3.8779e-02, -1.3541e-01],
|
81 |
+
# [ 8.8356e-05, 3.6444e-03, 2.4887e-04, ..., 1.3219e-03,
|
82 |
+
# 2.2221e-03, 1.1144e-03],
|
83 |
+
# ...,
|
84 |
+
# [-4.5300e-02, -4.6213e-02, -5.2453e-02, ..., 1.7336e-01,
|
85 |
+
# -2.6955e-02, -7.8869e-02],
|
86 |
+
# [ 8.0028e-03, -9.6458e-02, -2.1417e-01, ..., 5.1064e-01,
|
87 |
+
# -1.0858e-03, -2.7367e-02],
|
88 |
+
# [ 1.0856e-01, 4.4607e-02, -1.4409e-02, ..., 6.7812e-02,
|
89 |
+
# 5.6911e-02, 1.2650e-01]]], grad_fn=<MulBackward0>)
|
90 |
+
```
|
91 |
|
92 |
### Direct Use
|
93 |
|