thefrigidliquidation commited on
Commit
1b692d5
1 Parent(s): 0db3ac6

Add usage example to readme

Browse files
Files changed (1) hide show
  1. README.md +23 -24
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
- Mask *all* pronoun tokens. The use the fill mask pipeline to get the
22
- model's predictions.
23
 
24
  ```python
25
- PRONOUN_TOKENS = {
26
- 'I', 'ĠI',
27
- 'you', 'You', 'Ġyou', 'ĠYou',
28
- 'he', 'He', 'Ġhe', 'ĠHe',
29
- 'she', 'She', 'Ġshe', 'ĠShe',
30
- 'it', 'It', 'Ġit', 'ĠIt',
31
- 'we', 'We', 'Ġwe', 'ĠWe',
32
- 'they', 'They', 'Ġthey', 'ĠThey',
33
- 'my', 'My', 'Ġmy', 'ĠMy',
34
- 'your', 'Your', 'Ġyour', 'ĠYour',
35
- 'his', 'His', 'Ġhis', 'ĠHis',
36
- 'her', 'Her', 'Ġher', 'ĠHer',
37
- 'its', 'Its', 'Ġits', 'ĠIts',
38
- 'our', 'Our', 'Ġour', 'ĠOur',
39
- 'their', 'Their', 'Ġtheir', 'ĠTheir',
40
- 'mine', 'Mine', 'Ġmine', 'ĠMine',
41
- 'yours', 'Yours', 'Ġyours', 'ĠYours',
42
- 'hers', 'Hers', 'Ġhers', 'ĠHers',
43
- 'ours', 'Ours', 'Ġours', 'ĠOurs',
44
- 'theirs', 'Theirs', 'Ġtheirs', 'ĠTheirs',
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
+ ```