Update README.md
Browse files
README.md
CHANGED
@@ -39,7 +39,24 @@ WIP 🚧
|
|
39 |
|
40 |
## How to use with `transformers`
|
41 |
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
## Acknowledgments
|
45 |
|
|
|
39 |
|
40 |
## How to use with `transformers`
|
41 |
|
42 |
+
```py
|
43 |
+
from transformers import BartForConditionalGeneration, BartTokenizer
|
44 |
+
|
45 |
+
model_id = "mrm8488/bart-legal-base-es"
|
46 |
+
|
47 |
+
model = BartForConditionalGeneration.from_pretrained(model_id, forced_bos_token_id=0)
|
48 |
+
tokenizer = BartTokenizer.from_pretrained(model_id)
|
49 |
+
|
50 |
+
def fill_mask_span(text):
|
51 |
+
batch = tokenizer(text, return_tensors="pt")
|
52 |
+
generated_ids = model.generate(batch["input_ids"])
|
53 |
+
print(tokenizer.batch_decode(generated_ids, skip_special_tokens=True))
|
54 |
+
|
55 |
+
text = "Los españoles son <mask> ante la ley."
|
56 |
+
fill_mask_span(text)
|
57 |
+
# ['Los españoles son iguales ante la ley.1.ª y 2.ª ante la']
|
58 |
+
|
59 |
+
```
|
60 |
|
61 |
## Acknowledgments
|
62 |
|