balhafni commited on
Commit
ebdeb45
·
verified ·
1 Parent(s): 4ba221b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +45 -0
README.md CHANGED
@@ -18,6 +18,51 @@ The model was fine-tuned to fix punctuation (i.e., Pnx) errors. Details about th
18
  The fine-tuning code and associated resources are publicly available on our GitHub repository: https://github.com/CAMeL-Lab/text-editing.
19
 
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  ## Citation
23
  ```bibtex
 
18
  The fine-tuning code and associated resources are publicly available on our GitHub repository: https://github.com/CAMeL-Lab/text-editing.
19
 
20
 
21
+ ## Intended uses
22
+ To use the `CAMeL-Lab/text-editing-zaebuc-pnx` model, you must clone our text editing [GitHub repository](https://github.com/CAMeL-Lab/text-editing) and follow the installation requirements.
23
+ We used this SWEET<sub>Pnx</sub> model to report results on the ZAEBUC dev and test sets in our [paper](https://arxiv.org/abs/2503.00985).
24
+ This model is intended to be used with SWEET<sub>NoPnx</sub> ([`CAMeL-Lab/text-editing-zaebuc-nopnx`](https://huggingface.co/CAMeL-Lab/text-editing-zaebuc-nopnx)) model.
25
+
26
+ ## How to use
27
+ Clone our text editing [GitHub repository](https://github.com/CAMeL-Lab/text-editing) and follow the installation requirements
28
+
29
+ ```python
30
+ from transformers import BertTokenizer, BertForTokenClassification
31
+ import torch
32
+ import torch.nn.functional as F
33
+ from gec.tag import rewrite
34
+
35
+
36
+ nopnx_tokenizer = BertTokenizer.from_pretrained('CAMeL-Lab/text-editing-zaebuc-nopnx')
37
+ nopnx_model = BertForTokenClassification.from_pretrained('CAMeL-Lab/text-editing-zaebuc-nopnx')
38
+
39
+ pnx_tokenizer = BertTokenizer.from_pretrained('CAMeL-Lab/text-editing-zaebuc-pnx')
40
+ pnx_model = BertForTokenClassification.from_pretrained('CAMeL-Lab/text-editing-zaebuc-pnx')
41
+
42
+
43
+ def predict(model, tokenizer, text, decode_iter=1):
44
+ for _ in range(decode_iter):
45
+ tokenized_text = tokenizer(text, return_tensors="pt", is_split_into_words=True)
46
+ with torch.no_grad():
47
+ logits = model(**tokenized_text).logits
48
+ preds = F.softmax(logits.squeeze(), dim=-1)
49
+ preds = torch.argmax(preds, dim=-1).cpu().numpy()
50
+ edits = [model.config.id2label[p] for p in preds[1:-1]]
51
+
52
+ assert len(edits) == len(tokenized_text['input_ids'][0][1:-1])
53
+ subwords = tokenizer.convert_ids_to_tokens(tokenized_text['input_ids'][0][1:-1])
54
+ text = rewrite(subwords=[subwords], edits=[edits])[0][0]
55
+ return text
56
+
57
+
58
+ text = 'يجب الإهتمام ب الصحه و لا سيما ف ي الصحه النفسيه ياشباب المستقبل،،'.split()
59
+
60
+ output_sent = predict(nopnx_model, nopnx_tokenizer, text, decode_iter=2)
61
+ output_sent = predict(pnx_model, pnx_tokenizer, output_sent.split(), decode_iter=1)
62
+ print(output_sent) # يجب الاهتمام بالصحة ولا سيما في الصحة النفسية يا شباب المستقبل .
63
+
64
+ ```
65
+
66
 
67
  ## Citation
68
  ```bibtex