thefrigidliquidation
commited on
Commit
•
1b692d5
1
Parent(s):
0db3ac6
Add usage example to readme
Browse files
README.md
CHANGED
@@ -18,29 +18,28 @@ This model achieves an 88\% top1 accuracy, evaluated with a sliding window of 51
|
|
18 |
|
19 |
### How to use
|
20 |
|
21 |
-
|
22 |
-
model's predictions.
|
23 |
|
24 |
```python
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
```
|
|
|
18 |
|
19 |
### How to use
|
20 |
|
21 |
+
Use `fix_pronouns_in_text` from [pronoun_fixer.py](https://huggingface.co/thefrigidliquidation/roberta-base-pronouns/blob/main/pronoun_fixer.py)
|
|
|
22 |
|
23 |
```python
|
24 |
+
from transformers import AutoModelForMaskedLM, AutoTokenizer, FillMaskPipeline
|
25 |
+
import pronoun_fixer
|
26 |
+
|
27 |
+
|
28 |
+
# text produced by sentence level machine translation where the pronoun was ambiguous in the source language
|
29 |
+
# and is wrong in the target language
|
30 |
+
MTL_TEXT = """
|
31 |
+
Cadence Lee thought he was a normal girl, perhaps a little well to do, but not exceptionally so.
|
32 |
+
"""
|
33 |
+
|
34 |
+
device = 'cuda'
|
35 |
+
pronoun_checkpoint = "thefrigidliquidation/roberta-base-pronouns"
|
36 |
+
pronoun_model = AutoModelForMaskedLM.from_pretrained(pronoun_checkpoint).to(device)
|
37 |
+
pronoun_tokenizer = AutoTokenizer.from_pretrained(pronoun_checkpoint)
|
38 |
+
unmasker = FillMaskPipeline(model=pronoun_model, tokenizer=pronoun_tokenizer, device=device, top_k=10)
|
39 |
+
|
40 |
+
fixed_text = pronoun_fixer.fix_pronouns_in_text(unmasker, pronoun_tokenizer, MTL_TEXT)
|
41 |
+
|
42 |
+
print(fixed_text)
|
43 |
+
# Cadence Lee thought she was a normal girl, perhaps a little well to do, but not exceptionally so.
|
44 |
+
# now the pronoun is fixed
|
45 |
+
```
|